Modified: branches/safari-537.75-branch/Source/WebCore/ChangeLog (163883 => 163884)
--- branches/safari-537.75-branch/Source/WebCore/ChangeLog 2014-02-11 17:36:10 UTC (rev 163883)
+++ branches/safari-537.75-branch/Source/WebCore/ChangeLog 2014-02-11 17:49:30 UTC (rev 163884)
@@ -1,3 +1,30 @@
+2014-02-11 Matthew Hanson <[email protected]>
+
+ Merge r158058.
+
+ 2013-10-25 Mark Lam <[email protected]>
+
+ DatabaseManager's ProposedDatabases need to be thread-safe.
+ https://bugs.webkit.org/show_bug.cgi?id=123313.
+
+ Reviewed by Geoffrey Garen.
+
+ No new tests.
+
+ * Modules/webdatabase/DatabaseManager.cpp:
+ (WebCore::DatabaseManager::DatabaseManager):
+ (WebCore::DatabaseManager::existingDatabaseContextFor):
+ (WebCore::DatabaseManager::registerDatabaseContext):
+ (WebCore::DatabaseManager::unregisterDatabaseContext):
+ (WebCore::DatabaseManager::didConstructDatabaseContext):
+ (WebCore::DatabaseManager::didDestructDatabaseContext):
+ (WebCore::DatabaseManager::openDatabaseBackend):
+ (WebCore::DatabaseManager::addProposedDatabase):
+ (WebCore::DatabaseManager::removeProposedDatabase):
+ (WebCore::DatabaseManager::fullPathForDatabase):
+ (WebCore::DatabaseManager::detailsForNameAndOrigin):
+ * Modules/webdatabase/DatabaseManager.h:
+
2014-02-10 Lucas Forschler <[email protected]>
Merge r162486
Modified: branches/safari-537.75-branch/Source/WebCore/Modules/webdatabase/DatabaseManager.cpp (163883 => 163884)
--- branches/safari-537.75-branch/Source/WebCore/Modules/webdatabase/DatabaseManager.cpp 2014-02-11 17:36:10 UTC (rev 163883)
+++ branches/safari-537.75-branch/Source/WebCore/Modules/webdatabase/DatabaseManager.cpp 2014-02-11 17:49:30 UTC (rev 163884)
@@ -49,6 +49,20 @@
namespace WebCore {
+DatabaseManager::ProposedDatabase::ProposedDatabase(DatabaseManager& manager,
+ SecurityOrigin* origin, const String& name, const String& displayName, unsigned long estimatedSize)
+ : m_manager(manager)
+ , m_origin(origin->isolatedCopy())
+ , m_details(name.isolatedCopy(), displayName.isolatedCopy(), estimatedSize, 0)
+{
+ m_manager.addProposedDatabase(this);
+}
+
+DatabaseManager::ProposedDatabase::~ProposedDatabase()
+{
+ m_manager.removeProposedDatabase(this);
+}
+
DatabaseManager& DatabaseManager::manager()
{
static DatabaseManager* dbManager = 0;
@@ -128,7 +142,7 @@
PassRefPtr<DatabaseContext> DatabaseManager::existingDatabaseContextFor(ScriptExecutionContext* context)
{
- MutexLocker locker(m_contextMapLock);
+ MutexLocker locker(m_lock);
ASSERT(m_databaseContextRegisteredCount >= 0);
ASSERT(m_databaseContextInstanceCount >= 0);
@@ -159,7 +173,7 @@
void DatabaseManager::registerDatabaseContext(DatabaseContext* databaseContext)
{
- MutexLocker locker(m_contextMapLock);
+ MutexLocker locker(m_lock);
ScriptExecutionContext* context = databaseContext->scriptExecutionContext();
m_contextMap.set(context, databaseContext);
#if !ASSERT_DISABLED
@@ -169,7 +183,7 @@
void DatabaseManager::unregisterDatabaseContext(DatabaseContext* databaseContext)
{
- MutexLocker locker(m_contextMapLock);
+ MutexLocker locker(m_lock);
ScriptExecutionContext* context = databaseContext->scriptExecutionContext();
ASSERT(m_contextMap.get(context));
#if !ASSERT_DISABLED
@@ -181,13 +195,13 @@
#if !ASSERT_DISABLED
void DatabaseManager::didConstructDatabaseContext()
{
- MutexLocker lock(m_contextMapLock);
+ MutexLocker lock(m_lock);
m_databaseContextInstanceCount++;
}
void DatabaseManager::didDestructDatabaseContext()
{
- MutexLocker lock(m_contextMapLock);
+ MutexLocker lock(m_lock);
m_databaseContextInstanceCount--;
ASSERT(m_databaseContextRegisteredCount <= m_databaseContextInstanceCount);
}
@@ -278,6 +292,18 @@
return backend.release();
}
+void DatabaseManager::addProposedDatabase(ProposedDatabase* proposedDb)
+{
+ MutexLocker locker(m_lock);
+ m_proposedDatabases.add(proposedDb);
+}
+
+void DatabaseManager::removeProposedDatabase(ProposedDatabase* proposedDb)
+{
+ MutexLocker locker(m_lock);
+ m_proposedDatabases.remove(proposedDb);
+}
+
PassRefPtr<Database> DatabaseManager::openDatabase(ScriptExecutionContext* context,
const String& name, const String& expectedVersion, const String& displayName,
unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback,
@@ -351,6 +377,12 @@
String DatabaseManager::fullPathForDatabase(SecurityOrigin* origin, const String& name, bool createIfDoesNotExist)
{
+ {
+ MutexLocker locker(m_lock);
+ for (HashSet<ProposedDatabase*>::iterator iter = m_proposedDatabases.begin(); iter != m_proposedDatabases.end(); ++iter)
+ if ((*iter)->details().name() == name && (*iter)->origin()->equal(origin))
+ return String();
+ }
return m_server->fullPathForDatabase(origin, name, createIfDoesNotExist);
}
@@ -371,6 +403,14 @@
DatabaseDetails DatabaseManager::detailsForNameAndOrigin(const String& name, SecurityOrigin* origin)
{
+ {
+ MutexLocker locker(m_lock);
+ for (HashSet<ProposedDatabase*>::iterator iter = m_proposedDatabases.begin(); iter != m_proposedDatabases.end(); ++iter)
+ if ((*iter)->details().name() == name && (*iter)->origin()->equal(origin)) {
+ ASSERT((*iter)->details().thread() == currentThread() || isMainThread());
+ return (*iter)->details();
+ }
+ }
return m_server->detailsForNameAndOrigin(name, origin);
}
Modified: branches/safari-537.75-branch/Source/WebCore/Modules/webdatabase/DatabaseManager.h (163883 => 163884)
--- branches/safari-537.75-branch/Source/WebCore/Modules/webdatabase/DatabaseManager.h 2014-02-11 17:36:10 UTC (rev 163883)
+++ branches/safari-537.75-branch/Source/WebCore/Modules/webdatabase/DatabaseManager.h 2014-02-11 17:49:30 UTC (rev 163884)
@@ -33,6 +33,7 @@
#include "DatabaseError.h"
#include <wtf/Assertions.h>
#include <wtf/HashMap.h>
+#include <wtf/HashSet.h>
#include <wtf/PassRefPtr.h>
#include <wtf/Threading.h>
@@ -106,6 +107,21 @@
void interruptAllDatabasesForContext(ScriptExecutionContext*);
private:
+ class ProposedDatabase {
+ public:
+ ProposedDatabase(DatabaseManager&, SecurityOrigin*,
+ const String& name, const String& displayName, unsigned long estimatedSize);
+ ~ProposedDatabase();
+
+ SecurityOrigin* origin() { return m_origin.get(); }
+ DatabaseDetails& details() { return m_details; }
+
+ private:
+ DatabaseManager& m_manager;
+ RefPtr<SecurityOrigin> m_origin;
+ DatabaseDetails m_details;
+ };
+
DatabaseManager();
~DatabaseManager() { }
@@ -117,20 +133,26 @@
DatabaseType, const String& name, const String& expectedVersion, const String& displayName,
unsigned long estimatedSize, bool setVersionInNewDatabase, DatabaseError&, String& errorMessage);
+ void addProposedDatabase(ProposedDatabase*);
+ void removeProposedDatabase(ProposedDatabase*);
+
static void logErrorMessage(ScriptExecutionContext*, const String& message);
AbstractDatabaseServer* m_server;
DatabaseManagerClient* m_client;
bool m_databaseIsAvailable;
- // Access to the following fields require locking m_contextMapLock:
+ // Access to the following fields require locking m_lock below:
typedef HashMap<ScriptExecutionContext*, DatabaseContext*> ContextMap;
ContextMap m_contextMap;
#if !ASSERT_DISABLED
int m_databaseContextRegisteredCount;
int m_databaseContextInstanceCount;
#endif
- Mutex m_contextMapLock;
+ HashSet<ProposedDatabase*> m_proposedDatabases;
+
+ // This lock protects m_contextMap, and m_proposedDatabases.
+ Mutex m_lock;
};
} // namespace WebCore