Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 DatabaseCreationCallbackTask(PassRefPtrWillBeRawPtr<Database> database, Pass OwnPtr<DatabaseCallback> callback) | 84 DatabaseCreationCallbackTask(PassRefPtrWillBeRawPtr<Database> database, Pass OwnPtr<DatabaseCallback> callback) |
| 85 : m_database(database) | 85 : m_database(database) |
| 86 , m_creationCallback(callback) | 86 , m_creationCallback(callback) |
| 87 { | 87 { |
| 88 } | 88 } |
| 89 | 89 |
| 90 RefPtrWillBePersistent<Database> m_database; | 90 RefPtrWillBePersistent<Database> m_database; |
| 91 OwnPtr<DatabaseCallback> m_creationCallback; | 91 OwnPtr<DatabaseCallback> m_creationCallback; |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 PassRefPtr<DatabaseContext> DatabaseManager::existingDatabaseContextFor(Executio nContext* context) | 94 DatabaseContext* DatabaseManager::existingDatabaseContextFor(ExecutionContext* c ontext) |
| 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 |
| 102 RefPtr<DatabaseContext> databaseContext = adoptRef(m_contextMap.get(context) ); | 102 return m_contextMap.get(context); |
| 103 if (databaseContext) { | |
| 104 // If we're instantiating a new DatabaseContext, the new instance would | |
| 105 // carry a new refCount of 1. The client expects this and will simply | |
| 106 // adoptRef the databaseContext without ref'ing it. | |
| 107 // However, instead of instantiating a new instance, we're reusing | |
| 108 // an existing one that corresponds to the specified ExecutionContext. | |
| 109 // Hence, that new refCount need to be attributed to the reused instance | |
| 110 // to ensure that the refCount is accurate when the client adopts the re f. | |
| 111 // We do this by ref'ing the reused databaseContext before returning it. | |
| 112 databaseContext->ref(); | |
| 113 } | |
| 114 return databaseContext.release(); | |
|
tkent
2014/03/26 04:41:18
This code block is exactly equivalent to "return P
haraken
2014/03/26 04:57:24
I don't fully understand this.
RefPtr<DatabaseC
tkent
2014/03/26 05:15:46
No. the former is equivalent to just adoptRef(...
haraken
2014/03/26 05:37:50
sorry, I don't yet get it.
PassRefPtr<Foo> func1(
tkent
2014/03/26 05:50:20
Incorrect.
new Foo() creates a Foo with m_refCount
| |
| 115 } | 103 } |
| 116 | 104 |
| 117 PassRefPtr<DatabaseContext> DatabaseManager::databaseContextFor(ExecutionContext * context) | 105 DatabaseContext* DatabaseManager::databaseContextFor(ExecutionContext* context) |
| 118 { | 106 { |
| 119 RefPtr<DatabaseContext> databaseContext = existingDatabaseContextFor(context ); | 107 if (DatabaseContext* databaseContext = existingDatabaseContextFor(context)) |
| 120 if (!databaseContext) | 108 return databaseContext; |
| 121 databaseContext = DatabaseContext::create(context); | 109 // We don't need to hold a reference returned by DatabaseContext::create |
| 122 return databaseContext.release(); | 110 // because a DatabaseContext refers to itself internally. See |
| 111 // DataabseContext::create. | |
|
haraken
2014/03/26 04:57:24
Typo: DatabaseContext::create
tkent
2014/03/26 05:15:46
Will fix in the next CL.
| |
| 112 return DatabaseContext::create(context).get(); | |
| 123 } | 113 } |
| 124 | 114 |
| 125 void DatabaseManager::registerDatabaseContext(DatabaseContext* databaseContext) | 115 void DatabaseManager::registerDatabaseContext(DatabaseContext* databaseContext) |
| 126 { | 116 { |
| 127 MutexLocker locker(m_contextMapLock); | 117 MutexLocker locker(m_contextMapLock); |
| 128 ExecutionContext* context = databaseContext->executionContext(); | 118 ExecutionContext* context = databaseContext->executionContext(); |
| 129 m_contextMap.set(context, databaseContext); | 119 m_contextMap.set(context, databaseContext); |
| 130 #if !ASSERT_DISABLED | 120 #if !ASSERT_DISABLED |
| 131 m_databaseContextRegisteredCount++; | 121 m_databaseContextRegisteredCount++; |
| 132 #endif | 122 #endif |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 WTF_LOG(StorageAPI, "Database %s for origin %s not allowed to be established ", name.ascii().data(), | 169 WTF_LOG(StorageAPI, "Database %s for origin %s not allowed to be established ", name.ascii().data(), |
| 180 context->securityOrigin()->toString().ascii().data()); | 170 context->securityOrigin()->toString().ascii().data()); |
| 181 } | 171 } |
| 182 | 172 |
| 183 PassRefPtrWillBeRawPtr<DatabaseBackendBase> DatabaseManager::openDatabaseBackend (ExecutionContext* context, | 173 PassRefPtrWillBeRawPtr<DatabaseBackendBase> DatabaseManager::openDatabaseBackend (ExecutionContext* context, |
| 184 DatabaseType type, const String& name, const String& expectedVersion, const String& displayName, | 174 DatabaseType type, const String& name, const String& expectedVersion, const String& displayName, |
| 185 unsigned long estimatedSize, bool setVersionInNewDatabase, DatabaseError& er ror, String& errorMessage) | 175 unsigned long estimatedSize, bool setVersionInNewDatabase, DatabaseError& er ror, String& errorMessage) |
| 186 { | 176 { |
| 187 ASSERT(error == DatabaseError::None); | 177 ASSERT(error == DatabaseError::None); |
| 188 | 178 |
| 189 RefPtr<DatabaseContext> databaseContext = databaseContextFor(context); | |
| 190 RefPtr<DatabaseContext> backendContext = databaseContext->backend(); | |
| 191 | |
| 192 RefPtrWillBeRawPtr<DatabaseBackendBase> backend = m_server->openDatabase( | 179 RefPtrWillBeRawPtr<DatabaseBackendBase> backend = m_server->openDatabase( |
| 193 backendContext, type, name, expectedVersion, | 180 databaseContextFor(context)->backend(), type, name, expectedVersion, |
| 194 displayName, estimatedSize, setVersionInNewDatabase, error, errorMessage ); | 181 displayName, estimatedSize, setVersionInNewDatabase, error, errorMessage ); |
| 195 | 182 |
| 196 if (!backend) { | 183 if (!backend) { |
| 197 ASSERT(error != DatabaseError::None); | 184 ASSERT(error != DatabaseError::None); |
| 198 | 185 |
| 199 switch (error) { | 186 switch (error) { |
| 200 case DatabaseError::GenericSecurityError: | 187 case DatabaseError::GenericSecurityError: |
| 201 logOpenDatabaseError(context, name); | 188 logOpenDatabaseError(context, name); |
| 202 return nullptr; | 189 return nullptr; |
| 203 | 190 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 221 ASSERT(error == DatabaseError::None); | 208 ASSERT(error == DatabaseError::None); |
| 222 | 209 |
| 223 bool setVersionInNewDatabase = !creationCallback; | 210 bool setVersionInNewDatabase = !creationCallback; |
| 224 RefPtrWillBeRawPtr<DatabaseBackendBase> backend = openDatabaseBackend(contex t, DatabaseType::Async, name, | 211 RefPtrWillBeRawPtr<DatabaseBackendBase> backend = openDatabaseBackend(contex t, DatabaseType::Async, name, |
| 225 expectedVersion, displayName, estimatedSize, setVersionInNewDatabase, er ror, errorMessage); | 212 expectedVersion, displayName, estimatedSize, setVersionInNewDatabase, er ror, errorMessage); |
| 226 if (!backend) | 213 if (!backend) |
| 227 return nullptr; | 214 return nullptr; |
| 228 | 215 |
| 229 RefPtrWillBeRawPtr<Database> database = Database::create(context, backend); | 216 RefPtrWillBeRawPtr<Database> database = Database::create(context, backend); |
| 230 | 217 |
| 231 RefPtr<DatabaseContext> databaseContext = databaseContextFor(context); | 218 databaseContextFor(context)->setHasOpenDatabases(); |
| 232 databaseContext->setHasOpenDatabases(); | |
| 233 DatabaseClient::from(context)->didOpenDatabase(database, context->securityOr igin()->host(), name, expectedVersion); | 219 DatabaseClient::from(context)->didOpenDatabase(database, context->securityOr igin()->host(), name, expectedVersion); |
| 234 | 220 |
| 235 if (backend->isNew() && creationCallback.get()) { | 221 if (backend->isNew() && creationCallback.get()) { |
| 236 WTF_LOG(StorageAPI, "Scheduling DatabaseCreationCallbackTask for databas e %p\n", database.get()); | 222 WTF_LOG(StorageAPI, "Scheduling DatabaseCreationCallbackTask for databas e %p\n", database.get()); |
| 237 database->executionContext()->postTask(DatabaseCreationCallbackTask::cre ate(database, creationCallback)); | 223 database->executionContext()->postTask(DatabaseCreationCallbackTask::cre ate(database, creationCallback)); |
| 238 } | 224 } |
| 239 | 225 |
| 240 ASSERT(database); | 226 ASSERT(database); |
| 241 return database.release(); | 227 return database.release(); |
| 242 } | 228 } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 271 return m_server->fullPathForDatabase(origin, name, createIfDoesNotExist); | 257 return m_server->fullPathForDatabase(origin, name, createIfDoesNotExist); |
| 272 } | 258 } |
| 273 | 259 |
| 274 void DatabaseManager::closeDatabasesImmediately(const String& originIdentifier, const String& name) | 260 void DatabaseManager::closeDatabasesImmediately(const String& originIdentifier, const String& name) |
| 275 { | 261 { |
| 276 m_server->closeDatabasesImmediately(originIdentifier, name); | 262 m_server->closeDatabasesImmediately(originIdentifier, name); |
| 277 } | 263 } |
| 278 | 264 |
| 279 void DatabaseManager::interruptAllDatabasesForContext(DatabaseContext* databaseC ontext) | 265 void DatabaseManager::interruptAllDatabasesForContext(DatabaseContext* databaseC ontext) |
| 280 { | 266 { |
| 281 m_server->interruptAllDatabasesForContext(databaseContext->backend().get()); | 267 m_server->interruptAllDatabasesForContext(databaseContext->backend()); |
| 282 } | 268 } |
| 283 | 269 |
| 284 void DatabaseManager::logErrorMessage(ExecutionContext* context, const String& m essage) | 270 void DatabaseManager::logErrorMessage(ExecutionContext* context, const String& m essage) |
| 285 { | 271 { |
| 286 context->addConsoleMessage(StorageMessageSource, ErrorMessageLevel, message) ; | 272 context->addConsoleMessage(StorageMessageSource, ErrorMessageLevel, message) ; |
| 287 } | 273 } |
| 288 | 274 |
| 289 } // namespace WebCore | 275 } // namespace WebCore |
| OLD | NEW |