Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: content/child/indexed_db/indexed_db_dispatcher.cc

Issue 1074493002: IndexedDB: Added IDBObjectStore.getAll() implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_CallbacksSuccessValueWithKey, 150 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessValueWithKey,
148 OnSuccessValueWithKey) 151 OnSuccessValueWithKey)
149 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessInteger, OnSuccessInteger) 152 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessInteger, OnSuccessInteger)
150 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessUndefined, 153 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessUndefined,
151 OnSuccessUndefined) 154 OnSuccessUndefined)
152 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError) 155 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError)
153 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksIntBlocked, OnIntBlocked) 156 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksIntBlocked, OnIntBlocked)
154 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksUpgradeNeeded, OnUpgradeNeeded) 157 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksUpgradeNeeded, OnUpgradeNeeded)
155 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksForcedClose, 158 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksForcedClose,
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 init_params(&params, callbacks); 321 init_params(&params, callbacks);
319 params.ipc_database_id = ipc_database_id; 322 params.ipc_database_id = ipc_database_id;
320 params.transaction_id = transaction_id; 323 params.transaction_id = transaction_id;
321 params.object_store_id = object_store_id; 324 params.object_store_id = object_store_id;
322 params.index_id = index_id; 325 params.index_id = index_id;
323 params.key_range = key_range; 326 params.key_range = key_range;
324 params.key_only = key_only; 327 params.key_only = key_only;
325 Send(new IndexedDBHostMsg_DatabaseGet(params)); 328 Send(new IndexedDBHostMsg_DatabaseGet(params));
326 } 329 }
327 330
331 void IndexedDBDispatcher::RequestIDBDatabaseGetAll(
332 int32 ipc_database_id,
333 int64 transaction_id,
334 int64 object_store_id,
335 const IndexedDBKeyRange& key_range,
336 int64 max_count,
337 WebIDBCallbacks* callbacks) {
338 ResetCursorPrefetchCaches(transaction_id, kAllCursors);
339 IndexedDBHostMsg_DatabaseGetAll_Params params;
340 init_params(&params, callbacks);
341 params.ipc_database_id = ipc_database_id;
342 params.transaction_id = transaction_id;
343 params.object_store_id = object_store_id;
344 params.key_range = key_range;
345 params.max_count = max_count;
346 Send(new IndexedDBHostMsg_DatabaseGetAll(params));
347 }
348
328 void IndexedDBDispatcher::RequestIDBDatabasePut( 349 void IndexedDBDispatcher::RequestIDBDatabasePut(
329 int32 ipc_database_id, 350 int32 ipc_database_id,
330 int64 transaction_id, 351 int64 transaction_id,
331 int64 object_store_id, 352 int64 object_store_id,
332 const WebData& value, 353 const WebData& value,
333 const blink::WebVector<WebBlobInfo>& web_blob_info, 354 const blink::WebVector<WebBlobInfo>& web_blob_info,
334 const IndexedDBKey& key, 355 const IndexedDBKey& key,
335 blink::WebIDBPutMode put_mode, 356 blink::WebIDBPutMode put_mode,
336 WebIDBCallbacks* callbacks, 357 WebIDBCallbacks* callbacks,
337 const WebVector<long long>& index_ids, 358 const WebVector<long long>& index_ids,
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 int32 ipc_callbacks_id, 538 int32 ipc_callbacks_id,
518 const std::vector<base::string16>& value) { 539 const std::vector<base::string16>& value) {
519 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); 540 DCHECK_EQ(ipc_thread_id, CurrentWorkerId());
520 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); 541 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
521 if (!callbacks) 542 if (!callbacks)
522 return; 543 return;
523 callbacks->onSuccess(WebVector<WebString>(value)); 544 callbacks->onSuccess(WebVector<WebString>(value));
524 pending_callbacks_.Remove(ipc_callbacks_id); 545 pending_callbacks_.Remove(ipc_callbacks_id);
525 } 546 }
526 547
548 static void PrepareWebValue(const IndexedDBMsg_Value& value,
549 WebIDBValue* web_value) {
550 if (value.bits.empty())
551 return;
552
553 web_value->data.assign(&*value.bits.begin(), value.bits.size());
554 blink::WebVector<WebBlobInfo> local_blob_info(value.blob_or_file_info.size());
555 for (size_t i = 0; i < value.blob_or_file_info.size(); ++i) {
556 const IndexedDBMsg_BlobOrFileInfo& info = value.blob_or_file_info[i];
557 if (info.is_file) {
558 local_blob_info[i] = WebBlobInfo(
559 WebString::fromUTF8(info.uuid.c_str()), info.file_path,
560 info.file_name, info.mime_type, info.last_modified, info.size);
561 } else {
562 local_blob_info[i] = WebBlobInfo(WebString::fromUTF8(info.uuid.c_str()),
563 info.mime_type, info.size);
564 }
565 }
566 web_value->webBlobInfo.swap(local_blob_info);
567 }
568
527 static void PrepareWebValueAndBlobInfo( 569 static void PrepareWebValueAndBlobInfo(
528 const IndexedDBMsg_Value& value, 570 const IndexedDBMsg_Value& value,
529 WebData* web_value, 571 WebData* web_value,
530 blink::WebVector<WebBlobInfo>* web_blob_info) { 572 blink::WebVector<WebBlobInfo>* web_blob_info) {
531 if (value.bits.empty()) 573 if (value.bits.empty())
532 return; 574 return;
533 575
534 web_value->assign(&*value.bits.begin(), value.bits.size()); 576 web_value->assign(&*value.bits.begin(), value.bits.size());
535 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());
536 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) {
537 const IndexedDBMsg_BlobOrFileInfo& info = value.blob_or_file_info[i]; 579 const IndexedDBMsg_BlobOrFileInfo& info = value.blob_or_file_info[i];
538 if (info.is_file) { 580 if (info.is_file) {
539 local_blob_info[i] = WebBlobInfo(WebString::fromUTF8(info.uuid.c_str()), 581 local_blob_info[i] = WebBlobInfo(WebString::fromUTF8(info.uuid.c_str()),
540 info.file_path, 582 info.file_path,
541 info.file_name, 583 info.file_name,
542 info.mime_type, 584 info.mime_type,
543 info.last_modified, 585 info.last_modified,
544 info.size); 586 info.size);
545 } else { 587 } else {
546 local_blob_info[i] = WebBlobInfo( 588 local_blob_info[i] = WebBlobInfo(
547 WebString::fromUTF8(info.uuid.c_str()), info.mime_type, info.size); 589 WebString::fromUTF8(info.uuid.c_str()), info.mime_type, info.size);
548 } 590 }
549 } 591 }
550 web_blob_info->swap(local_blob_info); 592 web_blob_info->swap(local_blob_info);
551 } 593 }
552 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
553 void IndexedDBDispatcher::OnSuccessValue( 608 void IndexedDBDispatcher::OnSuccessValue(
554 const IndexedDBMsg_CallbacksSuccessValue_Params& params) { 609 const IndexedDBMsg_CallbacksSuccessValue_Params& params) {
555 DCHECK_EQ(params.ipc_thread_id, CurrentWorkerId()); 610 DCHECK_EQ(params.ipc_thread_id, CurrentWorkerId());
556 WebIDBCallbacks* callbacks = 611 WebIDBCallbacks* callbacks =
557 pending_callbacks_.Lookup(params.ipc_callbacks_id); 612 pending_callbacks_.Lookup(params.ipc_callbacks_id);
558 if (!callbacks) 613 if (!callbacks)
559 return; 614 return;
560 WebData web_value; 615 WebData web_value;
561 WebVector<WebBlobInfo> web_blob_info; 616 WebVector<WebBlobInfo> web_blob_info;
562 PrepareWebValueAndBlobInfo(params.value, &web_value, &web_blob_info); 617 PrepareWebValueAndBlobInfo(params.value, &web_value, &web_blob_info);
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 typedef std::map<int32, WebIDBCursorImpl*>::iterator Iterator; 841 typedef std::map<int32, WebIDBCursorImpl*>::iterator Iterator;
787 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { 842 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) {
788 if (i->first == ipc_exception_cursor_id || 843 if (i->first == ipc_exception_cursor_id ||
789 i->second->transaction_id() != transaction_id) 844 i->second->transaction_id() != transaction_id)
790 continue; 845 continue;
791 i->second->ResetPrefetchCache(); 846 i->second->ResetPrefetchCache();
792 } 847 }
793 } 848 }
794 849
795 } // namespace content 850 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698