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 <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 #include "content/common/indexed_db/indexed_db_key_range.h" | 39 #include "content/common/indexed_db/indexed_db_key_range.h" |
40 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
41 #include "net/url_request/url_request_context.h" | 41 #include "net/url_request/url_request_context.h" |
42 #include "storage/browser/blob/blob_data_handle.h" | 42 #include "storage/browser/blob/blob_data_handle.h" |
43 #include "storage/browser/fileapi/file_stream_writer.h" | 43 #include "storage/browser/fileapi/file_stream_writer.h" |
44 #include "storage/browser/fileapi/file_writer_delegate.h" | 44 #include "storage/browser/fileapi/file_writer_delegate.h" |
45 #include "storage/browser/fileapi/local_file_stream_writer.h" | 45 #include "storage/browser/fileapi/local_file_stream_writer.h" |
46 #include "storage/common/database/database_identifier.h" | 46 #include "storage/common/database/database_identifier.h" |
47 #include "storage/common/fileapi/file_system_mount_option.h" | 47 #include "storage/common/fileapi/file_system_mount_option.h" |
48 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" | 48 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" |
49 #include "third_party/WebKit/public/web/WebSerializedScriptValueVersion.h" | |
50 #include "third_party/leveldatabase/env_chromium.h" | 49 #include "third_party/leveldatabase/env_chromium.h" |
51 | 50 |
52 using base::FilePath; | 51 using base::FilePath; |
53 using base::StringPiece; | 52 using base::StringPiece; |
54 using leveldb::Status; | 53 using leveldb::Status; |
55 using storage::FileWriterDelegate; | 54 using storage::FileWriterDelegate; |
56 using url::Origin; | 55 using url::Origin; |
57 | 56 |
58 namespace content { | 57 namespace content { |
59 | 58 |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 } | 310 } |
312 | 311 |
313 int CompareKeys(const StringPiece& a, const StringPiece& b) { | 312 int CompareKeys(const StringPiece& a, const StringPiece& b) { |
314 return Compare(a, b, false /*index_keys*/); | 313 return Compare(a, b, false /*index_keys*/); |
315 } | 314 } |
316 | 315 |
317 int CompareIndexKeys(const StringPiece& a, const StringPiece& b) { | 316 int CompareIndexKeys(const StringPiece& a, const StringPiece& b) { |
318 return Compare(a, b, true /*index_keys*/); | 317 return Compare(a, b, true /*index_keys*/); |
319 } | 318 } |
320 | 319 |
321 WARN_UNUSED_RESULT bool IsSchemaKnown(LevelDBDatabase* db, bool* known) { | 320 WARN_UNUSED_RESULT bool IsSchemaKnown( |
| 321 LevelDBDatabase* db, |
| 322 const IndexedDBDataFormatVersion& latest_known_data_version, |
| 323 bool* known) { |
322 int64_t db_schema_version = 0; | 324 int64_t db_schema_version = 0; |
323 bool found = false; | 325 bool found = false; |
324 Status s = GetInt(db, SchemaVersionKey::Encode(), &db_schema_version, &found); | 326 Status s = GetInt(db, SchemaVersionKey::Encode(), &db_schema_version, &found); |
325 if (!s.ok()) | 327 if (!s.ok()) |
326 return false; | 328 return false; |
327 if (!found) { | 329 if (!found) { |
328 *known = true; | 330 *known = true; |
329 return true; | 331 return true; |
330 } | 332 } |
331 if (db_schema_version < 0) | 333 if (db_schema_version < 0) |
332 return false; // Only corruption should cause this. | 334 return false; // Only corruption should cause this. |
333 if (db_schema_version > kLatestKnownSchemaVersion) { | 335 if (db_schema_version > kLatestKnownSchemaVersion) { |
334 *known = false; | 336 *known = false; |
335 return true; | 337 return true; |
336 } | 338 } |
337 | 339 |
338 const uint32_t latest_known_data_version = | 340 int64_t raw_db_data_version = 0; |
339 blink::kSerializedScriptValueVersion; | 341 s = GetInt(db, DataVersionKey::Encode(), &raw_db_data_version, &found); |
340 int64_t db_data_version = 0; | |
341 s = GetInt(db, DataVersionKey::Encode(), &db_data_version, &found); | |
342 if (!s.ok()) | 342 if (!s.ok()) |
343 return false; | 343 return false; |
344 if (!found) { | 344 if (!found) { |
345 *known = true; | 345 *known = true; |
346 return true; | 346 return true; |
347 } | 347 } |
348 if (db_data_version < 0) | 348 if (raw_db_data_version < 0) |
349 return false; // Only corruption should cause this. | 349 return false; // Only corruption should cause this. |
350 if (db_data_version > latest_known_data_version) { | 350 IndexedDBDataFormatVersion db_data_version = |
| 351 IndexedDBDataFormatVersion::Decode(raw_db_data_version); |
| 352 if (!latest_known_data_version.IsAtLeast(db_data_version)) { |
351 *known = false; | 353 *known = false; |
352 return true; | 354 return true; |
353 } | 355 } |
354 | 356 |
355 *known = true; | 357 *known = true; |
356 return true; | 358 return true; |
357 } | 359 } |
358 | 360 |
359 template <typename DBOrTransaction> | 361 template <typename DBOrTransaction> |
360 WARN_UNUSED_RESULT Status | 362 WARN_UNUSED_RESULT Status |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 } | 1075 } |
1074 | 1076 |
1075 private: | 1077 private: |
1076 DISALLOW_COPY_AND_ASSIGN(DefaultLevelDBFactory); | 1078 DISALLOW_COPY_AND_ASSIGN(DefaultLevelDBFactory); |
1077 }; | 1079 }; |
1078 | 1080 |
1079 IndexedDBBackingStore::IndexedDBBackingStore( | 1081 IndexedDBBackingStore::IndexedDBBackingStore( |
1080 IndexedDBFactory* indexed_db_factory, | 1082 IndexedDBFactory* indexed_db_factory, |
1081 const Origin& origin, | 1083 const Origin& origin, |
1082 const FilePath& blob_path, | 1084 const FilePath& blob_path, |
| 1085 const IndexedDBDataFormatVersion& data_format_version, |
1083 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 1086 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
1084 std::unique_ptr<LevelDBDatabase> db, | 1087 std::unique_ptr<LevelDBDatabase> db, |
1085 std::unique_ptr<LevelDBComparator> comparator, | 1088 std::unique_ptr<LevelDBComparator> comparator, |
1086 base::SequencedTaskRunner* task_runner) | 1089 base::SequencedTaskRunner* task_runner) |
1087 : indexed_db_factory_(indexed_db_factory), | 1090 : indexed_db_factory_(indexed_db_factory), |
1088 origin_(origin), | 1091 origin_(origin), |
1089 blob_path_(blob_path), | 1092 blob_path_(blob_path), |
| 1093 data_format_version_(data_format_version), |
1090 origin_identifier_(ComputeOriginIdentifier(origin)), | 1094 origin_identifier_(ComputeOriginIdentifier(origin)), |
1091 request_context_getter_(request_context_getter), | 1095 request_context_getter_(request_context_getter), |
1092 task_runner_(task_runner), | 1096 task_runner_(task_runner), |
1093 db_(std::move(db)), | 1097 db_(std::move(db)), |
1094 comparator_(std::move(comparator)), | 1098 comparator_(std::move(comparator)), |
1095 active_blob_registry_(this), | 1099 active_blob_registry_(this), |
1096 committing_transaction_count_(0) {} | 1100 committing_transaction_count_(0) {} |
1097 | 1101 |
1098 IndexedDBBackingStore::~IndexedDBBackingStore() { | 1102 IndexedDBBackingStore::~IndexedDBBackingStore() { |
1099 if (!blob_path_.empty() && !child_process_ids_granted_.empty()) { | 1103 if (!blob_path_.empty() && !child_process_ids_granted_.empty()) { |
(...skipping 15 matching lines...) Expand all Loading... |
1115 } | 1119 } |
1116 IndexedDBBackingStore::RecordIdentifier::RecordIdentifier() | 1120 IndexedDBBackingStore::RecordIdentifier::RecordIdentifier() |
1117 : primary_key_(), version_(-1) {} | 1121 : primary_key_(), version_(-1) {} |
1118 IndexedDBBackingStore::RecordIdentifier::~RecordIdentifier() {} | 1122 IndexedDBBackingStore::RecordIdentifier::~RecordIdentifier() {} |
1119 | 1123 |
1120 // static | 1124 // static |
1121 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open( | 1125 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open( |
1122 IndexedDBFactory* indexed_db_factory, | 1126 IndexedDBFactory* indexed_db_factory, |
1123 const Origin& origin, | 1127 const Origin& origin, |
1124 const FilePath& path_base, | 1128 const FilePath& path_base, |
| 1129 const IndexedDBDataFormatVersion& data_format_version, |
1125 scoped_refptr<net::URLRequestContextGetter> request_context, | 1130 scoped_refptr<net::URLRequestContextGetter> request_context, |
1126 IndexedDBDataLossInfo* data_loss_info, | 1131 IndexedDBDataLossInfo* data_loss_info, |
1127 bool* disk_full, | 1132 bool* disk_full, |
1128 base::SequencedTaskRunner* task_runner, | 1133 base::SequencedTaskRunner* task_runner, |
1129 bool clean_journal, | 1134 bool clean_journal, |
1130 Status* status) { | 1135 Status* status) { |
1131 DefaultLevelDBFactory leveldb_factory; | 1136 DefaultLevelDBFactory leveldb_factory; |
1132 return IndexedDBBackingStore::Open( | 1137 return IndexedDBBackingStore::Open( |
1133 indexed_db_factory, origin, path_base, request_context, data_loss_info, | 1138 indexed_db_factory, origin, path_base, data_format_version, |
1134 disk_full, &leveldb_factory, task_runner, clean_journal, status); | 1139 request_context, data_loss_info, disk_full, &leveldb_factory, task_runner, |
| 1140 clean_journal, status); |
1135 } | 1141 } |
1136 | 1142 |
1137 Status IndexedDBBackingStore::DestroyBackingStore(const FilePath& path_base, | 1143 Status IndexedDBBackingStore::DestroyBackingStore(const FilePath& path_base, |
1138 const Origin& origin) { | 1144 const Origin& origin) { |
1139 const FilePath file_path = | 1145 const FilePath file_path = |
1140 path_base.Append(IndexedDBContextImpl::GetLevelDBFileName(origin)); | 1146 path_base.Append(IndexedDBContextImpl::GetLevelDBFileName(origin)); |
1141 DefaultLevelDBFactory leveldb_factory; | 1147 DefaultLevelDBFactory leveldb_factory; |
1142 return leveldb_factory.DestroyLevelDB(file_path); | 1148 return leveldb_factory.DestroyLevelDB(file_path); |
1143 } | 1149 } |
1144 | 1150 |
1145 WARN_UNUSED_RESULT Status IndexedDBBackingStore::SetUpMetadata() { | 1151 WARN_UNUSED_RESULT Status IndexedDBBackingStore::SetUpMetadata() { |
1146 const uint32_t latest_known_data_version = | 1152 const IndexedDBDataFormatVersion latest_known_data_version = |
1147 blink::kSerializedScriptValueVersion; | 1153 data_format_version_; |
1148 const std::string schema_version_key = SchemaVersionKey::Encode(); | 1154 const std::string schema_version_key = SchemaVersionKey::Encode(); |
1149 const std::string data_version_key = DataVersionKey::Encode(); | 1155 const std::string data_version_key = DataVersionKey::Encode(); |
1150 | 1156 |
1151 scoped_refptr<LevelDBTransaction> transaction = | 1157 scoped_refptr<LevelDBTransaction> transaction = |
1152 IndexedDBClassFactory::Get()->CreateLevelDBTransaction(db_.get()); | 1158 IndexedDBClassFactory::Get()->CreateLevelDBTransaction(db_.get()); |
1153 | 1159 |
1154 int64_t db_schema_version = 0; | 1160 int64_t db_schema_version = 0; |
1155 int64_t db_data_version = 0; | 1161 IndexedDBDataFormatVersion db_data_version; |
1156 bool found = false; | 1162 bool found = false; |
1157 Status s = | 1163 Status s = |
1158 GetInt(transaction.get(), schema_version_key, &db_schema_version, &found); | 1164 GetInt(transaction.get(), schema_version_key, &db_schema_version, &found); |
1159 if (!s.ok()) { | 1165 if (!s.ok()) { |
1160 INTERNAL_READ_ERROR_UNTESTED(SET_UP_METADATA); | 1166 INTERNAL_READ_ERROR_UNTESTED(SET_UP_METADATA); |
1161 return s; | 1167 return s; |
1162 } | 1168 } |
1163 if (!found) { | 1169 if (!found) { |
1164 // Initialize new backing store. | 1170 // Initialize new backing store. |
1165 db_schema_version = kLatestKnownSchemaVersion; | 1171 db_schema_version = kLatestKnownSchemaVersion; |
1166 PutInt(transaction.get(), schema_version_key, db_schema_version); | 1172 PutInt(transaction.get(), schema_version_key, db_schema_version); |
1167 db_data_version = latest_known_data_version; | 1173 db_data_version = latest_known_data_version; |
1168 PutInt(transaction.get(), data_version_key, db_data_version); | 1174 PutInt(transaction.get(), data_version_key, db_data_version.Encode()); |
1169 // If a blob directory already exists for this database, blow it away. It's | 1175 // If a blob directory already exists for this database, blow it away. It's |
1170 // leftover from a partially-purged previous generation of data. | 1176 // leftover from a partially-purged previous generation of data. |
1171 if (!base::DeleteFile(blob_path_, true)) { | 1177 if (!base::DeleteFile(blob_path_, true)) { |
1172 INTERNAL_WRITE_ERROR_UNTESTED(SET_UP_METADATA); | 1178 INTERNAL_WRITE_ERROR_UNTESTED(SET_UP_METADATA); |
1173 return IOErrorStatus(); | 1179 return IOErrorStatus(); |
1174 } | 1180 } |
1175 } else { | 1181 } else { |
1176 // Upgrade old backing store. | 1182 // Upgrade old backing store. |
1177 DCHECK_LE(db_schema_version, kLatestKnownSchemaVersion); | 1183 DCHECK_LE(db_schema_version, kLatestKnownSchemaVersion); |
1178 if (db_schema_version < 1) { | 1184 if (db_schema_version < 1) { |
(...skipping 20 matching lines...) Expand all Loading... |
1199 } | 1205 } |
1200 std::string version_key = DatabaseMetaDataKey::Encode( | 1206 std::string version_key = DatabaseMetaDataKey::Encode( |
1201 database_id, DatabaseMetaDataKey::USER_VERSION); | 1207 database_id, DatabaseMetaDataKey::USER_VERSION); |
1202 PutVarInt(transaction.get(), version_key, | 1208 PutVarInt(transaction.get(), version_key, |
1203 IndexedDBDatabaseMetadata::DEFAULT_VERSION); | 1209 IndexedDBDatabaseMetadata::DEFAULT_VERSION); |
1204 } | 1210 } |
1205 } | 1211 } |
1206 if (s.ok() && db_schema_version < 2) { | 1212 if (s.ok() && db_schema_version < 2) { |
1207 db_schema_version = 2; | 1213 db_schema_version = 2; |
1208 PutInt(transaction.get(), schema_version_key, db_schema_version); | 1214 PutInt(transaction.get(), schema_version_key, db_schema_version); |
1209 db_data_version = blink::kSerializedScriptValueVersion; | 1215 db_data_version = latest_known_data_version; |
1210 PutInt(transaction.get(), data_version_key, db_data_version); | 1216 PutInt(transaction.get(), data_version_key, db_data_version.Encode()); |
1211 } | 1217 } |
1212 if (db_schema_version < 3) { | 1218 if (db_schema_version < 3) { |
1213 db_schema_version = 3; | 1219 db_schema_version = 3; |
1214 if (!base::DeleteFile(blob_path_, true)) { | 1220 if (!base::DeleteFile(blob_path_, true)) { |
1215 INTERNAL_WRITE_ERROR_UNTESTED(SET_UP_METADATA); | 1221 INTERNAL_WRITE_ERROR_UNTESTED(SET_UP_METADATA); |
1216 return IOErrorStatus(); | 1222 return IOErrorStatus(); |
1217 } | 1223 } |
1218 } | 1224 } |
1219 } | 1225 } |
1220 | 1226 |
1221 if (!s.ok()) { | 1227 if (!s.ok()) { |
1222 INTERNAL_READ_ERROR_UNTESTED(SET_UP_METADATA); | 1228 INTERNAL_READ_ERROR_UNTESTED(SET_UP_METADATA); |
1223 return s; | 1229 return s; |
1224 } | 1230 } |
1225 | 1231 |
1226 // All new values will be written using this serialization version. | 1232 // All new values will be written using this serialization version. |
1227 found = false; | 1233 found = false; |
1228 s = GetInt(transaction.get(), data_version_key, &db_data_version, &found); | 1234 int64_t raw_db_data_version = 0; |
| 1235 s = GetInt(transaction.get(), data_version_key, &raw_db_data_version, &found); |
1229 if (!s.ok()) { | 1236 if (!s.ok()) { |
1230 INTERNAL_READ_ERROR_UNTESTED(SET_UP_METADATA); | 1237 INTERNAL_READ_ERROR_UNTESTED(SET_UP_METADATA); |
1231 return s; | 1238 return s; |
1232 } | 1239 } |
1233 if (!found) { | 1240 if (!found) { |
1234 INTERNAL_CONSISTENCY_ERROR_UNTESTED(SET_UP_METADATA); | 1241 INTERNAL_CONSISTENCY_ERROR_UNTESTED(SET_UP_METADATA); |
1235 return InternalInconsistencyStatus(); | 1242 return InternalInconsistencyStatus(); |
1236 } | 1243 } |
1237 if (db_data_version < latest_known_data_version) { | 1244 db_data_version = IndexedDBDataFormatVersion::Decode(raw_db_data_version); |
| 1245 if (latest_known_data_version == db_data_version) { |
| 1246 // Up to date. Nothing to do. |
| 1247 } else if (latest_known_data_version.IsAtLeast(db_data_version)) { |
1238 db_data_version = latest_known_data_version; | 1248 db_data_version = latest_known_data_version; |
1239 PutInt(transaction.get(), data_version_key, db_data_version); | 1249 PutInt(transaction.get(), data_version_key, db_data_version.Encode()); |
| 1250 } else { |
| 1251 // |db_data_version| is in the future according to at least one component. |
| 1252 INTERNAL_CONSISTENCY_ERROR(SET_UP_METADATA); |
| 1253 return InternalInconsistencyStatus(); |
1240 } | 1254 } |
1241 | 1255 |
1242 DCHECK_EQ(db_schema_version, kLatestKnownSchemaVersion); | 1256 DCHECK_EQ(db_schema_version, kLatestKnownSchemaVersion); |
1243 DCHECK_EQ(db_data_version, latest_known_data_version); | 1257 DCHECK(db_data_version == latest_known_data_version); |
1244 | 1258 |
1245 s = transaction->Commit(); | 1259 s = transaction->Commit(); |
1246 if (!s.ok()) | 1260 if (!s.ok()) |
1247 INTERNAL_WRITE_ERROR_UNTESTED(SET_UP_METADATA); | 1261 INTERNAL_WRITE_ERROR_UNTESTED(SET_UP_METADATA); |
1248 return s; | 1262 return s; |
1249 } | 1263 } |
1250 | 1264 |
1251 bool IndexedDBBackingStore::ReadCorruptionInfo(const FilePath& path_base, | 1265 bool IndexedDBBackingStore::ReadCorruptionInfo(const FilePath& path_base, |
1252 const Origin& origin, | 1266 const Origin& origin, |
1253 std::string* message) { | 1267 std::string* message) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1305 return false; | 1319 return false; |
1306 int written = file.Write(0, output_js.c_str(), output_js.length()); | 1320 int written = file.Write(0, output_js.c_str(), output_js.length()); |
1307 return size_t(written) == output_js.length(); | 1321 return size_t(written) == output_js.length(); |
1308 } | 1322 } |
1309 | 1323 |
1310 // static | 1324 // static |
1311 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open( | 1325 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open( |
1312 IndexedDBFactory* indexed_db_factory, | 1326 IndexedDBFactory* indexed_db_factory, |
1313 const Origin& origin, | 1327 const Origin& origin, |
1314 const FilePath& path_base, | 1328 const FilePath& path_base, |
| 1329 const IndexedDBDataFormatVersion& data_format_version, |
1315 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 1330 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
1316 IndexedDBDataLossInfo* data_loss_info, | 1331 IndexedDBDataLossInfo* data_loss_info, |
1317 bool* is_disk_full, | 1332 bool* is_disk_full, |
1318 LevelDBFactory* leveldb_factory, | 1333 LevelDBFactory* leveldb_factory, |
1319 base::SequencedTaskRunner* task_runner, | 1334 base::SequencedTaskRunner* task_runner, |
1320 bool clean_journal, | 1335 bool clean_journal, |
1321 Status* status) { | 1336 Status* status) { |
1322 IDB_TRACE("IndexedDBBackingStore::Open"); | 1337 IDB_TRACE("IndexedDBBackingStore::Open"); |
1323 DCHECK(!path_base.empty()); | 1338 DCHECK(!path_base.empty()); |
1324 *is_disk_full = false; | 1339 *is_disk_full = false; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1370 std::string corruption_message; | 1385 std::string corruption_message; |
1371 if (ReadCorruptionInfo(path_base, origin, &corruption_message)) { | 1386 if (ReadCorruptionInfo(path_base, origin, &corruption_message)) { |
1372 LOG(ERROR) << "IndexedDB recovering from a corrupted (and deleted) " | 1387 LOG(ERROR) << "IndexedDB recovering from a corrupted (and deleted) " |
1373 "database."; | 1388 "database."; |
1374 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_FAILED_PRIOR_CORRUPTION, | 1389 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_FAILED_PRIOR_CORRUPTION, |
1375 origin); | 1390 origin); |
1376 db.reset(); | 1391 db.reset(); |
1377 data_loss_info->status = blink::WebIDBDataLossTotal; | 1392 data_loss_info->status = blink::WebIDBDataLossTotal; |
1378 data_loss_info->message = | 1393 data_loss_info->message = |
1379 "IndexedDB (database was corrupt): " + corruption_message; | 1394 "IndexedDB (database was corrupt): " + corruption_message; |
1380 } else if (!IsSchemaKnown(db.get(), &is_schema_known)) { | 1395 } else if (!IsSchemaKnown(db.get(), data_format_version, |
| 1396 &is_schema_known)) { |
1381 LOG(ERROR) << "IndexedDB had IO error checking schema, treating it as " | 1397 LOG(ERROR) << "IndexedDB had IO error checking schema, treating it as " |
1382 "failure to open"; | 1398 "failure to open"; |
1383 HistogramOpenStatus( | 1399 HistogramOpenStatus( |
1384 INDEXED_DB_BACKING_STORE_OPEN_FAILED_IO_ERROR_CHECKING_SCHEMA, | 1400 INDEXED_DB_BACKING_STORE_OPEN_FAILED_IO_ERROR_CHECKING_SCHEMA, |
1385 origin); | 1401 origin); |
1386 db.reset(); | 1402 db.reset(); |
1387 data_loss_info->status = blink::WebIDBDataLossTotal; | 1403 data_loss_info->status = blink::WebIDBDataLossTotal; |
1388 data_loss_info->message = "I/O error checking schema"; | 1404 data_loss_info->message = "I/O error checking schema"; |
1389 } else if (!is_schema_known) { | 1405 } else if (!is_schema_known) { |
1390 LOG(ERROR) << "IndexedDB backing store had unknown schema, treating it " | 1406 LOG(ERROR) << "IndexedDB backing store had unknown schema, treating it " |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1431 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_CLEANUP_REOPEN_SUCCESS, | 1447 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_CLEANUP_REOPEN_SUCCESS, |
1432 origin); | 1448 origin); |
1433 } | 1449 } |
1434 | 1450 |
1435 base::trace_event::MemoryDumpManager::GetInstance() | 1451 base::trace_event::MemoryDumpManager::GetInstance() |
1436 ->RegisterDumpProviderWithSequencedTaskRunner( | 1452 ->RegisterDumpProviderWithSequencedTaskRunner( |
1437 db.get(), "IndexedDBBackingStore", task_runner, | 1453 db.get(), "IndexedDBBackingStore", task_runner, |
1438 base::trace_event::MemoryDumpProvider::Options()); | 1454 base::trace_event::MemoryDumpProvider::Options()); |
1439 | 1455 |
1440 scoped_refptr<IndexedDBBackingStore> backing_store = | 1456 scoped_refptr<IndexedDBBackingStore> backing_store = |
1441 Create(indexed_db_factory, origin, blob_path, request_context_getter, | 1457 Create(indexed_db_factory, origin, blob_path, data_format_version, |
1442 std::move(db), std::move(comparator), task_runner, status); | 1458 request_context_getter, std::move(db), std::move(comparator), |
| 1459 task_runner, status); |
1443 | 1460 |
1444 if (clean_journal && backing_store.get()) { | 1461 if (clean_journal && backing_store.get()) { |
1445 *status = backing_store->CleanUpBlobJournal(LiveBlobJournalKey::Encode()); | 1462 *status = backing_store->CleanUpBlobJournal(LiveBlobJournalKey::Encode()); |
1446 if (!status->ok()) { | 1463 if (!status->ok()) { |
1447 HistogramOpenStatus( | 1464 HistogramOpenStatus( |
1448 INDEXED_DB_BACKING_STORE_OPEN_FAILED_CLEANUP_JOURNAL_ERROR, origin); | 1465 INDEXED_DB_BACKING_STORE_OPEN_FAILED_CLEANUP_JOURNAL_ERROR, origin); |
1449 return scoped_refptr<IndexedDBBackingStore>(); | 1466 return scoped_refptr<IndexedDBBackingStore>(); |
1450 } | 1467 } |
1451 } | 1468 } |
1452 return backing_store; | 1469 return backing_store; |
1453 } | 1470 } |
1454 | 1471 |
1455 // static | 1472 // static |
1456 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::OpenInMemory( | 1473 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::OpenInMemory( |
1457 const Origin& origin, | 1474 const Origin& origin, |
| 1475 const IndexedDBDataFormatVersion& data_format_version, |
1458 base::SequencedTaskRunner* task_runner, | 1476 base::SequencedTaskRunner* task_runner, |
1459 Status* status) { | 1477 Status* status) { |
1460 DefaultLevelDBFactory leveldb_factory; | 1478 DefaultLevelDBFactory leveldb_factory; |
1461 return IndexedDBBackingStore::OpenInMemory(origin, &leveldb_factory, | 1479 return IndexedDBBackingStore::OpenInMemory( |
1462 task_runner, status); | 1480 origin, data_format_version, &leveldb_factory, task_runner, status); |
1463 } | 1481 } |
1464 | 1482 |
1465 // static | 1483 // static |
1466 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::OpenInMemory( | 1484 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::OpenInMemory( |
1467 const Origin& origin, | 1485 const Origin& origin, |
| 1486 const IndexedDBDataFormatVersion& data_format_version, |
1468 LevelDBFactory* leveldb_factory, | 1487 LevelDBFactory* leveldb_factory, |
1469 base::SequencedTaskRunner* task_runner, | 1488 base::SequencedTaskRunner* task_runner, |
1470 Status* status) { | 1489 Status* status) { |
1471 IDB_TRACE("IndexedDBBackingStore::OpenInMemory"); | 1490 IDB_TRACE("IndexedDBBackingStore::OpenInMemory"); |
1472 | 1491 |
1473 std::unique_ptr<LevelDBComparator> comparator(base::MakeUnique<Comparator>()); | 1492 std::unique_ptr<LevelDBComparator> comparator(base::MakeUnique<Comparator>()); |
1474 std::unique_ptr<LevelDBDatabase> db = | 1493 std::unique_ptr<LevelDBDatabase> db = |
1475 LevelDBDatabase::OpenInMemory(comparator.get()); | 1494 LevelDBDatabase::OpenInMemory(comparator.get()); |
1476 if (!db) { | 1495 if (!db) { |
1477 LOG(ERROR) << "LevelDBDatabase::OpenInMemory failed."; | 1496 LOG(ERROR) << "LevelDBDatabase::OpenInMemory failed."; |
1478 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_MEMORY_FAILED, origin); | 1497 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_MEMORY_FAILED, origin); |
1479 return scoped_refptr<IndexedDBBackingStore>(); | 1498 return scoped_refptr<IndexedDBBackingStore>(); |
1480 } | 1499 } |
1481 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_MEMORY_SUCCESS, origin); | 1500 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_MEMORY_SUCCESS, origin); |
1482 base::trace_event::MemoryDumpManager::GetInstance() | 1501 base::trace_event::MemoryDumpManager::GetInstance() |
1483 ->RegisterDumpProviderWithSequencedTaskRunner( | 1502 ->RegisterDumpProviderWithSequencedTaskRunner( |
1484 db.get(), "IndexedDBBackingStore", task_runner, | 1503 db.get(), "IndexedDBBackingStore", task_runner, |
1485 base::trace_event::MemoryDumpProvider::Options()); | 1504 base::trace_event::MemoryDumpProvider::Options()); |
1486 | 1505 |
1487 return Create(NULL /* indexed_db_factory */, origin, FilePath(), | 1506 return Create(NULL /* indexed_db_factory */, origin, FilePath(), |
1488 NULL /* request_context */, std::move(db), | 1507 data_format_version, NULL /* request_context */, std::move(db), |
1489 std::move(comparator), task_runner, status); | 1508 std::move(comparator), task_runner, status); |
1490 } | 1509 } |
1491 | 1510 |
1492 // static | 1511 // static |
1493 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Create( | 1512 scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Create( |
1494 IndexedDBFactory* indexed_db_factory, | 1513 IndexedDBFactory* indexed_db_factory, |
1495 const Origin& origin, | 1514 const Origin& origin, |
1496 const FilePath& blob_path, | 1515 const FilePath& blob_path, |
| 1516 const IndexedDBDataFormatVersion& data_format_version, |
1497 scoped_refptr<net::URLRequestContextGetter> request_context, | 1517 scoped_refptr<net::URLRequestContextGetter> request_context, |
1498 std::unique_ptr<LevelDBDatabase> db, | 1518 std::unique_ptr<LevelDBDatabase> db, |
1499 std::unique_ptr<LevelDBComparator> comparator, | 1519 std::unique_ptr<LevelDBComparator> comparator, |
1500 base::SequencedTaskRunner* task_runner, | 1520 base::SequencedTaskRunner* task_runner, |
1501 Status* status) { | 1521 Status* status) { |
1502 // TODO(jsbell): Handle comparator name changes. | 1522 // TODO(jsbell): Handle comparator name changes. |
1503 scoped_refptr<IndexedDBBackingStore> backing_store(new IndexedDBBackingStore( | 1523 scoped_refptr<IndexedDBBackingStore> backing_store(new IndexedDBBackingStore( |
1504 indexed_db_factory, origin, blob_path, request_context, std::move(db), | 1524 indexed_db_factory, origin, blob_path, data_format_version, |
1505 std::move(comparator), task_runner)); | 1525 request_context, std::move(db), std::move(comparator), task_runner)); |
1506 *status = backing_store->SetUpMetadata(); | 1526 *status = backing_store->SetUpMetadata(); |
1507 if (!status->ok()) | 1527 if (!status->ok()) |
1508 return scoped_refptr<IndexedDBBackingStore>(); | 1528 return scoped_refptr<IndexedDBBackingStore>(); |
1509 | 1529 |
1510 return backing_store; | 1530 return backing_store; |
1511 } | 1531 } |
1512 | 1532 |
1513 void IndexedDBBackingStore::GrantChildProcessPermissions(int child_process_id) { | 1533 void IndexedDBBackingStore::GrantChildProcessPermissions(int child_process_id) { |
1514 if (!child_process_ids_granted_.count(child_process_id)) { | 1534 if (!child_process_ids_granted_.count(child_process_id)) { |
1515 child_process_ids_granted_.insert(child_process_id); | 1535 child_process_ids_granted_.insert(child_process_id); |
(...skipping 2940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4456 | 4476 |
4457 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( | 4477 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( |
4458 const WriteDescriptor& other) = default; | 4478 const WriteDescriptor& other) = default; |
4459 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = | 4479 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = |
4460 default; | 4480 default; |
4461 IndexedDBBackingStore::Transaction::WriteDescriptor& | 4481 IndexedDBBackingStore::Transaction::WriteDescriptor& |
4462 IndexedDBBackingStore::Transaction::WriteDescriptor:: | 4482 IndexedDBBackingStore::Transaction::WriteDescriptor:: |
4463 operator=(const WriteDescriptor& other) = default; | 4483 operator=(const WriteDescriptor& other) = default; |
4464 | 4484 |
4465 } // namespace content | 4485 } // namespace content |
OLD | NEW |