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

Side by Side Diff: content/browser/indexed_db/indexed_db_factory_impl.cc

Issue 2140193002: IndexedDB: Saving data loss status in IndexedDBPendingConnection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@idb-data-loss
Patch Set: Deleted commented out code. Created 4 years, 5 months 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
OLDNEW
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 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 // All backing stores associated with this factory should be of the same 390 // All backing stores associated with this factory should be of the same
391 // type. 391 // type.
392 DCHECK_NE(session_only_backing_stores_.empty(), open_in_memory); 392 DCHECK_NE(session_only_backing_stores_.empty(), open_in_memory);
393 393
394 return backing_store; 394 return backing_store;
395 } 395 }
396 396
397 return 0; 397 return 0;
398 } 398 }
399 399
400 void IndexedDBFactoryImpl::Open(const base::string16& name, 400 void IndexedDBFactoryImpl::Open(
401 const IndexedDBPendingConnection& connection, 401 const base::string16& name,
402 net::URLRequestContext* request_context, 402 std::unique_ptr<IndexedDBPendingConnection> connection,
403 const Origin& origin, 403 net::URLRequestContext* request_context,
404 const base::FilePath& data_directory) { 404 const Origin& origin,
405 const base::FilePath& data_directory) {
405 IDB_TRACE("IndexedDBFactoryImpl::Open"); 406 IDB_TRACE("IndexedDBFactoryImpl::Open");
406 scoped_refptr<IndexedDBDatabase> database; 407 scoped_refptr<IndexedDBDatabase> database;
407 IndexedDBDatabase::Identifier unique_identifier(origin, name); 408 IndexedDBDatabase::Identifier unique_identifier(origin, name);
408 const auto& it = database_map_.find(unique_identifier); 409 const auto& it = database_map_.find(unique_identifier);
409 IndexedDBDataLossInfo data_loss_info; 410 IndexedDBDataLossInfo data_loss_info;
410 bool disk_full = false; 411 bool disk_full = false;
411 bool was_open = (it != database_map_.end()); 412 bool was_open = (it != database_map_.end());
412 if (!was_open) { 413 if (!was_open) {
413 leveldb::Status s; 414 leveldb::Status s;
414 scoped_refptr<IndexedDBBackingStore> backing_store = 415 scoped_refptr<IndexedDBBackingStore> backing_store =
415 OpenBackingStore(origin, data_directory, request_context, 416 OpenBackingStore(origin, data_directory, request_context,
416 &data_loss_info, &disk_full, &s); 417 &data_loss_info, &disk_full, &s);
417 if (!backing_store.get()) { 418 if (!backing_store.get()) {
418 if (disk_full) { 419 if (disk_full) {
419 connection.callbacks->OnError( 420 connection->callbacks->OnError(IndexedDBDatabaseError(
420 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionQuotaError, 421 blink::WebIDBDatabaseExceptionQuotaError,
421 ASCIIToUTF16( 422 ASCIIToUTF16("Encountered full disk while opening "
422 "Encountered full disk while opening " 423 "backing store for indexedDB.open.")));
423 "backing store for indexedDB.open.")));
424 return; 424 return;
425 } 425 }
426 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, 426 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
427 ASCIIToUTF16( 427 ASCIIToUTF16(
428 "Internal error opening backing store" 428 "Internal error opening backing store"
429 " for indexedDB.open.")); 429 " for indexedDB.open."));
430 connection.callbacks->OnError(error); 430 connection->callbacks->OnError(error);
431 if (s.IsCorruption()) { 431 if (s.IsCorruption()) {
432 HandleBackingStoreCorruption(origin, error); 432 HandleBackingStoreCorruption(origin, error);
433 } 433 }
434 return; 434 return;
435 } 435 }
436 436
437 database = IndexedDBDatabase::Create( 437 database = IndexedDBDatabase::Create(
438 name, backing_store.get(), this, unique_identifier, &s); 438 name, backing_store.get(), this, unique_identifier, &s);
439 if (!database.get()) { 439 if (!database.get()) {
440 DLOG(ERROR) << "Unable to create the database"; 440 DLOG(ERROR) << "Unable to create the database";
441 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, 441 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
442 ASCIIToUTF16( 442 ASCIIToUTF16(
443 "Internal error creating " 443 "Internal error creating "
444 "database backend for " 444 "database backend for "
445 "indexedDB.open.")); 445 "indexedDB.open."));
446 connection.callbacks->OnError(error); 446 connection->callbacks->OnError(error);
447 if (s.IsCorruption()) { 447 if (s.IsCorruption()) {
448 backing_store = NULL; // Closes the LevelDB so that it can be deleted 448 backing_store = NULL; // Closes the LevelDB so that it can be deleted
449 HandleBackingStoreCorruption(origin, error); 449 HandleBackingStoreCorruption(origin, error);
450 } 450 }
451 return; 451 return;
452 } 452 }
453 } else { 453 } else {
454 database = it->second; 454 database = it->second;
455 } 455 }
456 456
457 if (data_loss_info.status != blink::WebIDBDataLossNone) 457 connection->data_loss_info = data_loss_info;
458 connection.callbacks->OnDataLoss(data_loss_info);
459 458
460 database->OpenConnection(connection); 459 database->OpenConnection(std::move(connection));
461 460
462 if (!was_open && database->ConnectionCount() > 0) { 461 if (!was_open && database->ConnectionCount() > 0) {
463 database_map_[unique_identifier] = database.get(); 462 database_map_[unique_identifier] = database.get();
464 origin_dbs_.insert(std::make_pair(origin, database.get())); 463 origin_dbs_.insert(std::make_pair(origin, database.get()));
465 } 464 }
466 } 465 }
467 466
468 std::pair<IndexedDBFactoryImpl::OriginDBMapIterator, 467 std::pair<IndexedDBFactoryImpl::OriginDBMapIterator,
469 IndexedDBFactoryImpl::OriginDBMapIterator> 468 IndexedDBFactoryImpl::OriginDBMapIterator>
470 IndexedDBFactoryImpl::GetOpenDatabasesForOrigin(const Origin& origin) const { 469 IndexedDBFactoryImpl::GetOpenDatabasesForOrigin(const Origin& origin) const {
471 return origin_dbs_.equal_range(origin); 470 return origin_dbs_.equal_range(origin);
472 } 471 }
473 472
474 size_t IndexedDBFactoryImpl::GetConnectionCount(const Origin& origin) const { 473 size_t IndexedDBFactoryImpl::GetConnectionCount(const Origin& origin) const {
475 size_t count(0); 474 size_t count(0);
476 475
477 OriginDBs range = GetOpenDatabasesForOrigin(origin); 476 OriginDBs range = GetOpenDatabasesForOrigin(origin);
478 for (OriginDBMapIterator it = range.first; it != range.second; ++it) 477 for (OriginDBMapIterator it = range.first; it != range.second; ++it)
479 count += it->second->ConnectionCount(); 478 count += it->second->ConnectionCount();
480 479
481 return count; 480 return count;
482 } 481 }
483 482
484 } // namespace content 483 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_factory_impl.h ('k') | content/browser/indexed_db/indexed_db_factory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698