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

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

Issue 103473002: Manage WebSQL callbacks with OwnPtr instead of refcounting (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix RefPtr/OwnPtr transition gcc errors Created 7 years 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
« no previous file with comments | « Source/modules/webdatabase/DatabaseManager.h ('k') | Source/modules/webdatabase/DatabaseSync.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 : m_databaseContextRegisteredCount(0) 63 : m_databaseContextRegisteredCount(0)
64 , m_databaseContextInstanceCount(0) 64 , m_databaseContextInstanceCount(0)
65 #endif 65 #endif
66 { 66 {
67 m_server = new DatabaseServer; 67 m_server = new DatabaseServer;
68 ASSERT(m_server); // We should always have a server to work with. 68 ASSERT(m_server); // We should always have a server to work with.
69 } 69 }
70 70
71 class DatabaseCreationCallbackTask : public ExecutionContextTask { 71 class DatabaseCreationCallbackTask : public ExecutionContextTask {
72 public: 72 public:
73 static PassOwnPtr<DatabaseCreationCallbackTask> create(PassRefPtr<Database> database, PassRefPtr<DatabaseCallback> creationCallback) 73 static PassOwnPtr<DatabaseCreationCallbackTask> create(PassRefPtr<Database> database, PassOwnPtr<DatabaseCallback> creationCallback)
74 { 74 {
75 return adoptPtr(new DatabaseCreationCallbackTask(database, creationCallb ack)); 75 return adoptPtr(new DatabaseCreationCallbackTask(database, creationCallb ack));
76 } 76 }
77 77
78 virtual void performTask(ExecutionContext*) 78 virtual void performTask(ExecutionContext*)
79 { 79 {
80 m_creationCallback->handleEvent(m_database.get()); 80 m_creationCallback->handleEvent(m_database.get());
81 } 81 }
82 82
83 private: 83 private:
84 DatabaseCreationCallbackTask(PassRefPtr<Database> database, PassRefPtr<Datab aseCallback> callback) 84 DatabaseCreationCallbackTask(PassRefPtr<Database> database, PassOwnPtr<Datab aseCallback> callback)
85 : m_database(database) 85 : m_database(database)
86 , m_creationCallback(callback) 86 , m_creationCallback(callback)
87 { 87 {
88 } 88 }
89 89
90 RefPtr<Database> m_database; 90 RefPtr<Database> m_database;
91 RefPtr<DatabaseCallback> m_creationCallback; 91 OwnPtr<DatabaseCallback> m_creationCallback;
92 }; 92 };
93 93
94 PassRefPtr<DatabaseContext> DatabaseManager::existingDatabaseContextFor(Executio nContext* context) 94 PassRefPtr<DatabaseContext> DatabaseManager::existingDatabaseContextFor(Executio nContext* context)
95 { 95 {
96 MutexLocker locker(m_contextMapLock); 96 MutexLocker locker(m_contextMapLock);
97 97
98 ASSERT(m_databaseContextRegisteredCount >= 0); 98 ASSERT(m_databaseContextRegisteredCount >= 0);
99 ASSERT(m_databaseContextInstanceCount >= 0); 99 ASSERT(m_databaseContextInstanceCount >= 0);
100 ASSERT(m_databaseContextRegisteredCount <= m_databaseContextInstanceCount); 100 ASSERT(m_databaseContextRegisteredCount <= m_databaseContextInstanceCount);
101 101
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 default: 209 default:
210 ASSERT_NOT_REACHED(); 210 ASSERT_NOT_REACHED();
211 } 211 }
212 } 212 }
213 213
214 return backend.release(); 214 return backend.release();
215 } 215 }
216 216
217 PassRefPtr<Database> DatabaseManager::openDatabase(ExecutionContext* context, 217 PassRefPtr<Database> DatabaseManager::openDatabase(ExecutionContext* context,
218 const String& name, const String& expectedVersion, const String& displayName , 218 const String& name, const String& expectedVersion, const String& displayName ,
219 unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, 219 unsigned long estimatedSize, PassOwnPtr<DatabaseCallback> creationCallback,
220 DatabaseError& error, String& errorMessage) 220 DatabaseError& error, String& errorMessage)
221 { 221 {
222 ASSERT(error == DatabaseError::None); 222 ASSERT(error == DatabaseError::None);
223 223
224 bool setVersionInNewDatabase = !creationCallback; 224 bool setVersionInNewDatabase = !creationCallback;
225 RefPtr<DatabaseBackendBase> backend = openDatabaseBackend(context, DatabaseT ype::Async, name, 225 RefPtr<DatabaseBackendBase> backend = openDatabaseBackend(context, DatabaseT ype::Async, name,
226 expectedVersion, displayName, estimatedSize, setVersionInNewDatabase, er ror, errorMessage); 226 expectedVersion, displayName, estimatedSize, setVersionInNewDatabase, er ror, errorMessage);
227 if (!backend) 227 if (!backend)
228 return 0; 228 return 0;
229 229
230 RefPtr<Database> database = Database::create(context, backend); 230 RefPtr<Database> database = Database::create(context, backend);
231 231
232 RefPtr<DatabaseContext> databaseContext = databaseContextFor(context); 232 RefPtr<DatabaseContext> databaseContext = databaseContextFor(context);
233 databaseContext->setHasOpenDatabases(); 233 databaseContext->setHasOpenDatabases();
234 InspectorInstrumentation::didOpenDatabase(context, database, context->securi tyOrigin()->host(), name, expectedVersion); 234 InspectorInstrumentation::didOpenDatabase(context, database, context->securi tyOrigin()->host(), name, expectedVersion);
235 235
236 if (backend->isNew() && creationCallback.get()) { 236 if (backend->isNew() && creationCallback.get()) {
237 WTF_LOG(StorageAPI, "Scheduling DatabaseCreationCallbackTask for databas e %p\n", database.get()); 237 WTF_LOG(StorageAPI, "Scheduling DatabaseCreationCallbackTask for databas e %p\n", database.get());
238 database->m_executionContext->postTask(DatabaseCreationCallbackTask::cre ate(database, creationCallback)); 238 database->m_executionContext->postTask(DatabaseCreationCallbackTask::cre ate(database, creationCallback));
239 } 239 }
240 240
241 ASSERT(database); 241 ASSERT(database);
242 return database.release(); 242 return database.release();
243 } 243 }
244 244
245 PassRefPtr<DatabaseSync> DatabaseManager::openDatabaseSync(ExecutionContext* con text, 245 PassRefPtr<DatabaseSync> DatabaseManager::openDatabaseSync(ExecutionContext* con text,
246 const String& name, const String& expectedVersion, const String& displayName , 246 const String& name, const String& expectedVersion, const String& displayName ,
247 unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, 247 unsigned long estimatedSize, PassOwnPtr<DatabaseCallback> creationCallback,
248 DatabaseError& error, String& errorMessage) 248 DatabaseError& error, String& errorMessage)
249 { 249 {
250 ASSERT(context->isContextThread()); 250 ASSERT(context->isContextThread());
251 ASSERT(error == DatabaseError::None); 251 ASSERT(error == DatabaseError::None);
252 252
253 bool setVersionInNewDatabase = !creationCallback; 253 bool setVersionInNewDatabase = !creationCallback;
254 RefPtr<DatabaseBackendBase> backend = openDatabaseBackend(context, DatabaseT ype::Sync, name, 254 RefPtr<DatabaseBackendBase> backend = openDatabaseBackend(context, DatabaseT ype::Sync, name,
255 expectedVersion, displayName, estimatedSize, setVersionInNewDatabase, er ror, errorMessage); 255 expectedVersion, displayName, estimatedSize, setVersionInNewDatabase, er ror, errorMessage);
256 if (!backend) 256 if (!backend)
257 return 0; 257 return 0;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 if (databaseContext) 299 if (databaseContext)
300 m_server->interruptAllDatabasesForContext(databaseContext->backend().get ()); 300 m_server->interruptAllDatabasesForContext(databaseContext->backend().get ());
301 } 301 }
302 302
303 void DatabaseManager::logErrorMessage(ExecutionContext* context, const String& m essage) 303 void DatabaseManager::logErrorMessage(ExecutionContext* context, const String& m essage)
304 { 304 {
305 context->addConsoleMessage(StorageMessageSource, ErrorMessageLevel, message) ; 305 context->addConsoleMessage(StorageMessageSource, ErrorMessageLevel, message) ;
306 } 306 }
307 307
308 } // namespace WebCore 308 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/webdatabase/DatabaseManager.h ('k') | Source/modules/webdatabase/DatabaseSync.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698