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/modules/indexeddb/WebIDBDatabaseCal
lbacks.h" | 20 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseCal
lbacks.h" |
21 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseErr
or.h" | 21 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseErr
or.h" |
22 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc
eption.h" | 22 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc
eption.h" |
| 23 #include "third_party/WebKit/public/platform/modules/indexeddb/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 |
43 IndexedDBDispatcher* const kHasBeenDeleted = | 45 IndexedDBDispatcher* const kHasBeenDeleted = |
44 reinterpret_cast<IndexedDBDispatcher*>(0x1); | 46 reinterpret_cast<IndexedDBDispatcher*>(0x1); |
45 | 47 |
46 } // unnamed namespace | 48 } // unnamed namespace |
47 | 49 |
48 const size_t kMaxIDBMessageOverhead = 1024 * 1024; // 1MB; arbitrarily chosen. | |
49 const size_t kMaxIDBValueSizeInBytes = | 50 const size_t kMaxIDBValueSizeInBytes = |
50 IPC::Channel::kMaximumMessageSize - kMaxIDBMessageOverhead; | 51 IPC::Channel::kMaximumMessageSize - kMaxIDBMessageOverhead; |
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) { |
54 g_idb_dispatcher_tls.Pointer()->Set(this); | 55 g_idb_dispatcher_tls.Pointer()->Set(this); |
55 } | 56 } |
56 | 57 |
57 IndexedDBDispatcher::~IndexedDBDispatcher() { | 58 IndexedDBDispatcher::~IndexedDBDispatcher() { |
58 // Clear any pending callbacks - which may result in dispatch requests - | 59 // Clear any pending callbacks - which may result in dispatch requests - |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorContinue, | 137 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorContinue, |
137 OnSuccessCursorContinue) | 138 OnSuccessCursorContinue) |
138 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorPrefetch, | 139 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorPrefetch, |
139 OnSuccessCursorPrefetch) | 140 OnSuccessCursorPrefetch) |
140 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBDatabase, | 141 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBDatabase, |
141 OnSuccessIDBDatabase) | 142 OnSuccessIDBDatabase) |
142 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIndexedDBKey, | 143 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIndexedDBKey, |
143 OnSuccessIndexedDBKey) | 144 OnSuccessIndexedDBKey) |
144 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessStringList, | 145 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessStringList, |
145 OnSuccessStringList) | 146 OnSuccessStringList) |
| 147 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessArray, OnSuccessArray) |
146 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessValue, OnSuccessValue) | 148 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessValue, OnSuccessValue) |
147 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessInteger, OnSuccessInteger) | 149 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessInteger, OnSuccessInteger) |
148 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessUndefined, | 150 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessUndefined, |
149 OnSuccessUndefined) | 151 OnSuccessUndefined) |
150 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError) | 152 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError) |
151 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksIntBlocked, OnIntBlocked) | 153 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksIntBlocked, OnIntBlocked) |
152 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksUpgradeNeeded, OnUpgradeNeeded) | 154 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksUpgradeNeeded, OnUpgradeNeeded) |
153 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksForcedClose, | 155 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksForcedClose, |
154 OnForcedClose) | 156 OnForcedClose) |
155 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksIntVersionChange, | 157 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksIntVersionChange, |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 init_params(¶ms, callbacks); | 318 init_params(¶ms, callbacks); |
317 params.ipc_database_id = ipc_database_id; | 319 params.ipc_database_id = ipc_database_id; |
318 params.transaction_id = transaction_id; | 320 params.transaction_id = transaction_id; |
319 params.object_store_id = object_store_id; | 321 params.object_store_id = object_store_id; |
320 params.index_id = index_id; | 322 params.index_id = index_id; |
321 params.key_range = key_range; | 323 params.key_range = key_range; |
322 params.key_only = key_only; | 324 params.key_only = key_only; |
323 Send(new IndexedDBHostMsg_DatabaseGet(params)); | 325 Send(new IndexedDBHostMsg_DatabaseGet(params)); |
324 } | 326 } |
325 | 327 |
| 328 void IndexedDBDispatcher::RequestIDBDatabaseGetAll( |
| 329 int32 ipc_database_id, |
| 330 int64 transaction_id, |
| 331 int64 object_store_id, |
| 332 const IndexedDBKeyRange& key_range, |
| 333 int64 max_count, |
| 334 WebIDBCallbacks* callbacks) { |
| 335 ResetCursorPrefetchCaches(transaction_id, kAllCursors); |
| 336 IndexedDBHostMsg_DatabaseGetAll_Params params; |
| 337 init_params(¶ms, callbacks); |
| 338 params.ipc_database_id = ipc_database_id; |
| 339 params.transaction_id = transaction_id; |
| 340 params.object_store_id = object_store_id; |
| 341 params.key_range = key_range; |
| 342 params.max_count = max_count; |
| 343 Send(new IndexedDBHostMsg_DatabaseGetAll(params)); |
| 344 } |
| 345 |
326 void IndexedDBDispatcher::RequestIDBDatabasePut( | 346 void IndexedDBDispatcher::RequestIDBDatabasePut( |
327 int32 ipc_database_id, | 347 int32 ipc_database_id, |
328 int64 transaction_id, | 348 int64 transaction_id, |
329 int64 object_store_id, | 349 int64 object_store_id, |
330 const WebData& value, | 350 const WebData& value, |
331 const blink::WebVector<WebBlobInfo>& web_blob_info, | 351 const blink::WebVector<WebBlobInfo>& web_blob_info, |
332 const IndexedDBKey& key, | 352 const IndexedDBKey& key, |
333 blink::WebIDBPutMode put_mode, | 353 blink::WebIDBPutMode put_mode, |
334 WebIDBCallbacks* callbacks, | 354 WebIDBCallbacks* callbacks, |
335 const WebVector<long long>& index_ids, | 355 const WebVector<long long>& index_ids, |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 int32 ipc_callbacks_id, | 535 int32 ipc_callbacks_id, |
516 const std::vector<base::string16>& value) { | 536 const std::vector<base::string16>& value) { |
517 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | 537 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); |
518 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | 538 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); |
519 if (!callbacks) | 539 if (!callbacks) |
520 return; | 540 return; |
521 callbacks->onSuccess(WebVector<WebString>(value)); | 541 callbacks->onSuccess(WebVector<WebString>(value)); |
522 pending_callbacks_.Remove(ipc_callbacks_id); | 542 pending_callbacks_.Remove(ipc_callbacks_id); |
523 } | 543 } |
524 | 544 |
| 545 static void PrepareWebValue(const IndexedDBMsg_ReturnValue& value, |
| 546 WebIDBValue* web_value) { |
| 547 if (value.bits.empty()) |
| 548 return; |
| 549 |
| 550 web_value->data.assign(&*value.bits.begin(), value.bits.size()); |
| 551 blink::WebVector<WebBlobInfo> local_blob_info(value.blob_or_file_info.size()); |
| 552 for (size_t i = 0; i < value.blob_or_file_info.size(); ++i) { |
| 553 const IndexedDBMsg_BlobOrFileInfo& info = value.blob_or_file_info[i]; |
| 554 if (info.is_file) { |
| 555 local_blob_info[i] = WebBlobInfo( |
| 556 WebString::fromUTF8(info.uuid.c_str()), info.file_path, |
| 557 info.file_name, info.mime_type, info.last_modified, info.size); |
| 558 } else { |
| 559 local_blob_info[i] = WebBlobInfo(WebString::fromUTF8(info.uuid.c_str()), |
| 560 info.mime_type, info.size); |
| 561 } |
| 562 } |
| 563 |
| 564 web_value->webBlobInfo.swap(local_blob_info); |
| 565 web_value->primaryKey = WebIDBKeyBuilder::Build(value.primary_key); |
| 566 web_value->keyPath = WebIDBKeyPathBuilder::Build(value.key_path); |
| 567 } |
| 568 |
525 static void PrepareWebValueAndBlobInfo( | 569 static void PrepareWebValueAndBlobInfo( |
526 const IndexedDBMsg_Value& value, | 570 const IndexedDBMsg_Value& value, |
527 WebData* web_value, | 571 WebData* web_value, |
528 blink::WebVector<WebBlobInfo>* web_blob_info) { | 572 blink::WebVector<WebBlobInfo>* web_blob_info) { |
529 if (value.bits.empty()) | 573 if (value.bits.empty()) |
530 return; | 574 return; |
531 | 575 |
532 web_value->assign(&*value.bits.begin(), value.bits.size()); | 576 web_value->assign(&*value.bits.begin(), value.bits.size()); |
533 blink::WebVector<WebBlobInfo> local_blob_info(value.blob_or_file_info.size()); | 577 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) { | 578 for (size_t i = 0; i < value.blob_or_file_info.size(); ++i) { |
535 const IndexedDBMsg_BlobOrFileInfo& info = value.blob_or_file_info[i]; | 579 const IndexedDBMsg_BlobOrFileInfo& info = value.blob_or_file_info[i]; |
536 if (info.is_file) { | 580 if (info.is_file) { |
537 local_blob_info[i] = WebBlobInfo(WebString::fromUTF8(info.uuid.c_str()), | 581 local_blob_info[i] = WebBlobInfo(WebString::fromUTF8(info.uuid.c_str()), |
538 info.file_path, | 582 info.file_path, |
539 info.file_name, | 583 info.file_name, |
540 info.mime_type, | 584 info.mime_type, |
541 info.last_modified, | 585 info.last_modified, |
542 info.size); | 586 info.size); |
543 } else { | 587 } else { |
544 local_blob_info[i] = WebBlobInfo( | 588 local_blob_info[i] = WebBlobInfo( |
545 WebString::fromUTF8(info.uuid.c_str()), info.mime_type, info.size); | 589 WebString::fromUTF8(info.uuid.c_str()), info.mime_type, info.size); |
546 } | 590 } |
547 } | 591 } |
548 web_blob_info->swap(local_blob_info); | 592 web_blob_info->swap(local_blob_info); |
549 } | 593 } |
550 | 594 |
| 595 void IndexedDBDispatcher::OnSuccessArray( |
| 596 const IndexedDBMsg_CallbacksSuccessArray_Params& p) { |
| 597 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); |
| 598 int32 ipc_callbacks_id = p.ipc_callbacks_id; |
| 599 blink::WebVector<WebIDBValue> web_values(p.values.size()); |
| 600 for (size_t i = 0; i < p.values.size(); ++i) |
| 601 PrepareWebValue(p.values[i], &web_values[i]); |
| 602 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); |
| 603 DCHECK(callbacks); |
| 604 callbacks->onSuccess(web_values); |
| 605 pending_callbacks_.Remove(ipc_callbacks_id); |
| 606 } |
| 607 |
551 void IndexedDBDispatcher::OnSuccessValue( | 608 void IndexedDBDispatcher::OnSuccessValue( |
552 const IndexedDBMsg_CallbacksSuccessValue_Params& params) { | 609 const IndexedDBMsg_CallbacksSuccessValue_Params& params) { |
553 DCHECK_EQ(params.ipc_thread_id, CurrentWorkerId()); | 610 DCHECK_EQ(params.ipc_thread_id, CurrentWorkerId()); |
554 WebIDBCallbacks* callbacks = | 611 WebIDBCallbacks* callbacks = |
555 pending_callbacks_.Lookup(params.ipc_callbacks_id); | 612 pending_callbacks_.Lookup(params.ipc_callbacks_id); |
556 if (!callbacks) | 613 if (!callbacks) |
557 return; | 614 return; |
558 WebData web_value; | 615 WebIDBValue web_value; |
559 WebVector<WebBlobInfo> web_blob_info; | 616 PrepareWebValue(params.value, &web_value); |
560 PrepareWebValueAndBlobInfo(params.value, &web_value, &web_blob_info); | |
561 if (params.value.primary_key.IsValid()) { | 617 if (params.value.primary_key.IsValid()) { |
562 callbacks->onSuccess(web_value, web_blob_info, | 618 web_value.primaryKey = WebIDBKeyBuilder::Build(params.value.primary_key); |
563 WebIDBKeyBuilder::Build(params.value.primary_key), | 619 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 } | 620 } |
| 621 callbacks->onSuccess(web_value); |
| 622 cursor_transaction_ids_.erase(params.ipc_callbacks_id); |
569 pending_callbacks_.Remove(params.ipc_callbacks_id); | 623 pending_callbacks_.Remove(params.ipc_callbacks_id); |
570 } | 624 } |
571 | 625 |
572 void IndexedDBDispatcher::OnSuccessInteger(int32 ipc_thread_id, | 626 void IndexedDBDispatcher::OnSuccessInteger(int32 ipc_thread_id, |
573 int32 ipc_callbacks_id, | 627 int32 ipc_callbacks_id, |
574 int64 value) { | 628 int64 value) { |
575 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | 629 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); |
576 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | 630 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); |
577 if (!callbacks) | 631 if (!callbacks) |
578 return; | 632 return; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 typedef std::map<int32, WebIDBCursorImpl*>::iterator Iterator; | 827 typedef std::map<int32, WebIDBCursorImpl*>::iterator Iterator; |
774 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { | 828 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { |
775 if (i->first == ipc_exception_cursor_id || | 829 if (i->first == ipc_exception_cursor_id || |
776 i->second->transaction_id() != transaction_id) | 830 i->second->transaction_id() != transaction_id) |
777 continue; | 831 continue; |
778 i->second->ResetPrefetchCache(); | 832 i->second->ResetPrefetchCache(); |
779 } | 833 } |
780 } | 834 } |
781 | 835 |
782 } // namespace content | 836 } // namespace content |
OLD | NEW |