| OLD | NEW |
| 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/stl_util.h" |
| 13 #include "content/child/indexed_db/indexed_db_callbacks_impl.h" | 13 #include "content/child/indexed_db/indexed_db_callbacks_impl.h" |
| 14 #include "content/child/indexed_db/indexed_db_dispatcher.h" | 14 #include "content/child/indexed_db/indexed_db_dispatcher.h" |
| 15 #include "content/child/indexed_db/indexed_db_key_builders.h" | 15 #include "content/child/indexed_db/indexed_db_key_builders.h" |
| 16 #include "content/child/worker_thread_registry.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; | 28 using blink::WebIDBCursor; |
| 30 using blink::WebIDBDatabase; | 29 using blink::WebIDBDatabase; |
| 31 using blink::WebIDBDatabaseCallbacks; | 30 using blink::WebIDBDatabaseCallbacks; |
| 32 using blink::WebIDBMetadata; | 31 using blink::WebIDBMetadata; |
| 33 using blink::WebIDBKey; | 32 using blink::WebIDBKey; |
| 34 using blink::WebIDBKeyPath; | 33 using blink::WebIDBKeyPath; |
| 35 using blink::WebIDBKeyRange; | 34 using blink::WebIDBKeyRange; |
| 36 using blink::WebIDBObserver; | |
| 37 using blink::WebString; | 35 using blink::WebString; |
| 38 using blink::WebVector; | 36 using blink::WebVector; |
| 39 using indexed_db::mojom::CallbacksAssociatedPtrInfo; | 37 using indexed_db::mojom::CallbacksAssociatedPtrInfo; |
| 40 using indexed_db::mojom::DatabaseAssociatedPtrInfo; | 38 using indexed_db::mojom::DatabaseAssociatedPtrInfo; |
| 41 | 39 |
| 42 namespace content { | 40 namespace content { |
| 43 | 41 |
| 44 namespace { | 42 namespace { |
| 45 | 43 |
| 46 std::vector<content::IndexedDBIndexKeys> ConvertWebIndexKeys( | 44 std::vector<content::IndexedDBIndexKeys> ConvertWebIndexKeys( |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 blink::WebIDBTransactionMode mode) { | 206 blink::WebIDBTransactionMode mode) { |
| 209 io_runner_->PostTask( | 207 io_runner_->PostTask( |
| 210 FROM_HERE, | 208 FROM_HERE, |
| 211 base::Bind(&IOThreadHelper::CreateTransaction, base::Unretained(helper_), | 209 base::Bind(&IOThreadHelper::CreateTransaction, base::Unretained(helper_), |
| 212 transaction_id, std::vector<int64_t>(object_store_ids.begin(), | 210 transaction_id, std::vector<int64_t>(object_store_ids.begin(), |
| 213 object_store_ids.end()), | 211 object_store_ids.end()), |
| 214 mode)); | 212 mode)); |
| 215 } | 213 } |
| 216 | 214 |
| 217 void WebIDBDatabaseImpl::close() { | 215 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( | 216 io_runner_->PostTask( |
| 223 FROM_HERE, base::Bind(&IOThreadHelper::Close, base::Unretained(helper_))); | 217 FROM_HERE, base::Bind(&IOThreadHelper::Close, base::Unretained(helper_))); |
| 224 } | 218 } |
| 225 | 219 |
| 226 void WebIDBDatabaseImpl::versionChangeIgnored() { | 220 void WebIDBDatabaseImpl::versionChangeIgnored() { |
| 227 io_runner_->PostTask(FROM_HERE, | 221 io_runner_->PostTask(FROM_HERE, |
| 228 base::Bind(&IOThreadHelper::VersionChangeIgnored, | 222 base::Bind(&IOThreadHelper::VersionChangeIgnored, |
| 229 base::Unretained(helper_))); | 223 base::Unretained(helper_))); |
| 230 } | 224 } |
| 231 | 225 |
| 232 int32_t WebIDBDatabaseImpl::addObserver( | 226 void WebIDBDatabaseImpl::addObserver( |
| 233 std::unique_ptr<WebIDBObserver> observer, | 227 long long transaction_id, |
| 234 long long transaction_id) { | 228 int32_t observer_id, |
| 235 WebIDBObserver* observer_ptr = observer.get(); | 229 bool include_transaction, |
| 236 int32_t observer_id = | 230 bool no_records, |
| 237 IndexedDBDispatcher::ThreadSpecificInstance()->RegisterObserver( | 231 bool values, |
| 238 std::move(observer)); | 232 const std::bitset<blink::WebIDBOperationTypeCount>& operation_types) { |
| 239 observer_ids_.insert(observer_id); | |
| 240 static_assert(blink::WebIDBOperationTypeCount < sizeof(uint16_t) * CHAR_BIT, | 233 static_assert(blink::WebIDBOperationTypeCount < sizeof(uint16_t) * CHAR_BIT, |
| 241 "WebIDBOperationType Count exceeds size of uint16_t"); | 234 "WebIDBOperationType Count exceeds size of uint16_t"); |
| 242 io_runner_->PostTask( | 235 io_runner_->PostTask( |
| 243 FROM_HERE, | 236 FROM_HERE, |
| 244 base::Bind(&IOThreadHelper::AddObserver, base::Unretained(helper_), | 237 base::Bind(&IOThreadHelper::AddObserver, base::Unretained(helper_), |
| 245 transaction_id, observer_id, observer_ptr->transaction(), | 238 transaction_id, observer_id, include_transaction, no_records, |
| 246 observer_ptr->noRecords(), observer_ptr->values(), | 239 values, operation_types.to_ulong())); |
| 247 observer_ptr->operationTypes().to_ulong())); | |
| 248 return observer_id; | |
| 249 } | 240 } |
| 250 | 241 |
| 251 void WebIDBDatabaseImpl::removeObservers( | 242 void WebIDBDatabaseImpl::removeObservers( |
| 252 const WebVector<int32_t>& observer_ids_to_remove) { | 243 const WebVector<int32_t>& observer_ids_to_remove) { |
| 253 std::vector<int32_t> remove_observer_ids( | 244 std::vector<int32_t> remove_observer_ids( |
| 254 observer_ids_to_remove.data(), | 245 observer_ids_to_remove.data(), |
| 255 observer_ids_to_remove.data() + observer_ids_to_remove.size()); | 246 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 | 247 |
| 259 IndexedDBDispatcher::ThreadSpecificInstance()->RemoveObservers( | |
| 260 remove_observer_ids); | |
| 261 io_runner_->PostTask( | 248 io_runner_->PostTask( |
| 262 FROM_HERE, base::Bind(&IOThreadHelper::RemoveObservers, | 249 FROM_HERE, base::Bind(&IOThreadHelper::RemoveObservers, |
| 263 base::Unretained(helper_), remove_observer_ids)); | 250 base::Unretained(helper_), remove_observer_ids)); |
| 264 } | 251 } |
| 265 | 252 |
| 266 void WebIDBDatabaseImpl::get(long long transaction_id, | 253 void WebIDBDatabaseImpl::get(long long transaction_id, |
| 267 long long object_store_id, | 254 long long object_store_id, |
| 268 long long index_id, | 255 long long index_id, |
| 269 const WebIDBKeyRange& key_range, | 256 const WebIDBKeyRange& key_range, |
| 270 bool key_only, | 257 bool key_only, |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 std::unique_ptr<IndexedDBCallbacksImpl> callbacks) { | 692 std::unique_ptr<IndexedDBCallbacksImpl> callbacks) { |
| 706 CallbacksAssociatedPtrInfo ptr_info; | 693 CallbacksAssociatedPtrInfo ptr_info; |
| 707 indexed_db::mojom::CallbacksAssociatedRequest request; | 694 indexed_db::mojom::CallbacksAssociatedRequest request; |
| 708 database_.associated_group()->CreateAssociatedInterface( | 695 database_.associated_group()->CreateAssociatedInterface( |
| 709 mojo::AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request); | 696 mojo::AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request); |
| 710 mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request)); | 697 mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request)); |
| 711 return ptr_info; | 698 return ptr_info; |
| 712 } | 699 } |
| 713 | 700 |
| 714 } // namespace content | 701 } // namespace content |
| OLD | NEW |