diff options
author | jsbell@chromium.org <jsbell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-28 18:29:44 +0000 |
---|---|---|
committer | jsbell@chromium.org <jsbell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-28 18:29:44 +0000 |
commit | d59df431e82bdb5f52063c33de3f0285aca71702 (patch) | |
tree | 5086a2f1654db68216a52939562d1508e353c7eb /content/browser/indexed_db | |
parent | fdf880110f423ffb7f6c654e252782a0e416e954 (diff) | |
download | chromium_src-d59df431e82bdb5f52063c33de3f0285aca71702.zip chromium_src-d59df431e82bdb5f52063c33de3f0285aca71702.tar.gz chromium_src-d59df431e82bdb5f52063c33de3f0285aca71702.tar.bz2 |
Revert 260147 "Handling LevelDB errors encountered after open."
The browser test is showing Mac ASAN failures.
> Handling LevelDB errors encountered after open.
>
> The previous IndexedDB implementation only checked for (and reported)
> corrupted LevelDB's during open. If they are determined to be corrupted
> during use then the database was simply closed. The page would be unaware of
> this, and would likely reopen the database at a later time (which would work)
> only to fail again during a read/write operation. There was no way for the
> page to get out of that corrupted state - the user would have to delete all
> origin data.
>
> This change will record the fact that the backing store was corrupted, and
> during open this would be read and, if present, result in the same dataLoss
> state being reported to the page in the upgradeneeded event.
>
> Also split IndexedDBBackingStore's REPORT_ERROR macro in two:
> REPORT_ERROR_UNTESTED (which calls NOTREACHED) and REPORT_ERROR. REPORT_ERROR
> is used for errors which are encountered during tests. This was done so that
> runtime errors could still be caught during a debug build run.
>
> BUG=322707
> R=isherman@chromium.org, jochen@chromium.org, jsbell@chromium.org
>
> Review URL: https://codereview.chromium.org/197333009
>
> Patch from Christopher Mumford <cmumford@chromium.org>.
TBR=jsbell@chromium.org
Review URL: https://codereview.chromium.org/216433007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260209 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/indexed_db')
9 files changed, 118 insertions, 445 deletions
diff --git a/content/browser/indexed_db/indexed_db_backing_store.cc b/content/browser/indexed_db/indexed_db_backing_store.cc index 089a03a..e78ec1b0 100644 --- a/content/browser/indexed_db/indexed_db_backing_store.cc +++ b/content/browser/indexed_db/indexed_db_backing_store.cc @@ -5,14 +5,10 @@ #include "content/browser/indexed_db/indexed_db_backing_store.h" #include "base/file_util.h" -#include "base/json/json_reader.h" -#include "base/json/json_writer.h" #include "base/logging.h" #include "base/metrics/histogram.h" -#include "base/platform_file.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" -#include "content/browser/indexed_db/indexed_db_database_error.h" #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" #include "content/browser/indexed_db/indexed_db_metadata.h" #include "content/browser/indexed_db/indexed_db_tracing.h" @@ -45,11 +41,6 @@ static base::FilePath ComputeFileName(const GURL& origin_url) { .AddExtension(FILE_PATH_LITERAL(".indexeddb.leveldb")); } -static base::FilePath ComputeCorruptionFileName(const GURL& origin_url) { - return ComputeFileName(origin_url) - .Append(FILE_PATH_LITERAL("corruption_info.json")); -} - } // namespace static const int64 kKeyGeneratorInitialNumber = @@ -93,12 +84,13 @@ static void RecordInternalError(const char* type, ->Add(location); } -// Use to signal conditions caused by data corruption. -// A macro is used instead of an inline function so that the assert and log -// report the line number. +// Use to signal conditions that usually indicate developer error, but +// could be caused by data corruption. A macro is used instead of an +// inline function so that the assert and log report the line number. #define REPORT_ERROR(type, location) \ do { \ LOG(ERROR) << "IndexedDB " type " Error: " #location; \ + NOTREACHED(); \ RecordInternalError(type, location); \ } while (0) @@ -107,25 +99,6 @@ static void RecordInternalError(const char* type, REPORT_ERROR("Consistency", location) #define INTERNAL_WRITE_ERROR(location) REPORT_ERROR("Write", location) -// Use to signal conditions that usually indicate developer error, but -// could be caused by data corruption. A macro is used instead of an -// inline function so that the assert and log report the line number. -// TODO: Improve test coverage so that all error conditions are "tested" and -// then delete this macro. -#define REPORT_ERROR_UNTESTED(type, location) \ - do { \ - LOG(ERROR) << "IndexedDB " type " Error: " #location; \ - NOTREACHED(); \ - RecordInternalError(type, location); \ - } while (0) - -#define INTERNAL_READ_ERROR_UNTESTED(location) \ - REPORT_ERROR_UNTESTED("Read", location) -#define INTERNAL_CONSISTENCY_ERROR_UNTESTED(location) \ - REPORT_ERROR_UNTESTED("Consistency", location) -#define INTERNAL_WRITE_ERROR_UNTESTED(location) \ - REPORT_ERROR_UNTESTED("Write", location) - static void PutBool(LevelDBTransaction* transaction, const StringPiece& key, bool value) { @@ -303,7 +276,7 @@ WARN_UNUSED_RESULT static bool SetUpMetadata( leveldb::Status s = GetInt(transaction.get(), schema_version_key, &db_schema_version, &found); if (!s.ok()) { - INTERNAL_READ_ERROR_UNTESTED(SET_UP_METADATA); + INTERNAL_READ_ERROR(SET_UP_METADATA); return false; } if (!found) { @@ -330,11 +303,11 @@ WARN_UNUSED_RESULT static bool SetUpMetadata( found = false; s = GetInt(transaction.get(), it->Key(), &database_id, &found); if (!s.ok()) { - INTERNAL_READ_ERROR_UNTESTED(SET_UP_METADATA); + INTERNAL_READ_ERROR(SET_UP_METADATA); return false; } if (!found) { - INTERNAL_CONSISTENCY_ERROR_UNTESTED(SET_UP_METADATA); + INTERNAL_CONSISTENCY_ERROR(SET_UP_METADATA); return false; } std::string int_version_key = DatabaseMetaDataKey::Encode( @@ -356,11 +329,11 @@ WARN_UNUSED_RESULT static bool SetUpMetadata( found = false; s = GetInt(transaction.get(), data_version_key, &db_data_version, &found); if (!s.ok()) { - INTERNAL_READ_ERROR_UNTESTED(SET_UP_METADATA); + INTERNAL_READ_ERROR(SET_UP_METADATA); return false; } if (!found) { - INTERNAL_CONSISTENCY_ERROR_UNTESTED(SET_UP_METADATA); + INTERNAL_CONSISTENCY_ERROR(SET_UP_METADATA); return false; } if (db_data_version < latest_known_data_version) { @@ -373,7 +346,7 @@ WARN_UNUSED_RESULT static bool SetUpMetadata( s = transaction->Commit(); if (!s.ok()) { - INTERNAL_WRITE_ERROR_UNTESTED(SET_UP_METADATA); + INTERNAL_WRITE_ERROR(SET_UP_METADATA); return false; } return true; @@ -464,7 +437,6 @@ enum IndexedDBBackingStoreOpenResult { INDEXED_DB_BACKING_STORE_OPEN_DISK_FULL_DEPRECATED, INDEXED_DB_BACKING_STORE_OPEN_ORIGIN_TOO_LONG, INDEXED_DB_BACKING_STORE_OPEN_NO_RECOVERY, - INDEXED_DB_BACKING_STORE_OPEN_FAILED_PRIOR_CORRUPTION, INDEXED_DB_BACKING_STORE_OPEN_MAX, }; @@ -541,91 +513,6 @@ static bool IsPathTooLong(const base::FilePath& leveldb_dir) { return false; } -leveldb::Status IndexedDBBackingStore::DestroyBackingStore( - const base::FilePath& path_base, - const GURL& origin_url) { - const base::FilePath file_path = - path_base.Append(ComputeFileName(origin_url)); - DefaultLevelDBFactory leveldb_factory; - return leveldb_factory.DestroyLevelDB(file_path); -} - -bool IndexedDBBackingStore::ReadCorruptionInfo(const base::FilePath& path_base, - const GURL& origin_url, - std::string& message) { - - const base::FilePath info_path = - path_base.Append(ComputeCorruptionFileName(origin_url)); - - if (IsPathTooLong(info_path)) - return false; - - const int64 max_json_len = 4096; - int64 file_size(0); - if (!GetFileSize(info_path, &file_size) || file_size > max_json_len) - return false; - if (!file_size) { - NOTREACHED(); - return false; - } - - bool created(false); - base::PlatformFileError error(base::PLATFORM_FILE_OK); - base::PlatformFile file = base::CreatePlatformFile( - info_path, - base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, - &created, - &error); - bool success = false; - if (file) { - std::vector<char> bytes(file_size); - if (file_size == base::ReadPlatformFile(file, 0, &bytes[0], file_size)) { - std::string input_js(&bytes[0], file_size); - base::JSONReader reader; - scoped_ptr<base::Value> val(reader.ReadToValue(input_js)); - if (val && val->GetType() == base::Value::TYPE_DICTIONARY) { - base::DictionaryValue* dict_val = - static_cast<base::DictionaryValue*>(val.get()); - success = dict_val->GetString("message", &message); - } - } - base::ClosePlatformFile(file); - } - - base::DeleteFile(info_path, false); - - return success; -} - -bool IndexedDBBackingStore::RecordCorruptionInfo( - const base::FilePath& path_base, - const GURL& origin_url, - const std::string& message) { - const base::FilePath info_path = - path_base.Append(ComputeCorruptionFileName(origin_url)); - if (IsPathTooLong(info_path)) - return false; - - base::DictionaryValue root_dict; - root_dict.SetString("message", message); - std::string output_js; - base::JSONWriter::Write(&root_dict, &output_js); - - bool created(false); - base::PlatformFileError error(base::PLATFORM_FILE_OK); - base::PlatformFile file = base::CreatePlatformFile( - info_path, - base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE, - &created, - &error); - if (!file) - return false; - int written = - base::WritePlatformFile(file, 0, output_js.c_str(), output_js.length()); - base::ClosePlatformFile(file); - return size_t(written) == output_js.length(); -} - // static scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open( const GURL& origin_url, @@ -679,17 +566,8 @@ scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open( bool is_schema_known = false; if (db) { - std::string corruption_message; - if (ReadCorruptionInfo(path_base, origin_url, corruption_message)) { - LOG(ERROR) << "IndexedDB recovering from a corrupted (and deleted) " - "database."; - HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_FAILED_PRIOR_CORRUPTION, - origin_url); - db.reset(); - *data_loss = blink::WebIDBDataLossTotal; - *data_loss_message = - "IndexedDB (database was corrupt): " + corruption_message; - } else if (!IsSchemaKnown(db.get(), &is_schema_known)) { + bool ok = IsSchemaKnown(db.get(), &is_schema_known); + if (!ok) { LOG(ERROR) << "IndexedDB had IO error checking schema, treating it as " "failure to open"; HistogramOpenStatus( @@ -811,7 +689,7 @@ std::vector<base::string16> IndexedDBBackingStore::GetDatabaseNames() { StringPiece slice(it->Key()); DatabaseNameKey database_name_key; if (!DatabaseNameKey::Decode(&slice, &database_name_key)) { - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_DATABASE_NAMES); + INTERNAL_CONSISTENCY_ERROR(GET_DATABASE_NAMES); continue; } found_names.push_back(database_name_key.database_name()); @@ -828,7 +706,7 @@ leveldb::Status IndexedDBBackingStore::GetIDBDatabaseMetaData( leveldb::Status s = GetInt(db_.get(), key, &metadata->id, found); if (!s.ok()) { - INTERNAL_READ_ERROR_UNTESTED(GET_IDBDATABASE_METADATA); + INTERNAL_READ_ERROR(GET_IDBDATABASE_METADATA); return s; } if (!*found) @@ -840,11 +718,11 @@ leveldb::Status IndexedDBBackingStore::GetIDBDatabaseMetaData( &metadata->version, found); if (!s.ok()) { - INTERNAL_READ_ERROR_UNTESTED(GET_IDBDATABASE_METADATA); + INTERNAL_READ_ERROR(GET_IDBDATABASE_METADATA); return s; } if (!*found) { - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_IDBDATABASE_METADATA); + INTERNAL_CONSISTENCY_ERROR(GET_IDBDATABASE_METADATA); return InternalInconsistencyStatus(); } @@ -854,11 +732,11 @@ leveldb::Status IndexedDBBackingStore::GetIDBDatabaseMetaData( &metadata->int_version, found); if (!s.ok()) { - INTERNAL_READ_ERROR_UNTESTED(GET_IDBDATABASE_METADATA); + INTERNAL_READ_ERROR(GET_IDBDATABASE_METADATA); return s; } if (!*found) { - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_IDBDATABASE_METADATA); + INTERNAL_CONSISTENCY_ERROR(GET_IDBDATABASE_METADATA); return InternalInconsistencyStatus(); } @@ -868,7 +746,7 @@ leveldb::Status IndexedDBBackingStore::GetIDBDatabaseMetaData( s = GetMaxObjectStoreId( db_.get(), metadata->id, &metadata->max_object_store_id); if (!s.ok()) { - INTERNAL_READ_ERROR_UNTESTED(GET_IDBDATABASE_METADATA); + INTERNAL_READ_ERROR(GET_IDBDATABASE_METADATA); } return s; @@ -883,7 +761,7 @@ WARN_UNUSED_RESULT static leveldb::Status GetNewDatabaseId( leveldb::Status s = GetInt(transaction, MaxDatabaseIdKey::Encode(), &max_database_id, &found); if (!s.ok()) { - INTERNAL_READ_ERROR_UNTESTED(GET_NEW_DATABASE_ID); + INTERNAL_READ_ERROR(GET_NEW_DATABASE_ID); return s; } if (!found) @@ -926,7 +804,7 @@ leveldb::Status IndexedDBBackingStore::CreateIDBDatabaseMetaData( int_version); s = transaction->Commit(); if (!s.ok()) - INTERNAL_WRITE_ERROR_UNTESTED(CREATE_IDBDATABASE_METADATA); + INTERNAL_WRITE_ERROR(CREATE_IDBDATABASE_METADATA); return s; } @@ -982,7 +860,7 @@ leveldb::Status IndexedDBBackingStore::DeleteDatabase( s = transaction->Commit(); if (!s.ok()) { - INTERNAL_WRITE_ERROR_UNTESTED(DELETE_DATABASE); + INTERNAL_WRITE_ERROR(DELETE_DATABASE); return s; } db_->Compact(start_key, stop_key); @@ -1030,7 +908,7 @@ leveldb::Status IndexedDBBackingStore::GetObjectStores( bool ok = ObjectStoreMetaDataKey::Decode(&slice, &meta_data_key); DCHECK(ok); if (meta_data_key.MetaDataType() != ObjectStoreMetaDataKey::NAME) { - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_OBJECT_STORES); + INTERNAL_CONSISTENCY_ERROR(GET_OBJECT_STORES); // Possible stale metadata, but don't fail the load. it->Next(); continue; @@ -1044,7 +922,7 @@ leveldb::Status IndexedDBBackingStore::GetObjectStores( { StringPiece slice(it->Value()); if (!DecodeString(&slice, &object_store_name) || !slice.empty()) - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_OBJECT_STORES); + INTERNAL_CONSISTENCY_ERROR(GET_OBJECT_STORES); } it->Next(); @@ -1052,14 +930,14 @@ leveldb::Status IndexedDBBackingStore::GetObjectStores( stop_key, object_store_id, ObjectStoreMetaDataKey::KEY_PATH)) { - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_OBJECT_STORES); + INTERNAL_CONSISTENCY_ERROR(GET_OBJECT_STORES); break; } IndexedDBKeyPath key_path; { StringPiece slice(it->Value()); if (!DecodeIDBKeyPath(&slice, &key_path) || !slice.empty()) - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_OBJECT_STORES); + INTERNAL_CONSISTENCY_ERROR(GET_OBJECT_STORES); } it->Next(); @@ -1068,14 +946,14 @@ leveldb::Status IndexedDBBackingStore::GetObjectStores( stop_key, object_store_id, ObjectStoreMetaDataKey::AUTO_INCREMENT)) { - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_OBJECT_STORES); + INTERNAL_CONSISTENCY_ERROR(GET_OBJECT_STORES); break; } bool auto_increment; { StringPiece slice(it->Value()); if (!DecodeBool(&slice, &auto_increment) || !slice.empty()) - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_OBJECT_STORES); + INTERNAL_CONSISTENCY_ERROR(GET_OBJECT_STORES); } it->Next(); // Is evicatble. @@ -1083,7 +961,7 @@ leveldb::Status IndexedDBBackingStore::GetObjectStores( stop_key, object_store_id, ObjectStoreMetaDataKey::EVICTABLE)) { - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_OBJECT_STORES); + INTERNAL_CONSISTENCY_ERROR(GET_OBJECT_STORES); break; } @@ -1093,7 +971,7 @@ leveldb::Status IndexedDBBackingStore::GetObjectStores( stop_key, object_store_id, ObjectStoreMetaDataKey::LAST_VERSION)) { - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_OBJECT_STORES); + INTERNAL_CONSISTENCY_ERROR(GET_OBJECT_STORES); break; } @@ -1103,14 +981,14 @@ leveldb::Status IndexedDBBackingStore::GetObjectStores( stop_key, object_store_id, ObjectStoreMetaDataKey::MAX_INDEX_ID)) { - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_OBJECT_STORES); + INTERNAL_CONSISTENCY_ERROR(GET_OBJECT_STORES); break; } int64 max_index_id; { StringPiece slice(it->Value()); if (!DecodeInt(&slice, &max_index_id) || !slice.empty()) - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_OBJECT_STORES); + INTERNAL_CONSISTENCY_ERROR(GET_OBJECT_STORES); } it->Next(); // [optional] has key path (is not null) @@ -1122,7 +1000,7 @@ leveldb::Status IndexedDBBackingStore::GetObjectStores( { StringPiece slice(it->Value()); if (!DecodeBool(&slice, &has_key_path)) - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_OBJECT_STORES); + INTERNAL_CONSISTENCY_ERROR(GET_OBJECT_STORES); } // This check accounts for two layers of legacy coding: // (1) Initially, has_key_path was added to distinguish null vs. string. @@ -1131,7 +1009,7 @@ leveldb::Status IndexedDBBackingStore::GetObjectStores( if (!has_key_path && (key_path.type() == blink::WebIDBKeyPathTypeString && !key_path.string().empty())) { - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_OBJECT_STORES); + INTERNAL_CONSISTENCY_ERROR(GET_OBJECT_STORES); break; } if (!has_key_path) @@ -1147,7 +1025,7 @@ leveldb::Status IndexedDBBackingStore::GetObjectStores( ObjectStoreMetaDataKey::KEY_GENERATOR_CURRENT_NUMBER)) { StringPiece slice(it->Value()); if (!DecodeInt(&slice, &key_generator_current_number) || !slice.empty()) - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_OBJECT_STORES); + INTERNAL_CONSISTENCY_ERROR(GET_OBJECT_STORES); // TODO(jsbell): Return key_generator_current_number, cache in // object store, and write lazily to backing store. For now, @@ -1180,20 +1058,18 @@ WARN_UNUSED_RESULT static leveldb::Status SetMaxObjectStoreId( leveldb::Status s = GetMaxObjectStoreId( transaction, max_object_store_id_key, &max_object_store_id); if (!s.ok()) { - INTERNAL_READ_ERROR_UNTESTED(SET_MAX_OBJECT_STORE_ID); + INTERNAL_READ_ERROR(SET_MAX_OBJECT_STORE_ID); return s; } if (object_store_id <= max_object_store_id) { - INTERNAL_CONSISTENCY_ERROR_UNTESTED(SET_MAX_OBJECT_STORE_ID); + INTERNAL_CONSISTENCY_ERROR(SET_MAX_OBJECT_STORE_ID); return InternalInconsistencyStatus(); } PutInt(transaction, max_object_store_id_key, object_store_id); return s; } -void IndexedDBBackingStore::Compact() { db_->CompactAll(); } - leveldb::Status IndexedDBBackingStore::CreateObjectStore( IndexedDBBackingStore::Transaction* transaction, int64 database_id, @@ -1263,11 +1139,11 @@ leveldb::Status IndexedDBBackingStore::DeleteObjectStore( &object_store_name, &found); if (!s.ok()) { - INTERNAL_READ_ERROR_UNTESTED(DELETE_OBJECT_STORE); + INTERNAL_READ_ERROR(DELETE_OBJECT_STORE); return s; } if (!found) { - INTERNAL_CONSISTENCY_ERROR_UNTESTED(DELETE_OBJECT_STORE); + INTERNAL_CONSISTENCY_ERROR(DELETE_OBJECT_STORE); return InternalInconsistencyStatus(); } @@ -1315,14 +1191,14 @@ leveldb::Status IndexedDBBackingStore::GetRecord( if (!found) return s; if (data.empty()) { - INTERNAL_READ_ERROR_UNTESTED(GET_RECORD); + INTERNAL_READ_ERROR(GET_RECORD); return leveldb::Status::NotFound("Record contained no data"); } int64 version; StringPiece slice(data); if (!DecodeVarInt(&slice, &version)) { - INTERNAL_READ_ERROR_UNTESTED(GET_RECORD); + INTERNAL_READ_ERROR(GET_RECORD); return InternalInconsistencyStatus(); } @@ -1344,7 +1220,7 @@ WARN_UNUSED_RESULT static leveldb::Status GetNewVersionNumber( leveldb::Status s = GetInt(transaction, last_version_key, &last_version, &found); if (!s.ok()) { - INTERNAL_READ_ERROR_UNTESTED(GET_NEW_VERSION_NUMBER); + INTERNAL_READ_ERROR(GET_NEW_VERSION_NUMBER); return s; } if (!found) @@ -1460,13 +1336,13 @@ leveldb::Status IndexedDBBackingStore::GetKeyGeneratorCurrentNumber( leveldb::Status s = leveldb_transaction->Get(key_generator_current_number_key, &data, &found); if (!s.ok()) { - INTERNAL_READ_ERROR_UNTESTED(GET_KEY_GENERATOR_CURRENT_NUMBER); + INTERNAL_READ_ERROR(GET_KEY_GENERATOR_CURRENT_NUMBER); return s; } if (found && !data.empty()) { StringPiece slice(data); if (!DecodeInt(&slice, key_generator_current_number) || !slice.empty()) { - INTERNAL_READ_ERROR_UNTESTED(GET_KEY_GENERATOR_CURRENT_NUMBER); + INTERNAL_READ_ERROR(GET_KEY_GENERATOR_CURRENT_NUMBER); return InternalInconsistencyStatus(); } return s; @@ -1491,7 +1367,7 @@ leveldb::Status IndexedDBBackingStore::GetKeyGeneratorCurrentNumber( StringPiece slice(it->Key()); ObjectStoreDataKey data_key; if (!ObjectStoreDataKey::Decode(&slice, &data_key)) { - INTERNAL_READ_ERROR_UNTESTED(GET_KEY_GENERATOR_CURRENT_NUMBER); + INTERNAL_READ_ERROR(GET_KEY_GENERATOR_CURRENT_NUMBER); return InternalInconsistencyStatus(); } scoped_ptr<IndexedDBKey> user_key = data_key.user_key(); @@ -1553,13 +1429,13 @@ leveldb::Status IndexedDBBackingStore::KeyExistsInObjectStore( leveldb::Status s = transaction->transaction()->Get(leveldb_key, &data, found); if (!s.ok()) { - INTERNAL_READ_ERROR_UNTESTED(KEY_EXISTS_IN_OBJECT_STORE); + INTERNAL_READ_ERROR(KEY_EXISTS_IN_OBJECT_STORE); return s; } if (!*found) return leveldb::Status::OK(); if (!data.size()) { - INTERNAL_READ_ERROR_UNTESTED(KEY_EXISTS_IN_OBJECT_STORE); + INTERNAL_READ_ERROR(KEY_EXISTS_IN_OBJECT_STORE); return InternalInconsistencyStatus(); } @@ -1616,7 +1492,7 @@ leveldb::Status IndexedDBBackingStore::GetIndexes( bool ok = IndexMetaDataKey::Decode(&slice, &meta_data_key); DCHECK(ok); if (meta_data_key.meta_data_type() != IndexMetaDataKey::NAME) { - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_INDEXES); + INTERNAL_CONSISTENCY_ERROR(GET_INDEXES); // Possible stale metadata due to http://webkit.org/b/85557 but don't fail // the load. it->Next(); @@ -1630,33 +1506,33 @@ leveldb::Status IndexedDBBackingStore::GetIndexes( { StringPiece slice(it->Value()); if (!DecodeString(&slice, &index_name) || !slice.empty()) - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_INDEXES); + INTERNAL_CONSISTENCY_ERROR(GET_INDEXES); } it->Next(); // unique flag if (!CheckIndexAndMetaDataKey( it.get(), stop_key, index_id, IndexMetaDataKey::UNIQUE)) { - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_INDEXES); + INTERNAL_CONSISTENCY_ERROR(GET_INDEXES); break; } bool index_unique; { StringPiece slice(it->Value()); if (!DecodeBool(&slice, &index_unique) || !slice.empty()) - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_INDEXES); + INTERNAL_CONSISTENCY_ERROR(GET_INDEXES); } it->Next(); // key_path if (!CheckIndexAndMetaDataKey( it.get(), stop_key, index_id, IndexMetaDataKey::KEY_PATH)) { - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_INDEXES); + INTERNAL_CONSISTENCY_ERROR(GET_INDEXES); break; } IndexedDBKeyPath key_path; { StringPiece slice(it->Value()); if (!DecodeIDBKeyPath(&slice, &key_path) || !slice.empty()) - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_INDEXES); + INTERNAL_CONSISTENCY_ERROR(GET_INDEXES); } it->Next(); // [optional] multi_entry flag @@ -1665,7 +1541,7 @@ leveldb::Status IndexedDBBackingStore::GetIndexes( it.get(), stop_key, index_id, IndexMetaDataKey::MULTI_ENTRY)) { StringPiece slice(it->Value()); if (!DecodeBool(&slice, &index_multi_entry) || !slice.empty()) - INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_INDEXES); + INTERNAL_CONSISTENCY_ERROR(GET_INDEXES); it->Next(); } @@ -1688,14 +1564,14 @@ WARN_UNUSED_RESULT static leveldb::Status SetMaxIndexId( leveldb::Status s = GetInt(transaction, max_index_id_key, &max_index_id, &found); if (!s.ok()) { - INTERNAL_READ_ERROR_UNTESTED(SET_MAX_INDEX_ID); + INTERNAL_READ_ERROR(SET_MAX_INDEX_ID); return s; } if (!found) max_index_id = kMinimumIndexId; if (index_id <= max_index_id) { - INTERNAL_CONSISTENCY_ERROR_UNTESTED(SET_MAX_INDEX_ID); + INTERNAL_CONSISTENCY_ERROR(SET_MAX_INDEX_ID); return InternalInconsistencyStatus(); } @@ -1833,7 +1709,7 @@ static leveldb::Status VersionExists(LevelDBTransaction* transaction, leveldb::Status s = transaction->Get(key, &data, exists); if (!s.ok()) { - INTERNAL_READ_ERROR_UNTESTED(VERSION_EXISTS); + INTERNAL_READ_ERROR(VERSION_EXISTS); return s; } if (!*exists) @@ -1877,7 +1753,7 @@ leveldb::Status IndexedDBBackingStore::FindKeyInIndex( int64 version; if (!DecodeVarInt(&slice, &version)) { - INTERNAL_READ_ERROR_UNTESTED(FIND_KEY_IN_INDEX); + INTERNAL_READ_ERROR(FIND_KEY_IN_INDEX); return InternalInconsistencyStatus(); } *found_encoded_primary_key = slice.as_string(); @@ -1923,13 +1799,13 @@ leveldb::Status IndexedDBBackingStore::GetPrimaryKeyViaIndex( &found_encoded_primary_key, &found); if (!s.ok()) { - INTERNAL_READ_ERROR_UNTESTED(GET_PRIMARY_KEY_VIA_INDEX); + INTERNAL_READ_ERROR(GET_PRIMARY_KEY_VIA_INDEX); return s; } if (!found) return s; if (!found_encoded_primary_key.size()) { - INTERNAL_READ_ERROR_UNTESTED(GET_PRIMARY_KEY_VIA_INDEX); + INTERNAL_READ_ERROR(GET_PRIMARY_KEY_VIA_INDEX); return InvalidDBKeyStatus(); } @@ -1962,13 +1838,13 @@ leveldb::Status IndexedDBBackingStore::KeyExistsInIndex( &found_encoded_primary_key, exists); if (!s.ok()) { - INTERNAL_READ_ERROR_UNTESTED(KEY_EXISTS_IN_INDEX); + INTERNAL_READ_ERROR(KEY_EXISTS_IN_INDEX); return s; } if (!*exists) return leveldb::Status::OK(); if (found_encoded_primary_key.empty()) { - INTERNAL_READ_ERROR_UNTESTED(KEY_EXISTS_IN_INDEX); + INTERNAL_READ_ERROR(KEY_EXISTS_IN_INDEX); return InvalidDBKeyStatus(); } @@ -2211,7 +2087,7 @@ bool ObjectStoreKeyCursorImpl::LoadCurrentRow() { StringPiece slice(iterator_->Key()); ObjectStoreDataKey object_store_data_key; if (!ObjectStoreDataKey::Decode(&slice, &object_store_data_key)) { - INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); + INTERNAL_READ_ERROR(LOAD_CURRENT_ROW); return false; } @@ -2220,7 +2096,7 @@ bool ObjectStoreKeyCursorImpl::LoadCurrentRow() { int64 version; slice = StringPiece(iterator_->Value()); if (!DecodeVarInt(&slice, &version)) { - INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); + INTERNAL_READ_ERROR(LOAD_CURRENT_ROW); return false; } @@ -2268,7 +2144,7 @@ bool ObjectStoreCursorImpl::LoadCurrentRow() { StringPiece key_slice(iterator_->Key()); ObjectStoreDataKey object_store_data_key; if (!ObjectStoreDataKey::Decode(&key_slice, &object_store_data_key)) { - INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); + INTERNAL_READ_ERROR(LOAD_CURRENT_ROW); return false; } @@ -2277,7 +2153,7 @@ bool ObjectStoreCursorImpl::LoadCurrentRow() { int64 version; StringPiece value_slice = StringPiece(iterator_->Value()); if (!DecodeVarInt(&value_slice, &version)) { - INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); + INTERNAL_READ_ERROR(LOAD_CURRENT_ROW); return false; } @@ -2342,7 +2218,7 @@ bool IndexKeyCursorImpl::LoadCurrentRow() { StringPiece slice(iterator_->Key()); IndexDataKey index_data_key; if (!IndexDataKey::Decode(&slice, &index_data_key)) { - INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); + INTERNAL_READ_ERROR(LOAD_CURRENT_ROW); return false; } @@ -2352,12 +2228,12 @@ bool IndexKeyCursorImpl::LoadCurrentRow() { slice = StringPiece(iterator_->Value()); int64 index_data_version; if (!DecodeVarInt(&slice, &index_data_version)) { - INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); + INTERNAL_READ_ERROR(LOAD_CURRENT_ROW); return false; } if (!DecodeIDBKey(&slice, &primary_key_) || !slice.empty()) { - INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); + INTERNAL_READ_ERROR(LOAD_CURRENT_ROW); return false; } @@ -2370,7 +2246,7 @@ bool IndexKeyCursorImpl::LoadCurrentRow() { bool found = false; leveldb::Status s = transaction_->Get(primary_leveldb_key, &result, &found); if (!s.ok()) { - INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); + INTERNAL_READ_ERROR(LOAD_CURRENT_ROW); return false; } if (!found) { @@ -2378,14 +2254,14 @@ bool IndexKeyCursorImpl::LoadCurrentRow() { return false; } if (!result.size()) { - INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); + INTERNAL_READ_ERROR(LOAD_CURRENT_ROW); return false; } int64 object_store_data_version; slice = StringPiece(result); if (!DecodeVarInt(&slice, &object_store_data_version)) { - INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); + INTERNAL_READ_ERROR(LOAD_CURRENT_ROW); return false; } @@ -2450,7 +2326,7 @@ bool IndexCursorImpl::LoadCurrentRow() { StringPiece slice(iterator_->Key()); IndexDataKey index_data_key; if (!IndexDataKey::Decode(&slice, &index_data_key)) { - INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); + INTERNAL_READ_ERROR(LOAD_CURRENT_ROW); return false; } @@ -2460,11 +2336,11 @@ bool IndexCursorImpl::LoadCurrentRow() { slice = StringPiece(iterator_->Value()); int64 index_data_version; if (!DecodeVarInt(&slice, &index_data_version)) { - INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); + INTERNAL_READ_ERROR(LOAD_CURRENT_ROW); return false; } if (!DecodeIDBKey(&slice, &primary_key_)) { - INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); + INTERNAL_READ_ERROR(LOAD_CURRENT_ROW); return false; } @@ -2477,7 +2353,7 @@ bool IndexCursorImpl::LoadCurrentRow() { bool found = false; leveldb::Status s = transaction_->Get(primary_leveldb_key_, &result, &found); if (!s.ok()) { - INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); + INTERNAL_READ_ERROR(LOAD_CURRENT_ROW); return false; } if (!found) { @@ -2485,14 +2361,14 @@ bool IndexCursorImpl::LoadCurrentRow() { return false; } if (!result.size()) { - INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); + INTERNAL_READ_ERROR(LOAD_CURRENT_ROW); return false; } int64 object_store_data_version; slice = StringPiece(result); if (!DecodeVarInt(&slice, &object_store_data_version)) { - INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); + INTERNAL_READ_ERROR(LOAD_CURRENT_ROW); return false; } @@ -2763,7 +2639,7 @@ leveldb::Status IndexedDBBackingStore::Transaction::Commit() { leveldb::Status s = transaction_->Commit(); transaction_ = NULL; if (!s.ok()) - INTERNAL_WRITE_ERROR_UNTESTED(TRANSACTION_COMMIT_METHOD); + INTERNAL_WRITE_ERROR(TRANSACTION_COMMIT_METHOD); return s; } diff --git a/content/browser/indexed_db/indexed_db_backing_store.h b/content/browser/indexed_db/indexed_db_backing_store.h index 25e4126..e7aa21e 100644 --- a/content/browser/indexed_db/indexed_db_backing_store.h +++ b/content/browser/indexed_db/indexed_db_backing_store.h @@ -27,7 +27,6 @@ namespace content { -class IndexedDBDatabaseError; class LevelDBComparator; class LevelDBDatabase; struct IndexedDBValue; @@ -79,7 +78,6 @@ class CONTENT_EXPORT IndexedDBBackingStore const GURL& origin_url, LevelDBFactory* factory); - virtual void Compact(); virtual std::vector<base::string16> GetDatabaseNames(); virtual leveldb::Status GetIDBDatabaseMetaData( const base::string16& name, @@ -96,12 +94,6 @@ class CONTENT_EXPORT IndexedDBBackingStore int64 int_version); virtual leveldb::Status DeleteDatabase(const base::string16& name); - // Assumes caller has already closed the backing store. - static leveldb::Status DestroyBackingStore(const base::FilePath& path_base, - const GURL& origin_url); - static bool RecordCorruptionInfo(const base::FilePath& path_base, - const GURL& origin_url, - const std::string& message); leveldb::Status GetObjectStores( int64 database_id, IndexedDBDatabaseMetadata::ObjectStoreMap* map) WARN_UNUSED_RESULT; @@ -333,9 +325,6 @@ class CONTENT_EXPORT IndexedDBBackingStore const GURL& origin_url, scoped_ptr<LevelDBDatabase> db, scoped_ptr<LevelDBComparator> comparator); - static bool ReadCorruptionInfo(const base::FilePath& path_base, - const GURL& origin_url, - std::string& message); leveldb::Status FindKeyInIndex( IndexedDBBackingStore::Transaction* transaction, diff --git a/content/browser/indexed_db/indexed_db_browsertest.cc b/content/browser/indexed_db/indexed_db_browsertest.cc index 9bd83f0..478a07b 100644 --- a/content/browser/indexed_db/indexed_db_browsertest.cc +++ b/content/browser/indexed_db/indexed_db_browsertest.cc @@ -5,7 +5,6 @@ #include "base/bind.h" #include "base/command_line.h" #include "base/file_util.h" -#include "base/files/file_enumerator.h" #include "base/files/file_path.h" #include "base/memory/ref_counted.h" #include "base/message_loop/message_loop.h" @@ -25,10 +24,6 @@ #include "content/public/test/content_browser_test.h" #include "content/public/test/content_browser_test_utils.h" #include "content/shell/browser/shell.h" -#include "net/base/net_errors.h" -#include "net/test/embedded_test_server/embedded_test_server.h" -#include "net/test/embedded_test_server/http_request.h" -#include "net/test/embedded_test_server/http_response.h" #include "webkit/browser/database/database_util.h" #include "webkit/browser/quota/quota_manager.h" @@ -361,134 +356,6 @@ IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, CanDeleteWhenOverQuotaTest) { SimpleTest(GetTestUrl("indexeddb", "delete_over_quota.html")); } -namespace { - -static void CompactIndexedDBBackingStore( - scoped_refptr<IndexedDBContextImpl> context, - const GURL& origin_url) { - IndexedDBFactory* factory = context->GetIDBFactory(); - - std::pair<IndexedDBFactory::OriginDBMapIterator, - IndexedDBFactory::OriginDBMapIterator> range = - factory->GetOpenDatabasesForOrigin(origin_url); - - if (range.first == range.second) // If no open db's for this origin - return; - - // Compact the first db's backing store since all the db's are in the same - // backing store. - IndexedDBDatabase* db = range.first->second; - IndexedDBBackingStore* backing_store = db->backing_store(); - backing_store->Compact(); -} - -static void CorruptIndexedDBDatabase( - IndexedDBContextImpl* context, - const GURL& origin_url, - base::WaitableEvent* signal_when_finished) { - - CompactIndexedDBBackingStore(context, origin_url); - - int numFiles = 0; - int numErrors = 0; - base::FilePath idb_data_path = context->GetFilePath(origin_url); - const bool recursive = false; - base::FileEnumerator enumerator( - idb_data_path, recursive, base::FileEnumerator::FILES); - for (base::FilePath idb_file = enumerator.Next(); !idb_file.empty(); - idb_file = enumerator.Next()) { - int64 size(0); - GetFileSize(idb_file, &size); - - if (idb_file.Extension() == FILE_PATH_LITERAL(".ldb")) { - numFiles++; - base::ScopedFILE f(base::OpenFile(idb_file, "w")); - if (f) { - char zero(0); - if (size != (int64)fwrite(&zero, sizeof(zero), size, f.get())) - numErrors++; - } else { - numErrors++; - } - } - } - - VLOG(0) << "There were " << numFiles << " in " << idb_data_path.value() - << " with " << numErrors << " errors"; - signal_when_finished->Signal(); -} - -const std::string s_corrupt_db_test_prefix = "/corrupt/test/"; - -static scoped_ptr<net::test_server::HttpResponse> CorruptDBRequestHandler( - IndexedDBContextImpl* context, - const GURL& origin_url, - const std::string& path, - const net::test_server::HttpRequest& request) { - - std::string request_path; - if (path.find(s_corrupt_db_test_prefix) != std::string::npos) - request_path = request.relative_url.substr(s_corrupt_db_test_prefix.size()); - else - return scoped_ptr<net::test_server::HttpResponse>(); - - // Remove the query string if present. - std::string request_query; - size_t query_pos = request_path.find('?'); - if (query_pos != std::string::npos) { - request_query = request_path.substr(query_pos + 1); - request_path = request_path.substr(0, query_pos); - } - - if (request_path == "corruptdb" && !request_query.empty()) { - VLOG(0) << "Requested to corrupt IndexedDB: " << request_query; - base::WaitableEvent signal_when_finished(false, false); - context->TaskRunner()->PostTask(FROM_HERE, - base::Bind(&CorruptIndexedDBDatabase, - base::ConstRef(context), - origin_url, - &signal_when_finished)); - signal_when_finished.Wait(); - - scoped_ptr<net::test_server::BasicHttpResponse> http_response( - new net::test_server::BasicHttpResponse); - http_response->set_code(net::HTTP_OK); - return http_response.PassAs<net::test_server::HttpResponse>(); - } - - // A request for a test resource - base::FilePath resourcePath = - content::GetTestFilePath("indexeddb", request_path.c_str()); - scoped_ptr<net::test_server::BasicHttpResponse> http_response( - new net::test_server::BasicHttpResponse); - http_response->set_code(net::HTTP_OK); - std::string file_contents; - if (!base::ReadFileToString(resourcePath, &file_contents)) - return scoped_ptr<net::test_server::HttpResponse>(); - http_response->set_content(file_contents); - return http_response.PassAs<net::test_server::HttpResponse>(); -} - -} // namespace - -IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, CorruptedOpenDatabase) { - ASSERT_TRUE(embedded_test_server()->Started() || - embedded_test_server()->InitializeAndWaitUntilReady()); - const GURL& origin_url = embedded_test_server()->base_url(); - embedded_test_server()->RegisterRequestHandler( - base::Bind(&CorruptDBRequestHandler, - base::ConstRef(GetContext()), - origin_url, - s_corrupt_db_test_prefix)); - - std::string test_file = - s_corrupt_db_test_prefix + "corrupted_open_db_detection.html"; - SimpleTest(embedded_test_server()->GetURL(test_file)); - - test_file = s_corrupt_db_test_prefix + "corrupted_open_db_recovery.html"; - SimpleTest(embedded_test_server()->GetURL(test_file)); -} - IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, DeleteCompactsBackingStore) { const GURL test_url = GetTestUrl("indexeddb", "delete_compact.html"); SimpleTest(GURL(test_url.spec() + "#fill")); @@ -582,7 +449,6 @@ IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, ForceCloseEventTest) { base::string16 expected_title16(ASCIIToUTF16("connection closed")); TitleWatcher title_watcher(shell()->web_contents(), expected_title16); - title_watcher.AlsoWaitForTitle(ASCIIToUTF16("connection closed with error")); EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); } diff --git a/content/browser/indexed_db/indexed_db_database.cc b/content/browser/indexed_db/indexed_db_database.cc index c97048b..839d7af 100644 --- a/content/browser/indexed_db/indexed_db_database.cc +++ b/content/browser/indexed_db/indexed_db_database.cc @@ -14,7 +14,6 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" #include "content/browser/indexed_db/indexed_db_connection.h" -#include "content/browser/indexed_db/indexed_db_context_impl.h" #include "content/browser/indexed_db/indexed_db_cursor.h" #include "content/browser/indexed_db/indexed_db_factory.h" #include "content/browser/indexed_db/indexed_db_index_writer.h" @@ -295,22 +294,17 @@ void IndexedDBDatabase::CreateObjectStoreOperation( const IndexedDBObjectStoreMetadata& object_store_metadata, IndexedDBTransaction* transaction) { IDB_TRACE("IndexedDBDatabase::CreateObjectStoreOperation"); - leveldb::Status s = - backing_store_->CreateObjectStore(transaction->BackingStoreTransaction(), - transaction->database()->id(), - object_store_metadata.id, - object_store_metadata.name, - object_store_metadata.key_path, - object_store_metadata.auto_increment); - if (!s.ok()) { - IndexedDBDatabaseError error( + if (!backing_store_->CreateObjectStore( + transaction->BackingStoreTransaction(), + transaction->database()->id(), + object_store_metadata.id, + object_store_metadata.name, + object_store_metadata.key_path, + object_store_metadata.auto_increment).ok()) { + transaction->Abort(IndexedDBDatabaseError( blink::WebIDBDatabaseExceptionUnknownError, ASCIIToUTF16("Internal error creating object store '") + - object_store_metadata.name + ASCIIToUTF16("'.")); - transaction->Abort(error); - if (s.IsCorruption()) - factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), - error); + object_store_metadata.name + ASCIIToUTF16("'."))); return; } } @@ -442,12 +436,8 @@ void IndexedDBDatabase::DeleteIndexOperation( base::string16 error_string = ASCIIToUTF16("Internal error deleting index '") + index_metadata.name + ASCIIToUTF16("'."); - IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, - error_string); - transaction->Abort(error); - if (s.IsCorruption()) - factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), - error); + transaction->Abort(IndexedDBDatabaseError( + blink::WebIDBDatabaseExceptionUnknownError, error_string)); } } @@ -579,13 +569,9 @@ void IndexedDBDatabase::GetOperation( *key, &value); if (!s.ok()) { - IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, - "Internal error in GetRecord."); - callbacks->OnError(error); - - if (s.IsCorruption()) - factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), - error); + callbacks->OnError( + IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, + "Internal error in GetRecord.")); return; } @@ -613,12 +599,9 @@ void IndexedDBDatabase::GetOperation( *key, &primary_key); if (!s.ok()) { - IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, - "Internal error in GetPrimaryKeyViaIndex."); - callbacks->OnError(error); - if (s.IsCorruption()) - factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), - error); + callbacks->OnError( + IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, + "Internal error in GetPrimaryKeyViaIndex.")); return; } if (!primary_key) { @@ -639,12 +622,9 @@ void IndexedDBDatabase::GetOperation( *primary_key, &value); if (!s.ok()) { - IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, - "Internal error in GetRecord."); - callbacks->OnError(error); - if (s.IsCorruption()) - factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), - error); + callbacks->OnError( + IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, + "Internal error in GetRecord.")); return; } @@ -781,12 +761,9 @@ void IndexedDBDatabase::PutOperation(scoped_ptr<PutOperationParams> params, &record_identifier, &found); if (!s.ok()) { - IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, - "Internal error checking key existence."); - params->callbacks->OnError(error); - if (s.IsCorruption()) - factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), - error); + params->callbacks->OnError( + IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, + "Internal error checking key existence.")); return; } if (found) { @@ -832,13 +809,9 @@ void IndexedDBDatabase::PutOperation(scoped_ptr<PutOperationParams> params, params->value, &record_identifier); if (!s.ok()) { - IndexedDBDatabaseError error( + params->callbacks->OnError(IndexedDBDatabaseError( blink::WebIDBDatabaseExceptionUnknownError, - "Internal error: backing store error performing put/add."); - params->callbacks->OnError(error); - if (s.IsCorruption()) - factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), - error); + "Internal error: backing store error performing put/add.")); return; } @@ -861,12 +834,9 @@ void IndexedDBDatabase::PutOperation(scoped_ptr<PutOperationParams> params, *key, !key_was_generated); if (!s.ok()) { - IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, - "Internal error updating key generator."); - params->callbacks->OnError(error); - if (s.IsCorruption()) - factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), - error); + params->callbacks->OnError( + IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, + "Internal error updating key generator.")); return; } } @@ -896,12 +866,9 @@ void IndexedDBDatabase::SetIndexKeys(int64 transaction_id, &record_identifier, &found); if (!s.ok()) { - IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, - "Internal error setting index keys."); - transaction->Abort(error); - if (s.IsCorruption()) - factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), - error); + transaction->Abort( + IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, + "Internal error setting index keys.")); return; } if (!found) { @@ -1239,12 +1206,8 @@ void IndexedDBDatabase::DeleteObjectStoreOperation( base::string16 error_string = ASCIIToUTF16("Internal error deleting object store '") + object_store_metadata.name + ASCIIToUTF16("'."); - IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, - error_string); - transaction->Abort(error); - if (s.IsCorruption()) - factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), - error); + transaction->Abort(IndexedDBDatabaseError( + blink::WebIDBDatabaseExceptionUnknownError, error_string)); } } diff --git a/content/browser/indexed_db/indexed_db_factory.cc b/content/browser/indexed_db/indexed_db_factory.cc index 1130603..86af571 100644 --- a/content/browser/indexed_db/indexed_db_factory.cc +++ b/content/browser/indexed_db/indexed_db_factory.cc @@ -9,7 +9,6 @@ #include "base/time/time.h" #include "content/browser/indexed_db/indexed_db_backing_store.h" #include "content/browser/indexed_db/indexed_db_context_impl.h" -#include "content/browser/indexed_db/indexed_db_database_error.h" #include "content/browser/indexed_db/indexed_db_tracing.h" #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" @@ -235,24 +234,6 @@ void IndexedDBFactory::HandleBackingStoreFailure(const GURL& origin_url) { IndexedDBContextImpl::FORCE_CLOSE_BACKING_STORE_FAILURE); } -void IndexedDBFactory::HandleBackingStoreCorruption( - const GURL& origin_url, - const IndexedDBDatabaseError& error) { - // Make a copy of origin_url as this is likely a reference to a member of a - // backing store which this function will be deleting. - GURL saved_origin_url(origin_url); - DCHECK(context_); - base::FilePath path_base = context_->data_path(); - IndexedDBBackingStore::RecordCorruptionInfo( - path_base, saved_origin_url, base::UTF16ToUTF8(error.message())); - HandleBackingStoreFailure(saved_origin_url); - // Note: DestroyBackingStore only deletes LevelDB files, leaving all others, - // so our corruption info file will remain. - if (!IndexedDBBackingStore::DestroyBackingStore(path_base, saved_origin_url) - .ok()) - DLOG(ERROR) << "Unable to delete backing store"; -} - bool IndexedDBFactory::IsDatabaseOpen(const GURL& origin_url, const base::string16& name) const { diff --git a/content/browser/indexed_db/indexed_db_factory.h b/content/browser/indexed_db/indexed_db_factory.h index de2e1dd..af2ba54 100644 --- a/content/browser/indexed_db/indexed_db_factory.h +++ b/content/browser/indexed_db/indexed_db_factory.h @@ -50,12 +50,12 @@ class CONTENT_EXPORT IndexedDBFactory const base::FilePath& data_directory); void HandleBackingStoreFailure(const GURL& origin_url); - void HandleBackingStoreCorruption(const GURL& origin_url, - const IndexedDBDatabaseError& error); std::pair<OriginDBMapIterator, OriginDBMapIterator> GetOpenDatabasesForOrigin( const GURL& origin_url) const; + // Called by IndexedDBContext after all connections are closed, to + // ensure the backing store closed immediately. void ForceClose(const GURL& origin_url); // Called by the IndexedDBContext destructor so the factory can do cleanup. diff --git a/content/browser/indexed_db/indexed_db_transaction.cc b/content/browser/indexed_db/indexed_db_transaction.cc index c6dd950..ff7ba2b 100644 --- a/content/browser/indexed_db/indexed_db_transaction.cc +++ b/content/browser/indexed_db/indexed_db_transaction.cc @@ -259,9 +259,10 @@ void IndexedDBTransaction::Commit() { while (!abort_task_stack_.empty()) abort_task_stack_.pop().Run(NULL); - IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, - "Internal error committing transaction."); - callbacks_->OnAbort(id_, error); + callbacks_->OnAbort( + id_, + IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, + "Internal error committing transaction.")); database_->TransactionFinished(this, false); database_->TransactionCommitFailed(); } diff --git a/content/browser/indexed_db/leveldb/leveldb_database.cc b/content/browser/indexed_db/leveldb/leveldb_database.cc index 96218b3..3c27340 100644 --- a/content/browser/indexed_db/leveldb/leveldb_database.cc +++ b/content/browser/indexed_db/leveldb/leveldb_database.cc @@ -459,6 +459,4 @@ void LevelDBDatabase::Compact(const base::StringPiece& start, db_->CompactRange(&start_slice, &stop_slice); } -void LevelDBDatabase::CompactAll() { db_->CompactRange(NULL, NULL); } - } // namespace content diff --git a/content/browser/indexed_db/leveldb/leveldb_database.h b/content/browser/indexed_db/leveldb/leveldb_database.h index e4f6af9..27ffcd5 100644 --- a/content/browser/indexed_db/leveldb/leveldb_database.h +++ b/content/browser/indexed_db/leveldb/leveldb_database.h @@ -87,7 +87,6 @@ class CONTENT_EXPORT LevelDBDatabase { scoped_ptr<LevelDBIterator> CreateIterator(const LevelDBSnapshot* = 0); const LevelDBComparator* Comparator() const; void Compact(const base::StringPiece& start, const base::StringPiece& stop); - void CompactAll(); protected: LevelDBDatabase(); |