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

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

Issue 2449953008: Port messages sent by WebIDBDatabaseImpl to Mojo. (Closed)
Patch Set: Address dcheng@'s comments. Created 4 years, 1 month 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"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "content/browser/indexed_db/indexed_db_backing_store.h" 12 #include "content/browser/indexed_db/indexed_db_backing_store.h"
13 #include "content/browser/indexed_db/indexed_db_tracing.h" 13 #include "content/browser/indexed_db/indexed_db_tracing.h"
14 #include "content/browser/indexed_db/indexed_db_transaction.h" 14 #include "content/browser/indexed_db/indexed_db_transaction.h"
15 #include "content/common/indexed_db/indexed_db_key.h" 15 #include "content/common/indexed_db/indexed_db_key.h"
16 #include "content/common/indexed_db/indexed_db_key_path.h" 16 #include "content/common/indexed_db/indexed_db_key_path.h"
17 #include "content/common/indexed_db/indexed_db_key_range.h" 17 #include "content/common/indexed_db/indexed_db_key_range.h"
18 18
19 using base::ASCIIToUTF16; 19 using base::ASCIIToUTF16;
20 20
21 namespace content { 21 namespace content {
22 22
23 IndexWriter::IndexWriter( 23 IndexWriter::IndexWriter(
24 const IndexedDBIndexMetadata& index_metadata) 24 const IndexedDBIndexMetadata& index_metadata)
25 : index_metadata_(index_metadata) {} 25 : index_metadata_(index_metadata) {}
26 26
27 IndexWriter::IndexWriter( 27 IndexWriter::IndexWriter(const IndexedDBIndexMetadata& index_metadata,
28 const IndexedDBIndexMetadata& index_metadata, 28 const IndexedDBIndexKeys& index_keys)
29 const IndexedDBDatabase::IndexKeys& index_keys)
30 : index_metadata_(index_metadata), index_keys_(index_keys) {} 29 : index_metadata_(index_metadata), index_keys_(index_keys) {}
31 30
32 IndexWriter::~IndexWriter() {} 31 IndexWriter::~IndexWriter() {}
33 32
34 bool IndexWriter::VerifyIndexKeys( 33 bool IndexWriter::VerifyIndexKeys(
35 IndexedDBBackingStore* backing_store, 34 IndexedDBBackingStore* backing_store,
36 IndexedDBBackingStore::Transaction* transaction, 35 IndexedDBBackingStore::Transaction* transaction,
37 int64_t database_id, 36 int64_t database_id,
38 int64_t object_store_id, 37 int64_t object_store_id,
39 int64_t index_id, 38 int64_t index_id,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 &found_primary_key, 104 &found_primary_key,
106 &found); 105 &found);
107 if (!s.ok()) 106 if (!s.ok())
108 return false; 107 return false;
109 if (!found || 108 if (!found ||
110 (primary_key.IsValid() && found_primary_key->Equals(primary_key))) 109 (primary_key.IsValid() && found_primary_key->Equals(primary_key)))
111 *allowed = true; 110 *allowed = true;
112 return true; 111 return true;
113 } 112 }
114 113
115 bool MakeIndexWriters( 114 bool MakeIndexWriters(IndexedDBTransaction* transaction,
116 IndexedDBTransaction* transaction, 115 IndexedDBBackingStore* backing_store,
117 IndexedDBBackingStore* backing_store, 116 int64_t database_id,
118 int64_t database_id, 117 const IndexedDBObjectStoreMetadata& object_store,
119 const IndexedDBObjectStoreMetadata& object_store, 118 const IndexedDBKey& primary_key, // makes a copy
120 const IndexedDBKey& primary_key, // makes a copy 119 bool key_was_generated,
121 bool key_was_generated, 120 const std::vector<IndexedDBIndexKeys>& index_keys,
122 const std::vector<IndexedDBDatabase::IndexKeys>& index_keys, 121 std::vector<std::unique_ptr<IndexWriter>>* index_writers,
123 std::vector<std::unique_ptr<IndexWriter>>* index_writers, 122 base::string16* error_message,
124 base::string16* error_message, 123 bool* completed) {
125 bool* completed) {
126 *completed = false; 124 *completed = false;
127 125
128 for (const auto& it : index_keys) { 126 for (const auto& it : index_keys) {
129 const auto& found = object_store.indexes.find(it.first); 127 const auto& found = object_store.indexes.find(it.first);
130 if (found == object_store.indexes.end()) 128 if (found == object_store.indexes.end())
131 continue; 129 continue;
132 const IndexedDBIndexMetadata& index = found->second; 130 const IndexedDBIndexMetadata& index = found->second;
133 IndexedDBDatabase::IndexKeys keys = it; 131 IndexedDBIndexKeys keys = it;
134 132
135 // If the object_store is using auto_increment, then any indexes with an 133 // If the object_store is using auto_increment, then any indexes with an
136 // identical key_path need to also use the primary (generated) key as a key. 134 // identical key_path need to also use the primary (generated) key as a key.
137 if (key_was_generated && (index.key_path == object_store.key_path)) 135 if (key_was_generated && (index.key_path == object_store.key_path))
138 keys.second.push_back(primary_key); 136 keys.second.push_back(primary_key);
139 137
140 std::unique_ptr<IndexWriter> index_writer( 138 std::unique_ptr<IndexWriter> index_writer(
141 base::MakeUnique<IndexWriter>(index, keys)); 139 base::MakeUnique<IndexWriter>(index, keys));
142 bool can_add_keys = false; 140 bool can_add_keys = false;
143 bool backing_store_success = 141 bool backing_store_success =
(...skipping 11 matching lines...) Expand all
155 return true; 153 return true;
156 154
157 index_writers->push_back(std::move(index_writer)); 155 index_writers->push_back(std::move(index_writer));
158 } 156 }
159 157
160 *completed = true; 158 *completed = true;
161 return true; 159 return true;
162 } 160 }
163 161
164 } // namespace content 162 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698