Chromium Code Reviews| 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" |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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( | |
|
jsbell
2014/04/17 18:37:59
It seems like it would be nice to propagate the In
ericu
2014/04/17 21:56:02
Agreed; will add a TODO to my notes.
| |
| 524 WebData* web_value, | |
| 525 const std::string& value, | |
| 526 const std::vector<IndexedDBMsg_BlobOrFileInfo>& blob_info, | |
| 527 blink::WebVector<WebBlobInfo>* web_blob_info) { | |
|
jsbell
2014/04/17 18:37:59
Parameter order here looks odd - web_value, value,
ericu
2014/04/17 21:56:02
Huh. Yeah, that's terrible. Fixed to value, blob
| |
| 528 | |
| 529 if (!value.empty()) { | |
|
jsbell
2014/04/17 18:37:59
Make this an early exit, to reduce indentation?
ericu
2014/04/17 21:56:02
Done.
| |
| 530 web_value->assign(&*value.begin(), value.size()); | |
| 531 blink::WebVector<WebBlobInfo> local_blob_info(blob_info.size()); | |
| 532 for (size_t i = 0; i < blob_info.size(); ++i) { | |
| 533 const IndexedDBMsg_BlobOrFileInfo& info = blob_info[i]; | |
| 534 if (info.is_file) { | |
| 535 local_blob_info[i] = WebBlobInfo(WebString::fromUTF8(info.uuid.c_str()), | |
| 536 info.file_path, | |
| 537 info.file_name, | |
| 538 info.mime_type, | |
| 539 info.last_modified, | |
| 540 info.size); | |
| 541 } else { | |
| 542 local_blob_info[i] = WebBlobInfo( | |
| 543 WebString::fromUTF8(info.uuid.c_str()), info.mime_type, info.size); | |
| 544 } | |
| 545 } | |
| 546 web_blob_info->swap(local_blob_info); | |
| 547 } | |
| 548 } | |
| 549 | |
| 523 void IndexedDBDispatcher::OnSuccessValue( | 550 void IndexedDBDispatcher::OnSuccessValue( |
| 524 const IndexedDBMsg_CallbacksSuccessValue_Params& p) { | 551 const IndexedDBMsg_CallbacksSuccessValue_Params& params) { |
| 525 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); | 552 DCHECK_EQ(params.ipc_thread_id, CurrentWorkerId()); |
| 526 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(p.ipc_callbacks_id); | 553 WebIDBCallbacks* callbacks = |
| 554 pending_callbacks_.Lookup(params.ipc_callbacks_id); | |
| 527 if (!callbacks) | 555 if (!callbacks) |
| 528 return; | 556 return; |
| 529 WebData web_value; | 557 WebData web_value; |
| 530 if (!p.value.empty()) | 558 WebVector<WebBlobInfo> web_blob_info; |
| 531 web_value.assign(&*p.value.begin(), p.value.size()); | 559 PrepareWebValueAndBlobInfo( |
| 532 callbacks->onSuccess(web_value); | 560 &web_value, params.value, params.blob_or_file_info, &web_blob_info); |
| 533 pending_callbacks_.Remove(p.ipc_callbacks_id); | 561 callbacks->onSuccess(web_value, web_blob_info); |
| 534 cursor_transaction_ids_.erase(p.ipc_callbacks_id); | 562 pending_callbacks_.Remove(params.ipc_callbacks_id); |
| 563 cursor_transaction_ids_.erase(params.ipc_callbacks_id); | |
| 535 } | 564 } |
| 536 | 565 |
| 537 void IndexedDBDispatcher::OnSuccessValueWithKey( | 566 void IndexedDBDispatcher::OnSuccessValueWithKey( |
| 538 const IndexedDBMsg_CallbacksSuccessValueWithKey_Params& p) { | 567 const IndexedDBMsg_CallbacksSuccessValueWithKey_Params& params) { |
| 539 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); | 568 DCHECK_EQ(params.ipc_thread_id, CurrentWorkerId()); |
| 540 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(p.ipc_callbacks_id); | 569 WebIDBCallbacks* callbacks = |
| 570 pending_callbacks_.Lookup(params.ipc_callbacks_id); | |
| 541 if (!callbacks) | 571 if (!callbacks) |
| 542 return; | 572 return; |
| 543 WebData web_value; | 573 WebData web_value; |
| 544 if (p.value.size()) | 574 WebVector<WebBlobInfo> web_blob_info; |
| 545 web_value.assign(&*p.value.begin(), p.value.size()); | 575 PrepareWebValueAndBlobInfo( |
| 576 &web_value, params.value, params.blob_or_file_info, &web_blob_info); | |
| 546 callbacks->onSuccess(web_value, | 577 callbacks->onSuccess(web_value, |
| 547 WebIDBKeyBuilder::Build(p.primary_key), | 578 web_blob_info, |
| 548 WebIDBKeyPathBuilder::Build(p.key_path)); | 579 WebIDBKeyBuilder::Build(params.primary_key), |
| 549 pending_callbacks_.Remove(p.ipc_callbacks_id); | 580 WebIDBKeyPathBuilder::Build(params.key_path)); |
| 581 pending_callbacks_.Remove(params.ipc_callbacks_id); | |
| 550 } | 582 } |
| 551 | 583 |
| 552 void IndexedDBDispatcher::OnSuccessInteger(int32 ipc_thread_id, | 584 void IndexedDBDispatcher::OnSuccessInteger(int32 ipc_thread_id, |
| 553 int32 ipc_callbacks_id, | 585 int32 ipc_callbacks_id, |
| 554 int64 value) { | 586 int64 value) { |
| 555 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); | 587 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); |
| 556 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | 588 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); |
| 557 if (!callbacks) | 589 if (!callbacks) |
| 558 return; | 590 return; |
| 559 callbacks->onSuccess(value); | 591 callbacks->onSuccess(value); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 571 } | 603 } |
| 572 | 604 |
| 573 void IndexedDBDispatcher::OnSuccessOpenCursor( | 605 void IndexedDBDispatcher::OnSuccessOpenCursor( |
| 574 const IndexedDBMsg_CallbacksSuccessIDBCursor_Params& p) { | 606 const IndexedDBMsg_CallbacksSuccessIDBCursor_Params& p) { |
| 575 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); | 607 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); |
| 576 int32 ipc_callbacks_id = p.ipc_callbacks_id; | 608 int32 ipc_callbacks_id = p.ipc_callbacks_id; |
| 577 int32 ipc_object_id = p.ipc_cursor_id; | 609 int32 ipc_object_id = p.ipc_cursor_id; |
| 578 const IndexedDBKey& key = p.key; | 610 const IndexedDBKey& key = p.key; |
| 579 const IndexedDBKey& primary_key = p.primary_key; | 611 const IndexedDBKey& primary_key = p.primary_key; |
| 580 WebData web_value; | 612 WebData web_value; |
| 581 if (p.value.size()) | 613 WebVector<WebBlobInfo> web_blob_info; |
| 582 web_value.assign(&*p.value.begin(), p.value.size()); | 614 PrepareWebValueAndBlobInfo( |
| 615 &web_value, p.value, p.blob_or_file_info, &web_blob_info); | |
| 583 | 616 |
| 584 DCHECK(cursor_transaction_ids_.find(ipc_callbacks_id) != | 617 DCHECK(cursor_transaction_ids_.find(ipc_callbacks_id) != |
| 585 cursor_transaction_ids_.end()); | 618 cursor_transaction_ids_.end()); |
| 586 int64 transaction_id = cursor_transaction_ids_[ipc_callbacks_id]; | 619 int64 transaction_id = cursor_transaction_ids_[ipc_callbacks_id]; |
| 587 cursor_transaction_ids_.erase(ipc_callbacks_id); | 620 cursor_transaction_ids_.erase(ipc_callbacks_id); |
| 588 | 621 |
| 589 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | 622 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); |
| 590 if (!callbacks) | 623 if (!callbacks) |
| 591 return; | 624 return; |
| 592 | 625 |
| 593 WebIDBCursorImpl* cursor = new WebIDBCursorImpl( | 626 WebIDBCursorImpl* cursor = new WebIDBCursorImpl( |
| 594 ipc_object_id, transaction_id, thread_safe_sender_.get()); | 627 ipc_object_id, transaction_id, thread_safe_sender_.get()); |
| 595 cursors_[ipc_object_id] = cursor; | 628 cursors_[ipc_object_id] = cursor; |
| 596 callbacks->onSuccess(cursor, WebIDBKeyBuilder::Build(key), | 629 callbacks->onSuccess(cursor, |
| 597 WebIDBKeyBuilder::Build(primary_key), web_value); | 630 WebIDBKeyBuilder::Build(key), |
| 631 WebIDBKeyBuilder::Build(primary_key), | |
| 632 web_value, | |
| 633 web_blob_info); | |
| 598 | 634 |
| 599 pending_callbacks_.Remove(ipc_callbacks_id); | 635 pending_callbacks_.Remove(ipc_callbacks_id); |
| 600 } | 636 } |
| 601 | 637 |
| 602 void IndexedDBDispatcher::OnSuccessCursorContinue( | 638 void IndexedDBDispatcher::OnSuccessCursorContinue( |
| 603 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p) { | 639 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p) { |
| 604 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); | 640 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); |
| 605 int32 ipc_callbacks_id = p.ipc_callbacks_id; | 641 int32 ipc_callbacks_id = p.ipc_callbacks_id; |
| 606 int32 ipc_cursor_id = p.ipc_cursor_id; | 642 int32 ipc_cursor_id = p.ipc_cursor_id; |
| 607 const IndexedDBKey& key = p.key; | 643 const IndexedDBKey& key = p.key; |
| 608 const IndexedDBKey& primary_key = p.primary_key; | 644 const IndexedDBKey& primary_key = p.primary_key; |
| 609 const std::string& value = p.value; | 645 const std::string& value = p.value; |
| 610 | 646 |
| 611 WebIDBCursorImpl* cursor = cursors_[ipc_cursor_id]; | 647 WebIDBCursorImpl* cursor = cursors_[ipc_cursor_id]; |
| 612 DCHECK(cursor); | 648 DCHECK(cursor); |
| 613 | 649 |
| 614 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | 650 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); |
| 615 if (!callbacks) | 651 if (!callbacks) |
| 616 return; | 652 return; |
| 617 | 653 |
| 618 WebData web_value; | 654 WebData web_value; |
| 619 if (value.size()) | 655 WebVector<WebBlobInfo> web_blob_info; |
| 620 web_value.assign(&*value.begin(), value.size()); | 656 PrepareWebValueAndBlobInfo( |
| 657 &web_value, value, p.blob_or_file_info, &web_blob_info); | |
| 621 callbacks->onSuccess(WebIDBKeyBuilder::Build(key), | 658 callbacks->onSuccess(WebIDBKeyBuilder::Build(key), |
| 622 WebIDBKeyBuilder::Build(primary_key), web_value); | 659 WebIDBKeyBuilder::Build(primary_key), |
| 660 web_value, | |
| 661 web_blob_info); | |
| 623 | 662 |
| 624 pending_callbacks_.Remove(ipc_callbacks_id); | 663 pending_callbacks_.Remove(ipc_callbacks_id); |
| 625 } | 664 } |
| 626 | 665 |
| 627 void IndexedDBDispatcher::OnSuccessCursorPrefetch( | 666 void IndexedDBDispatcher::OnSuccessCursorPrefetch( |
| 628 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p) { | 667 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p) { |
| 629 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); | 668 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); |
| 630 int32 ipc_callbacks_id = p.ipc_callbacks_id; | 669 int32 ipc_callbacks_id = p.ipc_callbacks_id; |
| 631 int32 ipc_cursor_id = p.ipc_cursor_id; | 670 int32 ipc_cursor_id = p.ipc_cursor_id; |
| 632 const std::vector<IndexedDBKey>& keys = p.keys; | 671 const std::vector<IndexedDBKey>& keys = p.keys; |
| 633 const std::vector<IndexedDBKey>& primary_keys = p.primary_keys; | 672 const std::vector<IndexedDBKey>& primary_keys = p.primary_keys; |
| 634 std::vector<WebData> values(p.values.size()); | 673 std::vector<WebData> values(p.values.size()); |
| 674 DCHECK_EQ(p.values.size(), p.blob_or_file_infos.size()); | |
|
jsbell
2014/04/17 18:37:59
Bleah - sending same-sized vectors through is an a
ericu
2014/04/17 21:56:02
Added a TODO to indexed_db_messages.h for this mes
| |
| 675 std::vector<WebVector<WebBlobInfo> > blob_infos(p.blob_or_file_infos.size()); | |
| 635 for (size_t i = 0; i < p.values.size(); ++i) { | 676 for (size_t i = 0; i < p.values.size(); ++i) { |
| 636 if (p.values[i].size()) | 677 PrepareWebValueAndBlobInfo( |
| 637 values[i].assign(&*p.values[i].begin(), p.values[i].size()); | 678 &values[i], p.values[i], p.blob_or_file_infos[i], &blob_infos[i]); |
| 638 } | 679 } |
| 639 WebIDBCursorImpl* cursor = cursors_[ipc_cursor_id]; | 680 WebIDBCursorImpl* cursor = cursors_[ipc_cursor_id]; |
| 640 DCHECK(cursor); | 681 DCHECK(cursor); |
| 641 cursor->SetPrefetchData(keys, primary_keys, values); | 682 cursor->SetPrefetchData(keys, primary_keys, values, blob_infos); |
| 642 | 683 |
| 643 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); | 684 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); |
| 644 DCHECK(callbacks); | 685 DCHECK(callbacks); |
| 645 cursor->CachedContinue(callbacks); | 686 cursor->CachedContinue(callbacks); |
| 646 pending_callbacks_.Remove(ipc_callbacks_id); | 687 pending_callbacks_.Remove(ipc_callbacks_id); |
| 647 } | 688 } |
| 648 | 689 |
| 649 void IndexedDBDispatcher::OnIntBlocked(int32 ipc_thread_id, | 690 void IndexedDBDispatcher::OnIntBlocked(int32 ipc_thread_id, |
| 650 int32 ipc_callbacks_id, | 691 int32 ipc_callbacks_id, |
| 651 int64 existing_version) { | 692 int64 existing_version) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 typedef std::map<int32, WebIDBCursorImpl*>::iterator Iterator; | 788 typedef std::map<int32, WebIDBCursorImpl*>::iterator Iterator; |
| 748 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { | 789 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { |
| 749 if (i->first == ipc_exception_cursor_id || | 790 if (i->first == ipc_exception_cursor_id || |
| 750 i->second->transaction_id() != transaction_id) | 791 i->second->transaction_id() != transaction_id) |
| 751 continue; | 792 continue; |
| 752 i->second->ResetPrefetchCache(); | 793 i->second->ResetPrefetchCache(); |
| 753 } | 794 } |
| 754 } | 795 } |
| 755 | 796 |
| 756 } // namespace content | 797 } // namespace content |
| OLD | NEW |