Commit d130cbec authored by tkent@chromium.org's avatar tkent@chromium.org

Oilpan: Prepare to move DatabaseContext to Oilpan heap.

We need to change
  HashMap<ExecutionContext*, RefPtr<DatabaseContext>>
to
  HashMap<ExecutionContext*, OwnPtr<Persistent<DatabaseContext>>>
Because we can't use PersistentHeapHashMap due to mutiple threads, and can't put
Persistent<> to HashMap directly.

BUG=347902

Review URL: https://codereview.chromium.org/215063005

git-svn-id: svn://svn.chromium.org/blink/trunk@170246 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 2a11d731
...@@ -85,6 +85,7 @@ Database::~Database() ...@@ -85,6 +85,7 @@ Database::~Database()
void Database::trace(Visitor* visitor) void Database::trace(Visitor* visitor)
{ {
visitor->trace(m_databaseContext);
DatabaseBackend::trace(visitor); DatabaseBackend::trace(visitor);
} }
......
...@@ -86,7 +86,7 @@ private: ...@@ -86,7 +86,7 @@ private:
void reportCommitTransactionResult(int errorSite, int webSqlErrorCode, int sqliteErrorCode); void reportCommitTransactionResult(int errorSite, int webSqlErrorCode, int sqliteErrorCode);
RefPtr<SecurityOrigin> m_databaseThreadSecurityOrigin; RefPtr<SecurityOrigin> m_databaseThreadSecurityOrigin;
RefPtr<DatabaseContext> m_databaseContext; RefPtrWillBeMember<DatabaseContext> m_databaseContext;
friend class DatabaseManager; friend class DatabaseManager;
friend class DatabaseServer; // FIXME: remove this when the backend has been split out. friend class DatabaseServer; // FIXME: remove this when the backend has been split out.
......
...@@ -250,6 +250,7 @@ DatabaseBackendBase::~DatabaseBackendBase() ...@@ -250,6 +250,7 @@ DatabaseBackendBase::~DatabaseBackendBase()
void DatabaseBackendBase::trace(Visitor* visitor) void DatabaseBackendBase::trace(Visitor* visitor)
{ {
visitor->trace(m_databaseContext);
visitor->trace(m_sqliteDatabase); visitor->trace(m_sqliteDatabase);
visitor->trace(m_databaseAuthorizer); visitor->trace(m_databaseAuthorizer);
} }
......
...@@ -122,7 +122,7 @@ protected: ...@@ -122,7 +122,7 @@ protected:
static const char* databaseInfoTableName(); static const char* databaseInfoTableName();
RefPtr<SecurityOrigin> m_contextThreadSecurityOrigin; RefPtr<SecurityOrigin> m_contextThreadSecurityOrigin;
RefPtr<DatabaseContext> m_databaseContext; // Associated with m_executionContext. RefPtrWillBeMember<DatabaseContext> m_databaseContext; // Associated with m_executionContext.
String m_name; String m_name;
String m_expectedVersion; String m_expectedVersion;
......
...@@ -87,9 +87,9 @@ namespace WebCore { ...@@ -87,9 +87,9 @@ namespace WebCore {
// The RefPtrs in the Databases and ExecutionContext will ensure that the // The RefPtrs in the Databases and ExecutionContext will ensure that the
// DatabaseContext will outlive both regardless of which of the 2 destructs first. // DatabaseContext will outlive both regardless of which of the 2 destructs first.
PassRefPtr<DatabaseContext> DatabaseContext::create(ExecutionContext* context) PassRefPtrWillBeRawPtr<DatabaseContext> DatabaseContext::create(ExecutionContext* context)
{ {
RefPtr<DatabaseContext> self = adoptRef(new DatabaseContext(context)); RefPtrWillBeRawPtr<DatabaseContext> self = adoptRefWillBeNoop(new DatabaseContext(context));
DatabaseManager::manager().registerDatabaseContext(self.get()); DatabaseManager::manager().registerDatabaseContext(self.get());
return self.release(); return self.release();
} }
...@@ -109,13 +109,17 @@ DatabaseContext::DatabaseContext(ExecutionContext* context) ...@@ -109,13 +109,17 @@ DatabaseContext::DatabaseContext(ExecutionContext* context)
DatabaseContext::~DatabaseContext() DatabaseContext::~DatabaseContext()
{ {
ASSERT(!m_databaseThread || m_databaseThread->terminationRequested());
// For debug accounting only. We must call this last. The assertions assume // For debug accounting only. We must call this last. The assertions assume
// this. // this.
DatabaseManager::manager().didDestructDatabaseContext(); DatabaseManager::manager().didDestructDatabaseContext();
} }
void DatabaseContext::trace(Visitor* visitor)
{
visitor->trace(m_databaseThread);
visitor->trace(m_openSyncDatabases);
}
// This is called if the associated ExecutionContext is destructing while // This is called if the associated ExecutionContext is destructing while
// we're still associated with it. That's our cue to disassociate and shutdown. // we're still associated with it. That's our cue to disassociate and shutdown.
// To do this, we stop the database and let everything shutdown naturally // To do this, we stop the database and let everything shutdown naturally
...@@ -123,7 +127,7 @@ DatabaseContext::~DatabaseContext() ...@@ -123,7 +127,7 @@ DatabaseContext::~DatabaseContext()
// It is not safe to just delete the context here. // It is not safe to just delete the context here.
void DatabaseContext::contextDestroyed() void DatabaseContext::contextDestroyed()
{ {
RefPtr<DatabaseContext> protector(this); RefPtrWillBeRawPtr<DatabaseContext> protector(this);
stopDatabases(); stopDatabases();
DatabaseManager::manager().unregisterDatabaseContext(this); DatabaseManager::manager().unregisterDatabaseContext(this);
ActiveDOMObject::contextDestroyed(); ActiveDOMObject::contextDestroyed();
......
...@@ -43,13 +43,14 @@ class DatabaseThread; ...@@ -43,13 +43,14 @@ class DatabaseThread;
class ExecutionContext; class ExecutionContext;
class SecurityOrigin; class SecurityOrigin;
class DatabaseContext FINAL : public ThreadSafeRefCounted<DatabaseContext>, public ActiveDOMObject { class DatabaseContext FINAL : public ThreadSafeRefCountedWillBeGarbageCollectedFinalized<DatabaseContext>, public ActiveDOMObject {
public: public:
friend class DatabaseManager; friend class DatabaseManager;
static PassRefPtr<DatabaseContext> create(ExecutionContext*); static PassRefPtrWillBeRawPtr<DatabaseContext> create(ExecutionContext*);
virtual ~DatabaseContext(); virtual ~DatabaseContext();
void trace(Visitor*);
// For life-cycle management (inherited from ActiveDOMObject): // For life-cycle management (inherited from ActiveDOMObject):
virtual void contextDestroyed() OVERRIDE; virtual void contextDestroyed() OVERRIDE;
...@@ -75,7 +76,7 @@ private: ...@@ -75,7 +76,7 @@ private:
void stopSyncDatabases(); void stopSyncDatabases();
RefPtrWillBePersistent<DatabaseThread> m_databaseThread; RefPtrWillBeMember<DatabaseThread> m_databaseThread;
#if ENABLE(OILPAN) #if ENABLE(OILPAN)
class DatabaseCloser { class DatabaseCloser {
public: public:
...@@ -85,7 +86,7 @@ private: ...@@ -85,7 +86,7 @@ private:
private: private:
DatabaseBackendBase& m_database; DatabaseBackendBase& m_database;
}; };
PersistentHeapHashMap<WeakMember<DatabaseBackendBase>, OwnPtr<DatabaseCloser> > m_openSyncDatabases; HeapHashMap<WeakMember<DatabaseBackendBase>, OwnPtr<DatabaseCloser> > m_openSyncDatabases;
#else #else
// The contents of m_openSyncDatabases are raw pointers. It's safe because // The contents of m_openSyncDatabases are raw pointers. It's safe because
// DatabaseBackendSync is always closed before destruction. // DatabaseBackendSync is always closed before destruction.
......
...@@ -102,8 +102,12 @@ DatabaseContext* DatabaseManager::existingDatabaseContextFor(ExecutionContext* c ...@@ -102,8 +102,12 @@ DatabaseContext* DatabaseManager::existingDatabaseContextFor(ExecutionContext* c
ASSERT(m_databaseContextRegisteredCount >= 0); ASSERT(m_databaseContextRegisteredCount >= 0);
ASSERT(m_databaseContextInstanceCount >= 0); ASSERT(m_databaseContextInstanceCount >= 0);
ASSERT(m_databaseContextRegisteredCount <= m_databaseContextInstanceCount); ASSERT(m_databaseContextRegisteredCount <= m_databaseContextInstanceCount);
#if ENABLE(OILPAN)
const Persistent<DatabaseContext>* databaseContext = m_contextMap.get(context);
return databaseContext ? databaseContext->get() : 0;
#else
return m_contextMap.get(context); return m_contextMap.get(context);
#endif
} }
DatabaseContext* DatabaseManager::databaseContextFor(ExecutionContext* context) DatabaseContext* DatabaseManager::databaseContextFor(ExecutionContext* context)
...@@ -120,7 +124,11 @@ void DatabaseManager::registerDatabaseContext(DatabaseContext* databaseContext) ...@@ -120,7 +124,11 @@ void DatabaseManager::registerDatabaseContext(DatabaseContext* databaseContext)
{ {
MutexLocker locker(m_contextMapLock); MutexLocker locker(m_contextMapLock);
ExecutionContext* context = databaseContext->executionContext(); ExecutionContext* context = databaseContext->executionContext();
#if ENABLE(OILPAN)
m_contextMap.set(context, adoptPtr(new Persistent<DatabaseContext>(databaseContext)));
#else
m_contextMap.set(context, databaseContext); m_contextMap.set(context, databaseContext);
#endif
#if !ASSERT_DISABLED #if !ASSERT_DISABLED
m_databaseContextRegisteredCount++; m_databaseContextRegisteredCount++;
#endif #endif
......
...@@ -99,7 +99,12 @@ private: ...@@ -99,7 +99,12 @@ private:
AbstractDatabaseServer* m_server; AbstractDatabaseServer* m_server;
// Access to the following fields require locking m_contextMapLock: // Access to the following fields require locking m_contextMapLock:
#if ENABLE(OILPAN)
// We can't use PersistentHeapHashMap because multiple threads update the map.
typedef HashMap<ExecutionContext*, OwnPtr<Persistent<DatabaseContext> > > ContextMap;
#else
typedef HashMap<ExecutionContext*, RefPtr<DatabaseContext> > ContextMap; typedef HashMap<ExecutionContext*, RefPtr<DatabaseContext> > ContextMap;
#endif
ContextMap m_contextMap; ContextMap m_contextMap;
#if !ASSERT_DISABLED #if !ASSERT_DISABLED
int m_databaseContextRegisteredCount; int m_databaseContextRegisteredCount;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment