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

Side by Side Diff: content/browser/indexed_db/indexed_db_dispatcher_host.cc

Issue 2255853003: IndexedDB: ScopedVector<T> -> vector<unique_ptr<T>> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback Created 4 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/indexed_db/indexed_db_dispatcher_host.h" 5 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/guid.h" 12 #include "base/guid.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/memory/scoped_vector.h"
15 #include "base/process/process.h" 14 #include "base/process/process.h"
16 #include "base/stl_util.h" 15 #include "base/stl_util.h"
17 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
18 #include "content/browser/bad_message.h" 17 #include "content/browser/bad_message.h"
19 #include "content/browser/child_process_security_policy_impl.h" 18 #include "content/browser/child_process_security_policy_impl.h"
20 #include "content/browser/indexed_db/indexed_db_callbacks.h" 19 #include "content/browser/indexed_db/indexed_db_callbacks.h"
21 #include "content/browser/indexed_db/indexed_db_connection.h" 20 #include "content/browser/indexed_db/indexed_db_connection.h"
22 #include "content/browser/indexed_db/indexed_db_context_impl.h" 21 #include "content/browser/indexed_db/indexed_db_context_impl.h"
23 #include "content/browser/indexed_db/indexed_db_cursor.h" 22 #include "content/browser/indexed_db/indexed_db_cursor.h"
24 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" 23 #include "content/browser/indexed_db/indexed_db_database_callbacks.h"
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 params.name, request_context_getter_, 371 params.name, request_context_getter_,
373 new IndexedDBCallbacks(this, params.ipc_thread_id, 372 new IndexedDBCallbacks(this, params.ipc_thread_id,
374 params.ipc_callbacks_id), 373 params.ipc_callbacks_id),
375 params.origin, indexed_db_path); 374 params.origin, indexed_db_path);
376 } 375 }
377 376
378 // OnPutHelper exists only to allow us to hop threads while holding a reference 377 // OnPutHelper exists only to allow us to hop threads while holding a reference
379 // to the IndexedDBDispatcherHost. 378 // to the IndexedDBDispatcherHost.
380 void IndexedDBDispatcherHost::OnPutHelper( 379 void IndexedDBDispatcherHost::OnPutHelper(
381 const IndexedDBHostMsg_DatabasePut_Params& params, 380 const IndexedDBHostMsg_DatabasePut_Params& params,
382 std::vector<storage::BlobDataHandle*> handles) { 381 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles) {
383 database_dispatcher_host_->OnPut(params, handles); 382 database_dispatcher_host_->OnPut(params, std::move(handles));
384 } 383 }
385 384
386 void IndexedDBDispatcherHost::OnAckReceivedBlobs( 385 void IndexedDBDispatcherHost::OnAckReceivedBlobs(
387 const std::vector<std::string>& uuids) { 386 const std::vector<std::string>& uuids) {
388 DCHECK_CURRENTLY_ON(BrowserThread::IO); 387 DCHECK_CURRENTLY_ON(BrowserThread::IO);
389 for (const auto& uuid : uuids) 388 for (const auto& uuid : uuids)
390 DropBlobData(uuid); 389 DropBlobData(uuid);
391 } 390 }
392 391
393 void IndexedDBDispatcherHost::FinishTransaction(int64_t host_transaction_id, 392 void IndexedDBDispatcherHost::FinishTransaction(int64_t host_transaction_id,
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( 675 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
677 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); 676 parent_, params.ipc_thread_id, params.ipc_callbacks_id));
678 connection->database()->GetAll( 677 connection->database()->GetAll(
679 parent_->HostTransactionId(params.transaction_id), params.object_store_id, 678 parent_->HostTransactionId(params.transaction_id), params.object_store_id,
680 params.index_id, base::MakeUnique<IndexedDBKeyRange>(params.key_range), 679 params.index_id, base::MakeUnique<IndexedDBKeyRange>(params.key_range),
681 params.key_only, params.max_count, callbacks); 680 params.key_only, params.max_count, callbacks);
682 } 681 }
683 682
684 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPutWrapper( 683 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPutWrapper(
685 const IndexedDBHostMsg_DatabasePut_Params& params) { 684 const IndexedDBHostMsg_DatabasePut_Params& params) {
686 std::vector<storage::BlobDataHandle*> handles; 685 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles;
687 for (size_t i = 0; i < params.value.blob_or_file_info.size(); ++i) { 686 for (const auto& info : params.value.blob_or_file_info) {
688 const IndexedDBMsg_BlobOrFileInfo& info = params.value.blob_or_file_info[i]; 687 handles.push_back(
689 handles.push_back(parent_->blob_storage_context_->context() 688 parent_->blob_storage_context_->context()->GetBlobDataFromUUID(
690 ->GetBlobDataFromUUID(info.uuid) 689 info.uuid));
691 .release());
692 } 690 }
693 parent_->context()->TaskRunner()->PostTask( 691 parent_->context()->TaskRunner()->PostTask(
694 FROM_HERE, base::Bind(&IndexedDBDispatcherHost::OnPutHelper, parent_, 692 FROM_HERE, base::Bind(&IndexedDBDispatcherHost::OnPutHelper, parent_,
695 params, handles)); 693 params, base::Passed(&handles)));
696 } 694 }
697 695
698 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut( 696 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut(
699 const IndexedDBHostMsg_DatabasePut_Params& params, 697 const IndexedDBHostMsg_DatabasePut_Params& params,
700 std::vector<storage::BlobDataHandle*> handles) { 698 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles) {
701 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 699 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
702 700
703 ScopedVector<storage::BlobDataHandle> scoped_handles; 701 std::vector<std::unique_ptr<storage::BlobDataHandle>> scoped_handles;
704 scoped_handles.swap(handles); 702 scoped_handles.swap(handles);
705 703
706 IndexedDBConnection* connection = 704 IndexedDBConnection* connection =
707 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 705 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
708 if (!connection || !connection->IsConnected()) 706 if (!connection || !connection->IsConnected())
709 return; 707 return;
710 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( 708 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
711 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); 709 parent_, params.ipc_thread_id, params.ipc_callbacks_id));
712 710
713 int64_t host_transaction_id = 711 int64_t host_transaction_id =
714 parent_->HostTransactionId(params.transaction_id); 712 parent_->HostTransactionId(params.transaction_id);
715 713
716 std::vector<IndexedDBBlobInfo> blob_info( 714 std::vector<IndexedDBBlobInfo> blob_info(
717 params.value.blob_or_file_info.size()); 715 params.value.blob_or_file_info.size());
718 716
719 ChildProcessSecurityPolicyImpl* policy = 717 ChildProcessSecurityPolicyImpl* policy =
720 ChildProcessSecurityPolicyImpl::GetInstance(); 718 ChildProcessSecurityPolicyImpl::GetInstance();
721 719
722 for (size_t i = 0; i < params.value.blob_or_file_info.size(); ++i) { 720 size_t i = 0;
723 const IndexedDBMsg_BlobOrFileInfo& info = params.value.blob_or_file_info[i]; 721 for (const auto& info : params.value.blob_or_file_info) {
724 if (info.is_file) { 722 if (info.is_file) {
725 base::FilePath path; 723 base::FilePath path;
726 if (!info.file_path.empty()) { 724 if (!info.file_path.empty()) {
727 path = base::FilePath::FromUTF16Unsafe(info.file_path); 725 path = base::FilePath::FromUTF16Unsafe(info.file_path);
728 if (!policy->CanReadFile(parent_->ipc_process_id_, path)) { 726 if (!policy->CanReadFile(parent_->ipc_process_id_, path)) {
729 bad_message::ReceivedBadMessage(parent_, 727 bad_message::ReceivedBadMessage(parent_,
730 bad_message::IDBDH_CAN_READ_FILE); 728 bad_message::IDBDH_CAN_READ_FILE);
731 return; 729 return;
732 } 730 }
733 } 731 }
734 blob_info[i] = 732 blob_info[i] =
735 IndexedDBBlobInfo(info.uuid, path, info.file_name, info.mime_type); 733 IndexedDBBlobInfo(info.uuid, path, info.file_name, info.mime_type);
736 if (info.size != static_cast<uint64_t>(-1)) { 734 if (info.size != static_cast<uint64_t>(-1)) {
737 blob_info[i].set_last_modified( 735 blob_info[i].set_last_modified(
738 base::Time::FromDoubleT(info.last_modified)); 736 base::Time::FromDoubleT(info.last_modified));
739 blob_info[i].set_size(info.size); 737 blob_info[i].set_size(info.size);
740 } 738 }
741 } else { 739 } else {
742 blob_info[i] = IndexedDBBlobInfo(info.uuid, info.mime_type, info.size); 740 blob_info[i] = IndexedDBBlobInfo(info.uuid, info.mime_type, info.size);
743 } 741 }
742 ++i;
744 } 743 }
745 744
746 // TODO(alecflett): Avoid a copy here. 745 // TODO(alecflett): Avoid a copy here.
747 IndexedDBValue value; 746 IndexedDBValue value;
748 value.bits = params.value.bits; 747 value.bits = params.value.bits;
749 value.blob_info.swap(blob_info); 748 value.blob_info.swap(blob_info);
750 connection->database()->Put(host_transaction_id, params.object_store_id, 749 connection->database()->Put(host_transaction_id, params.object_store_id,
751 &value, &scoped_handles, 750 &value, &scoped_handles,
752 base::MakeUnique<IndexedDBKey>(params.key), 751 base::MakeUnique<IndexedDBKey>(params.key),
753 params.put_mode, callbacks, params.index_keys); 752 params.put_mode, callbacks, params.index_keys);
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 DLOG(ERROR) << "Unable to reset prefetch"; 1057 DLOG(ERROR) << "Unable to reset prefetch";
1059 } 1058 }
1060 1059
1061 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( 1060 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed(
1062 int32_t ipc_object_id) { 1061 int32_t ipc_object_id) {
1063 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 1062 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
1064 parent_->DestroyObject(&map_, ipc_object_id); 1063 parent_->DestroyObject(&map_, ipc_object_id);
1065 } 1064 }
1066 1065
1067 } // namespace content 1066 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_dispatcher_host.h ('k') | content/browser/indexed_db/indexed_db_fake_backing_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698