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()
void Database::trace(Visitor* visitor)
{
visitor->trace(m_databaseContext);
DatabaseBackend::trace(visitor);
}
......
......@@ -86,7 +86,7 @@ private:
void reportCommitTransactionResult(int errorSite, int webSqlErrorCode, int sqliteErrorCode);
RefPtr<SecurityOrigin> m_databaseThreadSecurityOrigin;
RefPtr<DatabaseContext> m_databaseContext;
RefPtrWillBeMember<DatabaseContext> m_databaseContext;
friend class DatabaseManager;
friend class DatabaseServer; // FIXME: remove this when the backend has been split out.
......
......@@ -250,6 +250,7 @@ DatabaseBackendBase::~DatabaseBackendBase()
void DatabaseBackendBase::trace(Visitor* visitor)
{
visitor->trace(m_databaseContext);
visitor->trace(m_sqliteDatabase);
visitor->trace(m_databaseAuthorizer);
}
......
......@@ -122,7 +122,7 @@ protected:
static const char* databaseInfoTableName();
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_expectedVersion;
......
......@@ -87,9 +87,9 @@ namespace WebCore {
// The RefPtrs in the Databases and ExecutionContext will ensure that the
// 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());
return self.release();
}
......@@ -109,13 +109,17 @@ DatabaseContext::DatabaseContext(ExecutionContext* context)
DatabaseContext::~DatabaseContext()
{
ASSERT(!m_databaseThread || m_databaseThread->terminationRequested());
// For debug accounting only. We must call this last. The assertions assume
// this.
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
// 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
......@@ -123,7 +127,7 @@ DatabaseContext::~DatabaseContext()
// It is not safe to just delete the context here.
void DatabaseContext::contextDestroyed()
{
RefPtr<DatabaseContext> protector(this);
RefPtrWillBeRawPtr<DatabaseContext> protector(this);
stopDatabases();
DatabaseManager::manager().unregisterDatabaseContext(this);
ActiveDOMObject::contextDestroyed();
......
......@@ -43,13 +43,14 @@ class DatabaseThread;
class ExecutionContext;
class SecurityOrigin;
class DatabaseContext FINAL : public ThreadSafeRefCounted<DatabaseContext>, public ActiveDOMObject {
class DatabaseContext FINAL : public ThreadSafeRefCountedWillBeGarbageCollectedFinalized<DatabaseContext>, public ActiveDOMObject {
public:
friend class DatabaseManager;
static PassRefPtr<DatabaseContext> create(ExecutionContext*);
static PassRefPtrWillBeRawPtr<DatabaseContext> create(ExecutionContext*);
virtual ~DatabaseContext();
void trace(Visitor*);
// For life-cycle management (inherited from ActiveDOMObject):
virtual void contextDestroyed() OVERRIDE;
......@@ -75,7 +76,7 @@ private:
void stopSyncDatabases();
RefPtrWillBePersistent<DatabaseThread> m_databaseThread;
RefPtrWillBeMember<DatabaseThread> m_databaseThread;
#if ENABLE(OILPAN)
class DatabaseCloser {
public:
......@@ -85,7 +86,7 @@ private:
private:
DatabaseBackendBase& m_database;
};
PersistentHeapHashMap<WeakMember<DatabaseBackendBase>, OwnPtr<DatabaseCloser> > m_openSyncDatabases;
HeapHashMap<WeakMember<DatabaseBackendBase>, OwnPtr<DatabaseCloser> > m_openSyncDatabases;
#else
// The contents of m_openSyncDatabases are raw pointers. It's safe because
// DatabaseBackendSync is always closed before destruction.
......
......@@ -102,8 +102,12 @@ DatabaseContext* DatabaseManager::existingDatabaseContextFor(ExecutionContext* c
ASSERT(m_databaseContextRegisteredCount >= 0);
ASSERT(m_databaseContextInstanceCount >= 0);
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);
#endif
}
DatabaseContext* DatabaseManager::databaseContextFor(ExecutionContext* context)
......@@ -120,7 +124,11 @@ void DatabaseManager::registerDatabaseContext(DatabaseContext* databaseContext)
{
MutexLocker locker(m_contextMapLock);
ExecutionContext* context = databaseContext->executionContext();
#if ENABLE(OILPAN)
m_contextMap.set(context, adoptPtr(new Persistent<DatabaseContext>(databaseContext)));
#else
m_contextMap.set(context, databaseContext);
#endif
#if !ASSERT_DISABLED
m_databaseContextRegisteredCount++;
#endif
......
......@@ -99,7 +99,12 @@ private:
AbstractDatabaseServer* m_server;
// 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;
#endif
ContextMap m_contextMap;
#if !ASSERT_DISABLED
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