OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/indexed_db/indexed_db_factory.h" | 5 #include "content/browser/indexed_db/indexed_db_factory.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 10 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
11 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 11 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
12 #include "content/browser/indexed_db/indexed_db_database_error.h" | 12 #include "content/browser/indexed_db/indexed_db_database_error.h" |
13 #include "content/browser/indexed_db/indexed_db_tracing.h" | 13 #include "content/browser/indexed_db/indexed_db_tracing.h" |
14 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" | 14 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" |
15 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" | 15 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" |
16 #include "third_party/leveldatabase/env_chromium.h" | |
17 #include "webkit/common/database/database_identifier.h" | 16 #include "webkit/common/database/database_identifier.h" |
18 | 17 |
19 using base::ASCIIToUTF16; | 18 using base::ASCIIToUTF16; |
20 | 19 |
21 namespace content { | 20 namespace content { |
22 | 21 |
23 const int64 kBackingStoreGracePeriodMs = 2000; | 22 const int64 kBackingStoreGracePeriodMs = 2000; |
24 | 23 |
25 IndexedDBFactory::IndexedDBFactory(IndexedDBContextImpl* context) | 24 IndexedDBFactory::IndexedDBFactory(IndexedDBContextImpl* context) |
26 : context_(context) {} | 25 : context_(context) {} |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 leveldb::Status s; | 243 leveldb::Status s; |
245 scoped_refptr<IndexedDBDatabase> database = IndexedDBDatabase::Create( | 244 scoped_refptr<IndexedDBDatabase> database = IndexedDBDatabase::Create( |
246 name, backing_store, this, unique_identifier, &s); | 245 name, backing_store, this, unique_identifier, &s); |
247 if (!database) { | 246 if (!database) { |
248 IndexedDBDatabaseError error( | 247 IndexedDBDatabaseError error( |
249 blink::WebIDBDatabaseExceptionUnknownError, | 248 blink::WebIDBDatabaseExceptionUnknownError, |
250 ASCIIToUTF16( | 249 ASCIIToUTF16( |
251 "Internal error creating database backend for " | 250 "Internal error creating database backend for " |
252 "indexedDB.deleteDatabase.")); | 251 "indexedDB.deleteDatabase.")); |
253 callbacks->OnError(error); | 252 callbacks->OnError(error); |
254 if (leveldb_env::IsCorruption(s)) | 253 if (s.IsCorruption()) |
255 HandleBackingStoreCorruption(origin_url, error); | 254 HandleBackingStoreCorruption(origin_url, error); |
256 return; | 255 return; |
257 } | 256 } |
258 | 257 |
259 database_map_[unique_identifier] = database; | 258 database_map_[unique_identifier] = database; |
260 origin_dbs_.insert(std::make_pair(origin_url, database)); | 259 origin_dbs_.insert(std::make_pair(origin_url, database)); |
261 database->DeleteDatabase(callbacks); | 260 database->DeleteDatabase(callbacks); |
262 RemoveDatabaseFromMaps(unique_identifier); | 261 RemoveDatabaseFromMaps(unique_identifier); |
263 database = NULL; | 262 database = NULL; |
264 backing_store = NULL; | 263 backing_store = NULL; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 database = IndexedDBDatabase::Create( | 429 database = IndexedDBDatabase::Create( |
431 name, backing_store, this, unique_identifier, &s); | 430 name, backing_store, this, unique_identifier, &s); |
432 if (!database) { | 431 if (!database) { |
433 DLOG(ERROR) << "Unable to create the database"; | 432 DLOG(ERROR) << "Unable to create the database"; |
434 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 433 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
435 ASCIIToUTF16( | 434 ASCIIToUTF16( |
436 "Internal error creating " | 435 "Internal error creating " |
437 "database backend for " | 436 "database backend for " |
438 "indexedDB.open.")); | 437 "indexedDB.open.")); |
439 connection.callbacks->OnError(error); | 438 connection.callbacks->OnError(error); |
440 if (leveldb_env::IsCorruption(s)) { | 439 if (s.IsCorruption()) { |
441 backing_store = NULL; // Closes the LevelDB so that it can be deleted | 440 backing_store = NULL; // Closes the LevelDB so that it can be deleted |
442 HandleBackingStoreCorruption(origin_url, error); | 441 HandleBackingStoreCorruption(origin_url, error); |
443 } | 442 } |
444 return; | 443 return; |
445 } | 444 } |
446 } else { | 445 } else { |
447 database = it->second; | 446 database = it->second; |
448 } | 447 } |
449 | 448 |
450 if (data_loss != blink::WebIDBDataLossNone) | 449 if (data_loss != blink::WebIDBDataLossNone) |
(...skipping 18 matching lines...) Expand all Loading... |
469 | 468 |
470 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = | 469 std::pair<OriginDBMapIterator, OriginDBMapIterator> range = |
471 GetOpenDatabasesForOrigin(origin_url); | 470 GetOpenDatabasesForOrigin(origin_url); |
472 for (OriginDBMapIterator it = range.first; it != range.second; ++it) | 471 for (OriginDBMapIterator it = range.first; it != range.second; ++it) |
473 count += it->second->ConnectionCount(); | 472 count += it->second->ConnectionCount(); |
474 | 473 |
475 return count; | 474 return count; |
476 } | 475 } |
477 | 476 |
478 } // namespace content | 477 } // namespace content |
OLD | NEW |