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/webidbdatabase_impl.h" | 5 #include "content/browser/indexed_db/webidbdatabase_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "content/browser/indexed_db/indexed_db_callbacks_wrapper.h" | 11 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
12 #include "content/browser/indexed_db/indexed_db_cursor.h" | 12 #include "content/browser/indexed_db/indexed_db_cursor.h" |
13 #include "content/browser/indexed_db/indexed_db_database.h" | |
14 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | |
15 #include "content/browser/indexed_db/indexed_db_database_error.h" | 13 #include "content/browser/indexed_db/indexed_db_database_error.h" |
16 #include "content/browser/indexed_db/indexed_db_metadata.h" | 14 #include "content/browser/indexed_db/indexed_db_metadata.h" |
17 #include "content/common/indexed_db/indexed_db_key_range.h" | 15 #include "content/common/indexed_db/indexed_db_key_range.h" |
18 | 16 |
19 namespace content { | 17 namespace content { |
20 | 18 |
21 WebIDBDatabaseImpl::WebIDBDatabaseImpl( | 19 WebIDBDatabaseImpl::WebIDBDatabaseImpl( |
22 scoped_refptr<IndexedDBDatabase> database_backend, | 20 scoped_refptr<IndexedDBDatabase> database_backend, |
23 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks) | 21 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks) |
24 : database_backend_(database_backend), | 22 : database_backend_(database_backend), |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 const IndexedDBDatabaseError& error) { | 77 const IndexedDBDatabaseError& error) { |
80 if (database_backend_.get()) | 78 if (database_backend_.get()) |
81 database_backend_->Abort(transaction_id, error); | 79 database_backend_->Abort(transaction_id, error); |
82 } | 80 } |
83 | 81 |
84 void WebIDBDatabaseImpl::commit(long long transaction_id) { | 82 void WebIDBDatabaseImpl::commit(long long transaction_id) { |
85 if (database_backend_.get()) | 83 if (database_backend_.get()) |
86 database_backend_->Commit(transaction_id); | 84 database_backend_->Commit(transaction_id); |
87 } | 85 } |
88 | 86 |
89 void WebIDBDatabaseImpl::openCursor(long long transaction_id, | 87 void WebIDBDatabaseImpl::openCursor( |
90 long long object_store_id, | 88 long long transaction_id, |
91 long long index_id, | 89 long long object_store_id, |
92 const IndexedDBKeyRange& key_range, | 90 long long index_id, |
93 unsigned short direction, | 91 const IndexedDBKeyRange& key_range, |
94 bool key_only, | 92 unsigned short direction, |
95 WebKit::WebIDBDatabase::TaskType task_type, | 93 bool key_only, |
96 IndexedDBCallbacksBase* callbacks) { | 94 WebKit::WebIDBDatabase::TaskType task_type, |
| 95 scoped_refptr<IndexedDBCallbacks> callbacks) { |
97 if (database_backend_.get()) | 96 if (database_backend_.get()) |
98 database_backend_->OpenCursor( | 97 database_backend_->OpenCursor( |
99 transaction_id, | 98 transaction_id, |
100 object_store_id, | 99 object_store_id, |
101 index_id, | 100 index_id, |
102 make_scoped_ptr(new IndexedDBKeyRange(key_range)), | 101 make_scoped_ptr(new IndexedDBKeyRange(key_range)), |
103 static_cast<indexed_db::CursorDirection>(direction), | 102 static_cast<indexed_db::CursorDirection>(direction), |
104 key_only, | 103 key_only, |
105 static_cast<IndexedDBDatabase::TaskType>(task_type), | 104 static_cast<IndexedDBDatabase::TaskType>(task_type), |
106 IndexedDBCallbacksWrapper::Create(callbacks)); | 105 callbacks); |
107 } | 106 } |
108 | 107 |
109 void WebIDBDatabaseImpl::count(long long transaction_id, | 108 void WebIDBDatabaseImpl::count(long long transaction_id, |
110 long long object_store_id, | 109 long long object_store_id, |
111 long long index_id, | 110 long long index_id, |
112 const IndexedDBKeyRange& key_range, | 111 const IndexedDBKeyRange& key_range, |
113 IndexedDBCallbacksBase* callbacks) { | 112 scoped_refptr<IndexedDBCallbacks> callbacks) { |
114 if (database_backend_.get()) | 113 if (database_backend_.get()) |
115 database_backend_->Count(transaction_id, | 114 database_backend_->Count(transaction_id, |
116 object_store_id, | 115 object_store_id, |
117 index_id, | 116 index_id, |
118 make_scoped_ptr(new IndexedDBKeyRange(key_range)), | 117 make_scoped_ptr(new IndexedDBKeyRange(key_range)), |
119 IndexedDBCallbacksWrapper::Create(callbacks)); | 118 callbacks); |
120 } | 119 } |
121 | 120 |
122 void WebIDBDatabaseImpl::get(long long transaction_id, | 121 void WebIDBDatabaseImpl::get(long long transaction_id, |
123 long long object_store_id, | 122 long long object_store_id, |
124 long long index_id, | 123 long long index_id, |
125 const IndexedDBKeyRange& key_range, | 124 const IndexedDBKeyRange& key_range, |
126 bool key_only, | 125 bool key_only, |
127 IndexedDBCallbacksBase* callbacks) { | 126 scoped_refptr<IndexedDBCallbacks> callbacks) { |
128 if (database_backend_.get()) | 127 if (database_backend_.get()) |
129 database_backend_->Get(transaction_id, | 128 database_backend_->Get(transaction_id, |
130 object_store_id, | 129 object_store_id, |
131 index_id, | 130 index_id, |
132 make_scoped_ptr(new IndexedDBKeyRange(key_range)), | 131 make_scoped_ptr(new IndexedDBKeyRange(key_range)), |
133 key_only, | 132 key_only, |
134 IndexedDBCallbacksWrapper::Create(callbacks)); | 133 callbacks); |
135 } | 134 } |
136 | 135 |
137 void WebIDBDatabaseImpl::put(long long transaction_id, | 136 void WebIDBDatabaseImpl::put(long long transaction_id, |
138 long long object_store_id, | 137 long long object_store_id, |
139 std::vector<char>* value, | 138 std::vector<char>* value, |
140 const IndexedDBKey& key, | 139 const IndexedDBKey& key, |
141 WebKit::WebIDBDatabase::PutMode put_mode, | 140 WebKit::WebIDBDatabase::PutMode put_mode, |
142 IndexedDBCallbacksBase* callbacks, | 141 scoped_refptr<IndexedDBCallbacks> callbacks, |
143 const std::vector<int64>& index_ids, | 142 const std::vector<int64>& index_ids, |
144 const std::vector<IndexKeys>& index_keys) { | 143 const std::vector<IndexKeys>& index_keys) { |
145 if (!database_backend_.get()) | 144 if (!database_backend_.get()) |
146 return; | 145 return; |
147 | 146 |
148 DCHECK_EQ(index_ids.size(), index_keys.size()); | 147 DCHECK_EQ(index_ids.size(), index_keys.size()); |
149 | 148 |
150 database_backend_->Put(transaction_id, | 149 database_backend_->Put(transaction_id, |
151 object_store_id, | 150 object_store_id, |
152 value, | 151 value, |
153 make_scoped_ptr(new IndexedDBKey(key)), | 152 make_scoped_ptr(new IndexedDBKey(key)), |
154 static_cast<IndexedDBDatabase::PutMode>(put_mode), | 153 static_cast<IndexedDBDatabase::PutMode>(put_mode), |
155 IndexedDBCallbacksWrapper::Create(callbacks), | 154 callbacks, |
156 index_ids, | 155 index_ids, |
157 index_keys); | 156 index_keys); |
158 } | 157 } |
159 | 158 |
160 void WebIDBDatabaseImpl::setIndexKeys( | 159 void WebIDBDatabaseImpl::setIndexKeys( |
161 long long transaction_id, | 160 long long transaction_id, |
162 long long object_store_id, | 161 long long object_store_id, |
163 const IndexedDBKey& primary_key, | 162 const IndexedDBKey& primary_key, |
164 const std::vector<int64>& index_ids, | 163 const std::vector<int64>& index_ids, |
165 const std::vector<IndexKeys>& index_keys) { | 164 const std::vector<IndexKeys>& index_keys) { |
(...skipping 16 matching lines...) Expand all Loading... |
182 if (!database_backend_.get()) | 181 if (!database_backend_.get()) |
183 return; | 182 return; |
184 | 183 |
185 std::vector<int64> index_ids(web_index_ids.size()); | 184 std::vector<int64> index_ids(web_index_ids.size()); |
186 for (size_t i = 0; i < web_index_ids.size(); ++i) | 185 for (size_t i = 0; i < web_index_ids.size(); ++i) |
187 index_ids[i] = web_index_ids[i]; | 186 index_ids[i] = web_index_ids[i]; |
188 database_backend_->SetIndexesReady( | 187 database_backend_->SetIndexesReady( |
189 transaction_id, object_store_id, index_ids); | 188 transaction_id, object_store_id, index_ids); |
190 } | 189 } |
191 | 190 |
192 void WebIDBDatabaseImpl::deleteRange(long long transaction_id, | 191 void WebIDBDatabaseImpl::deleteRange( |
193 long long object_store_id, | 192 long long transaction_id, |
194 const IndexedDBKeyRange& key_range, | 193 long long object_store_id, |
195 IndexedDBCallbacksBase* callbacks) { | 194 const IndexedDBKeyRange& key_range, |
| 195 scoped_refptr<IndexedDBCallbacks> callbacks) { |
196 if (database_backend_.get()) | 196 if (database_backend_.get()) |
197 database_backend_->DeleteRange( | 197 database_backend_->DeleteRange( |
198 transaction_id, | 198 transaction_id, |
199 object_store_id, | 199 object_store_id, |
200 make_scoped_ptr(new IndexedDBKeyRange(key_range)), | 200 make_scoped_ptr(new IndexedDBKeyRange(key_range)), |
201 IndexedDBCallbacksWrapper::Create(callbacks)); | 201 callbacks); |
202 } | 202 } |
203 | 203 |
204 void WebIDBDatabaseImpl::clear(long long transaction_id, | 204 void WebIDBDatabaseImpl::clear(long long transaction_id, |
205 long long object_store_id, | 205 long long object_store_id, |
206 IndexedDBCallbacksBase* callbacks) { | 206 scoped_refptr<IndexedDBCallbacks> callbacks) { |
207 if (database_backend_.get()) | 207 if (database_backend_.get()) |
208 database_backend_->Clear(transaction_id, | 208 database_backend_->Clear(transaction_id, object_store_id, callbacks); |
209 object_store_id, | |
210 IndexedDBCallbacksWrapper::Create(callbacks)); | |
211 } | 209 } |
212 | 210 |
213 void WebIDBDatabaseImpl::createIndex(long long transaction_id, | 211 void WebIDBDatabaseImpl::createIndex(long long transaction_id, |
214 long long object_store_id, | 212 long long object_store_id, |
215 long long index_id, | 213 long long index_id, |
216 const string16& name, | 214 const string16& name, |
217 const IndexedDBKeyPath& key_path, | 215 const IndexedDBKeyPath& key_path, |
218 bool unique, | 216 bool unique, |
219 bool multi_entry) { | 217 bool multi_entry) { |
220 if (database_backend_.get()) | 218 if (database_backend_.get()) |
221 database_backend_->CreateIndex(transaction_id, | 219 database_backend_->CreateIndex(transaction_id, |
222 object_store_id, | 220 object_store_id, |
223 index_id, | 221 index_id, |
224 name, | 222 name, |
225 IndexedDBKeyPath(key_path), | 223 IndexedDBKeyPath(key_path), |
226 unique, | 224 unique, |
227 multi_entry); | 225 multi_entry); |
228 } | 226 } |
229 | 227 |
230 void WebIDBDatabaseImpl::deleteIndex(long long transaction_id, | 228 void WebIDBDatabaseImpl::deleteIndex(long long transaction_id, |
231 long long object_store_id, | 229 long long object_store_id, |
232 long long index_id) { | 230 long long index_id) { |
233 if (database_backend_.get()) | 231 if (database_backend_.get()) |
234 database_backend_->DeleteIndex(transaction_id, object_store_id, index_id); | 232 database_backend_->DeleteIndex(transaction_id, object_store_id, index_id); |
235 } | 233 } |
236 | 234 |
237 } // namespace WebKit | 235 } // namespace WebKit |
OLD | NEW |