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_impl.h" | 5 #include "content/browser/indexed_db/indexed_db_factory_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 std::string data_loss_message; | 420 std::string data_loss_message; |
421 bool disk_full = false; | 421 bool disk_full = false; |
422 bool was_open = (it != database_map_.end()); | 422 bool was_open = (it != database_map_.end()); |
423 if (!was_open) { | 423 if (!was_open) { |
424 leveldb::Status s; | 424 leveldb::Status s; |
425 scoped_refptr<IndexedDBBackingStore> backing_store = | 425 scoped_refptr<IndexedDBBackingStore> backing_store = |
426 OpenBackingStore(origin, data_directory, request_context, &data_loss, | 426 OpenBackingStore(origin, data_directory, request_context, &data_loss, |
427 &data_loss_message, &disk_full, &s); | 427 &data_loss_message, &disk_full, &s); |
428 if (!backing_store.get()) { | 428 if (!backing_store.get()) { |
429 if (disk_full) { | 429 if (disk_full) { |
430 connection.callbacks->OnError( | 430 connection.OnError(IndexedDBDatabaseError( |
431 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionQuotaError, | 431 blink::WebIDBDatabaseExceptionQuotaError, |
432 ASCIIToUTF16( | 432 ASCIIToUTF16("Encountered full disk while opening " |
433 "Encountered full disk while opening " | 433 "backing store for indexedDB.open."))); |
434 "backing store for indexedDB.open."))); | |
435 return; | 434 return; |
436 } | 435 } |
437 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 436 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
438 ASCIIToUTF16( | 437 ASCIIToUTF16( |
439 "Internal error opening backing store" | 438 "Internal error opening backing store" |
440 " for indexedDB.open.")); | 439 " for indexedDB.open.")); |
441 connection.callbacks->OnError(error); | 440 connection.OnError(error); |
442 if (s.IsCorruption()) { | 441 if (s.IsCorruption()) { |
443 HandleBackingStoreCorruption(origin, error); | 442 HandleBackingStoreCorruption(origin, error); |
444 } | 443 } |
445 return; | 444 return; |
446 } | 445 } |
447 | 446 |
448 database = IndexedDBDatabase::Create( | 447 database = IndexedDBDatabase::Create( |
449 name, backing_store.get(), this, unique_identifier, &s); | 448 name, backing_store.get(), this, unique_identifier, &s); |
450 if (!database.get()) { | 449 if (!database.get()) { |
451 DLOG(ERROR) << "Unable to create the database"; | 450 DLOG(ERROR) << "Unable to create the database"; |
452 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 451 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
453 ASCIIToUTF16( | 452 ASCIIToUTF16( |
454 "Internal error creating " | 453 "Internal error creating " |
455 "database backend for " | 454 "database backend for " |
456 "indexedDB.open.")); | 455 "indexedDB.open.")); |
457 connection.callbacks->OnError(error); | 456 connection.OnError(error); |
458 if (s.IsCorruption()) { | 457 if (s.IsCorruption()) { |
459 backing_store = NULL; // Closes the LevelDB so that it can be deleted | 458 backing_store = NULL; // Closes the LevelDB so that it can be deleted |
460 HandleBackingStoreCorruption(origin, error); | 459 HandleBackingStoreCorruption(origin, error); |
461 } | 460 } |
462 return; | 461 return; |
463 } | 462 } |
464 } else { | 463 } else { |
465 database = it->second; | 464 database = it->second; |
466 } | 465 } |
467 | 466 |
468 if (data_loss != blink::WebIDBDataLossNone) | 467 if (data_loss != blink::WebIDBDataLossNone) |
469 connection.callbacks->OnDataLoss(data_loss, data_loss_message); | 468 connection.OnDataLoss(data_loss, data_loss_message); |
470 | 469 |
471 database->OpenConnection(connection); | 470 database->OpenConnection(connection); |
472 | 471 |
473 if (!was_open && database->ConnectionCount() > 0) { | 472 if (!was_open && database->ConnectionCount() > 0) { |
474 database_map_[unique_identifier] = database.get(); | 473 database_map_[unique_identifier] = database.get(); |
475 origin_dbs_.insert(std::make_pair(origin, database.get())); | 474 origin_dbs_.insert(std::make_pair(origin, database.get())); |
476 } | 475 } |
477 } | 476 } |
478 | 477 |
479 std::pair<IndexedDBFactoryImpl::OriginDBMapIterator, | 478 std::pair<IndexedDBFactoryImpl::OriginDBMapIterator, |
480 IndexedDBFactoryImpl::OriginDBMapIterator> | 479 IndexedDBFactoryImpl::OriginDBMapIterator> |
481 IndexedDBFactoryImpl::GetOpenDatabasesForOrigin(const Origin& origin) const { | 480 IndexedDBFactoryImpl::GetOpenDatabasesForOrigin(const Origin& origin) const { |
482 return origin_dbs_.equal_range(origin); | 481 return origin_dbs_.equal_range(origin); |
483 } | 482 } |
484 | 483 |
485 size_t IndexedDBFactoryImpl::GetConnectionCount(const Origin& origin) const { | 484 size_t IndexedDBFactoryImpl::GetConnectionCount(const Origin& origin) const { |
486 size_t count(0); | 485 size_t count(0); |
487 | 486 |
488 OriginDBs range = GetOpenDatabasesForOrigin(origin); | 487 OriginDBs range = GetOpenDatabasesForOrigin(origin); |
489 for (OriginDBMapIterator it = range.first; it != range.second; ++it) | 488 for (OriginDBMapIterator it = range.first; it != range.second; ++it) |
490 count += it->second->ConnectionCount(); | 489 count += it->second->ConnectionCount(); |
491 | 490 |
492 return count; | 491 return count; |
493 } | 492 } |
494 | 493 |
495 } // namespace content | 494 } // namespace content |
OLD | NEW |