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

Side by Side Diff: content/child/indexed_db/webidbdatabase_impl.cc

Issue 2511403003: Send IndexedDB observations through IDBDatabaseCallbacks. (Closed)
Patch Set: Remove unnecessary forward declaration. Created 4 years 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/child/indexed_db/webidbdatabase_impl.h" 5 #include "content/child/indexed_db/webidbdatabase_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/stl_util.h" 12 #include "base/strings/string16.h"
13 #include "base/strings/stringprintf.h"
13 #include "content/child/indexed_db/indexed_db_callbacks_impl.h" 14 #include "content/child/indexed_db/indexed_db_callbacks_impl.h"
14 #include "content/child/indexed_db/indexed_db_dispatcher.h" 15 #include "content/child/indexed_db/indexed_db_dispatcher.h"
15 #include "content/child/indexed_db/indexed_db_key_builders.h" 16 #include "content/child/indexed_db/indexed_db_key_builders.h"
16 #include "content/child/worker_thread_registry.h"
17 #include "content/common/indexed_db/indexed_db_messages.h"
18 #include "mojo/public/cpp/bindings/strong_associated_binding.h" 17 #include "mojo/public/cpp/bindings/strong_associated_binding.h"
19 #include "third_party/WebKit/public/platform/WebBlobInfo.h" 18 #include "third_party/WebKit/public/platform/WebBlobInfo.h"
20 #include "third_party/WebKit/public/platform/WebString.h" 19 #include "third_party/WebKit/public/platform/WebString.h"
21 #include "third_party/WebKit/public/platform/WebVector.h" 20 #include "third_party/WebKit/public/platform/WebVector.h"
22 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseErr or.h" 21 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseErr or.h"
23 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h" 22 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h"
24 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBKeyPath.h" 23 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBKeyPath.h"
25 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBMetadata.h" 24 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBMetadata.h"
26 25
27 using blink::WebBlobInfo; 26 using blink::WebBlobInfo;
28 using blink::WebIDBCallbacks; 27 using blink::WebIDBCallbacks;
29 using blink::WebIDBCursor;
30 using blink::WebIDBDatabase; 28 using blink::WebIDBDatabase;
31 using blink::WebIDBDatabaseCallbacks; 29 using blink::WebIDBDatabaseCallbacks;
32 using blink::WebIDBMetadata; 30 using blink::WebIDBMetadata;
33 using blink::WebIDBKey; 31 using blink::WebIDBKey;
34 using blink::WebIDBKeyPath; 32 using blink::WebIDBKeyPath;
35 using blink::WebIDBKeyRange; 33 using blink::WebIDBKeyRange;
36 using blink::WebIDBObserver;
37 using blink::WebString; 34 using blink::WebString;
38 using blink::WebVector; 35 using blink::WebVector;
39 using indexed_db::mojom::CallbacksAssociatedPtrInfo; 36 using indexed_db::mojom::CallbacksAssociatedPtrInfo;
40 using indexed_db::mojom::DatabaseAssociatedPtrInfo; 37 using indexed_db::mojom::DatabaseAssociatedPtrInfo;
41 38
42 namespace content { 39 namespace content {
43 40
44 namespace { 41 namespace {
45 42
46 std::vector<content::IndexedDBIndexKeys> ConvertWebIndexKeys( 43 std::vector<content::IndexedDBIndexKeys> ConvertWebIndexKeys(
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 blink::WebIDBTransactionMode mode) { 205 blink::WebIDBTransactionMode mode) {
209 io_runner_->PostTask( 206 io_runner_->PostTask(
210 FROM_HERE, 207 FROM_HERE,
211 base::Bind(&IOThreadHelper::CreateTransaction, base::Unretained(helper_), 208 base::Bind(&IOThreadHelper::CreateTransaction, base::Unretained(helper_),
212 transaction_id, std::vector<int64_t>(object_store_ids.begin(), 209 transaction_id, std::vector<int64_t>(object_store_ids.begin(),
213 object_store_ids.end()), 210 object_store_ids.end()),
214 mode)); 211 mode));
215 } 212 }
216 213
217 void WebIDBDatabaseImpl::close() { 214 void WebIDBDatabaseImpl::close() {
218 std::vector<int32_t> remove_observer_ids(observer_ids_.begin(),
219 observer_ids_.end());
220 IndexedDBDispatcher::ThreadSpecificInstance()->RemoveObservers(
221 remove_observer_ids);
222 io_runner_->PostTask( 215 io_runner_->PostTask(
223 FROM_HERE, base::Bind(&IOThreadHelper::Close, base::Unretained(helper_))); 216 FROM_HERE, base::Bind(&IOThreadHelper::Close, base::Unretained(helper_)));
224 } 217 }
225 218
226 void WebIDBDatabaseImpl::versionChangeIgnored() { 219 void WebIDBDatabaseImpl::versionChangeIgnored() {
227 io_runner_->PostTask(FROM_HERE, 220 io_runner_->PostTask(FROM_HERE,
228 base::Bind(&IOThreadHelper::VersionChangeIgnored, 221 base::Bind(&IOThreadHelper::VersionChangeIgnored,
229 base::Unretained(helper_))); 222 base::Unretained(helper_)));
230 } 223 }
231 224
232 int32_t WebIDBDatabaseImpl::addObserver( 225 void WebIDBDatabaseImpl::addObserver(
233 std::unique_ptr<WebIDBObserver> observer, 226 long long transaction_id,
234 long long transaction_id) { 227 int32_t observer_id,
235 WebIDBObserver* observer_ptr = observer.get(); 228 bool include_transaction,
236 int32_t observer_id = 229 bool no_records,
237 IndexedDBDispatcher::ThreadSpecificInstance()->RegisterObserver( 230 bool values,
238 std::move(observer)); 231 const std::bitset<blink::WebIDBOperationTypeCount>& operation_types) {
239 observer_ids_.insert(observer_id);
240 static_assert(blink::WebIDBOperationTypeCount < sizeof(uint16_t) * CHAR_BIT, 232 static_assert(blink::WebIDBOperationTypeCount < sizeof(uint16_t) * CHAR_BIT,
241 "WebIDBOperationType Count exceeds size of uint16_t"); 233 "WebIDBOperationType Count exceeds size of uint16_t");
242 io_runner_->PostTask( 234 io_runner_->PostTask(
243 FROM_HERE, 235 FROM_HERE,
244 base::Bind(&IOThreadHelper::AddObserver, base::Unretained(helper_), 236 base::Bind(&IOThreadHelper::AddObserver, base::Unretained(helper_),
245 transaction_id, observer_id, observer_ptr->transaction(), 237 transaction_id, observer_id, include_transaction, no_records,
246 observer_ptr->noRecords(), observer_ptr->values(), 238 values, operation_types.to_ulong()));
247 observer_ptr->operationTypes().to_ulong()));
248 return observer_id;
249 } 239 }
250 240
251 void WebIDBDatabaseImpl::removeObservers( 241 void WebIDBDatabaseImpl::removeObservers(
252 const WebVector<int32_t>& observer_ids_to_remove) { 242 const WebVector<int32_t>& observer_ids_to_remove) {
253 std::vector<int32_t> remove_observer_ids( 243 std::vector<int32_t> remove_observer_ids(
254 observer_ids_to_remove.data(), 244 observer_ids_to_remove.data(),
255 observer_ids_to_remove.data() + observer_ids_to_remove.size()); 245 observer_ids_to_remove.data() + observer_ids_to_remove.size());
256 for (int32_t id : observer_ids_to_remove)
257 observer_ids_.erase(id);
258 246
259 IndexedDBDispatcher::ThreadSpecificInstance()->RemoveObservers(
260 remove_observer_ids);
261 io_runner_->PostTask( 247 io_runner_->PostTask(
262 FROM_HERE, base::Bind(&IOThreadHelper::RemoveObservers, 248 FROM_HERE, base::Bind(&IOThreadHelper::RemoveObservers,
263 base::Unretained(helper_), remove_observer_ids)); 249 base::Unretained(helper_), remove_observer_ids));
264 } 250 }
265 251
266 void WebIDBDatabaseImpl::get(long long transaction_id, 252 void WebIDBDatabaseImpl::get(long long transaction_id,
267 long long object_store_id, 253 long long object_store_id,
268 long long index_id, 254 long long index_id,
269 const WebIDBKeyRange& key_range, 255 const WebIDBKeyRange& key_range,
270 bool key_only, 256 bool key_only,
(...skipping 26 matching lines...) Expand all
297 FROM_HERE, 283 FROM_HERE,
298 base::Bind(&IOThreadHelper::GetAll, base::Unretained(helper_), 284 base::Bind(&IOThreadHelper::GetAll, base::Unretained(helper_),
299 transaction_id, object_store_id, index_id, 285 transaction_id, object_store_id, index_id,
300 IndexedDBKeyRangeBuilder::Build(key_range), max_count, 286 IndexedDBKeyRangeBuilder::Build(key_range), max_count,
301 key_only, base::Passed(&callbacks_impl))); 287 key_only, base::Passed(&callbacks_impl)));
302 } 288 }
303 289
304 void WebIDBDatabaseImpl::put(long long transaction_id, 290 void WebIDBDatabaseImpl::put(long long transaction_id,
305 long long object_store_id, 291 long long object_store_id,
306 const blink::WebData& value, 292 const blink::WebData& value,
307 const blink::WebVector<WebBlobInfo>& web_blob_info, 293 const WebVector<WebBlobInfo>& web_blob_info,
308 const WebIDBKey& web_key, 294 const WebIDBKey& web_key,
309 blink::WebIDBPutMode put_mode, 295 blink::WebIDBPutMode put_mode,
310 WebIDBCallbacks* callbacks, 296 WebIDBCallbacks* callbacks,
311 const WebVector<long long>& index_ids, 297 const WebVector<long long>& index_ids,
312 const WebVector<WebIndexKeys>& index_keys) { 298 const WebVector<WebIndexKeys>& index_keys) {
313 IndexedDBKey key = IndexedDBKeyBuilder::Build(web_key); 299 IndexedDBKey key = IndexedDBKeyBuilder::Build(web_key);
314 300
315 if (value.size() + key.size_estimate() > max_put_value_size_) { 301 if (value.size() + key.size_estimate() > max_put_value_size_) {
316 callbacks->onError(blink::WebIDBDatabaseError( 302 callbacks->onError(blink::WebIDBDatabaseError(
317 blink::WebIDBDatabaseExceptionUnknownError, 303 blink::WebIDBDatabaseExceptionUnknownError,
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 std::unique_ptr<IndexedDBCallbacksImpl> callbacks) { 691 std::unique_ptr<IndexedDBCallbacksImpl> callbacks) {
706 CallbacksAssociatedPtrInfo ptr_info; 692 CallbacksAssociatedPtrInfo ptr_info;
707 indexed_db::mojom::CallbacksAssociatedRequest request; 693 indexed_db::mojom::CallbacksAssociatedRequest request;
708 database_.associated_group()->CreateAssociatedInterface( 694 database_.associated_group()->CreateAssociatedInterface(
709 mojo::AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request); 695 mojo::AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request);
710 mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request)); 696 mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request));
711 return ptr_info; 697 return ptr_info;
712 } 698 }
713 699
714 } // namespace content 700 } // namespace content
OLDNEW
« no previous file with comments | « content/child/indexed_db/webidbdatabase_impl.h ('k') | content/child/indexed_db/webidbfactory_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698