| 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_backing_store.h" | 5 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 : primary_key_(primary_key), version_(version) { | 377 : primary_key_(primary_key), version_(version) { |
| 378 DCHECK(!primary_key.empty()); | 378 DCHECK(!primary_key.empty()); |
| 379 } | 379 } |
| 380 IndexedDBBackingStore::RecordIdentifier::RecordIdentifier() | 380 IndexedDBBackingStore::RecordIdentifier::RecordIdentifier() |
| 381 : primary_key_(), version_(-1) {} | 381 : primary_key_(), version_(-1) {} |
| 382 IndexedDBBackingStore::RecordIdentifier::~RecordIdentifier() {} | 382 IndexedDBBackingStore::RecordIdentifier::~RecordIdentifier() {} |
| 383 | 383 |
| 384 IndexedDBBackingStore::Cursor::CursorOptions::CursorOptions() {} | 384 IndexedDBBackingStore::Cursor::CursorOptions::CursorOptions() {} |
| 385 IndexedDBBackingStore::Cursor::CursorOptions::~CursorOptions() {} | 385 IndexedDBBackingStore::Cursor::CursorOptions::~CursorOptions() {} |
| 386 | 386 |
| 387 enum IndexedDBLevelDBBackingStoreOpenResult { | 387 enum IndexedDBBackingStoreOpenResult { |
| 388 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MEMORY_SUCCESS, | 388 INDEXED_DB_BACKING_STORE_OPEN_MEMORY_SUCCESS, |
| 389 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_SUCCESS, | 389 INDEXED_DB_BACKING_STORE_OPEN_SUCCESS, |
| 390 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_FAILED_DIRECTORY, | 390 INDEXED_DB_BACKING_STORE_OPEN_FAILED_DIRECTORY, |
| 391 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_FAILED_UNKNOWN_SCHEMA, | 391 INDEXED_DB_BACKING_STORE_OPEN_FAILED_UNKNOWN_SCHEMA, |
| 392 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_CLEANUP_DESTROY_FAILED, | 392 INDEXED_DB_BACKING_STORE_OPEN_CLEANUP_DESTROY_FAILED, |
| 393 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_CLEANUP_REOPEN_FAILED, | 393 INDEXED_DB_BACKING_STORE_OPEN_CLEANUP_REOPEN_FAILED, |
| 394 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_CLEANUP_REOPEN_SUCCESS, | 394 INDEXED_DB_BACKING_STORE_OPEN_CLEANUP_REOPEN_SUCCESS, |
| 395 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_FAILED_IO_ERROR_CHECKING_SCHEMA, | 395 INDEXED_DB_BACKING_STORE_OPEN_FAILED_IO_ERROR_CHECKING_SCHEMA, |
| 396 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_FAILED_UNKNOWN_ERR, | 396 INDEXED_DB_BACKING_STORE_OPEN_FAILED_UNKNOWN_ERR, |
| 397 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MEMORY_FAILED, | 397 INDEXED_DB_BACKING_STORE_OPEN_MEMORY_FAILED, |
| 398 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_ATTEMPT_NON_ASCII, | 398 INDEXED_DB_BACKING_STORE_OPEN_ATTEMPT_NON_ASCII, |
| 399 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_DISK_FULL, | 399 INDEXED_DB_BACKING_STORE_OPEN_DISK_FULL, |
| 400 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_ORIGIN_TOO_LONG, | 400 INDEXED_DB_BACKING_STORE_OPEN_ORIGIN_TOO_LONG, |
| 401 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_NO_RECOVERY, | 401 INDEXED_DB_BACKING_STORE_OPEN_NO_RECOVERY, |
| 402 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX, | 402 INDEXED_DB_BACKING_STORE_OPEN_MAX, |
| 403 }; | 403 }; |
| 404 | 404 |
| 405 // TODO(dgrogan): Move to leveldb_env. | 405 // TODO(dgrogan): Move to leveldb_env. |
| 406 bool RecoveryCouldBeFruitful(leveldb::Status status) { | 406 bool RecoveryCouldBeFruitful(leveldb::Status status) { |
| 407 leveldb_env::MethodID method; | 407 leveldb_env::MethodID method; |
| 408 int error = -1; | 408 int error = -1; |
| 409 leveldb_env::ErrorParsingResult result = leveldb_env::ParseMethodAndError( | 409 leveldb_env::ErrorParsingResult result = leveldb_env::ParseMethodAndError( |
| 410 status.ToString().c_str(), &method, &error); | 410 status.ToString().c_str(), &method, &error); |
| 411 switch (result) { | 411 switch (result) { |
| 412 case leveldb_env::NONE: | 412 case leveldb_env::NONE: |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 *data_loss = WebKit::WebIDBCallbacks::DataLossNone; | 447 *data_loss = WebKit::WebIDBCallbacks::DataLossNone; |
| 448 DefaultLevelDBFactory leveldb_factory; | 448 DefaultLevelDBFactory leveldb_factory; |
| 449 return IndexedDBBackingStore::Open(origin_identifier, | 449 return IndexedDBBackingStore::Open(origin_identifier, |
| 450 path_base, | 450 path_base, |
| 451 file_identifier, | 451 file_identifier, |
| 452 data_loss, | 452 data_loss, |
| 453 disk_full, | 453 disk_full, |
| 454 &leveldb_factory); | 454 &leveldb_factory); |
| 455 } | 455 } |
| 456 | 456 |
| 457 static void HistogramOpenStatus(IndexedDBBackingStoreOpenResult result) { |
| 458 UMA_HISTOGRAM_ENUMERATION("WebCore.IndexedDB.BackingStore.OpenStatus", |
| 459 result, |
| 460 INDEXED_DB_BACKING_STORE_OPEN_MAX); |
| 461 } |
| 462 |
| 463 static bool IsPathTooLong(const base::FilePath& leveldb_dir) { |
| 464 int limit = file_util::GetMaximumPathComponentLength(leveldb_dir.DirName()); |
| 465 if (limit == -1) { |
| 466 DLOG(WARNING) << "GetMaximumPathComponentLength returned -1"; |
| 467 // In limited testing, ChromeOS returns 143, other OSes 255. |
| 468 #if defined(OS_CHROMEOS) |
| 469 limit = 143; |
| 470 #else |
| 471 limit = 255; |
| 472 #endif |
| 473 } |
| 474 size_t component_length = leveldb_dir.BaseName().value().length(); |
| 475 if (component_length > static_cast<uint32_t>(limit)) { |
| 476 DLOG(WARNING) << "Path component length (" << component_length |
| 477 << ") exceeds maximum (" << limit |
| 478 << ") allowed by this filesystem."; |
| 479 const int min = 140; |
| 480 const int max = 300; |
| 481 const int num_buckets = 12; |
| 482 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 483 "WebCore.IndexedDB.BackingStore.OverlyLargeOriginLength", |
| 484 component_length, |
| 485 min, |
| 486 max, |
| 487 num_buckets); |
| 488 return true; |
| 489 } |
| 490 return false; |
| 491 } |
| 492 |
| 457 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open( | 493 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open( |
| 458 const std::string& origin_identifier, | 494 const std::string& origin_identifier, |
| 459 const base::FilePath& path_base, | 495 const base::FilePath& path_base, |
| 460 const std::string& file_identifier, | 496 const std::string& file_identifier, |
| 461 WebKit::WebIDBCallbacks::DataLoss* data_loss, | 497 WebKit::WebIDBCallbacks::DataLoss* data_loss, |
| 462 bool* is_disk_full, | 498 bool* is_disk_full, |
| 463 LevelDBFactory* leveldb_factory) { | 499 LevelDBFactory* leveldb_factory) { |
| 464 IDB_TRACE("IndexedDBBackingStore::Open"); | 500 IDB_TRACE("IndexedDBBackingStore::Open"); |
| 465 DCHECK(!path_base.empty()); | 501 DCHECK(!path_base.empty()); |
| 466 *data_loss = WebKit::WebIDBCallbacks::DataLossNone; | 502 *data_loss = WebKit::WebIDBCallbacks::DataLossNone; |
| 467 *is_disk_full = false; | 503 *is_disk_full = false; |
| 468 | 504 |
| 469 scoped_ptr<LevelDBComparator> comparator(new Comparator()); | 505 scoped_ptr<LevelDBComparator> comparator(new Comparator()); |
| 470 | 506 |
| 471 if (!IsStringASCII(path_base.AsUTF8Unsafe())) { | 507 if (!IsStringASCII(path_base.AsUTF8Unsafe())) { |
| 472 base::Histogram::FactoryGet("WebCore.IndexedDB.BackingStore.OpenStatus", | 508 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_ATTEMPT_NON_ASCII); |
| 473 1, | |
| 474 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX, | |
| 475 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX + 1, | |
| 476 base::HistogramBase::kUmaTargetedHistogramFlag) | |
| 477 ->Add(INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_ATTEMPT_NON_ASCII); | |
| 478 } | 509 } |
| 479 if (!file_util::CreateDirectory(path_base)) { | 510 if (!file_util::CreateDirectory(path_base)) { |
| 480 LOG(ERROR) << "Unable to create IndexedDB database path " | 511 LOG(ERROR) << "Unable to create IndexedDB database path " |
| 481 << path_base.AsUTF8Unsafe(); | 512 << path_base.AsUTF8Unsafe(); |
| 482 base::Histogram::FactoryGet("WebCore.IndexedDB.BackingStore.OpenStatus", | 513 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_FAILED_DIRECTORY); |
| 483 1, | |
| 484 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX, | |
| 485 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX + 1, | |
| 486 base::HistogramBase::kUmaTargetedHistogramFlag) | |
| 487 ->Add(INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_FAILED_DIRECTORY); | |
| 488 return scoped_refptr<IndexedDBBackingStore>(); | 514 return scoped_refptr<IndexedDBBackingStore>(); |
| 489 } | 515 } |
| 490 | 516 |
| 491 base::FilePath identifier_path = | 517 base::FilePath file_path = |
| 492 base::FilePath().AppendASCII(origin_identifier) | 518 path_base.AppendASCII(origin_identifier) |
| 493 .AddExtension(FILE_PATH_LITERAL(".indexeddb.leveldb")); | 519 .AddExtension(FILE_PATH_LITERAL(".indexeddb.leveldb")); |
| 494 | 520 |
| 495 int limit = file_util::GetMaximumPathComponentLength(path_base); | 521 if (IsPathTooLong(file_path)) { |
| 496 if (limit == -1) { | 522 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_ORIGIN_TOO_LONG); |
| 497 DLOG(WARNING) << "GetMaximumPathComponentLength returned -1"; | |
| 498 // In limited testing, ChromeOS returns 143, other OSes 255. | |
| 499 #if defined(OS_CHROMEOS) | |
| 500 limit = 143; | |
| 501 #else | |
| 502 limit = 255; | |
| 503 #endif | |
| 504 } | |
| 505 if (identifier_path.value().length() > static_cast<uint32_t>(limit)) { | |
| 506 DLOG(WARNING) << "Path component length (" | |
| 507 << identifier_path.value().length() << ") exceeds maximum (" | |
| 508 << limit << ") allowed by this filesystem."; | |
| 509 const int min = 140; | |
| 510 const int max = 300; | |
| 511 const int num_buckets = 12; | |
| 512 // TODO(dgrogan): Remove WebCore from these histogram names. | |
| 513 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
| 514 "WebCore.IndexedDB.BackingStore.OverlyLargeOriginLength", | |
| 515 identifier_path.value().length(), | |
| 516 min, | |
| 517 max, | |
| 518 num_buckets); | |
| 519 // TODO(dgrogan): Translate the FactoryGet calls to | |
| 520 // UMA_HISTOGRAM_ENUMERATION. FactoryGet was the most direct translation | |
| 521 // from the WebCore code. | |
| 522 base::Histogram::FactoryGet("WebCore.IndexedDB.BackingStore.OpenStatus", | |
| 523 1, | |
| 524 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX, | |
| 525 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX + 1, | |
| 526 base::HistogramBase::kUmaTargetedHistogramFlag) | |
| 527 ->Add(INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_ORIGIN_TOO_LONG); | |
| 528 return scoped_refptr<IndexedDBBackingStore>(); | 523 return scoped_refptr<IndexedDBBackingStore>(); |
| 529 } | 524 } |
| 530 | 525 |
| 531 base::FilePath file_path = path_base.Append(identifier_path); | |
| 532 | |
| 533 scoped_ptr<LevelDBDatabase> db; | 526 scoped_ptr<LevelDBDatabase> db; |
| 534 leveldb::Status status = leveldb_factory->OpenLevelDB( | 527 leveldb::Status status = leveldb_factory->OpenLevelDB( |
| 535 file_path, comparator.get(), &db, is_disk_full); | 528 file_path, comparator.get(), &db, is_disk_full); |
| 536 | 529 |
| 537 if (!status.ok() && leveldb_env::IndicatesDiskFull(status)) { | 530 if (!status.ok() && leveldb_env::IndicatesDiskFull(status)) { |
| 538 DCHECK(!db); | 531 DCHECK(!db); |
| 539 *is_disk_full = true; | 532 *is_disk_full = true; |
| 540 } | 533 } |
| 541 | 534 |
| 542 if (db) { | 535 if (db) { |
| 543 bool known = false; | 536 bool known = false; |
| 544 bool ok = IsSchemaKnown(db.get(), &known); | 537 bool ok = IsSchemaKnown(db.get(), &known); |
| 545 if (!ok) { | 538 if (!ok) { |
| 546 LOG(ERROR) << "IndexedDB had IO error checking schema, treating it as " | 539 LOG(ERROR) << "IndexedDB had IO error checking schema, treating it as " |
| 547 "failure to open"; | 540 "failure to open"; |
| 548 base::Histogram::FactoryGet( | 541 HistogramOpenStatus( |
| 549 "WebCore.IndexedDB.BackingStore.OpenStatus", | 542 INDEXED_DB_BACKING_STORE_OPEN_FAILED_IO_ERROR_CHECKING_SCHEMA); |
| 550 1, | |
| 551 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX, | |
| 552 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX + 1, | |
| 553 base::HistogramBase::kUmaTargetedHistogramFlag) | |
| 554 ->Add(INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_FAILED_IO_ERROR_CHECKING_
SCHEMA); | |
| 555 db.reset(); | 543 db.reset(); |
| 556 } else if (!known) { | 544 } else if (!known) { |
| 557 LOG(ERROR) << "IndexedDB backing store had unknown schema, treating it " | 545 LOG(ERROR) << "IndexedDB backing store had unknown schema, treating it " |
| 558 "as failure to open"; | 546 "as failure to open"; |
| 559 base::Histogram::FactoryGet( | 547 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_FAILED_UNKNOWN_SCHEMA); |
| 560 "WebCore.IndexedDB.BackingStore.OpenStatus", | |
| 561 1, | |
| 562 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX, | |
| 563 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX + 1, | |
| 564 base::HistogramBase::kUmaTargetedHistogramFlag) | |
| 565 ->Add(INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_FAILED_UNKNOWN_SCHEMA); | |
| 566 db.reset(); | 548 db.reset(); |
| 567 } | 549 } |
| 568 } | 550 } |
| 569 | 551 |
| 570 if (db) { | 552 if (db) { |
| 571 base::Histogram::FactoryGet("WebCore.IndexedDB.BackingStore.OpenStatus", | 553 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_SUCCESS); |
| 572 1, | |
| 573 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX, | |
| 574 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX + 1, | |
| 575 base::HistogramBase::kUmaTargetedHistogramFlag) | |
| 576 ->Add(INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_SUCCESS); | |
| 577 } else if (!RecoveryCouldBeFruitful(status)) { | 554 } else if (!RecoveryCouldBeFruitful(status)) { |
| 578 LOG(ERROR) << "Unable to open backing store, not trying to recover - " | 555 LOG(ERROR) << "Unable to open backing store, not trying to recover - " |
| 579 << status.ToString(); | 556 << status.ToString(); |
| 580 base::Histogram::FactoryGet("WebCore.IndexedDB.BackingStore.OpenStatus", | 557 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_NO_RECOVERY); |
| 581 1, | |
| 582 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX, | |
| 583 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX + 1, | |
| 584 base::HistogramBase::kUmaTargetedHistogramFlag) | |
| 585 ->Add(INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_NO_RECOVERY); | |
| 586 return scoped_refptr<IndexedDBBackingStore>(); | 558 return scoped_refptr<IndexedDBBackingStore>(); |
| 587 } else if (*is_disk_full) { | 559 } else if (*is_disk_full) { |
| 588 LOG(ERROR) << "Unable to open backing store - disk is full."; | 560 LOG(ERROR) << "Unable to open backing store - disk is full."; |
| 589 base::Histogram::FactoryGet("WebCore.IndexedDB.BackingStore.OpenStatus", | 561 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_DISK_FULL); |
| 590 1, | |
| 591 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX, | |
| 592 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX + 1, | |
| 593 base::HistogramBase::kUmaTargetedHistogramFlag) | |
| 594 ->Add(INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_DISK_FULL); | |
| 595 return scoped_refptr<IndexedDBBackingStore>(); | 562 return scoped_refptr<IndexedDBBackingStore>(); |
| 596 } else { | 563 } else { |
| 597 LOG(ERROR) << "IndexedDB backing store open failed, attempting cleanup"; | 564 LOG(ERROR) << "IndexedDB backing store open failed, attempting cleanup"; |
| 598 *data_loss = WebKit::WebIDBCallbacks::DataLossTotal; | 565 *data_loss = WebKit::WebIDBCallbacks::DataLossTotal; |
| 599 bool success = leveldb_factory->DestroyLevelDB(file_path); | 566 bool success = leveldb_factory->DestroyLevelDB(file_path); |
| 600 if (!success) { | 567 if (!success) { |
| 601 LOG(ERROR) << "IndexedDB backing store cleanup failed"; | 568 LOG(ERROR) << "IndexedDB backing store cleanup failed"; |
| 602 base::Histogram::FactoryGet( | 569 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_CLEANUP_DESTROY_FAILED); |
| 603 "WebCore.IndexedDB.BackingStore.OpenStatus", | |
| 604 1, | |
| 605 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX, | |
| 606 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX + 1, | |
| 607 base::HistogramBase::kUmaTargetedHistogramFlag) | |
| 608 ->Add(INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_CLEANUP_DESTROY_FAILED); | |
| 609 return scoped_refptr<IndexedDBBackingStore>(); | 570 return scoped_refptr<IndexedDBBackingStore>(); |
| 610 } | 571 } |
| 611 | 572 |
| 612 LOG(ERROR) << "IndexedDB backing store cleanup succeeded, reopening"; | 573 LOG(ERROR) << "IndexedDB backing store cleanup succeeded, reopening"; |
| 613 leveldb_factory->OpenLevelDB(file_path, comparator.get(), &db, NULL); | 574 leveldb_factory->OpenLevelDB(file_path, comparator.get(), &db, NULL); |
| 614 if (!db) { | 575 if (!db) { |
| 615 LOG(ERROR) << "IndexedDB backing store reopen after recovery failed"; | 576 LOG(ERROR) << "IndexedDB backing store reopen after recovery failed"; |
| 616 base::Histogram::FactoryGet( | 577 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_CLEANUP_REOPEN_FAILED); |
| 617 "WebCore.IndexedDB.BackingStore.OpenStatus", | |
| 618 1, | |
| 619 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX, | |
| 620 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX + 1, | |
| 621 base::HistogramBase::kUmaTargetedHistogramFlag) | |
| 622 ->Add(INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_CLEANUP_REOPEN_FAILED); | |
| 623 return scoped_refptr<IndexedDBBackingStore>(); | 578 return scoped_refptr<IndexedDBBackingStore>(); |
| 624 } | 579 } |
| 625 base::Histogram::FactoryGet("WebCore.IndexedDB.BackingStore.OpenStatus", | 580 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_CLEANUP_REOPEN_SUCCESS); |
| 626 1, | |
| 627 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX, | |
| 628 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX + 1, | |
| 629 base::HistogramBase::kUmaTargetedHistogramFlag) | |
| 630 ->Add(INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_CLEANUP_REOPEN_SUCCESS); | |
| 631 } | 581 } |
| 632 | 582 |
| 633 if (!db) { | 583 if (!db) { |
| 634 NOTREACHED(); | 584 NOTREACHED(); |
| 635 base::Histogram::FactoryGet("WebCore.IndexedDB.BackingStore.OpenStatus", | 585 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_FAILED_UNKNOWN_ERR); |
| 636 1, | |
| 637 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX, | |
| 638 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX + 1, | |
| 639 base::HistogramBase::kUmaTargetedHistogramFlag) | |
| 640 ->Add(INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_FAILED_UNKNOWN_ERR); | |
| 641 return scoped_refptr<IndexedDBBackingStore>(); | 586 return scoped_refptr<IndexedDBBackingStore>(); |
| 642 } | 587 } |
| 643 | 588 |
| 644 return Create(file_identifier, db.Pass(), comparator.Pass()); | 589 return Create(file_identifier, db.Pass(), comparator.Pass()); |
| 645 } | 590 } |
| 646 | 591 |
| 647 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::OpenInMemory( | 592 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::OpenInMemory( |
| 648 const std::string& file_identifier) { | 593 const std::string& file_identifier) { |
| 649 DefaultLevelDBFactory leveldb_factory; | 594 DefaultLevelDBFactory leveldb_factory; |
| 650 return IndexedDBBackingStore::OpenInMemory(file_identifier, &leveldb_factory); | 595 return IndexedDBBackingStore::OpenInMemory(file_identifier, &leveldb_factory); |
| 651 } | 596 } |
| 652 | 597 |
| 653 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::OpenInMemory( | 598 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::OpenInMemory( |
| 654 const std::string& file_identifier, | 599 const std::string& file_identifier, |
| 655 LevelDBFactory* leveldb_factory) { | 600 LevelDBFactory* leveldb_factory) { |
| 656 IDB_TRACE("IndexedDBBackingStore::OpenInMemory"); | 601 IDB_TRACE("IndexedDBBackingStore::OpenInMemory"); |
| 657 | 602 |
| 658 scoped_ptr<LevelDBComparator> comparator(new Comparator()); | 603 scoped_ptr<LevelDBComparator> comparator(new Comparator()); |
| 659 scoped_ptr<LevelDBDatabase> db = | 604 scoped_ptr<LevelDBDatabase> db = |
| 660 LevelDBDatabase::OpenInMemory(comparator.get()); | 605 LevelDBDatabase::OpenInMemory(comparator.get()); |
| 661 if (!db) { | 606 if (!db) { |
| 662 LOG(ERROR) << "LevelDBDatabase::OpenInMemory failed."; | 607 LOG(ERROR) << "LevelDBDatabase::OpenInMemory failed."; |
| 663 base::Histogram::FactoryGet("WebCore.IndexedDB.BackingStore.OpenStatus", | 608 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_MEMORY_FAILED); |
| 664 1, | |
| 665 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX, | |
| 666 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX + 1, | |
| 667 base::HistogramBase::kUmaTargetedHistogramFlag) | |
| 668 ->Add(INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MEMORY_FAILED); | |
| 669 return scoped_refptr<IndexedDBBackingStore>(); | 609 return scoped_refptr<IndexedDBBackingStore>(); |
| 670 } | 610 } |
| 671 base::Histogram::FactoryGet("WebCore.IndexedDB.BackingStore.OpenStatus", | 611 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_MEMORY_SUCCESS); |
| 672 1, | |
| 673 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX, | |
| 674 INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MAX + 1, | |
| 675 base::HistogramBase::kUmaTargetedHistogramFlag) | |
| 676 ->Add(INDEXED_DB_LEVEL_DB_BACKING_STORE_OPEN_MEMORY_SUCCESS); | |
| 677 | 612 |
| 678 return Create(file_identifier, db.Pass(), comparator.Pass()); | 613 return Create(file_identifier, db.Pass(), comparator.Pass()); |
| 679 } | 614 } |
| 680 | 615 |
| 681 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Create( | 616 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Create( |
| 682 const std::string& identifier, | 617 const std::string& identifier, |
| 683 scoped_ptr<LevelDBDatabase> db, | 618 scoped_ptr<LevelDBDatabase> db, |
| 684 scoped_ptr<LevelDBComparator> comparator) { | 619 scoped_ptr<LevelDBComparator> comparator) { |
| 685 // TODO(jsbell): Handle comparator name changes. | 620 // TODO(jsbell): Handle comparator name changes. |
| 686 scoped_refptr<IndexedDBBackingStore> backing_store( | 621 scoped_refptr<IndexedDBBackingStore> backing_store( |
| (...skipping 1951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2638 } | 2573 } |
| 2639 | 2574 |
| 2640 void IndexedDBBackingStore::Transaction::Rollback() { | 2575 void IndexedDBBackingStore::Transaction::Rollback() { |
| 2641 IDB_TRACE("IndexedDBBackingStore::Transaction::Rollback"); | 2576 IDB_TRACE("IndexedDBBackingStore::Transaction::Rollback"); |
| 2642 DCHECK(transaction_.get()); | 2577 DCHECK(transaction_.get()); |
| 2643 transaction_->Rollback(); | 2578 transaction_->Rollback(); |
| 2644 transaction_ = NULL; | 2579 transaction_ = NULL; |
| 2645 } | 2580 } |
| 2646 | 2581 |
| 2647 } // namespace content | 2582 } // namespace content |
| OLD | NEW |