| 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/indexed_db_dispatcher.h" | 5 #include "content/child/indexed_db/indexed_db_dispatcher.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/threading/thread_local.h" | 12 #include "base/threading/thread_local.h" |
| 13 #include "content/child/child_thread_impl.h" |
| 13 #include "content/child/indexed_db/indexed_db_key_builders.h" | 14 #include "content/child/indexed_db/indexed_db_key_builders.h" |
| 14 #include "content/child/indexed_db/webidbcursor_impl.h" | 15 #include "content/child/indexed_db/webidbcursor_impl.h" |
| 15 #include "content/child/indexed_db/webidbdatabase_impl.h" | 16 #include "content/child/indexed_db/webidbdatabase_impl.h" |
| 16 #include "content/child/thread_safe_sender.h" | 17 #include "content/child/thread_safe_sender.h" |
| 17 #include "content/common/indexed_db/indexed_db_messages.h" | 18 #include "content/common/indexed_db/indexed_db_messages.h" |
| 18 #include "ipc/ipc_channel.h" | 19 #include "ipc/ipc_channel.h" |
| 19 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseCal
lbacks.h" | 20 #include "ipc/ipc_sync_channel.h" |
| 21 #include "services/shell/public/cpp/interface_provider.h" |
| 20 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseErr
or.h" | 22 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseErr
or.h" |
| 21 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc
eption.h" | 23 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc
eption.h" |
| 22 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBObservation
.h" | 24 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBObservation
.h" |
| 23 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBValue.h" | 25 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBValue.h" |
| 24 | 26 |
| 25 using blink::WebBlobInfo; | 27 using blink::WebBlobInfo; |
| 26 using blink::WebData; | 28 using blink::WebData; |
| 27 using blink::WebIDBCallbacks; | 29 using blink::WebIDBCallbacks; |
| 28 using blink::WebIDBCursor; | 30 using blink::WebIDBCursor; |
| 29 using blink::WebIDBDatabase; | 31 using blink::WebIDBDatabase; |
| 30 using blink::WebIDBDatabaseCallbacks; | |
| 31 using blink::WebIDBDatabaseError; | 32 using blink::WebIDBDatabaseError; |
| 32 using blink::WebIDBKey; | 33 using blink::WebIDBKey; |
| 33 using blink::WebIDBMetadata; | 34 using blink::WebIDBMetadata; |
| 34 using blink::WebIDBObservation; | 35 using blink::WebIDBObservation; |
| 35 using blink::WebIDBObserver; | 36 using blink::WebIDBObserver; |
| 36 using blink::WebIDBValue; | 37 using blink::WebIDBValue; |
| 37 using blink::WebString; | 38 using blink::WebString; |
| 38 using blink::WebVector; | 39 using blink::WebVector; |
| 39 using base::ThreadLocalPointer; | 40 using base::ThreadLocalPointer; |
| 40 | 41 |
| 41 namespace content { | 42 namespace content { |
| 42 static base::LazyInstance<ThreadLocalPointer<IndexedDBDispatcher> >::Leaky | 43 static base::LazyInstance<ThreadLocalPointer<IndexedDBDispatcher> >::Leaky |
| 43 g_idb_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; | 44 g_idb_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; |
| 44 | 45 |
| 45 namespace { | 46 namespace { |
| 46 | 47 |
| 47 IndexedDBDispatcher* const kHasBeenDeleted = | 48 IndexedDBDispatcher* const kHasBeenDeleted = |
| 48 reinterpret_cast<IndexedDBDispatcher*>(0x1); | 49 reinterpret_cast<IndexedDBDispatcher*>(0x1); |
| 49 | 50 |
| 50 } // unnamed namespace | 51 } // unnamed namespace |
| 51 | 52 |
| 52 IndexedDBDispatcher::IndexedDBDispatcher(ThreadSafeSender* thread_safe_sender) | 53 IndexedDBDispatcher::IndexedDBDispatcher(ThreadSafeSender* thread_safe_sender) |
| 53 : thread_safe_sender_(thread_safe_sender) { | 54 : thread_safe_sender_(thread_safe_sender) { |
| 55 ChildThreadImpl* child_thread = ChildThreadImpl::current(); |
| 56 if (child_thread) |
| 57 child_thread->channel()->GetRemoteAssociatedInterface(&database_factory_); |
| 54 g_idb_dispatcher_tls.Pointer()->Set(this); | 58 g_idb_dispatcher_tls.Pointer()->Set(this); |
| 55 } | 59 } |
| 56 | 60 |
| 57 IndexedDBDispatcher::~IndexedDBDispatcher() { | 61 IndexedDBDispatcher::~IndexedDBDispatcher() { |
| 58 // Clear any pending callbacks - which may result in dispatch requests - | 62 // Clear any pending callbacks - which may result in dispatch requests - |
| 59 // before marking the dispatcher as deleted. | 63 // before marking the dispatcher as deleted. |
| 60 pending_callbacks_.Clear(); | 64 pending_callbacks_.Clear(); |
| 61 pending_database_callbacks_.Clear(); | |
| 62 | 65 |
| 63 DCHECK(pending_callbacks_.IsEmpty()); | 66 DCHECK(pending_callbacks_.IsEmpty()); |
| 64 DCHECK(pending_database_callbacks_.IsEmpty()); | |
| 65 | 67 |
| 66 g_idb_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); | 68 g_idb_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); |
| 67 } | 69 } |
| 68 | 70 |
| 69 IndexedDBDispatcher* IndexedDBDispatcher::ThreadSpecificInstance( | 71 IndexedDBDispatcher* IndexedDBDispatcher::ThreadSpecificInstance( |
| 70 ThreadSafeSender* thread_safe_sender) { | 72 ThreadSafeSender* thread_safe_sender) { |
| 71 if (g_idb_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) { | 73 if (g_idb_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) { |
| 72 NOTREACHED() << "Re-instantiating TLS IndexedDBDispatcher."; | 74 NOTREACHED() << "Re-instantiating TLS IndexedDBDispatcher."; |
| 73 g_idb_dispatcher_tls.Pointer()->Set(NULL); | 75 g_idb_dispatcher_tls.Pointer()->Set(NULL); |
| 74 } | 76 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessStringList, | 162 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessStringList, |
| 161 OnSuccessStringList) | 163 OnSuccessStringList) |
| 162 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessArray, OnSuccessArray) | 164 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessArray, OnSuccessArray) |
| 163 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessValue, OnSuccessValue) | 165 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessValue, OnSuccessValue) |
| 164 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessInteger, OnSuccessInteger) | 166 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessInteger, OnSuccessInteger) |
| 165 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessUndefined, | 167 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessUndefined, |
| 166 OnSuccessUndefined) | 168 OnSuccessUndefined) |
| 167 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError) | 169 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError) |
| 168 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksIntBlocked, OnIntBlocked) | 170 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksIntBlocked, OnIntBlocked) |
| 169 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksUpgradeNeeded, OnUpgradeNeeded) | 171 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksUpgradeNeeded, OnUpgradeNeeded) |
| 170 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksForcedClose, | |
| 171 OnForcedClose) | |
| 172 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksVersionChange, | |
| 173 OnVersionChange) | |
| 174 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksAbort, OnAbort) | |
| 175 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksComplete, OnComplete) | |
| 176 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksChanges, | 172 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksChanges, |
| 177 OnDatabaseChanges) | 173 OnDatabaseChanges) |
| 178 IPC_MESSAGE_UNHANDLED(handled = false) | 174 IPC_MESSAGE_UNHANDLED(handled = false) |
| 179 IPC_END_MESSAGE_MAP() | 175 IPC_END_MESSAGE_MAP() |
| 180 // If a message gets here, IndexedDBMessageFilter already determined that it | 176 // If a message gets here, IndexedDBMessageFilter already determined that it |
| 181 // is an IndexedDB message. | 177 // is an IndexedDB message. |
| 182 DCHECK(handled) << "Didn't handle a message defined at line " | 178 DCHECK(handled) << "Didn't handle a message defined at line " |
| 183 << IPC_MESSAGE_ID_LINE(msg.type()); | 179 << IPC_MESSAGE_ID_LINE(msg.type()); |
| 184 } | 180 } |
| 185 | 181 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 } | 262 } |
| 267 | 263 |
| 268 void IndexedDBDispatcher::RequestIDBCursorPrefetchReset(int used_prefetches, | 264 void IndexedDBDispatcher::RequestIDBCursorPrefetchReset(int used_prefetches, |
| 269 int unused_prefetches, | 265 int unused_prefetches, |
| 270 int32_t ipc_cursor_id) { | 266 int32_t ipc_cursor_id) { |
| 271 Send(new IndexedDBHostMsg_CursorPrefetchReset( | 267 Send(new IndexedDBHostMsg_CursorPrefetchReset( |
| 272 ipc_cursor_id, used_prefetches, unused_prefetches)); | 268 ipc_cursor_id, used_prefetches, unused_prefetches)); |
| 273 } | 269 } |
| 274 | 270 |
| 275 void IndexedDBDispatcher::RequestIDBFactoryOpen( | 271 void IndexedDBDispatcher::RequestIDBFactoryOpen( |
| 276 const base::string16& name, | 272 const std::string& name, |
| 277 int64_t version, | 273 int64_t version, |
| 278 int64_t transaction_id, | 274 int64_t transaction_id, |
| 279 WebIDBCallbacks* callbacks_ptr, | 275 WebIDBCallbacks* callbacks, |
| 280 WebIDBDatabaseCallbacks* database_callbacks_ptr, | 276 mojo::ScopedInterfaceEndpointHandle* client_interface_endpoint, |
| 281 const url::Origin& origin) { | 277 const url::Origin& origin) { |
| 282 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | 278 indexed_db::mojom::DatabaseClientAssociatedPtrInfo clientInfo; |
| 283 std::unique_ptr<WebIDBDatabaseCallbacks> database_callbacks( | 279 indexed_db::mojom::DatabaseClientAssociatedRequest clientRequest; |
| 284 database_callbacks_ptr); | 280 database_factory_.associated_group()->CreateAssociatedInterface( |
| 281 mojo::AssociatedGroup::WILL_PASS_PTR, &clientInfo, &clientRequest); |
| 282 *client_interface_endpoint = clientRequest.PassHandle(); |
| 285 | 283 |
| 286 IndexedDBHostMsg_FactoryOpen_Params params; | 284 database_factory_->Open(name, version, transaction_id, origin, |
| 287 params.ipc_thread_id = CurrentWorkerId(); | 285 std::move(clientInfo), CurrentWorkerId(), |
| 288 params.ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); | 286 pending_callbacks_.Add(callbacks)); |
| 289 params.ipc_database_callbacks_id = | |
| 290 pending_database_callbacks_.Add(database_callbacks.release()); | |
| 291 params.origin = origin; | |
| 292 params.name = name; | |
| 293 params.transaction_id = transaction_id; | |
| 294 params.version = version; | |
| 295 Send(new IndexedDBHostMsg_FactoryOpen(params)); | |
| 296 } | 287 } |
| 297 | 288 |
| 298 void IndexedDBDispatcher::RequestIDBFactoryGetDatabaseNames( | 289 void IndexedDBDispatcher::RequestIDBFactoryGetDatabaseNames( |
| 299 WebIDBCallbacks* callbacks_ptr, | 290 WebIDBCallbacks* callbacks_ptr, |
| 300 const url::Origin& origin) { | 291 const url::Origin& origin) { |
| 301 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | 292 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); |
| 302 | 293 |
| 303 IndexedDBHostMsg_FactoryGetDatabaseNames_Params params; | 294 IndexedDBHostMsg_FactoryGetDatabaseNames_Params params; |
| 304 params.ipc_thread_id = CurrentWorkerId(); | 295 params.ipc_thread_id = CurrentWorkerId(); |
| 305 params.ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); | 296 params.ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); |
| 306 params.origin = origin; | 297 params.origin = origin; |
| 307 Send(new IndexedDBHostMsg_FactoryGetDatabaseNames(params)); | 298 Send(new IndexedDBHostMsg_FactoryGetDatabaseNames(params)); |
| 308 } | 299 } |
| 309 | 300 |
| 310 void IndexedDBDispatcher::RequestIDBFactoryDeleteDatabase( | 301 void IndexedDBDispatcher::RequestIDBFactoryDeleteDatabase( |
| 311 const base::string16& name, | 302 const base::string16& name, |
| 312 WebIDBCallbacks* callbacks_ptr, | 303 WebIDBCallbacks* callbacks_ptr, |
| 313 const url::Origin& origin) { | 304 const url::Origin& origin) { |
| 314 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | 305 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); |
| 315 | 306 |
| 316 IndexedDBHostMsg_FactoryDeleteDatabase_Params params; | 307 IndexedDBHostMsg_FactoryDeleteDatabase_Params params; |
| 317 params.ipc_thread_id = CurrentWorkerId(); | 308 params.ipc_thread_id = CurrentWorkerId(); |
| 318 params.ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); | 309 params.ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); |
| 319 params.origin = origin; | 310 params.origin = origin; |
| 320 params.name = name; | 311 params.name = name; |
| 321 Send(new IndexedDBHostMsg_FactoryDeleteDatabase(params)); | 312 Send(new IndexedDBHostMsg_FactoryDeleteDatabase(params)); |
| 322 } | 313 } |
| 323 | 314 |
| 324 void IndexedDBDispatcher::RequestIDBDatabaseClose( | 315 void IndexedDBDispatcher::RequestIDBDatabaseClose(int32_t ipc_database_id) { |
| 325 int32_t ipc_database_id, | |
| 326 int32_t ipc_database_callbacks_id) { | |
| 327 Send(new IndexedDBHostMsg_DatabaseClose(ipc_database_id)); | 316 Send(new IndexedDBHostMsg_DatabaseClose(ipc_database_id)); |
| 328 // There won't be pending database callbacks if the transaction was aborted in | |
| 329 // the initial upgradeneeded event handler. | |
| 330 if (pending_database_callbacks_.Lookup(ipc_database_callbacks_id)) | |
| 331 pending_database_callbacks_.Remove(ipc_database_callbacks_id); | |
| 332 } | 317 } |
| 333 | 318 |
| 334 void IndexedDBDispatcher::NotifyIDBDatabaseVersionChangeIgnored( | 319 void IndexedDBDispatcher::NotifyIDBDatabaseVersionChangeIgnored( |
| 335 int32_t ipc_database_id) { | 320 int32_t ipc_database_id) { |
| 336 Send(new IndexedDBHostMsg_DatabaseVersionChangeIgnored(ipc_database_id)); | 321 Send(new IndexedDBHostMsg_DatabaseVersionChangeIgnored(ipc_database_id)); |
| 337 } | 322 } |
| 338 | 323 |
| 339 void IndexedDBDispatcher::RequestIDBDatabaseCreateTransaction( | 324 void IndexedDBDispatcher::RequestIDBDatabaseCreateTransaction( |
| 340 int32_t ipc_database_id, | 325 int32_t ipc_database_id, |
| 341 int64_t transaction_id, | 326 int64_t transaction_id, |
| 342 WebIDBDatabaseCallbacks* database_callbacks_ptr, | |
| 343 WebVector<long long> object_store_ids, | 327 WebVector<long long> object_store_ids, |
| 344 blink::WebIDBTransactionMode mode) { | 328 blink::WebIDBTransactionMode mode) { |
| 345 std::unique_ptr<WebIDBDatabaseCallbacks> database_callbacks( | |
| 346 database_callbacks_ptr); | |
| 347 IndexedDBHostMsg_DatabaseCreateTransaction_Params params; | 329 IndexedDBHostMsg_DatabaseCreateTransaction_Params params; |
| 348 params.ipc_thread_id = CurrentWorkerId(); | 330 params.ipc_thread_id = CurrentWorkerId(); |
| 349 params.ipc_database_id = ipc_database_id; | 331 params.ipc_database_id = ipc_database_id; |
| 350 params.transaction_id = transaction_id; | 332 params.transaction_id = transaction_id; |
| 351 params.ipc_database_callbacks_id = | |
| 352 pending_database_callbacks_.Add(database_callbacks.release()); | |
| 353 params.object_store_ids | 333 params.object_store_ids |
| 354 .assign(object_store_ids.data(), | 334 .assign(object_store_ids.data(), |
| 355 object_store_ids.data() + object_store_ids.size()); | 335 object_store_ids.data() + object_store_ids.size()); |
| 356 params.mode = mode; | 336 params.mode = mode; |
| 357 | 337 |
| 358 Send(new IndexedDBHostMsg_DatabaseCreateTransaction(params)); | 338 Send(new IndexedDBHostMsg_DatabaseCreateTransaction(params)); |
| 359 } | 339 } |
| 360 | 340 |
| 361 void IndexedDBDispatcher::RequestIDBDatabaseGet( | 341 void IndexedDBDispatcher::RequestIDBDatabaseGet( |
| 362 int32_t ipc_database_id, | 342 int32_t ipc_database_id, |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 } | 526 } |
| 547 | 527 |
| 548 void IndexedDBDispatcher::DatabaseDestroyed(int32_t ipc_database_id) { | 528 void IndexedDBDispatcher::DatabaseDestroyed(int32_t ipc_database_id) { |
| 549 DCHECK_EQ(databases_.count(ipc_database_id), 1u); | 529 DCHECK_EQ(databases_.count(ipc_database_id), 1u); |
| 550 databases_.erase(ipc_database_id); | 530 databases_.erase(ipc_database_id); |
| 551 } | 531 } |
| 552 | 532 |
| 553 void IndexedDBDispatcher::OnSuccessIDBDatabase( | 533 void IndexedDBDispatcher::OnSuccessIDBDatabase( |
| 554 int32_t ipc_thread_id, | 534 int32_t ipc_thread_id, |
| 555 int32_t ipc_callbacks_id, | 535 int32_t ipc_callbacks_id, |
| 556 int32_t ipc_database_callbacks_id, | |
| 557 int32_t ipc_object_id, | 536 int32_t ipc_object_id, |
| 558 const IndexedDBDatabaseMetadata& idb_metadata) { | 537 const IndexedDBDatabaseMetadata& idb_metadata) { |
| 559 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | 538 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); |
| 560 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | 539 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); |
| 561 if (!callbacks) | 540 if (!callbacks) |
| 562 return; | 541 return; |
| 563 WebIDBMetadata metadata(ConvertMetadata(idb_metadata)); | 542 WebIDBMetadata metadata(ConvertMetadata(idb_metadata)); |
| 564 // If an upgrade was performed, count will be non-zero. | 543 // If an upgrade was performed, count will be non-zero. |
| 565 WebIDBDatabase* database = NULL; | 544 WebIDBDatabase* database = NULL; |
| 566 | 545 |
| 567 // Back-end will send kNoDatabase if it was already sent in OnUpgradeNeeded. | 546 // Back-end will send kNoDatabase if it was already sent in OnUpgradeNeeded. |
| 568 // May already be deleted and removed from the table, but do not recreate.. | 547 // May already be deleted and removed from the table, but do not recreate.. |
| 569 if (ipc_object_id != kNoDatabase) { | 548 if (ipc_object_id != kNoDatabase) { |
| 570 DCHECK(!databases_.count(ipc_object_id)); | 549 DCHECK(!databases_.count(ipc_object_id)); |
| 571 database = databases_[ipc_object_id] = new WebIDBDatabaseImpl( | 550 database = databases_[ipc_object_id] = |
| 572 ipc_object_id, ipc_database_callbacks_id, thread_safe_sender_.get()); | 551 new WebIDBDatabaseImpl(ipc_object_id, thread_safe_sender_.get()); |
| 573 } | 552 } |
| 574 | 553 |
| 575 callbacks->onSuccess(database, metadata); | 554 callbacks->onSuccess(database, metadata); |
| 576 pending_callbacks_.Remove(ipc_callbacks_id); | 555 pending_callbacks_.Remove(ipc_callbacks_id); |
| 577 } | 556 } |
| 578 | 557 |
| 579 void IndexedDBDispatcher::OnSuccessIndexedDBKey(int32_t ipc_thread_id, | 558 void IndexedDBDispatcher::OnSuccessIndexedDBKey(int32_t ipc_thread_id, |
| 580 int32_t ipc_callbacks_id, | 559 int32_t ipc_callbacks_id, |
| 581 const IndexedDBKey& key) { | 560 const IndexedDBKey& key) { |
| 582 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | 561 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 | 745 |
| 767 void IndexedDBDispatcher::OnUpgradeNeeded( | 746 void IndexedDBDispatcher::OnUpgradeNeeded( |
| 768 const IndexedDBMsg_CallbacksUpgradeNeeded_Params& p) { | 747 const IndexedDBMsg_CallbacksUpgradeNeeded_Params& p) { |
| 769 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); | 748 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); |
| 770 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(p.ipc_callbacks_id); | 749 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(p.ipc_callbacks_id); |
| 771 DCHECK(callbacks); | 750 DCHECK(callbacks); |
| 772 WebIDBMetadata metadata(ConvertMetadata(p.idb_metadata)); | 751 WebIDBMetadata metadata(ConvertMetadata(p.idb_metadata)); |
| 773 DCHECK(!databases_.count(p.ipc_database_id)); | 752 DCHECK(!databases_.count(p.ipc_database_id)); |
| 774 databases_[p.ipc_database_id] = | 753 databases_[p.ipc_database_id] = |
| 775 new WebIDBDatabaseImpl(p.ipc_database_id, | 754 new WebIDBDatabaseImpl(p.ipc_database_id, |
| 776 p.ipc_database_callbacks_id, | |
| 777 thread_safe_sender_.get()); | 755 thread_safe_sender_.get()); |
| 778 callbacks->onUpgradeNeeded( | 756 callbacks->onUpgradeNeeded( |
| 779 p.old_version, | 757 p.old_version, |
| 780 databases_[p.ipc_database_id], | 758 databases_[p.ipc_database_id], |
| 781 metadata, | 759 metadata, |
| 782 static_cast<blink::WebIDBDataLoss>(p.data_loss), | 760 static_cast<blink::WebIDBDataLoss>(p.data_loss), |
| 783 WebString::fromUTF8(p.data_loss_message)); | 761 WebString::fromUTF8(p.data_loss_message)); |
| 784 } | 762 } |
| 785 | 763 |
| 786 void IndexedDBDispatcher::OnError(int32_t ipc_thread_id, | 764 void IndexedDBDispatcher::OnError(int32_t ipc_thread_id, |
| 787 int32_t ipc_callbacks_id, | 765 int32_t ipc_callbacks_id, |
| 788 int code, | 766 int code, |
| 789 const base::string16& message) { | 767 const base::string16& message) { |
| 790 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | 768 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); |
| 791 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | 769 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); |
| 792 if (!callbacks) | 770 if (!callbacks) |
| 793 return; | 771 return; |
| 794 if (message.empty()) | 772 if (message.empty()) |
| 795 callbacks->onError(WebIDBDatabaseError(code)); | 773 callbacks->onError(WebIDBDatabaseError(code)); |
| 796 else | 774 else |
| 797 callbacks->onError(WebIDBDatabaseError(code, message)); | 775 callbacks->onError(WebIDBDatabaseError(code, message)); |
| 798 pending_callbacks_.Remove(ipc_callbacks_id); | 776 pending_callbacks_.Remove(ipc_callbacks_id); |
| 799 cursor_transaction_ids_.erase(ipc_callbacks_id); | 777 cursor_transaction_ids_.erase(ipc_callbacks_id); |
| 800 } | 778 } |
| 801 | 779 |
| 802 void IndexedDBDispatcher::OnAbort(int32_t ipc_thread_id, | |
| 803 int32_t ipc_database_callbacks_id, | |
| 804 int64_t transaction_id, | |
| 805 int code, | |
| 806 const base::string16& message) { | |
| 807 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | |
| 808 WebIDBDatabaseCallbacks* callbacks = | |
| 809 pending_database_callbacks_.Lookup(ipc_database_callbacks_id); | |
| 810 if (!callbacks) | |
| 811 return; | |
| 812 if (message.empty()) | |
| 813 callbacks->onAbort(transaction_id, WebIDBDatabaseError(code)); | |
| 814 else | |
| 815 callbacks->onAbort(transaction_id, WebIDBDatabaseError(code, message)); | |
| 816 } | |
| 817 | |
| 818 void IndexedDBDispatcher::OnComplete(int32_t ipc_thread_id, | |
| 819 int32_t ipc_database_callbacks_id, | |
| 820 int64_t transaction_id) { | |
| 821 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | |
| 822 WebIDBDatabaseCallbacks* callbacks = | |
| 823 pending_database_callbacks_.Lookup(ipc_database_callbacks_id); | |
| 824 if (!callbacks) | |
| 825 return; | |
| 826 callbacks->onComplete(transaction_id); | |
| 827 } | |
| 828 | |
| 829 void IndexedDBDispatcher::OnDatabaseChanges( | 780 void IndexedDBDispatcher::OnDatabaseChanges( |
| 830 int32_t ipc_thread_id, | 781 int32_t ipc_thread_id, |
| 831 int32_t ipc_database_id, | 782 int32_t ipc_database_id, |
| 832 const IndexedDBMsg_ObserverChanges& changes) { | 783 const IndexedDBMsg_ObserverChanges& changes) { |
| 833 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | 784 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); |
| 834 std::vector<WebIDBObservation> observations( | 785 std::vector<WebIDBObservation> observations( |
| 835 ConvertObservations(changes.observations)); | 786 ConvertObservations(changes.observations)); |
| 836 for (auto& it : changes.observation_index) { | 787 for (auto& it : changes.observation_index) { |
| 837 WebIDBObserver* observer = observers_.Lookup(it.first); | 788 WebIDBObserver* observer = observers_.Lookup(it.first); |
| 838 // An observer can be removed from the renderer, but still exist in the | 789 // An observer can be removed from the renderer, but still exist in the |
| 839 // backend. Moreover, observer might have recorded some changes before being | 790 // backend. Moreover, observer might have recorded some changes before being |
| 840 // removed from the backend and thus, have its id be present in changes. | 791 // removed from the backend and thus, have its id be present in changes. |
| 841 if (!observer) | 792 if (!observer) |
| 842 continue; | 793 continue; |
| 843 observer->onChange(observations, std::move(it.second)); | 794 observer->onChange(observations, std::move(it.second)); |
| 844 } | 795 } |
| 845 } | 796 } |
| 846 | 797 |
| 847 void IndexedDBDispatcher::OnForcedClose(int32_t ipc_thread_id, | |
| 848 int32_t ipc_database_callbacks_id) { | |
| 849 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | |
| 850 WebIDBDatabaseCallbacks* callbacks = | |
| 851 pending_database_callbacks_.Lookup(ipc_database_callbacks_id); | |
| 852 if (!callbacks) | |
| 853 return; | |
| 854 callbacks->onForcedClose(); | |
| 855 } | |
| 856 | |
| 857 void IndexedDBDispatcher::OnVersionChange(int32_t ipc_thread_id, | |
| 858 int32_t ipc_database_callbacks_id, | |
| 859 int64_t old_version, | |
| 860 int64_t new_version) { | |
| 861 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | |
| 862 WebIDBDatabaseCallbacks* callbacks = | |
| 863 pending_database_callbacks_.Lookup(ipc_database_callbacks_id); | |
| 864 // callbacks would be NULL if a versionchange event is received after close | |
| 865 // has been called. | |
| 866 if (!callbacks) | |
| 867 return; | |
| 868 callbacks->onVersionChange(old_version, new_version); | |
| 869 } | |
| 870 | |
| 871 void IndexedDBDispatcher::ResetCursorPrefetchCaches( | 798 void IndexedDBDispatcher::ResetCursorPrefetchCaches( |
| 872 int64_t transaction_id, | 799 int64_t transaction_id, |
| 873 int32_t ipc_exception_cursor_id) { | 800 int32_t ipc_exception_cursor_id) { |
| 874 typedef std::map<int32_t, WebIDBCursorImpl*>::iterator Iterator; | 801 typedef std::map<int32_t, WebIDBCursorImpl*>::iterator Iterator; |
| 875 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { | 802 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { |
| 876 if (i->first == ipc_exception_cursor_id || | 803 if (i->first == ipc_exception_cursor_id || |
| 877 i->second->transaction_id() != transaction_id) | 804 i->second->transaction_id() != transaction_id) |
| 878 continue; | 805 continue; |
| 879 i->second->ResetPrefetchCache(); | 806 i->second->ResetPrefetchCache(); |
| 880 } | 807 } |
| 881 } | 808 } |
| 882 | 809 |
| 883 } // namespace content | 810 } // namespace content |
| OLD | NEW |