| OLD | NEW |
| 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 <unordered_map> |
| 8 #include <utility> |
| 9 |
| 7 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "content/child/indexed_db/indexed_db_callbacks_impl.h" |
| 8 #include "content/child/indexed_db/indexed_db_dispatcher.h" | 12 #include "content/child/indexed_db/indexed_db_dispatcher.h" |
| 9 #include "content/child/indexed_db/indexed_db_key_builders.h" | 13 #include "content/child/indexed_db/indexed_db_key_builders.h" |
| 10 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseCal
lbacks.h" | 14 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseCal
lbacks.h" |
| 11 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseErr
or.h" | 15 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseErr
or.h" |
| 12 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBObservation
.h" | 16 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBObservation
.h" |
| 13 | 17 |
| 14 using blink::WebIDBDatabaseCallbacks; | 18 using blink::WebIDBDatabaseCallbacks; |
| 15 | 19 |
| 16 namespace content { | 20 namespace content { |
| 17 | 21 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 34 | 38 |
| 35 void BuildObservationsAndNotify(WebIDBDatabaseCallbacks* callbacks, | 39 void BuildObservationsAndNotify(WebIDBDatabaseCallbacks* callbacks, |
| 36 indexed_db::mojom::ObserverChangesPtr changes) { | 40 indexed_db::mojom::ObserverChangesPtr changes) { |
| 37 std::vector<blink::WebIDBObservation> web_observations; | 41 std::vector<blink::WebIDBObservation> web_observations; |
| 38 for (const auto& observation : changes->observations) { | 42 for (const auto& observation : changes->observations) { |
| 39 blink::WebIDBObservation web_observation; | 43 blink::WebIDBObservation web_observation; |
| 40 web_observation.objectStoreId = observation->object_store_id; | 44 web_observation.objectStoreId = observation->object_store_id; |
| 41 web_observation.type = observation->type; | 45 web_observation.type = observation->type; |
| 42 web_observation.keyRange = | 46 web_observation.keyRange = |
| 43 WebIDBKeyRangeBuilder::Build(observation->key_range); | 47 WebIDBKeyRangeBuilder::Build(observation->key_range); |
| 44 // TODO(palakj): Assign value to web_observation. | 48 if (observation->value) { |
| 49 IndexedDBCallbacksImpl::ConvertValue(observation->value, |
| 50 &web_observation.value); |
| 51 } |
| 45 web_observations.push_back(std::move(web_observation)); | 52 web_observations.push_back(std::move(web_observation)); |
| 46 } | 53 } |
| 47 callbacks->onChanges(changes->observation_index_map, web_observations); | 54 std::unordered_map<int32_t, std::pair<int64_t, std::vector<int64_t>>> |
| 55 observer_transactions; |
| 56 |
| 57 for (const auto& transaction_pair : changes->transaction_map) { |
| 58 std::pair<int64_t, std::vector<int64_t>>& obs_txn = |
| 59 observer_transactions[transaction_pair.first]; |
| 60 obs_txn.first = transaction_pair.second->id; |
| 61 for (int64_t scope : transaction_pair.second->scope) { |
| 62 obs_txn.second.push_back(scope); |
| 63 } |
| 64 } |
| 65 |
| 66 callbacks->onChanges(changes->observation_index_map, web_observations, |
| 67 observer_transactions); |
| 48 } | 68 } |
| 49 | 69 |
| 50 } // namespace | 70 } // namespace |
| 51 | 71 |
| 52 IndexedDBDatabaseCallbacksImpl::IndexedDBDatabaseCallbacksImpl( | 72 IndexedDBDatabaseCallbacksImpl::IndexedDBDatabaseCallbacksImpl( |
| 53 std::unique_ptr<WebIDBDatabaseCallbacks> callbacks) | 73 std::unique_ptr<WebIDBDatabaseCallbacks> callbacks) |
| 54 : callback_runner_(base::ThreadTaskRunnerHandle::Get()), | 74 : callback_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 55 callbacks_(callbacks.release()) { | 75 callbacks_(callbacks.release()) { |
| 56 IndexedDBDispatcher::ThreadSpecificInstance() | 76 IndexedDBDispatcher::ThreadSpecificInstance() |
| 57 ->RegisterMojoOwnedDatabaseCallbacks(callbacks_); | 77 ->RegisterMojoOwnedDatabaseCallbacks(callbacks_); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 113 } |
| 94 | 114 |
| 95 void IndexedDBDatabaseCallbacksImpl::Changes( | 115 void IndexedDBDatabaseCallbacksImpl::Changes( |
| 96 indexed_db::mojom::ObserverChangesPtr changes) { | 116 indexed_db::mojom::ObserverChangesPtr changes) { |
| 97 callback_runner_->PostTask(FROM_HERE, base::Bind(&BuildObservationsAndNotify, | 117 callback_runner_->PostTask(FROM_HERE, base::Bind(&BuildObservationsAndNotify, |
| 98 base::Unretained(callbacks_), | 118 base::Unretained(callbacks_), |
| 99 base::Passed(&changes))); | 119 base::Passed(&changes))); |
| 100 } | 120 } |
| 101 | 121 |
| 102 } // namespace content | 122 } // namespace content |
| OLD | NEW |