OLD | NEW |
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> |
| 8 |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
9 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 11 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
10 #include "content/browser/indexed_db/indexed_db_tracing.h" | 12 #include "content/browser/indexed_db/indexed_db_tracing.h" |
11 #include "content/browser/indexed_db/indexed_db_transaction.h" | 13 #include "content/browser/indexed_db/indexed_db_transaction.h" |
12 #include "content/common/indexed_db/indexed_db_key.h" | 14 #include "content/common/indexed_db/indexed_db_key.h" |
13 #include "content/common/indexed_db/indexed_db_key_path.h" | 15 #include "content/common/indexed_db/indexed_db_key_path.h" |
14 #include "content/common/indexed_db/indexed_db_key_range.h" | 16 #include "content/common/indexed_db/indexed_db_key_range.h" |
15 | 17 |
16 using base::ASCIIToUTF16; | 18 using base::ASCIIToUTF16; |
17 | 19 |
18 namespace content { | 20 namespace content { |
19 | 21 |
20 IndexWriter::IndexWriter( | 22 IndexWriter::IndexWriter( |
21 const IndexedDBIndexMetadata& index_metadata) | 23 const IndexedDBIndexMetadata& index_metadata) |
22 : index_metadata_(index_metadata) {} | 24 : index_metadata_(index_metadata) {} |
23 | 25 |
24 IndexWriter::IndexWriter( | 26 IndexWriter::IndexWriter( |
25 const IndexedDBIndexMetadata& index_metadata, | 27 const IndexedDBIndexMetadata& index_metadata, |
26 const IndexedDBDatabase::IndexKeys& index_keys) | 28 const IndexedDBDatabase::IndexKeys& index_keys) |
27 : index_metadata_(index_metadata), index_keys_(index_keys) {} | 29 : index_metadata_(index_metadata), index_keys_(index_keys) {} |
28 | 30 |
29 IndexWriter::~IndexWriter() {} | 31 IndexWriter::~IndexWriter() {} |
30 | 32 |
31 bool IndexWriter::VerifyIndexKeys( | 33 bool IndexWriter::VerifyIndexKeys( |
32 IndexedDBBackingStore* backing_store, | 34 IndexedDBBackingStore* backing_store, |
33 IndexedDBBackingStore::Transaction* transaction, | 35 IndexedDBBackingStore::Transaction* transaction, |
34 int64 database_id, | 36 int64_t database_id, |
35 int64 object_store_id, | 37 int64_t object_store_id, |
36 int64 index_id, | 38 int64_t index_id, |
37 bool* can_add_keys, | 39 bool* can_add_keys, |
38 const IndexedDBKey& primary_key, | 40 const IndexedDBKey& primary_key, |
39 base::string16* error_message) const { | 41 base::string16* error_message) const { |
40 *can_add_keys = false; | 42 *can_add_keys = false; |
41 DCHECK_EQ(index_id, index_keys_.first); | 43 DCHECK_EQ(index_id, index_keys_.first); |
42 for (size_t i = 0; i < index_keys_.second.size(); ++i) { | 44 for (size_t i = 0; i < index_keys_.second.size(); ++i) { |
43 bool ok = AddingKeyAllowed(backing_store, | 45 bool ok = AddingKeyAllowed(backing_store, |
44 transaction, | 46 transaction, |
45 database_id, | 47 database_id, |
46 object_store_id, | 48 object_store_id, |
(...skipping 14 matching lines...) Expand all Loading... |
61 } | 63 } |
62 } | 64 } |
63 *can_add_keys = true; | 65 *can_add_keys = true; |
64 return true; | 66 return true; |
65 } | 67 } |
66 | 68 |
67 void IndexWriter::WriteIndexKeys( | 69 void IndexWriter::WriteIndexKeys( |
68 const IndexedDBBackingStore::RecordIdentifier& record_identifier, | 70 const IndexedDBBackingStore::RecordIdentifier& record_identifier, |
69 IndexedDBBackingStore* backing_store, | 71 IndexedDBBackingStore* backing_store, |
70 IndexedDBBackingStore::Transaction* transaction, | 72 IndexedDBBackingStore::Transaction* transaction, |
71 int64 database_id, | 73 int64_t database_id, |
72 int64 object_store_id) const { | 74 int64_t object_store_id) const { |
73 int64 index_id = index_metadata_.id; | 75 int64_t index_id = index_metadata_.id; |
74 DCHECK_EQ(index_id, index_keys_.first); | 76 DCHECK_EQ(index_id, index_keys_.first); |
75 for (size_t i = 0; i < index_keys_.second.size(); ++i) { | 77 for (size_t i = 0; i < index_keys_.second.size(); ++i) { |
76 leveldb::Status s = | 78 leveldb::Status s = |
77 backing_store->PutIndexDataForRecord(transaction, | 79 backing_store->PutIndexDataForRecord(transaction, |
78 database_id, | 80 database_id, |
79 object_store_id, | 81 object_store_id, |
80 index_id, | 82 index_id, |
81 index_keys_.second[i], | 83 index_keys_.second[i], |
82 record_identifier); | 84 record_identifier); |
83 // This should have already been verified as a valid write during | 85 // This should have already been verified as a valid write during |
84 // verify_index_keys. | 86 // verify_index_keys. |
85 DCHECK(s.ok()); | 87 DCHECK(s.ok()); |
86 } | 88 } |
87 } | 89 } |
88 | 90 |
89 bool IndexWriter::AddingKeyAllowed( | 91 bool IndexWriter::AddingKeyAllowed( |
90 IndexedDBBackingStore* backing_store, | 92 IndexedDBBackingStore* backing_store, |
91 IndexedDBBackingStore::Transaction* transaction, | 93 IndexedDBBackingStore::Transaction* transaction, |
92 int64 database_id, | 94 int64_t database_id, |
93 int64 object_store_id, | 95 int64_t object_store_id, |
94 int64 index_id, | 96 int64_t index_id, |
95 const IndexedDBKey& index_key, | 97 const IndexedDBKey& index_key, |
96 const IndexedDBKey& primary_key, | 98 const IndexedDBKey& primary_key, |
97 bool* allowed) const { | 99 bool* allowed) const { |
98 *allowed = false; | 100 *allowed = false; |
99 if (!index_metadata_.unique) { | 101 if (!index_metadata_.unique) { |
100 *allowed = true; | 102 *allowed = true; |
101 return true; | 103 return true; |
102 } | 104 } |
103 | 105 |
104 scoped_ptr<IndexedDBKey> found_primary_key; | 106 scoped_ptr<IndexedDBKey> found_primary_key; |
105 bool found = false; | 107 bool found = false; |
106 leveldb::Status s = backing_store->KeyExistsInIndex(transaction, | 108 leveldb::Status s = backing_store->KeyExistsInIndex(transaction, |
107 database_id, | 109 database_id, |
108 object_store_id, | 110 object_store_id, |
109 index_id, | 111 index_id, |
110 index_key, | 112 index_key, |
111 &found_primary_key, | 113 &found_primary_key, |
112 &found); | 114 &found); |
113 if (!s.ok()) | 115 if (!s.ok()) |
114 return false; | 116 return false; |
115 if (!found || | 117 if (!found || |
116 (primary_key.IsValid() && found_primary_key->Equals(primary_key))) | 118 (primary_key.IsValid() && found_primary_key->Equals(primary_key))) |
117 *allowed = true; | 119 *allowed = true; |
118 return true; | 120 return true; |
119 } | 121 } |
120 | 122 |
121 bool MakeIndexWriters( | 123 bool MakeIndexWriters( |
122 IndexedDBTransaction* transaction, | 124 IndexedDBTransaction* transaction, |
123 IndexedDBBackingStore* backing_store, | 125 IndexedDBBackingStore* backing_store, |
124 int64 database_id, | 126 int64_t database_id, |
125 const IndexedDBObjectStoreMetadata& object_store, | 127 const IndexedDBObjectStoreMetadata& object_store, |
126 const IndexedDBKey& primary_key, // makes a copy | 128 const IndexedDBKey& primary_key, // makes a copy |
127 bool key_was_generated, | 129 bool key_was_generated, |
128 const std::vector<IndexedDBDatabase::IndexKeys>& index_keys, | 130 const std::vector<IndexedDBDatabase::IndexKeys>& index_keys, |
129 ScopedVector<IndexWriter>* index_writers, | 131 ScopedVector<IndexWriter>* index_writers, |
130 base::string16* error_message, | 132 base::string16* error_message, |
131 bool* completed) { | 133 bool* completed) { |
132 *completed = false; | 134 *completed = false; |
133 | 135 |
134 for (const auto& it : index_keys) { | 136 for (const auto& it : index_keys) { |
(...skipping 26 matching lines...) Expand all Loading... |
161 return true; | 163 return true; |
162 | 164 |
163 index_writers->push_back(index_writer.Pass()); | 165 index_writers->push_back(index_writer.Pass()); |
164 } | 166 } |
165 | 167 |
166 *completed = true; | 168 *completed = true; |
167 return true; | 169 return true; |
168 } | 170 } |
169 | 171 |
170 } // namespace content | 172 } // namespace content |
OLD | NEW |