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

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

Issue 240003010: The chromium-side backchannel plumbing for blobs in IDB. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove TODO Created 6 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 | Annotate | Revision Log
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"
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 int32 ipc_callbacks_id, 513 int32 ipc_callbacks_id,
514 const std::vector<base::string16>& value) { 514 const std::vector<base::string16>& value) {
515 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); 515 DCHECK_EQ(ipc_thread_id, CurrentWorkerId());
516 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); 516 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
517 if (!callbacks) 517 if (!callbacks)
518 return; 518 return;
519 callbacks->onSuccess(WebVector<WebString>(value)); 519 callbacks->onSuccess(WebVector<WebString>(value));
520 pending_callbacks_.Remove(ipc_callbacks_id); 520 pending_callbacks_.Remove(ipc_callbacks_id);
521 } 521 }
522 522
523 static void PrepareWebValueAndBlobInfo(
524 const std::string& value,
525 const std::vector<IndexedDBMsg_BlobOrFileInfo>& blob_info,
526 WebData* web_value,
527 blink::WebVector<WebBlobInfo>* web_blob_info) {
528
529 if (value.empty())
530 return;
531
532 web_value->assign(&*value.begin(), value.size());
533 blink::WebVector<WebBlobInfo> local_blob_info(blob_info.size());
cmumford 2014/04/17 22:26:53 Why create a local array and then swap at the end?
ericu 2014/04/17 22:33:11 Outside of the constructor, you can't set the size
534 for (size_t i = 0; i < blob_info.size(); ++i) {
535 const IndexedDBMsg_BlobOrFileInfo& info = blob_info[i];
536 if (info.is_file) {
537 local_blob_info[i] = WebBlobInfo(WebString::fromUTF8(info.uuid.c_str()),
538 info.file_path,
539 info.file_name,
540 info.mime_type,
541 info.last_modified,
542 info.size);
543 } else {
544 local_blob_info[i] = WebBlobInfo(
545 WebString::fromUTF8(info.uuid.c_str()), info.mime_type, info.size);
546 }
547 }
548 web_blob_info->swap(local_blob_info);
549 }
550
523 void IndexedDBDispatcher::OnSuccessValue( 551 void IndexedDBDispatcher::OnSuccessValue(
524 const IndexedDBMsg_CallbacksSuccessValue_Params& p) { 552 const IndexedDBMsg_CallbacksSuccessValue_Params& params) {
525 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); 553 DCHECK_EQ(params.ipc_thread_id, CurrentWorkerId());
526 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(p.ipc_callbacks_id); 554 WebIDBCallbacks* callbacks =
555 pending_callbacks_.Lookup(params.ipc_callbacks_id);
527 if (!callbacks) 556 if (!callbacks)
528 return; 557 return;
529 WebData web_value; 558 WebData web_value;
530 if (!p.value.empty()) 559 WebVector<WebBlobInfo> web_blob_info;
531 web_value.assign(&*p.value.begin(), p.value.size()); 560 PrepareWebValueAndBlobInfo(
532 callbacks->onSuccess(web_value); 561 params.value, params.blob_or_file_info, &web_value, &web_blob_info);
533 pending_callbacks_.Remove(p.ipc_callbacks_id); 562 callbacks->onSuccess(web_value, web_blob_info);
534 cursor_transaction_ids_.erase(p.ipc_callbacks_id); 563 pending_callbacks_.Remove(params.ipc_callbacks_id);
564 cursor_transaction_ids_.erase(params.ipc_callbacks_id);
535 } 565 }
536 566
537 void IndexedDBDispatcher::OnSuccessValueWithKey( 567 void IndexedDBDispatcher::OnSuccessValueWithKey(
538 const IndexedDBMsg_CallbacksSuccessValueWithKey_Params& p) { 568 const IndexedDBMsg_CallbacksSuccessValueWithKey_Params& params) {
539 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); 569 DCHECK_EQ(params.ipc_thread_id, CurrentWorkerId());
540 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(p.ipc_callbacks_id); 570 WebIDBCallbacks* callbacks =
571 pending_callbacks_.Lookup(params.ipc_callbacks_id);
541 if (!callbacks) 572 if (!callbacks)
542 return; 573 return;
543 WebData web_value; 574 WebData web_value;
544 if (p.value.size()) 575 WebVector<WebBlobInfo> web_blob_info;
545 web_value.assign(&*p.value.begin(), p.value.size()); 576 PrepareWebValueAndBlobInfo(
577 params.value, params.blob_or_file_info, &web_value, &web_blob_info);
546 callbacks->onSuccess(web_value, 578 callbacks->onSuccess(web_value,
547 WebIDBKeyBuilder::Build(p.primary_key), 579 web_blob_info,
548 WebIDBKeyPathBuilder::Build(p.key_path)); 580 WebIDBKeyBuilder::Build(params.primary_key),
549 pending_callbacks_.Remove(p.ipc_callbacks_id); 581 WebIDBKeyPathBuilder::Build(params.key_path));
582 pending_callbacks_.Remove(params.ipc_callbacks_id);
550 } 583 }
551 584
552 void IndexedDBDispatcher::OnSuccessInteger(int32 ipc_thread_id, 585 void IndexedDBDispatcher::OnSuccessInteger(int32 ipc_thread_id,
553 int32 ipc_callbacks_id, 586 int32 ipc_callbacks_id,
554 int64 value) { 587 int64 value) {
555 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); 588 DCHECK_EQ(ipc_thread_id, CurrentWorkerId());
556 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); 589 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
557 if (!callbacks) 590 if (!callbacks)
558 return; 591 return;
559 callbacks->onSuccess(value); 592 callbacks->onSuccess(value);
(...skipping 11 matching lines...) Expand all
571 } 604 }
572 605
573 void IndexedDBDispatcher::OnSuccessOpenCursor( 606 void IndexedDBDispatcher::OnSuccessOpenCursor(
574 const IndexedDBMsg_CallbacksSuccessIDBCursor_Params& p) { 607 const IndexedDBMsg_CallbacksSuccessIDBCursor_Params& p) {
575 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); 608 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId());
576 int32 ipc_callbacks_id = p.ipc_callbacks_id; 609 int32 ipc_callbacks_id = p.ipc_callbacks_id;
577 int32 ipc_object_id = p.ipc_cursor_id; 610 int32 ipc_object_id = p.ipc_cursor_id;
578 const IndexedDBKey& key = p.key; 611 const IndexedDBKey& key = p.key;
579 const IndexedDBKey& primary_key = p.primary_key; 612 const IndexedDBKey& primary_key = p.primary_key;
580 WebData web_value; 613 WebData web_value;
581 if (p.value.size()) 614 WebVector<WebBlobInfo> web_blob_info;
582 web_value.assign(&*p.value.begin(), p.value.size()); 615 PrepareWebValueAndBlobInfo(
616 p.value, p.blob_or_file_info, &web_value, &web_blob_info);
583 617
584 DCHECK(cursor_transaction_ids_.find(ipc_callbacks_id) != 618 DCHECK(cursor_transaction_ids_.find(ipc_callbacks_id) !=
585 cursor_transaction_ids_.end()); 619 cursor_transaction_ids_.end());
586 int64 transaction_id = cursor_transaction_ids_[ipc_callbacks_id]; 620 int64 transaction_id = cursor_transaction_ids_[ipc_callbacks_id];
587 cursor_transaction_ids_.erase(ipc_callbacks_id); 621 cursor_transaction_ids_.erase(ipc_callbacks_id);
588 622
589 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); 623 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
590 if (!callbacks) 624 if (!callbacks)
591 return; 625 return;
592 626
593 WebIDBCursorImpl* cursor = new WebIDBCursorImpl( 627 WebIDBCursorImpl* cursor = new WebIDBCursorImpl(
594 ipc_object_id, transaction_id, thread_safe_sender_.get()); 628 ipc_object_id, transaction_id, thread_safe_sender_.get());
595 cursors_[ipc_object_id] = cursor; 629 cursors_[ipc_object_id] = cursor;
596 callbacks->onSuccess(cursor, WebIDBKeyBuilder::Build(key), 630 callbacks->onSuccess(cursor,
597 WebIDBKeyBuilder::Build(primary_key), web_value); 631 WebIDBKeyBuilder::Build(key),
632 WebIDBKeyBuilder::Build(primary_key),
633 web_value,
634 web_blob_info);
598 635
599 pending_callbacks_.Remove(ipc_callbacks_id); 636 pending_callbacks_.Remove(ipc_callbacks_id);
600 } 637 }
601 638
602 void IndexedDBDispatcher::OnSuccessCursorContinue( 639 void IndexedDBDispatcher::OnSuccessCursorContinue(
603 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p) { 640 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p) {
604 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); 641 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId());
605 int32 ipc_callbacks_id = p.ipc_callbacks_id; 642 int32 ipc_callbacks_id = p.ipc_callbacks_id;
606 int32 ipc_cursor_id = p.ipc_cursor_id; 643 int32 ipc_cursor_id = p.ipc_cursor_id;
607 const IndexedDBKey& key = p.key; 644 const IndexedDBKey& key = p.key;
608 const IndexedDBKey& primary_key = p.primary_key; 645 const IndexedDBKey& primary_key = p.primary_key;
609 const std::string& value = p.value; 646 const std::string& value = p.value;
610 647
611 WebIDBCursorImpl* cursor = cursors_[ipc_cursor_id]; 648 WebIDBCursorImpl* cursor = cursors_[ipc_cursor_id];
612 DCHECK(cursor); 649 DCHECK(cursor);
613 650
614 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); 651 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
615 if (!callbacks) 652 if (!callbacks)
616 return; 653 return;
617 654
618 WebData web_value; 655 WebData web_value;
619 if (value.size()) 656 WebVector<WebBlobInfo> web_blob_info;
620 web_value.assign(&*value.begin(), value.size()); 657 PrepareWebValueAndBlobInfo(
658 value, p.blob_or_file_info, &web_value, &web_blob_info);
621 callbacks->onSuccess(WebIDBKeyBuilder::Build(key), 659 callbacks->onSuccess(WebIDBKeyBuilder::Build(key),
622 WebIDBKeyBuilder::Build(primary_key), web_value); 660 WebIDBKeyBuilder::Build(primary_key),
661 web_value,
662 web_blob_info);
623 663
624 pending_callbacks_.Remove(ipc_callbacks_id); 664 pending_callbacks_.Remove(ipc_callbacks_id);
625 } 665 }
626 666
627 void IndexedDBDispatcher::OnSuccessCursorPrefetch( 667 void IndexedDBDispatcher::OnSuccessCursorPrefetch(
628 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p) { 668 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p) {
629 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); 669 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId());
630 int32 ipc_callbacks_id = p.ipc_callbacks_id; 670 int32 ipc_callbacks_id = p.ipc_callbacks_id;
631 int32 ipc_cursor_id = p.ipc_cursor_id; 671 int32 ipc_cursor_id = p.ipc_cursor_id;
632 const std::vector<IndexedDBKey>& keys = p.keys; 672 const std::vector<IndexedDBKey>& keys = p.keys;
633 const std::vector<IndexedDBKey>& primary_keys = p.primary_keys; 673 const std::vector<IndexedDBKey>& primary_keys = p.primary_keys;
634 std::vector<WebData> values(p.values.size()); 674 std::vector<WebData> values(p.values.size());
675 DCHECK_EQ(p.values.size(), p.blob_or_file_infos.size());
676 std::vector<WebVector<WebBlobInfo> > blob_infos(p.blob_or_file_infos.size());
635 for (size_t i = 0; i < p.values.size(); ++i) { 677 for (size_t i = 0; i < p.values.size(); ++i) {
636 if (p.values[i].size()) 678 PrepareWebValueAndBlobInfo(
637 values[i].assign(&*p.values[i].begin(), p.values[i].size()); 679 p.values[i], p.blob_or_file_infos[i], &values[i], &blob_infos[i]);
638 } 680 }
639 WebIDBCursorImpl* cursor = cursors_[ipc_cursor_id]; 681 WebIDBCursorImpl* cursor = cursors_[ipc_cursor_id];
640 DCHECK(cursor); 682 DCHECK(cursor);
641 cursor->SetPrefetchData(keys, primary_keys, values); 683 cursor->SetPrefetchData(keys, primary_keys, values, blob_infos);
642 684
643 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); 685 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
644 DCHECK(callbacks); 686 DCHECK(callbacks);
645 cursor->CachedContinue(callbacks); 687 cursor->CachedContinue(callbacks);
646 pending_callbacks_.Remove(ipc_callbacks_id); 688 pending_callbacks_.Remove(ipc_callbacks_id);
647 } 689 }
648 690
649 void IndexedDBDispatcher::OnIntBlocked(int32 ipc_thread_id, 691 void IndexedDBDispatcher::OnIntBlocked(int32 ipc_thread_id,
650 int32 ipc_callbacks_id, 692 int32 ipc_callbacks_id,
651 int64 existing_version) { 693 int64 existing_version) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 typedef std::map<int32, WebIDBCursorImpl*>::iterator Iterator; 789 typedef std::map<int32, WebIDBCursorImpl*>::iterator Iterator;
748 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { 790 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) {
749 if (i->first == ipc_exception_cursor_id || 791 if (i->first == ipc_exception_cursor_id ||
750 i->second->transaction_id() != transaction_id) 792 i->second->transaction_id() != transaction_id)
751 continue; 793 continue;
752 i->second->ResetPrefetchCache(); 794 i->second->ResetPrefetchCache();
753 } 795 }
754 } 796 }
755 797
756 } // namespace content 798 } // namespace content
OLDNEW
« no previous file with comments | « content/child/indexed_db/indexed_db_dispatcher.h ('k') | content/child/indexed_db/indexed_db_dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698