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/indexed_db/indexed_db_key_builders.h" | 13 #include "content/child/indexed_db/indexed_db_key_builders.h" |
14 #include "content/child/indexed_db/webidbcursor_impl.h" | 14 #include "content/child/indexed_db/webidbcursor_impl.h" |
15 #include "content/child/indexed_db/webidbdatabase_impl.h" | 15 #include "content/child/indexed_db/webidbdatabase_impl.h" |
16 #include "content/child/thread_safe_sender.h" | 16 #include "content/child/thread_safe_sender.h" |
17 #include "content/common/indexed_db/indexed_db_constants.h" | 17 #include "content/common/indexed_db/indexed_db_constants.h" |
18 #include "content/common/indexed_db/indexed_db_messages.h" | 18 #include "content/common/indexed_db/indexed_db_messages.h" |
19 #include "ipc/ipc_channel.h" | 19 #include "ipc/ipc_channel.h" |
20 #include "third_party/WebKit/public/platform/WebIDBDatabaseCallbacks.h" | 20 #include "third_party/WebKit/public/platform/WebIDBDatabaseCallbacks.h" |
21 #include "third_party/WebKit/public/platform/WebIDBDatabaseError.h" | 21 #include "third_party/WebKit/public/platform/WebIDBDatabaseError.h" |
22 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" | 22 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" |
| 23 #include "third_party/WebKit/public/platform/WebIDBValue.h" |
23 | 24 |
24 using blink::WebBlobInfo; | 25 using blink::WebBlobInfo; |
25 using blink::WebData; | 26 using blink::WebData; |
26 using blink::WebIDBCallbacks; | 27 using blink::WebIDBCallbacks; |
27 using blink::WebIDBCursor; | 28 using blink::WebIDBCursor; |
28 using blink::WebIDBDatabase; | 29 using blink::WebIDBDatabase; |
29 using blink::WebIDBDatabaseCallbacks; | 30 using blink::WebIDBDatabaseCallbacks; |
30 using blink::WebIDBDatabaseError; | 31 using blink::WebIDBDatabaseError; |
31 using blink::WebIDBKey; | 32 using blink::WebIDBKey; |
32 using blink::WebIDBMetadata; | 33 using blink::WebIDBMetadata; |
| 34 using blink::WebIDBValue; |
33 using blink::WebString; | 35 using blink::WebString; |
34 using blink::WebVector; | 36 using blink::WebVector; |
35 using base::ThreadLocalPointer; | 37 using base::ThreadLocalPointer; |
36 | 38 |
37 namespace content { | 39 namespace content { |
38 static base::LazyInstance<ThreadLocalPointer<IndexedDBDispatcher> >::Leaky | 40 static base::LazyInstance<ThreadLocalPointer<IndexedDBDispatcher> >::Leaky |
39 g_idb_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; | 41 g_idb_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; |
40 | 42 |
41 namespace { | 43 namespace { |
42 | 44 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorContinue, | 138 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorContinue, |
137 OnSuccessCursorContinue) | 139 OnSuccessCursorContinue) |
138 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorPrefetch, | 140 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorPrefetch, |
139 OnSuccessCursorPrefetch) | 141 OnSuccessCursorPrefetch) |
140 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBDatabase, | 142 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBDatabase, |
141 OnSuccessIDBDatabase) | 143 OnSuccessIDBDatabase) |
142 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIndexedDBKey, | 144 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIndexedDBKey, |
143 OnSuccessIndexedDBKey) | 145 OnSuccessIndexedDBKey) |
144 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessStringList, | 146 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessStringList, |
145 OnSuccessStringList) | 147 OnSuccessStringList) |
| 148 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessArray, OnSuccessArray) |
146 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessValue, OnSuccessValue) | 149 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessValue, OnSuccessValue) |
147 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessInteger, OnSuccessInteger) | 150 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessInteger, OnSuccessInteger) |
148 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessUndefined, | 151 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessUndefined, |
149 OnSuccessUndefined) | 152 OnSuccessUndefined) |
150 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError) | 153 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError) |
151 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksIntBlocked, OnIntBlocked) | 154 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksIntBlocked, OnIntBlocked) |
152 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksUpgradeNeeded, OnUpgradeNeeded) | 155 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksUpgradeNeeded, OnUpgradeNeeded) |
153 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksForcedClose, | 156 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksForcedClose, |
154 OnForcedClose) | 157 OnForcedClose) |
155 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksIntVersionChange, | 158 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksIntVersionChange, |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 init_params(¶ms, callbacks); | 319 init_params(¶ms, callbacks); |
317 params.ipc_database_id = ipc_database_id; | 320 params.ipc_database_id = ipc_database_id; |
318 params.transaction_id = transaction_id; | 321 params.transaction_id = transaction_id; |
319 params.object_store_id = object_store_id; | 322 params.object_store_id = object_store_id; |
320 params.index_id = index_id; | 323 params.index_id = index_id; |
321 params.key_range = key_range; | 324 params.key_range = key_range; |
322 params.key_only = key_only; | 325 params.key_only = key_only; |
323 Send(new IndexedDBHostMsg_DatabaseGet(params)); | 326 Send(new IndexedDBHostMsg_DatabaseGet(params)); |
324 } | 327 } |
325 | 328 |
| 329 void IndexedDBDispatcher::RequestIDBDatabaseGetAll( |
| 330 int32 ipc_database_id, |
| 331 int64 transaction_id, |
| 332 int64 object_store_id, |
| 333 const IndexedDBKeyRange& key_range, |
| 334 int64 max_count, |
| 335 WebIDBCallbacks* callbacks) { |
| 336 ResetCursorPrefetchCaches(transaction_id, kAllCursors); |
| 337 IndexedDBHostMsg_DatabaseGetAll_Params params; |
| 338 init_params(¶ms, callbacks); |
| 339 params.ipc_database_id = ipc_database_id; |
| 340 params.transaction_id = transaction_id; |
| 341 params.object_store_id = object_store_id; |
| 342 params.key_range = key_range; |
| 343 params.max_count = max_count; |
| 344 Send(new IndexedDBHostMsg_DatabaseGetAll(params)); |
| 345 } |
| 346 |
326 void IndexedDBDispatcher::RequestIDBDatabasePut( | 347 void IndexedDBDispatcher::RequestIDBDatabasePut( |
327 int32 ipc_database_id, | 348 int32 ipc_database_id, |
328 int64 transaction_id, | 349 int64 transaction_id, |
329 int64 object_store_id, | 350 int64 object_store_id, |
330 const WebData& value, | 351 const WebData& value, |
331 const blink::WebVector<WebBlobInfo>& web_blob_info, | 352 const blink::WebVector<WebBlobInfo>& web_blob_info, |
332 const IndexedDBKey& key, | 353 const IndexedDBKey& key, |
333 blink::WebIDBPutMode put_mode, | 354 blink::WebIDBPutMode put_mode, |
334 WebIDBCallbacks* callbacks, | 355 WebIDBCallbacks* callbacks, |
335 const WebVector<long long>& index_ids, | 356 const WebVector<long long>& index_ids, |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 int32 ipc_callbacks_id, | 536 int32 ipc_callbacks_id, |
516 const std::vector<base::string16>& value) { | 537 const std::vector<base::string16>& value) { |
517 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | 538 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); |
518 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | 539 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); |
519 if (!callbacks) | 540 if (!callbacks) |
520 return; | 541 return; |
521 callbacks->onSuccess(WebVector<WebString>(value)); | 542 callbacks->onSuccess(WebVector<WebString>(value)); |
522 pending_callbacks_.Remove(ipc_callbacks_id); | 543 pending_callbacks_.Remove(ipc_callbacks_id); |
523 } | 544 } |
524 | 545 |
| 546 static void PrepareWebValue(const IndexedDBMsg_ReturnValue& value, |
| 547 WebIDBValue* web_value) { |
| 548 if (value.bits.empty()) |
| 549 return; |
| 550 |
| 551 web_value->data.assign(&*value.bits.begin(), value.bits.size()); |
| 552 blink::WebVector<WebBlobInfo> local_blob_info(value.blob_or_file_info.size()); |
| 553 for (size_t i = 0; i < value.blob_or_file_info.size(); ++i) { |
| 554 const IndexedDBMsg_BlobOrFileInfo& info = value.blob_or_file_info[i]; |
| 555 if (info.is_file) { |
| 556 local_blob_info[i] = WebBlobInfo( |
| 557 WebString::fromUTF8(info.uuid.c_str()), info.file_path, |
| 558 info.file_name, info.mime_type, info.last_modified, info.size); |
| 559 } else { |
| 560 local_blob_info[i] = WebBlobInfo(WebString::fromUTF8(info.uuid.c_str()), |
| 561 info.mime_type, info.size); |
| 562 } |
| 563 } |
| 564 |
| 565 web_value->webBlobInfo.swap(local_blob_info); |
| 566 web_value->primaryKey = WebIDBKeyBuilder::Build(value.primary_key); |
| 567 web_value->keyPath = WebIDBKeyPathBuilder::Build(value.key_path); |
| 568 } |
| 569 |
525 static void PrepareWebValueAndBlobInfo( | 570 static void PrepareWebValueAndBlobInfo( |
526 const IndexedDBMsg_Value& value, | 571 const IndexedDBMsg_Value& value, |
527 WebData* web_value, | 572 WebData* web_value, |
528 blink::WebVector<WebBlobInfo>* web_blob_info) { | 573 blink::WebVector<WebBlobInfo>* web_blob_info) { |
529 if (value.bits.empty()) | 574 if (value.bits.empty()) |
530 return; | 575 return; |
531 | 576 |
532 web_value->assign(&*value.bits.begin(), value.bits.size()); | 577 web_value->assign(&*value.bits.begin(), value.bits.size()); |
533 blink::WebVector<WebBlobInfo> local_blob_info(value.blob_or_file_info.size()); | 578 blink::WebVector<WebBlobInfo> local_blob_info(value.blob_or_file_info.size()); |
534 for (size_t i = 0; i < value.blob_or_file_info.size(); ++i) { | 579 for (size_t i = 0; i < value.blob_or_file_info.size(); ++i) { |
535 const IndexedDBMsg_BlobOrFileInfo& info = value.blob_or_file_info[i]; | 580 const IndexedDBMsg_BlobOrFileInfo& info = value.blob_or_file_info[i]; |
536 if (info.is_file) { | 581 if (info.is_file) { |
537 local_blob_info[i] = WebBlobInfo(WebString::fromUTF8(info.uuid.c_str()), | 582 local_blob_info[i] = WebBlobInfo(WebString::fromUTF8(info.uuid.c_str()), |
538 info.file_path, | 583 info.file_path, |
539 info.file_name, | 584 info.file_name, |
540 info.mime_type, | 585 info.mime_type, |
541 info.last_modified, | 586 info.last_modified, |
542 info.size); | 587 info.size); |
543 } else { | 588 } else { |
544 local_blob_info[i] = WebBlobInfo( | 589 local_blob_info[i] = WebBlobInfo( |
545 WebString::fromUTF8(info.uuid.c_str()), info.mime_type, info.size); | 590 WebString::fromUTF8(info.uuid.c_str()), info.mime_type, info.size); |
546 } | 591 } |
547 } | 592 } |
548 web_blob_info->swap(local_blob_info); | 593 web_blob_info->swap(local_blob_info); |
549 } | 594 } |
550 | 595 |
| 596 void IndexedDBDispatcher::OnSuccessArray( |
| 597 const IndexedDBMsg_CallbacksSuccessArray_Params& p) { |
| 598 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); |
| 599 int32 ipc_callbacks_id = p.ipc_callbacks_id; |
| 600 blink::WebVector<WebIDBValue> web_values(p.values.size()); |
| 601 for (size_t i = 0; i < p.values.size(); ++i) |
| 602 PrepareWebValue(p.values[i], &web_values[i]); |
| 603 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); |
| 604 DCHECK(callbacks); |
| 605 callbacks->onSuccess(web_values); |
| 606 pending_callbacks_.Remove(ipc_callbacks_id); |
| 607 } |
| 608 |
551 void IndexedDBDispatcher::OnSuccessValue( | 609 void IndexedDBDispatcher::OnSuccessValue( |
552 const IndexedDBMsg_CallbacksSuccessValue_Params& params) { | 610 const IndexedDBMsg_CallbacksSuccessValue_Params& params) { |
553 DCHECK_EQ(params.ipc_thread_id, CurrentWorkerId()); | 611 DCHECK_EQ(params.ipc_thread_id, CurrentWorkerId()); |
554 WebIDBCallbacks* callbacks = | 612 WebIDBCallbacks* callbacks = |
555 pending_callbacks_.Lookup(params.ipc_callbacks_id); | 613 pending_callbacks_.Lookup(params.ipc_callbacks_id); |
556 if (!callbacks) | 614 if (!callbacks) |
557 return; | 615 return; |
558 WebData web_value; | 616 WebIDBValue web_value; |
559 WebVector<WebBlobInfo> web_blob_info; | 617 PrepareWebValue(params.value, &web_value); |
560 PrepareWebValueAndBlobInfo(params.value, &web_value, &web_blob_info); | |
561 if (params.value.primary_key.IsValid()) { | 618 if (params.value.primary_key.IsValid()) { |
562 callbacks->onSuccess(web_value, web_blob_info, | 619 web_value.primaryKey = WebIDBKeyBuilder::Build(params.value.primary_key); |
563 WebIDBKeyBuilder::Build(params.value.primary_key), | 620 web_value.keyPath = WebIDBKeyPathBuilder::Build(params.value.key_path); |
564 WebIDBKeyPathBuilder::Build(params.value.key_path)); | |
565 } else { | |
566 callbacks->onSuccess(web_value, web_blob_info); | |
567 cursor_transaction_ids_.erase(params.ipc_callbacks_id); | |
568 } | 621 } |
| 622 callbacks->onSuccess(web_value); |
| 623 cursor_transaction_ids_.erase(params.ipc_callbacks_id); |
569 pending_callbacks_.Remove(params.ipc_callbacks_id); | 624 pending_callbacks_.Remove(params.ipc_callbacks_id); |
570 } | 625 } |
571 | 626 |
572 void IndexedDBDispatcher::OnSuccessInteger(int32 ipc_thread_id, | 627 void IndexedDBDispatcher::OnSuccessInteger(int32 ipc_thread_id, |
573 int32 ipc_callbacks_id, | 628 int32 ipc_callbacks_id, |
574 int64 value) { | 629 int64 value) { |
575 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | 630 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); |
576 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | 631 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); |
577 if (!callbacks) | 632 if (!callbacks) |
578 return; | 633 return; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 typedef std::map<int32, WebIDBCursorImpl*>::iterator Iterator; | 828 typedef std::map<int32, WebIDBCursorImpl*>::iterator Iterator; |
774 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { | 829 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { |
775 if (i->first == ipc_exception_cursor_id || | 830 if (i->first == ipc_exception_cursor_id || |
776 i->second->transaction_id() != transaction_id) | 831 i->second->transaction_id() != transaction_id) |
777 continue; | 832 continue; |
778 i->second->ResetPrefetchCache(); | 833 i->second->ResetPrefetchCache(); |
779 } | 834 } |
780 } | 835 } |
781 | 836 |
782 } // namespace content | 837 } // namespace content |
OLD | NEW |