Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(436)

Side by Side Diff: Source/modules/webdatabase/DatabaseManager.cpp

Issue 567453002: Web SQL: Make sure DatabaseManager is used only in the main thread. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 30 matching lines...) Expand all
41 #include "modules/webdatabase/DatabaseClient.h" 41 #include "modules/webdatabase/DatabaseClient.h"
42 #include "modules/webdatabase/DatabaseContext.h" 42 #include "modules/webdatabase/DatabaseContext.h"
43 #include "modules/webdatabase/DatabaseServer.h" 43 #include "modules/webdatabase/DatabaseServer.h"
44 #include "modules/webdatabase/DatabaseTask.h" 44 #include "modules/webdatabase/DatabaseTask.h"
45 #include "platform/weborigin/SecurityOrigin.h" 45 #include "platform/weborigin/SecurityOrigin.h"
46 46
47 namespace blink { 47 namespace blink {
48 48
49 DatabaseManager& DatabaseManager::manager() 49 DatabaseManager& DatabaseManager::manager()
50 { 50 {
51 AtomicallyInitializedStatic(DatabaseManager*, dbManager = new DatabaseManage r); 51 ASSERT(isMainThread());
52 return *dbManager; 52 DEFINE_STATIC_LOCAL(DatabaseManager, dbManager, ());
53 return dbManager;
53 } 54 }
54 55
55 DatabaseManager::DatabaseManager() 56 DatabaseManager::DatabaseManager()
56 #if ENABLE(ASSERT) 57 #if ENABLE(ASSERT)
57 : m_databaseContextRegisteredCount(0) 58 : m_databaseContextRegisteredCount(0)
58 , m_databaseContextInstanceCount(0) 59 , m_databaseContextInstanceCount(0)
59 #endif 60 #endif
60 { 61 {
61 m_server = new DatabaseServer; 62 m_server = new DatabaseServer;
62 ASSERT(m_server); // We should always have a server to work with. 63 ASSERT(m_server); // We should always have a server to work with.
(...skipping 21 matching lines...) Expand all
84 , m_creationCallback(callback) 85 , m_creationCallback(callback)
85 { 86 {
86 } 87 }
87 88
88 RefPtrWillBePersistent<Database> m_database; 89 RefPtrWillBePersistent<Database> m_database;
89 OwnPtrWillBePersistent<DatabaseCallback> m_creationCallback; 90 OwnPtrWillBePersistent<DatabaseCallback> m_creationCallback;
90 }; 91 };
91 92
92 DatabaseContext* DatabaseManager::existingDatabaseContextFor(ExecutionContext* c ontext) 93 DatabaseContext* DatabaseManager::existingDatabaseContextFor(ExecutionContext* c ontext)
93 { 94 {
94 MutexLocker locker(m_contextMapLock);
95
96 ASSERT(m_databaseContextRegisteredCount >= 0); 95 ASSERT(m_databaseContextRegisteredCount >= 0);
97 ASSERT(m_databaseContextInstanceCount >= 0); 96 ASSERT(m_databaseContextInstanceCount >= 0);
98 ASSERT(m_databaseContextRegisteredCount <= m_databaseContextInstanceCount); 97 ASSERT(m_databaseContextRegisteredCount <= m_databaseContextInstanceCount);
99 #if ENABLE(OILPAN)
100 const Persistent<DatabaseContext>* databaseContext = m_contextMap.get(contex t);
101 return databaseContext ? databaseContext->get() : 0;
102 #else
103 return m_contextMap.get(context); 98 return m_contextMap.get(context);
104 #endif
105 } 99 }
106 100
107 DatabaseContext* DatabaseManager::databaseContextFor(ExecutionContext* context) 101 DatabaseContext* DatabaseManager::databaseContextFor(ExecutionContext* context)
108 { 102 {
109 if (DatabaseContext* databaseContext = existingDatabaseContextFor(context)) 103 if (DatabaseContext* databaseContext = existingDatabaseContextFor(context))
110 return databaseContext; 104 return databaseContext;
111 // We don't need to hold a reference returned by DatabaseContext::create 105 // We don't need to hold a reference returned by DatabaseContext::create
112 // because DatabaseContext::create calls registerDatabaseContext, and the 106 // because DatabaseContext::create calls registerDatabaseContext, and the
113 // DatabaseManager holds a reference. 107 // DatabaseManager holds a reference.
114 return DatabaseContext::create(context).get(); 108 return DatabaseContext::create(context).get();
115 } 109 }
116 110
117 void DatabaseManager::registerDatabaseContext(DatabaseContext* databaseContext) 111 void DatabaseManager::registerDatabaseContext(DatabaseContext* databaseContext)
118 { 112 {
119 MutexLocker locker(m_contextMapLock);
120 ExecutionContext* context = databaseContext->executionContext(); 113 ExecutionContext* context = databaseContext->executionContext();
121 #if ENABLE(OILPAN)
122 m_contextMap.set(context, adoptPtr(new Persistent<DatabaseContext>(databaseC ontext)));
123 #else
124 m_contextMap.set(context, databaseContext); 114 m_contextMap.set(context, databaseContext);
125 #endif
126 #if ENABLE(ASSERT) 115 #if ENABLE(ASSERT)
127 m_databaseContextRegisteredCount++; 116 m_databaseContextRegisteredCount++;
128 #endif 117 #endif
129 } 118 }
130 119
131 void DatabaseManager::unregisterDatabaseContext(DatabaseContext* databaseContext ) 120 void DatabaseManager::unregisterDatabaseContext(DatabaseContext* databaseContext )
132 { 121 {
133 MutexLocker locker(m_contextMapLock);
134 ExecutionContext* context = databaseContext->executionContext(); 122 ExecutionContext* context = databaseContext->executionContext();
135 ASSERT(m_contextMap.get(context)); 123 ASSERT(m_contextMap.get(context));
136 #if ENABLE(ASSERT) 124 #if ENABLE(ASSERT)
137 m_databaseContextRegisteredCount--; 125 m_databaseContextRegisteredCount--;
138 #endif 126 #endif
139 m_contextMap.remove(context); 127 m_contextMap.remove(context);
140 } 128 }
141 129
142 #if ENABLE(ASSERT) 130 #if ENABLE(ASSERT)
143 void DatabaseManager::didConstructDatabaseContext() 131 void DatabaseManager::didConstructDatabaseContext()
144 { 132 {
145 MutexLocker lock(m_contextMapLock);
146 m_databaseContextInstanceCount++; 133 m_databaseContextInstanceCount++;
147 } 134 }
148 135
149 void DatabaseManager::didDestructDatabaseContext() 136 void DatabaseManager::didDestructDatabaseContext()
150 { 137 {
151 MutexLocker lock(m_contextMapLock);
152 m_databaseContextInstanceCount--; 138 m_databaseContextInstanceCount--;
153 ASSERT(m_databaseContextRegisteredCount <= m_databaseContextInstanceCount); 139 ASSERT(m_databaseContextRegisteredCount <= m_databaseContextInstanceCount);
154 } 140 }
155 #endif 141 #endif
156 142
157 void DatabaseManager::throwExceptionForDatabaseError(DatabaseError error, const String& errorMessage, ExceptionState& exceptionState) 143 void DatabaseManager::throwExceptionForDatabaseError(DatabaseError error, const String& errorMessage, ExceptionState& exceptionState)
158 { 144 {
159 switch (error) { 145 switch (error) {
160 case DatabaseError::None: 146 case DatabaseError::None:
161 return; 147 return;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 217
232 ASSERT(database); 218 ASSERT(database);
233 return database.release(); 219 return database.release();
234 } 220 }
235 221
236 String DatabaseManager::fullPathForDatabase(SecurityOrigin* origin, const String & name, bool createIfDoesNotExist) 222 String DatabaseManager::fullPathForDatabase(SecurityOrigin* origin, const String & name, bool createIfDoesNotExist)
237 { 223 {
238 return m_server->fullPathForDatabase(origin, name, createIfDoesNotExist); 224 return m_server->fullPathForDatabase(origin, name, createIfDoesNotExist);
239 } 225 }
240 226
241 void DatabaseManager::closeDatabasesImmediately(const String& originIdentifier, const String& name)
242 {
243 m_server->closeDatabasesImmediately(originIdentifier, name);
244 }
245
246 void DatabaseManager::logErrorMessage(ExecutionContext* context, const String& m essage) 227 void DatabaseManager::logErrorMessage(ExecutionContext* context, const String& m essage)
247 { 228 {
248 context->addConsoleMessage(ConsoleMessage::create(StorageMessageSource, Erro rMessageLevel, message)); 229 context->addConsoleMessage(ConsoleMessage::create(StorageMessageSource, Erro rMessageLevel, message));
249 } 230 }
250 231
251 } // namespace blink 232 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/webdatabase/DatabaseManager.h ('k') | Source/modules/webdatabase/DatabaseServer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698