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

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

Issue 2511403003: Send IndexedDB observations through IDBDatabaseCallbacks. (Closed)
Patch Set: Rebased. 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/indexed_db_database_callbacks_impl.h" 5 #include "content/child/indexed_db/indexed_db_database_callbacks_impl.h"
6 6
7 #include "content/child/indexed_db/indexed_db_dispatcher.h" 7 #include "content/child/indexed_db/indexed_db_dispatcher.h"
8 #include "content/child/indexed_db/indexed_db_key_builders.h"
8 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseCal lbacks.h" 9 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseCal lbacks.h"
9 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseErr or.h" 10 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseErr or.h"
11 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBObservation .h"
10 12
11 using blink::WebIDBDatabaseCallbacks; 13 using blink::WebIDBDatabaseCallbacks;
12 14
13 namespace content { 15 namespace content {
14 16
15 namespace { 17 namespace {
16 18
17 void DeleteDatabaseCallbacks(WebIDBDatabaseCallbacks* callbacks) { 19 void DeleteDatabaseCallbacks(WebIDBDatabaseCallbacks* callbacks) {
18 IndexedDBDispatcher::ThreadSpecificInstance() 20 IndexedDBDispatcher::ThreadSpecificInstance()
19 ->UnregisterMojoOwnedDatabaseCallbacks(callbacks); 21 ->UnregisterMojoOwnedDatabaseCallbacks(callbacks);
20 delete callbacks; 22 delete callbacks;
21 } 23 }
22 24
23 void BuildErrorAndAbort(WebIDBDatabaseCallbacks* callbacks, 25 void BuildErrorAndAbort(WebIDBDatabaseCallbacks* callbacks,
24 int64_t transaction_id, 26 int64_t transaction_id,
25 int32_t code, 27 int32_t code,
26 const base::string16& message) { 28 const base::string16& message) {
27 callbacks->onAbort(transaction_id, blink::WebIDBDatabaseError(code, message)); 29 callbacks->onAbort(transaction_id, blink::WebIDBDatabaseError(code, message));
28 } 30 }
29 31
32 void BuildObservationsAndNotify(WebIDBDatabaseCallbacks* callbacks,
33 indexed_db::mojom::ObserverChangesPtr changes) {
34 std::vector<blink::WebIDBObservation> web_observations;
35 for (const auto& observation : changes->observations) {
36 blink::WebIDBObservation web_observation;
37 web_observation.objectStoreId = observation->object_store_id;
38 web_observation.type = observation->type;
39 web_observation.keyRange =
40 WebIDBKeyRangeBuilder::Build(observation->key_range);
41 // TODO(palakj): Assign value to web_observation.
42 web_observations.push_back(std::move(web_observation));
43 }
44 callbacks->onChanges(changes->observation_index_map, web_observations);
45 }
46
30 } // namespace 47 } // namespace
31 48
32 IndexedDBDatabaseCallbacksImpl::IndexedDBDatabaseCallbacksImpl( 49 IndexedDBDatabaseCallbacksImpl::IndexedDBDatabaseCallbacksImpl(
33 std::unique_ptr<WebIDBDatabaseCallbacks> callbacks) 50 std::unique_ptr<WebIDBDatabaseCallbacks> callbacks)
34 : callback_runner_(base::ThreadTaskRunnerHandle::Get()), 51 : callback_runner_(base::ThreadTaskRunnerHandle::Get()),
35 callbacks_(callbacks.release()) { 52 callbacks_(callbacks.release()) {
36 IndexedDBDispatcher::ThreadSpecificInstance() 53 IndexedDBDispatcher::ThreadSpecificInstance()
37 ->RegisterMojoOwnedDatabaseCallbacks(callbacks_); 54 ->RegisterMojoOwnedDatabaseCallbacks(callbacks_);
38 } 55 }
39 56
(...skipping 25 matching lines...) Expand all
65 FROM_HERE, base::Bind(&BuildErrorAndAbort, base::Unretained(callbacks_), 82 FROM_HERE, base::Bind(&BuildErrorAndAbort, base::Unretained(callbacks_),
66 transaction_id, code, message)); 83 transaction_id, code, message));
67 } 84 }
68 85
69 void IndexedDBDatabaseCallbacksImpl::Complete(int64_t transaction_id) { 86 void IndexedDBDatabaseCallbacksImpl::Complete(int64_t transaction_id) {
70 callback_runner_->PostTask( 87 callback_runner_->PostTask(
71 FROM_HERE, base::Bind(&WebIDBDatabaseCallbacks::onComplete, 88 FROM_HERE, base::Bind(&WebIDBDatabaseCallbacks::onComplete,
72 base::Unretained(callbacks_), transaction_id)); 89 base::Unretained(callbacks_), transaction_id));
73 } 90 }
74 91
92 void IndexedDBDatabaseCallbacksImpl::Changes(
93 indexed_db::mojom::ObserverChangesPtr changes) {
94 callback_runner_->PostTask(FROM_HERE, base::Bind(&BuildObservationsAndNotify,
95 base::Unretained(callbacks_),
96 base::Passed(&changes)));
97 }
98
75 } // namespace content 99 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698