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

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

Issue 1706413002: Indexed DB: Rename "int version" to "version" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/indexed_db/indexed_db_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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 found = false; 406 found = false;
407 s = GetInt(transaction.get(), it->Key(), &database_id, &found); 407 s = GetInt(transaction.get(), it->Key(), &database_id, &found);
408 if (!s.ok()) { 408 if (!s.ok()) {
409 INTERNAL_READ_ERROR_UNTESTED(SET_UP_METADATA); 409 INTERNAL_READ_ERROR_UNTESTED(SET_UP_METADATA);
410 return s; 410 return s;
411 } 411 }
412 if (!found) { 412 if (!found) {
413 INTERNAL_CONSISTENCY_ERROR_UNTESTED(SET_UP_METADATA); 413 INTERNAL_CONSISTENCY_ERROR_UNTESTED(SET_UP_METADATA);
414 return InternalInconsistencyStatus(); 414 return InternalInconsistencyStatus();
415 } 415 }
416 std::string int_version_key = DatabaseMetaDataKey::Encode( 416 std::string version_key = DatabaseMetaDataKey::Encode(
417 database_id, DatabaseMetaDataKey::USER_INT_VERSION); 417 database_id, DatabaseMetaDataKey::USER_VERSION);
418 PutVarInt(transaction.get(), 418 PutVarInt(transaction.get(), version_key,
419 int_version_key, 419 IndexedDBDatabaseMetadata::DEFAULT_VERSION);
420 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION);
421 } 420 }
422 } 421 }
423 if (s.ok() && db_schema_version < 2) { 422 if (s.ok() && db_schema_version < 2) {
424 db_schema_version = 2; 423 db_schema_version = 2;
425 PutInt(transaction.get(), schema_version_key, db_schema_version); 424 PutInt(transaction.get(), schema_version_key, db_schema_version);
426 db_data_version = blink::kSerializedScriptValueVersion; 425 db_data_version = blink::kSerializedScriptValueVersion;
427 PutInt(transaction.get(), data_version_key, db_data_version); 426 PutInt(transaction.get(), data_version_key, db_data_version);
428 } 427 }
429 if (db_schema_version < 3) { 428 if (db_schema_version < 3) {
430 db_schema_version = 3; 429 db_schema_version = 3;
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 // Decode database id (in iterator value). 1210 // Decode database id (in iterator value).
1212 int64_t database_id = 0; 1211 int64_t database_id = 0;
1213 StringPiece value_slice(it->Value()); 1212 StringPiece value_slice(it->Value());
1214 if (!DecodeInt(&value_slice, &database_id) || !value_slice.empty()) { 1213 if (!DecodeInt(&value_slice, &database_id) || !value_slice.empty()) {
1215 INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_DATABASE_NAMES); 1214 INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_DATABASE_NAMES);
1216 continue; 1215 continue;
1217 } 1216 }
1218 1217
1219 // Look up version by id. 1218 // Look up version by id.
1220 bool found = false; 1219 bool found = false;
1221 int64_t database_version = IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION; 1220 int64_t database_version = IndexedDBDatabaseMetadata::DEFAULT_VERSION;
1222 *s = GetVarInt(db_.get(), 1221 *s = GetVarInt(db_.get(),
1223 DatabaseMetaDataKey::Encode( 1222 DatabaseMetaDataKey::Encode(
1224 database_id, DatabaseMetaDataKey::USER_INT_VERSION), 1223 database_id, DatabaseMetaDataKey::USER_VERSION),
1225 &database_version, 1224 &database_version, &found);
1226 &found);
1227 if (!s->ok() || !found) { 1225 if (!s->ok() || !found) {
1228 INTERNAL_READ_ERROR_UNTESTED(GET_DATABASE_NAMES); 1226 INTERNAL_READ_ERROR_UNTESTED(GET_DATABASE_NAMES);
1229 continue; 1227 continue;
1230 } 1228 }
1231 1229
1232 // Ignore stale metadata from failed initial opens. 1230 // Ignore stale metadata from failed initial opens.
1233 if (database_version != IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION) 1231 if (database_version != IndexedDBDatabaseMetadata::DEFAULT_VERSION)
1234 found_names.push_back(database_name_key.database_name()); 1232 found_names.push_back(database_name_key.database_name());
1235 } 1233 }
1236 1234
1237 if (!s->ok()) 1235 if (!s->ok())
1238 INTERNAL_READ_ERROR(GET_DATABASE_NAMES); 1236 INTERNAL_READ_ERROR(GET_DATABASE_NAMES);
1239 1237
1240 return found_names; 1238 return found_names;
1241 } 1239 }
1242 1240
1243 leveldb::Status IndexedDBBackingStore::GetIDBDatabaseMetaData( 1241 leveldb::Status IndexedDBBackingStore::GetIDBDatabaseMetaData(
1244 const base::string16& name, 1242 const base::string16& name,
1245 IndexedDBDatabaseMetadata* metadata, 1243 IndexedDBDatabaseMetadata* metadata,
1246 bool* found) { 1244 bool* found) {
1247 const std::string key = DatabaseNameKey::Encode(origin_identifier_, name); 1245 const std::string key = DatabaseNameKey::Encode(origin_identifier_, name);
1248 *found = false; 1246 *found = false;
1249 1247
1250 leveldb::Status s = GetInt(db_.get(), key, &metadata->id, found); 1248 leveldb::Status s = GetInt(db_.get(), key, &metadata->id, found);
1251 if (!s.ok()) { 1249 if (!s.ok()) {
1252 INTERNAL_READ_ERROR(GET_IDBDATABASE_METADATA); 1250 INTERNAL_READ_ERROR(GET_IDBDATABASE_METADATA);
1253 return s; 1251 return s;
1254 } 1252 }
1255 if (!*found) 1253 if (!*found)
1256 return leveldb::Status::OK(); 1254 return leveldb::Status::OK();
1257 1255
1258 s = GetVarInt(db_.get(), 1256 s = GetVarInt(db_.get(), DatabaseMetaDataKey::Encode(
1259 DatabaseMetaDataKey::Encode( 1257 metadata->id, DatabaseMetaDataKey::USER_VERSION),
1260 metadata->id, DatabaseMetaDataKey::USER_INT_VERSION), 1258 &metadata->version, found);
1261 &metadata->int_version,
1262 found);
1263 if (!s.ok()) { 1259 if (!s.ok()) {
1264 INTERNAL_READ_ERROR_UNTESTED(GET_IDBDATABASE_METADATA); 1260 INTERNAL_READ_ERROR_UNTESTED(GET_IDBDATABASE_METADATA);
1265 return s; 1261 return s;
1266 } 1262 }
1267 if (!*found) { 1263 if (!*found) {
1268 INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_IDBDATABASE_METADATA); 1264 INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_IDBDATABASE_METADATA);
1269 return InternalInconsistencyStatus(); 1265 return InternalInconsistencyStatus();
1270 } 1266 }
1271 1267
1272 if (metadata->int_version == IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION) 1268 if (metadata->version == IndexedDBDatabaseMetadata::DEFAULT_VERSION)
1273 metadata->int_version = IndexedDBDatabaseMetadata::NO_INT_VERSION; 1269 metadata->version = IndexedDBDatabaseMetadata::NO_VERSION;
1274 1270
1275 s = GetMaxObjectStoreId( 1271 s = GetMaxObjectStoreId(
1276 db_.get(), metadata->id, &metadata->max_object_store_id); 1272 db_.get(), metadata->id, &metadata->max_object_store_id);
1277 if (!s.ok()) { 1273 if (!s.ok()) {
1278 INTERNAL_READ_ERROR_UNTESTED(GET_IDBDATABASE_METADATA); 1274 INTERNAL_READ_ERROR_UNTESTED(GET_IDBDATABASE_METADATA);
1279 } 1275 }
1280 1276
1281 // We don't cache this, we just check it if it's there. 1277 // We don't cache this, we just check it if it's there.
1282 int64_t blob_key_generator_current_number = 1278 int64_t blob_key_generator_current_number =
1283 DatabaseMetaDataKey::kInvalidBlobKey; 1279 DatabaseMetaDataKey::kInvalidBlobKey;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 DCHECK_GE(max_database_id, 0); 1318 DCHECK_GE(max_database_id, 0);
1323 1319
1324 int64_t database_id = max_database_id + 1; 1320 int64_t database_id = max_database_id + 1;
1325 PutInt(transaction, MaxDatabaseIdKey::Encode(), database_id); 1321 PutInt(transaction, MaxDatabaseIdKey::Encode(), database_id);
1326 *new_id = database_id; 1322 *new_id = database_id;
1327 return leveldb::Status::OK(); 1323 return leveldb::Status::OK();
1328 } 1324 }
1329 1325
1330 leveldb::Status IndexedDBBackingStore::CreateIDBDatabaseMetaData( 1326 leveldb::Status IndexedDBBackingStore::CreateIDBDatabaseMetaData(
1331 const base::string16& name, 1327 const base::string16& name,
1332 int64_t int_version, 1328 int64_t version,
1333 int64_t* row_id) { 1329 int64_t* row_id) {
1334 // TODO(jsbell): Don't persist metadata if open fails. http://crbug.com/395472 1330 // TODO(jsbell): Don't persist metadata if open fails. http://crbug.com/395472
1335 scoped_refptr<LevelDBTransaction> transaction = 1331 scoped_refptr<LevelDBTransaction> transaction =
1336 IndexedDBClassFactory::Get()->CreateLevelDBTransaction(db_.get()); 1332 IndexedDBClassFactory::Get()->CreateLevelDBTransaction(db_.get());
1337 1333
1338 leveldb::Status s = GetNewDatabaseId(transaction.get(), row_id); 1334 leveldb::Status s = GetNewDatabaseId(transaction.get(), row_id);
1339 if (!s.ok()) 1335 if (!s.ok())
1340 return s; 1336 return s;
1341 DCHECK_GE(*row_id, 0); 1337 DCHECK_GE(*row_id, 0);
1342 1338
1343 if (int_version == IndexedDBDatabaseMetadata::NO_INT_VERSION) 1339 if (version == IndexedDBDatabaseMetadata::NO_VERSION)
1344 int_version = IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION; 1340 version = IndexedDBDatabaseMetadata::DEFAULT_VERSION;
1345 1341
1346 PutInt(transaction.get(), 1342 PutInt(transaction.get(),
1347 DatabaseNameKey::Encode(origin_identifier_, name), 1343 DatabaseNameKey::Encode(origin_identifier_, name),
1348 *row_id); 1344 *row_id);
1349 PutVarInt(transaction.get(), 1345 PutVarInt(transaction.get(), DatabaseMetaDataKey::Encode(
1350 DatabaseMetaDataKey::Encode(*row_id, 1346 *row_id, DatabaseMetaDataKey::USER_VERSION),
1351 DatabaseMetaDataKey::USER_INT_VERSION), 1347 version);
1352 int_version);
1353 PutVarInt( 1348 PutVarInt(
1354 transaction.get(), 1349 transaction.get(),
1355 DatabaseMetaDataKey::Encode( 1350 DatabaseMetaDataKey::Encode(
1356 *row_id, DatabaseMetaDataKey::BLOB_KEY_GENERATOR_CURRENT_NUMBER), 1351 *row_id, DatabaseMetaDataKey::BLOB_KEY_GENERATOR_CURRENT_NUMBER),
1357 DatabaseMetaDataKey::kBlobKeyGeneratorInitialNumber); 1352 DatabaseMetaDataKey::kBlobKeyGeneratorInitialNumber);
1358 1353
1359 s = transaction->Commit(); 1354 s = transaction->Commit();
1360 if (!s.ok()) 1355 if (!s.ok())
1361 INTERNAL_WRITE_ERROR_UNTESTED(CREATE_IDBDATABASE_METADATA); 1356 INTERNAL_WRITE_ERROR_UNTESTED(CREATE_IDBDATABASE_METADATA);
1362 return s; 1357 return s;
1363 } 1358 }
1364 1359
1365 bool IndexedDBBackingStore::UpdateIDBDatabaseIntVersion( 1360 bool IndexedDBBackingStore::UpdateIDBDatabaseIntVersion(
1366 IndexedDBBackingStore::Transaction* transaction, 1361 IndexedDBBackingStore::Transaction* transaction,
1367 int64_t row_id, 1362 int64_t row_id,
1368 int64_t int_version) { 1363 int64_t version) {
1369 if (int_version == IndexedDBDatabaseMetadata::NO_INT_VERSION) 1364 if (version == IndexedDBDatabaseMetadata::NO_VERSION)
1370 int_version = IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION; 1365 version = IndexedDBDatabaseMetadata::DEFAULT_VERSION;
1371 DCHECK_GE(int_version, 0) << "int_version was " << int_version; 1366 DCHECK_GE(version, 0) << "version was " << version;
1372 PutVarInt(transaction->transaction(), 1367 PutVarInt(
1373 DatabaseMetaDataKey::Encode(row_id, 1368 transaction->transaction(),
1374 DatabaseMetaDataKey::USER_INT_VERSION), 1369 DatabaseMetaDataKey::Encode(row_id, DatabaseMetaDataKey::USER_VERSION),
1375 int_version); 1370 version);
1376 return true; 1371 return true;
1377 } 1372 }
1378 1373
1379 // If you're deleting a range that contains user keys that have blob info, this 1374 // If you're deleting a range that contains user keys that have blob info, this
1380 // won't clean up the blobs. 1375 // won't clean up the blobs.
1381 static leveldb::Status DeleteRangeBasic(LevelDBTransaction* transaction, 1376 static leveldb::Status DeleteRangeBasic(LevelDBTransaction* transaction,
1382 const std::string& begin, 1377 const std::string& begin,
1383 const std::string& end, 1378 const std::string& end,
1384 bool upper_open) { 1379 bool upper_open) {
1385 scoped_ptr<LevelDBIterator> it = transaction->CreateIterator(); 1380 scoped_ptr<LevelDBIterator> it = transaction->CreateIterator();
(...skipping 3099 matching lines...) Expand 10 before | Expand all | Expand 10 after
4485 4480
4486 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( 4481 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor(
4487 const WriteDescriptor& other) = default; 4482 const WriteDescriptor& other) = default;
4488 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = 4483 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() =
4489 default; 4484 default;
4490 IndexedDBBackingStore::Transaction::WriteDescriptor& 4485 IndexedDBBackingStore::Transaction::WriteDescriptor&
4491 IndexedDBBackingStore::Transaction::WriteDescriptor:: 4486 IndexedDBBackingStore::Transaction::WriteDescriptor::
4492 operator=(const WriteDescriptor& other) = default; 4487 operator=(const WriteDescriptor& other) = default;
4493 4488
4494 } // namespace content 4489 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_backing_store.h ('k') | content/browser/indexed_db/indexed_db_backing_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698