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

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

Issue 2255853003: IndexedDB: ScopedVector<T> -> vector<unique_ptr<T>> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback Created 4 years, 4 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_index_writer.h" 5 #include "content/browser/indexed_db/indexed_db_index_writer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 24 matching lines...) Expand all
35 IndexedDBBackingStore* backing_store, 35 IndexedDBBackingStore* backing_store,
36 IndexedDBBackingStore::Transaction* transaction, 36 IndexedDBBackingStore::Transaction* transaction,
37 int64_t database_id, 37 int64_t database_id,
38 int64_t object_store_id, 38 int64_t object_store_id,
39 int64_t index_id, 39 int64_t index_id,
40 bool* can_add_keys, 40 bool* can_add_keys,
41 const IndexedDBKey& primary_key, 41 const IndexedDBKey& primary_key,
42 base::string16* error_message) const { 42 base::string16* error_message) const {
43 *can_add_keys = false; 43 *can_add_keys = false;
44 DCHECK_EQ(index_id, index_keys_.first); 44 DCHECK_EQ(index_id, index_keys_.first);
45 for (size_t i = 0; i < index_keys_.second.size(); ++i) { 45 for (const auto& key : index_keys_.second) {
46 bool ok = AddingKeyAllowed(backing_store, 46 bool ok = AddingKeyAllowed(backing_store, transaction, database_id,
47 transaction, 47 object_store_id, index_id, key, primary_key,
48 database_id,
49 object_store_id,
50 index_id,
51 (index_keys_.second)[i],
52 primary_key,
53 can_add_keys); 48 can_add_keys);
54 if (!ok) 49 if (!ok)
55 return false; 50 return false;
56 if (!*can_add_keys) { 51 if (!*can_add_keys) {
57 if (error_message) { 52 if (error_message) {
58 *error_message = ASCIIToUTF16("Unable to add key to index '") + 53 *error_message = ASCIIToUTF16("Unable to add key to index '") +
59 index_metadata_.name + 54 index_metadata_.name +
60 ASCIIToUTF16("': at least one key does not satisfy " 55 ASCIIToUTF16("': at least one key does not satisfy "
61 "the uniqueness requirements."); 56 "the uniqueness requirements.");
62 } 57 }
63 return true; 58 return true;
64 } 59 }
65 } 60 }
66 *can_add_keys = true; 61 *can_add_keys = true;
67 return true; 62 return true;
68 } 63 }
69 64
70 void IndexWriter::WriteIndexKeys( 65 void IndexWriter::WriteIndexKeys(
71 const IndexedDBBackingStore::RecordIdentifier& record_identifier, 66 const IndexedDBBackingStore::RecordIdentifier& record_identifier,
72 IndexedDBBackingStore* backing_store, 67 IndexedDBBackingStore* backing_store,
73 IndexedDBBackingStore::Transaction* transaction, 68 IndexedDBBackingStore::Transaction* transaction,
74 int64_t database_id, 69 int64_t database_id,
75 int64_t object_store_id) const { 70 int64_t object_store_id) const {
76 int64_t index_id = index_metadata_.id; 71 int64_t index_id = index_metadata_.id;
77 DCHECK_EQ(index_id, index_keys_.first); 72 DCHECK_EQ(index_id, index_keys_.first);
78 for (size_t i = 0; i < index_keys_.second.size(); ++i) { 73 for (const auto& key : index_keys_.second) {
79 leveldb::Status s = 74 leveldb::Status s = backing_store->PutIndexDataForRecord(
80 backing_store->PutIndexDataForRecord(transaction, 75 transaction, database_id, object_store_id, index_id, key,
81 database_id, 76 record_identifier);
82 object_store_id,
83 index_id,
84 index_keys_.second[i],
85 record_identifier);
86 // This should have already been verified as a valid write during 77 // This should have already been verified as a valid write during
87 // verify_index_keys. 78 // verify_index_keys.
88 DCHECK(s.ok()); 79 DCHECK(s.ok());
89 } 80 }
90 } 81 }
91 82
92 bool IndexWriter::AddingKeyAllowed( 83 bool IndexWriter::AddingKeyAllowed(
93 IndexedDBBackingStore* backing_store, 84 IndexedDBBackingStore* backing_store,
94 IndexedDBBackingStore::Transaction* transaction, 85 IndexedDBBackingStore::Transaction* transaction,
95 int64_t database_id, 86 int64_t database_id,
(...skipping 26 matching lines...) Expand all
122 } 113 }
123 114
124 bool MakeIndexWriters( 115 bool MakeIndexWriters(
125 IndexedDBTransaction* transaction, 116 IndexedDBTransaction* transaction,
126 IndexedDBBackingStore* backing_store, 117 IndexedDBBackingStore* backing_store,
127 int64_t database_id, 118 int64_t database_id,
128 const IndexedDBObjectStoreMetadata& object_store, 119 const IndexedDBObjectStoreMetadata& object_store,
129 const IndexedDBKey& primary_key, // makes a copy 120 const IndexedDBKey& primary_key, // makes a copy
130 bool key_was_generated, 121 bool key_was_generated,
131 const std::vector<IndexedDBDatabase::IndexKeys>& index_keys, 122 const std::vector<IndexedDBDatabase::IndexKeys>& index_keys,
132 ScopedVector<IndexWriter>* index_writers, 123 std::vector<std::unique_ptr<IndexWriter>>* index_writers,
133 base::string16* error_message, 124 base::string16* error_message,
134 bool* completed) { 125 bool* completed) {
135 *completed = false; 126 *completed = false;
136 127
137 for (const auto& it : index_keys) { 128 for (const auto& it : index_keys) {
138 const auto& found = object_store.indexes.find(it.first); 129 const auto& found = object_store.indexes.find(it.first);
139 if (found == object_store.indexes.end()) 130 if (found == object_store.indexes.end())
140 continue; 131 continue;
141 const IndexedDBIndexMetadata& index = found->second; 132 const IndexedDBIndexMetadata& index = found->second;
142 IndexedDBDatabase::IndexKeys keys = it; 133 IndexedDBDatabase::IndexKeys keys = it;
(...skipping 21 matching lines...) Expand all
164 return true; 155 return true;
165 156
166 index_writers->push_back(std::move(index_writer)); 157 index_writers->push_back(std::move(index_writer));
167 } 158 }
168 159
169 *completed = true; 160 *completed = true;
170 return true; 161 return true;
171 } 162 }
172 163
173 } // namespace content 164 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_index_writer.h ('k') | content/browser/indexed_db/indexed_db_observer_changes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698