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

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

Issue 2119283002: Use container::back() and container::pop_back() for content. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
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 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 std::unique_ptr<LevelDBIterator> it = 1389 std::unique_ptr<LevelDBIterator> it =
1390 transaction->transaction()->CreateIterator(); 1390 transaction->transaction()->CreateIterator();
1391 leveldb::Status s = it->Seek(start_key); 1391 leveldb::Status s = it->Seek(start_key);
1392 for (; s.ok() && it->IsValid() && 1392 for (; s.ok() && it->IsValid() &&
1393 (upper_open ? CompareKeys(it->Key(), end_key) < 0 1393 (upper_open ? CompareKeys(it->Key(), end_key) < 0
1394 : CompareKeys(it->Key(), end_key) <= 0); 1394 : CompareKeys(it->Key(), end_key) <= 0);
1395 s = it->Next()) { 1395 s = it->Next()) {
1396 StringPiece key_piece(it->Key()); 1396 StringPiece key_piece(it->Key());
1397 std::string user_key = 1397 std::string user_key =
1398 BlobEntryKey::ReencodeToObjectStoreDataKey(&key_piece); 1398 BlobEntryKey::ReencodeToObjectStoreDataKey(&key_piece);
1399 if (!user_key.size()) { 1399 if (user_key.empty()) {
1400 INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_IDBDATABASE_METADATA); 1400 INTERNAL_CONSISTENCY_ERROR_UNTESTED(GET_IDBDATABASE_METADATA);
1401 return InternalInconsistencyStatus(); 1401 return InternalInconsistencyStatus();
1402 } 1402 }
1403 transaction->PutBlobInfo( 1403 transaction->PutBlobInfo(
1404 database_id, object_store_id, user_key, NULL, NULL); 1404 database_id, object_store_id, user_key, NULL, NULL);
1405 } 1405 }
1406 return s; 1406 return s;
1407 } 1407 }
1408 1408
1409 static leveldb::Status DeleteBlobsInObjectStore( 1409 static leveldb::Status DeleteBlobsInObjectStore(
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 v.append(value->bits); 1929 v.append(value->bits);
1930 1930
1931 leveldb_transaction->Put(object_store_data_key, &v); 1931 leveldb_transaction->Put(object_store_data_key, &v);
1932 s = transaction->PutBlobInfoIfNeeded(database_id, 1932 s = transaction->PutBlobInfoIfNeeded(database_id,
1933 object_store_id, 1933 object_store_id,
1934 object_store_data_key, 1934 object_store_data_key,
1935 &value->blob_info, 1935 &value->blob_info,
1936 handles); 1936 handles);
1937 if (!s.ok()) 1937 if (!s.ok())
1938 return s; 1938 return s;
1939 DCHECK(!handles->size()); 1939 DCHECK(handles->empty());
1940 1940
1941 const std::string exists_entry_key = 1941 const std::string exists_entry_key =
1942 ExistsEntryKey::Encode(database_id, object_store_id, key); 1942 ExistsEntryKey::Encode(database_id, object_store_id, key);
1943 std::string version_encoded; 1943 std::string version_encoded;
1944 EncodeInt(version, &version_encoded); 1944 EncodeInt(version, &version_encoded);
1945 leveldb_transaction->Put(exists_entry_key, &version_encoded); 1945 leveldb_transaction->Put(exists_entry_key, &version_encoded);
1946 1946
1947 std::string key_encoded; 1947 std::string key_encoded;
1948 EncodeIDBKey(key, &key_encoded); 1948 EncodeIDBKey(key, &key_encoded);
1949 record_identifier->Reset(key_encoded, version); 1949 record_identifier->Reset(key_encoded, version);
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
2173 std::string data; 2173 std::string data;
2174 2174
2175 leveldb::Status s = 2175 leveldb::Status s =
2176 transaction->transaction()->Get(leveldb_key, &data, found); 2176 transaction->transaction()->Get(leveldb_key, &data, found);
2177 if (!s.ok()) { 2177 if (!s.ok()) {
2178 INTERNAL_READ_ERROR_UNTESTED(KEY_EXISTS_IN_OBJECT_STORE); 2178 INTERNAL_READ_ERROR_UNTESTED(KEY_EXISTS_IN_OBJECT_STORE);
2179 return s; 2179 return s;
2180 } 2180 }
2181 if (!*found) 2181 if (!*found)
2182 return leveldb::Status::OK(); 2182 return leveldb::Status::OK();
2183 if (!data.size()) { 2183 if (data.empty()) {
2184 INTERNAL_READ_ERROR_UNTESTED(KEY_EXISTS_IN_OBJECT_STORE); 2184 INTERNAL_READ_ERROR_UNTESTED(KEY_EXISTS_IN_OBJECT_STORE);
2185 return InternalInconsistencyStatus(); 2185 return InternalInconsistencyStatus();
2186 } 2186 }
2187 2187
2188 int64_t version; 2188 int64_t version;
2189 StringPiece slice(data); 2189 StringPiece slice(data);
2190 if (!DecodeVarInt(&slice, &version)) 2190 if (!DecodeVarInt(&slice, &version))
2191 return InternalInconsistencyStatus(); 2191 return InternalInconsistencyStatus();
2192 2192
2193 std::string encoded_key; 2193 std::string encoded_key;
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after
3037 index_id, 3037 index_id,
3038 key, 3038 key,
3039 &found_encoded_primary_key, 3039 &found_encoded_primary_key,
3040 &found); 3040 &found);
3041 if (!s.ok()) { 3041 if (!s.ok()) {
3042 INTERNAL_READ_ERROR_UNTESTED(GET_PRIMARY_KEY_VIA_INDEX); 3042 INTERNAL_READ_ERROR_UNTESTED(GET_PRIMARY_KEY_VIA_INDEX);
3043 return s; 3043 return s;
3044 } 3044 }
3045 if (!found) 3045 if (!found)
3046 return s; 3046 return s;
3047 if (!found_encoded_primary_key.size()) { 3047 if (found_encoded_primary_key.empty()) {
3048 INTERNAL_READ_ERROR_UNTESTED(GET_PRIMARY_KEY_VIA_INDEX); 3048 INTERNAL_READ_ERROR_UNTESTED(GET_PRIMARY_KEY_VIA_INDEX);
3049 return InvalidDBKeyStatus(); 3049 return InvalidDBKeyStatus();
3050 } 3050 }
3051 3051
3052 StringPiece slice(found_encoded_primary_key); 3052 StringPiece slice(found_encoded_primary_key);
3053 if (DecodeIDBKey(&slice, primary_key) && slice.empty()) 3053 if (DecodeIDBKey(&slice, primary_key) && slice.empty())
3054 return s; 3054 return s;
3055 else 3055 else
3056 return InvalidDBKeyStatus(); 3056 return InvalidDBKeyStatus();
3057 } 3057 }
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
3599 bool found = false; 3599 bool found = false;
3600 *s = transaction_->transaction()->Get(primary_leveldb_key, &result, &found); 3600 *s = transaction_->transaction()->Get(primary_leveldb_key, &result, &found);
3601 if (!s->ok()) { 3601 if (!s->ok()) {
3602 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); 3602 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW);
3603 return false; 3603 return false;
3604 } 3604 }
3605 if (!found) { 3605 if (!found) {
3606 transaction_->transaction()->Remove(iterator_->Key()); 3606 transaction_->transaction()->Remove(iterator_->Key());
3607 return false; 3607 return false;
3608 } 3608 }
3609 if (!result.size()) { 3609 if (result.empty()) {
3610 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); 3610 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW);
3611 return false; 3611 return false;
3612 } 3612 }
3613 3613
3614 int64_t object_store_data_version; 3614 int64_t object_store_data_version;
3615 slice = StringPiece(result); 3615 slice = StringPiece(result);
3616 if (!DecodeVarInt(&slice, &object_store_data_version)) { 3616 if (!DecodeVarInt(&slice, &object_store_data_version)) {
3617 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); 3617 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW);
3618 *s = InternalInconsistencyStatus(); 3618 *s = InternalInconsistencyStatus();
3619 return false; 3619 return false;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
3716 bool found = false; 3716 bool found = false;
3717 *s = transaction_->transaction()->Get(primary_leveldb_key_, &result, &found); 3717 *s = transaction_->transaction()->Get(primary_leveldb_key_, &result, &found);
3718 if (!s->ok()) { 3718 if (!s->ok()) {
3719 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); 3719 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW);
3720 return false; 3720 return false;
3721 } 3721 }
3722 if (!found) { 3722 if (!found) {
3723 transaction_->transaction()->Remove(iterator_->Key()); 3723 transaction_->transaction()->Remove(iterator_->Key());
3724 return false; 3724 return false;
3725 } 3725 }
3726 if (!result.size()) { 3726 if (result.empty()) {
3727 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); 3727 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW);
3728 return false; 3728 return false;
3729 } 3729 }
3730 3730
3731 int64_t object_store_data_version; 3731 int64_t object_store_data_version;
3732 slice = StringPiece(result); 3732 slice = StringPiece(result);
3733 if (!DecodeVarInt(&slice, &object_store_data_version)) { 3733 if (!DecodeVarInt(&slice, &object_store_data_version)) {
3734 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); 3734 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW);
3735 *s = InternalInconsistencyStatus(); 3735 *s = InternalInconsistencyStatus();
3736 return false; 3736 return false;
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
4158 4158
4159 BlobEntryKeyValuePairVec new_blob_entries; 4159 BlobEntryKeyValuePairVec new_blob_entries;
4160 WriteDescriptorVec new_files_to_write; 4160 WriteDescriptorVec new_files_to_write;
4161 s = HandleBlobPreTransaction(&new_blob_entries, &new_files_to_write); 4161 s = HandleBlobPreTransaction(&new_blob_entries, &new_files_to_write);
4162 if (!s.ok()) { 4162 if (!s.ok()) {
4163 INTERNAL_WRITE_ERROR_UNTESTED(TRANSACTION_COMMIT_METHOD); 4163 INTERNAL_WRITE_ERROR_UNTESTED(TRANSACTION_COMMIT_METHOD);
4164 transaction_ = NULL; 4164 transaction_ = NULL;
4165 return s; 4165 return s;
4166 } 4166 }
4167 4167
4168 DCHECK(!new_files_to_write.size() || 4168 DCHECK(new_files_to_write.empty() ||
4169 KeyPrefix::IsValidDatabaseId(database_id_)); 4169 KeyPrefix::IsValidDatabaseId(database_id_));
4170 if (!CollectBlobFilesToRemove()) { 4170 if (!CollectBlobFilesToRemove()) {
4171 INTERNAL_WRITE_ERROR_UNTESTED(TRANSACTION_COMMIT_METHOD); 4171 INTERNAL_WRITE_ERROR_UNTESTED(TRANSACTION_COMMIT_METHOD);
4172 transaction_ = NULL; 4172 transaction_ = NULL;
4173 return InternalInconsistencyStatus(); 4173 return InternalInconsistencyStatus();
4174 } 4174 }
4175 4175
4176 committing_ = true; 4176 committing_ = true;
4177 ++backing_store_->committing_transaction_count_; 4177 ++backing_store_->committing_transaction_count_;
4178 4178
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
4437 BlobChangeRecord* record = NULL; 4437 BlobChangeRecord* record = NULL;
4438 if (it == blob_change_map_.end()) { 4438 if (it == blob_change_map_.end()) {
4439 record = new BlobChangeRecord(object_store_data_key, object_store_id); 4439 record = new BlobChangeRecord(object_store_data_key, object_store_id);
4440 blob_change_map_[object_store_data_key] = record; 4440 blob_change_map_[object_store_data_key] = record;
4441 } else { 4441 } else {
4442 record = it->second; 4442 record = it->second;
4443 } 4443 }
4444 DCHECK_EQ(record->object_store_id(), object_store_id); 4444 DCHECK_EQ(record->object_store_id(), object_store_id);
4445 record->SetBlobInfo(blob_info); 4445 record->SetBlobInfo(blob_info);
4446 record->SetHandles(handles); 4446 record->SetHandles(handles);
4447 DCHECK(!handles || !handles->size()); 4447 DCHECK(!handles || handles->empty());
4448 } 4448 }
4449 4449
4450 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( 4450 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor(
4451 const GURL& url, 4451 const GURL& url,
4452 int64_t key, 4452 int64_t key,
4453 int64_t size, 4453 int64_t size,
4454 base::Time last_modified) 4454 base::Time last_modified)
4455 : is_file_(false), 4455 : is_file_(false),
4456 url_(url), 4456 url_(url),
4457 key_(key), 4457 key_(key),
(...skipping 15 matching lines...) Expand all
4473 4473
4474 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( 4474 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor(
4475 const WriteDescriptor& other) = default; 4475 const WriteDescriptor& other) = default;
4476 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = 4476 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() =
4477 default; 4477 default;
4478 IndexedDBBackingStore::Transaction::WriteDescriptor& 4478 IndexedDBBackingStore::Transaction::WriteDescriptor&
4479 IndexedDBBackingStore::Transaction::WriteDescriptor:: 4479 IndexedDBBackingStore::Transaction::WriteDescriptor::
4480 operator=(const WriteDescriptor& other) = default; 4480 operator=(const WriteDescriptor& other) = default;
4481 4481
4482 } // namespace content 4482 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698