| 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 19 matching lines...) Expand all Loading... |
| 30 #include "bindings/core/v8/ExceptionState.h" | 30 #include "bindings/core/v8/ExceptionState.h" |
| 31 #include "core/dom/ExceptionCode.h" | 31 #include "core/dom/ExceptionCode.h" |
| 32 #include "core/dom/ExecutionContext.h" | 32 #include "core/dom/ExecutionContext.h" |
| 33 #include "core/dom/ExecutionContextTask.h" | 33 #include "core/dom/ExecutionContextTask.h" |
| 34 #include "core/inspector/ConsoleMessage.h" | 34 #include "core/inspector/ConsoleMessage.h" |
| 35 #include "platform/Logging.h" | 35 #include "platform/Logging.h" |
| 36 #include "modules/webdatabase/AbstractDatabaseServer.h" | 36 #include "modules/webdatabase/AbstractDatabaseServer.h" |
| 37 #include "modules/webdatabase/Database.h" | 37 #include "modules/webdatabase/Database.h" |
| 38 #include "modules/webdatabase/DatabaseBackend.h" | 38 #include "modules/webdatabase/DatabaseBackend.h" |
| 39 #include "modules/webdatabase/DatabaseBackendBase.h" | 39 #include "modules/webdatabase/DatabaseBackendBase.h" |
| 40 #include "modules/webdatabase/DatabaseBackendSync.h" | |
| 41 #include "modules/webdatabase/DatabaseCallback.h" | 40 #include "modules/webdatabase/DatabaseCallback.h" |
| 42 #include "modules/webdatabase/DatabaseClient.h" | 41 #include "modules/webdatabase/DatabaseClient.h" |
| 43 #include "modules/webdatabase/DatabaseContext.h" | 42 #include "modules/webdatabase/DatabaseContext.h" |
| 44 #include "modules/webdatabase/DatabaseServer.h" | 43 #include "modules/webdatabase/DatabaseServer.h" |
| 45 #include "modules/webdatabase/DatabaseSync.h" | |
| 46 #include "modules/webdatabase/DatabaseTask.h" | 44 #include "modules/webdatabase/DatabaseTask.h" |
| 47 #include "platform/weborigin/SecurityOrigin.h" | 45 #include "platform/weborigin/SecurityOrigin.h" |
| 48 | 46 |
| 49 namespace blink { | 47 namespace blink { |
| 50 | 48 |
| 51 DatabaseManager& DatabaseManager::manager() | 49 DatabaseManager& DatabaseManager::manager() |
| 52 { | 50 { |
| 53 AtomicallyInitializedStatic(DatabaseManager*, dbManager = new DatabaseManage
r); | 51 AtomicallyInitializedStatic(DatabaseManager*, dbManager = new DatabaseManage
r); |
| 54 return *dbManager; | 52 return *dbManager; |
| 55 } | 53 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 170 } |
| 173 } | 171 } |
| 174 | 172 |
| 175 static void logOpenDatabaseError(ExecutionContext* context, const String& name) | 173 static void logOpenDatabaseError(ExecutionContext* context, const String& name) |
| 176 { | 174 { |
| 177 WTF_LOG(StorageAPI, "Database %s for origin %s not allowed to be established
", name.ascii().data(), | 175 WTF_LOG(StorageAPI, "Database %s for origin %s not allowed to be established
", name.ascii().data(), |
| 178 context->securityOrigin()->toString().ascii().data()); | 176 context->securityOrigin()->toString().ascii().data()); |
| 179 } | 177 } |
| 180 | 178 |
| 181 PassRefPtrWillBeRawPtr<DatabaseBackendBase> DatabaseManager::openDatabaseBackend
(ExecutionContext* context, | 179 PassRefPtrWillBeRawPtr<DatabaseBackendBase> DatabaseManager::openDatabaseBackend
(ExecutionContext* context, |
| 182 DatabaseType type, const String& name, const String& expectedVersion, const
String& displayName, | 180 const String& name, const String& expectedVersion, const String& displayName
, |
| 183 unsigned long estimatedSize, bool setVersionInNewDatabase, DatabaseError& er
ror, String& errorMessage) | 181 unsigned long estimatedSize, bool setVersionInNewDatabase, DatabaseError& er
ror, String& errorMessage) |
| 184 { | 182 { |
| 185 ASSERT(error == DatabaseError::None); | 183 ASSERT(error == DatabaseError::None); |
| 186 | 184 |
| 187 RefPtrWillBeRawPtr<DatabaseBackendBase> backend = m_server->openDatabase( | 185 RefPtrWillBeRawPtr<DatabaseBackendBase> backend = m_server->openDatabase( |
| 188 databaseContextFor(context)->backend(), type, name, expectedVersion, | 186 databaseContextFor(context)->backend(), name, expectedVersion, |
| 189 displayName, estimatedSize, setVersionInNewDatabase, error, errorMessage
); | 187 displayName, estimatedSize, setVersionInNewDatabase, error, errorMessage
); |
| 190 | 188 |
| 191 if (!backend) { | 189 if (!backend) { |
| 192 ASSERT(error != DatabaseError::None); | 190 ASSERT(error != DatabaseError::None); |
| 193 | 191 |
| 194 switch (error) { | 192 switch (error) { |
| 195 case DatabaseError::GenericSecurityError: | 193 case DatabaseError::GenericSecurityError: |
| 196 logOpenDatabaseError(context, name); | 194 logOpenDatabaseError(context, name); |
| 197 return nullptr; | 195 return nullptr; |
| 198 | 196 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 209 } | 207 } |
| 210 | 208 |
| 211 PassRefPtrWillBeRawPtr<Database> DatabaseManager::openDatabase(ExecutionContext*
context, | 209 PassRefPtrWillBeRawPtr<Database> DatabaseManager::openDatabase(ExecutionContext*
context, |
| 212 const String& name, const String& expectedVersion, const String& displayName
, | 210 const String& name, const String& expectedVersion, const String& displayName
, |
| 213 unsigned long estimatedSize, PassOwnPtrWillBeRawPtr<DatabaseCallback> creati
onCallback, | 211 unsigned long estimatedSize, PassOwnPtrWillBeRawPtr<DatabaseCallback> creati
onCallback, |
| 214 DatabaseError& error, String& errorMessage) | 212 DatabaseError& error, String& errorMessage) |
| 215 { | 213 { |
| 216 ASSERT(error == DatabaseError::None); | 214 ASSERT(error == DatabaseError::None); |
| 217 | 215 |
| 218 bool setVersionInNewDatabase = !creationCallback; | 216 bool setVersionInNewDatabase = !creationCallback; |
| 219 RefPtrWillBeRawPtr<DatabaseBackendBase> backend = openDatabaseBackend(contex
t, DatabaseType::Async, name, | 217 RefPtrWillBeRawPtr<DatabaseBackendBase> backend = openDatabaseBackend(contex
t, name, |
| 220 expectedVersion, displayName, estimatedSize, setVersionInNewDatabase, er
ror, errorMessage); | 218 expectedVersion, displayName, estimatedSize, setVersionInNewDatabase, er
ror, errorMessage); |
| 221 if (!backend) | 219 if (!backend) |
| 222 return nullptr; | 220 return nullptr; |
| 223 | 221 |
| 224 RefPtrWillBeRawPtr<Database> database = Database::create(context, backend); | 222 RefPtrWillBeRawPtr<Database> database = Database::create(context, backend); |
| 225 | 223 |
| 226 databaseContextFor(context)->setHasOpenDatabases(); | 224 databaseContextFor(context)->setHasOpenDatabases(); |
| 227 DatabaseClient::from(context)->didOpenDatabase(database, context->securityOr
igin()->host(), name, expectedVersion); | 225 DatabaseClient::from(context)->didOpenDatabase(database, context->securityOr
igin()->host(), name, expectedVersion); |
| 228 | 226 |
| 229 if (backend->isNew() && creationCallback.get()) { | 227 if (backend->isNew() && creationCallback.get()) { |
| 230 WTF_LOG(StorageAPI, "Scheduling DatabaseCreationCallbackTask for databas
e %p\n", database.get()); | 228 WTF_LOG(StorageAPI, "Scheduling DatabaseCreationCallbackTask for databas
e %p\n", database.get()); |
| 231 database->executionContext()->postTask(DatabaseCreationCallbackTask::cre
ate(database, creationCallback)); | 229 database->executionContext()->postTask(DatabaseCreationCallbackTask::cre
ate(database, creationCallback)); |
| 232 } | 230 } |
| 233 | 231 |
| 234 ASSERT(database); | 232 ASSERT(database); |
| 235 return database.release(); | 233 return database.release(); |
| 236 } | 234 } |
| 237 | 235 |
| 238 PassRefPtrWillBeRawPtr<DatabaseSync> DatabaseManager::openDatabaseSync(Execution
Context* context, | |
| 239 const String& name, const String& expectedVersion, const String& displayName
, | |
| 240 unsigned long estimatedSize, PassOwnPtrWillBeRawPtr<DatabaseCallback> creati
onCallback, | |
| 241 DatabaseError& error, String& errorMessage) | |
| 242 { | |
| 243 ASSERT(context->isContextThread()); | |
| 244 ASSERT(error == DatabaseError::None); | |
| 245 | |
| 246 bool setVersionInNewDatabase = !creationCallback; | |
| 247 RefPtrWillBeRawPtr<DatabaseBackendBase> backend = openDatabaseBackend(contex
t, DatabaseType::Sync, name, | |
| 248 expectedVersion, displayName, estimatedSize, setVersionInNewDatabase, er
ror, errorMessage); | |
| 249 if (!backend) | |
| 250 return nullptr; | |
| 251 | |
| 252 RefPtrWillBeRawPtr<DatabaseSync> database = DatabaseSync::create(context, ba
ckend); | |
| 253 | |
| 254 if (backend->isNew() && creationCallback.get()) { | |
| 255 WTF_LOG(StorageAPI, "Invoking the creation callback for database %p\n",
database.get()); | |
| 256 creationCallback->handleEvent(database.get()); | |
| 257 } | |
| 258 | |
| 259 ASSERT(database); | |
| 260 return database.release(); | |
| 261 } | |
| 262 | |
| 263 String DatabaseManager::fullPathForDatabase(SecurityOrigin* origin, const String
& name, bool createIfDoesNotExist) | 236 String DatabaseManager::fullPathForDatabase(SecurityOrigin* origin, const String
& name, bool createIfDoesNotExist) |
| 264 { | 237 { |
| 265 return m_server->fullPathForDatabase(origin, name, createIfDoesNotExist); | 238 return m_server->fullPathForDatabase(origin, name, createIfDoesNotExist); |
| 266 } | 239 } |
| 267 | 240 |
| 268 void DatabaseManager::closeDatabasesImmediately(const String& originIdentifier,
const String& name) | 241 void DatabaseManager::closeDatabasesImmediately(const String& originIdentifier,
const String& name) |
| 269 { | 242 { |
| 270 m_server->closeDatabasesImmediately(originIdentifier, name); | 243 m_server->closeDatabasesImmediately(originIdentifier, name); |
| 271 } | 244 } |
| 272 | 245 |
| 273 void DatabaseManager::interruptAllDatabasesForContext(DatabaseContext* databaseC
ontext) | |
| 274 { | |
| 275 m_server->interruptAllDatabasesForContext(databaseContext->backend()); | |
| 276 } | |
| 277 | |
| 278 void DatabaseManager::logErrorMessage(ExecutionContext* context, const String& m
essage) | 246 void DatabaseManager::logErrorMessage(ExecutionContext* context, const String& m
essage) |
| 279 { | 247 { |
| 280 context->addConsoleMessage(ConsoleMessage::create(StorageMessageSource, Erro
rMessageLevel, message)); | 248 context->addConsoleMessage(ConsoleMessage::create(StorageMessageSource, Erro
rMessageLevel, message)); |
| 281 } | 249 } |
| 282 | 250 |
| 283 } // namespace blink | 251 } // namespace blink |
| OLD | NEW |