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

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

Issue 19117005: IndexedDB: Coding conventions and cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
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 "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 return true; 227 return true;
228 } 228 }
229 229
230 WARN_UNUSED_RESULT static bool SetUpMetadata( 230 WARN_UNUSED_RESULT static bool SetUpMetadata(
231 LevelDBDatabase* db, 231 LevelDBDatabase* db,
232 const std::string& origin_identifier) { 232 const std::string& origin_identifier) {
233 const uint32 latest_known_data_version = kWireVersion; 233 const uint32 latest_known_data_version = kWireVersion;
234 const std::string schema_version_key = SchemaVersionKey::Encode(); 234 const std::string schema_version_key = SchemaVersionKey::Encode();
235 const std::string data_version_key = DataVersionKey::Encode(); 235 const std::string data_version_key = DataVersionKey::Encode();
236 236
237 scoped_refptr<LevelDBTransaction> transaction = 237 scoped_refptr<LevelDBTransaction> transaction = new LevelDBTransaction(db);
238 LevelDBTransaction::Create(db);
239 238
240 int64 db_schema_version = 0; 239 int64 db_schema_version = 0;
241 int64 db_data_version = 0; 240 int64 db_data_version = 0;
242 bool found = false; 241 bool found = false;
243 bool ok = 242 bool ok =
244 GetInt(transaction.get(), schema_version_key, &db_schema_version, &found); 243 GetInt(transaction.get(), schema_version_key, &db_schema_version, &found);
245 if (!ok) { 244 if (!ok) {
246 INTERNAL_READ_ERROR(SET_UP_METADATA); 245 INTERNAL_READ_ERROR(SET_UP_METADATA);
247 return false; 246 return false;
248 } 247 }
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 if (!ok) { 714 if (!ok) {
716 INTERNAL_READ_ERROR(GET_IDBDATABASE_METADATA); 715 INTERNAL_READ_ERROR(GET_IDBDATABASE_METADATA);
717 return false; 716 return false;
718 } 717 }
719 718
720 return true; 719 return true;
721 } 720 }
722 721
723 WARN_UNUSED_RESULT static bool GetNewDatabaseId(LevelDBDatabase* db, 722 WARN_UNUSED_RESULT static bool GetNewDatabaseId(LevelDBDatabase* db,
724 int64* new_id) { 723 int64* new_id) {
725 scoped_refptr<LevelDBTransaction> transaction = 724 scoped_refptr<LevelDBTransaction> transaction = new LevelDBTransaction(db);
726 LevelDBTransaction::Create(db);
727 725
728 *new_id = -1; 726 *new_id = -1;
729 int64 max_database_id = -1; 727 int64 max_database_id = -1;
730 bool found = false; 728 bool found = false;
731 bool ok = GetInt( 729 bool ok = GetInt(
732 transaction.get(), MaxDatabaseIdKey::Encode(), &max_database_id, &found); 730 transaction.get(), MaxDatabaseIdKey::Encode(), &max_database_id, &found);
733 if (!ok) { 731 if (!ok) {
734 INTERNAL_READ_ERROR(GET_NEW_DATABASE_ID); 732 INTERNAL_READ_ERROR(GET_NEW_DATABASE_ID);
735 return false; 733 return false;
736 } 734 }
(...skipping 18 matching lines...) Expand all
755 int64* row_id) { 753 int64* row_id) {
756 bool ok = GetNewDatabaseId(db_.get(), row_id); 754 bool ok = GetNewDatabaseId(db_.get(), row_id);
757 if (!ok) 755 if (!ok)
758 return false; 756 return false;
759 DCHECK_GE(*row_id, 0); 757 DCHECK_GE(*row_id, 0);
760 758
761 if (int_version == IndexedDBDatabaseMetadata::NO_INT_VERSION) 759 if (int_version == IndexedDBDatabaseMetadata::NO_INT_VERSION)
762 int_version = IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION; 760 int_version = IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION;
763 761
764 scoped_refptr<LevelDBTransaction> transaction = 762 scoped_refptr<LevelDBTransaction> transaction =
765 LevelDBTransaction::Create(db_.get()); 763 new LevelDBTransaction(db_.get());
766 PutInt( 764 PutInt(
767 transaction.get(), DatabaseNameKey::Encode(identifier_, name), *row_id); 765 transaction.get(), DatabaseNameKey::Encode(identifier_, name), *row_id);
768 PutString( 766 PutString(
769 transaction.get(), 767 transaction.get(),
770 DatabaseMetaDataKey::Encode(*row_id, DatabaseMetaDataKey::USER_VERSION), 768 DatabaseMetaDataKey::Encode(*row_id, DatabaseMetaDataKey::USER_VERSION),
771 version); 769 version);
772 PutVarInt(transaction.get(), 770 PutVarInt(transaction.get(),
773 DatabaseMetaDataKey::Encode(*row_id, 771 DatabaseMetaDataKey::Encode(*row_id,
774 DatabaseMetaDataKey::USER_INT_VERSION), 772 DatabaseMetaDataKey::USER_INT_VERSION),
775 int_version); 773 int_version);
(...skipping 1799 matching lines...) Expand 10 before | Expand all | Expand 10 after
2575 2573
2576 IndexedDBBackingStore::Transaction::Transaction( 2574 IndexedDBBackingStore::Transaction::Transaction(
2577 IndexedDBBackingStore* backing_store) 2575 IndexedDBBackingStore* backing_store)
2578 : backing_store_(backing_store) {} 2576 : backing_store_(backing_store) {}
2579 2577
2580 IndexedDBBackingStore::Transaction::~Transaction() {} 2578 IndexedDBBackingStore::Transaction::~Transaction() {}
2581 2579
2582 void IndexedDBBackingStore::Transaction::Begin() { 2580 void IndexedDBBackingStore::Transaction::Begin() {
2583 IDB_TRACE("IndexedDBBackingStore::Transaction::Begin"); 2581 IDB_TRACE("IndexedDBBackingStore::Transaction::Begin");
2584 DCHECK(!transaction_.get()); 2582 DCHECK(!transaction_.get());
2585 transaction_ = LevelDBTransaction::Create(backing_store_->db_.get()); 2583 transaction_ = new LevelDBTransaction(backing_store_->db_.get());
2586 } 2584 }
2587 2585
2588 bool IndexedDBBackingStore::Transaction::Commit() { 2586 bool IndexedDBBackingStore::Transaction::Commit() {
2589 IDB_TRACE("IndexedDBBackingStore::Transaction::Commit"); 2587 IDB_TRACE("IndexedDBBackingStore::Transaction::Commit");
2590 DCHECK(transaction_.get()); 2588 DCHECK(transaction_.get());
2591 bool result = transaction_->Commit(); 2589 bool result = transaction_->Commit();
2592 transaction_ = NULL; 2590 transaction_ = NULL;
2593 if (!result) 2591 if (!result)
2594 INTERNAL_WRITE_ERROR(TRANSACTION_COMMIT_METHOD); 2592 INTERNAL_WRITE_ERROR(TRANSACTION_COMMIT_METHOD);
2595 return result; 2593 return result;
2596 } 2594 }
2597 2595
2598 void IndexedDBBackingStore::Transaction::Rollback() { 2596 void IndexedDBBackingStore::Transaction::Rollback() {
2599 IDB_TRACE("IndexedDBBackingStore::Transaction::Rollback"); 2597 IDB_TRACE("IndexedDBBackingStore::Transaction::Rollback");
2600 DCHECK(transaction_.get()); 2598 DCHECK(transaction_.get());
2601 transaction_->Rollback(); 2599 transaction_->Rollback();
2602 transaction_ = NULL; 2600 transaction_ = NULL;
2603 } 2601 }
2604 2602
2605 } // namespace content 2603 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698