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

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: 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 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 params.name, request_context_, 399 params.name, request_context_,
401 new IndexedDBCallbacks(this, params.ipc_thread_id, 400 new IndexedDBCallbacks(this, params.ipc_thread_id,
402 params.ipc_callbacks_id), 401 params.ipc_callbacks_id),
403 params.origin, indexed_db_path); 402 params.origin, indexed_db_path);
404 } 403 }
405 404
406 // OnPutHelper exists only to allow us to hop threads while holding a reference 405 // OnPutHelper exists only to allow us to hop threads while holding a reference
407 // to the IndexedDBDispatcherHost. 406 // to the IndexedDBDispatcherHost.
408 void IndexedDBDispatcherHost::OnPutHelper( 407 void IndexedDBDispatcherHost::OnPutHelper(
409 const IndexedDBHostMsg_DatabasePut_Params& params, 408 const IndexedDBHostMsg_DatabasePut_Params& params,
410 std::vector<storage::BlobDataHandle*> handles) { 409 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles) {
411 database_dispatcher_host_->OnPut(params, handles); 410 database_dispatcher_host_->OnPut(params, std::move(handles));
412 } 411 }
413 412
414 void IndexedDBDispatcherHost::OnAckReceivedBlobs( 413 void IndexedDBDispatcherHost::OnAckReceivedBlobs(
415 const std::vector<std::string>& uuids) { 414 const std::vector<std::string>& uuids) {
416 DCHECK_CURRENTLY_ON(BrowserThread::IO); 415 DCHECK_CURRENTLY_ON(BrowserThread::IO);
417 for (const auto& uuid : uuids) 416 for (const auto& uuid : uuids)
418 DropBlobData(uuid); 417 DropBlobData(uuid);
419 } 418 }
420 419
421 void IndexedDBDispatcherHost::FinishTransaction(int64_t host_transaction_id, 420 void IndexedDBDispatcherHost::FinishTransaction(int64_t host_transaction_id,
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( 703 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
705 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); 704 parent_, params.ipc_thread_id, params.ipc_callbacks_id));
706 connection->database()->GetAll( 705 connection->database()->GetAll(
707 parent_->HostTransactionId(params.transaction_id), params.object_store_id, 706 parent_->HostTransactionId(params.transaction_id), params.object_store_id,
708 params.index_id, base::MakeUnique<IndexedDBKeyRange>(params.key_range), 707 params.index_id, base::MakeUnique<IndexedDBKeyRange>(params.key_range),
709 params.key_only, params.max_count, callbacks); 708 params.key_only, params.max_count, callbacks);
710 } 709 }
711 710
712 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPutWrapper( 711 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPutWrapper(
713 const IndexedDBHostMsg_DatabasePut_Params& params) { 712 const IndexedDBHostMsg_DatabasePut_Params& params) {
714 std::vector<storage::BlobDataHandle*> handles; 713 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles;
715 for (size_t i = 0; i < params.value.blob_or_file_info.size(); ++i) { 714 for (const auto& info : params.value.blob_or_file_info) {
716 const IndexedDBMsg_BlobOrFileInfo& info = params.value.blob_or_file_info[i]; 715 handles.push_back(
717 handles.push_back(parent_->blob_storage_context_->context() 716 parent_->blob_storage_context_->context()->GetBlobDataFromUUID(
718 ->GetBlobDataFromUUID(info.uuid) 717 info.uuid));
719 .release());
720 } 718 }
721 parent_->context()->TaskRunner()->PostTask( 719 parent_->context()->TaskRunner()->PostTask(
722 FROM_HERE, base::Bind(&IndexedDBDispatcherHost::OnPutHelper, parent_, 720 FROM_HERE, base::Bind(&IndexedDBDispatcherHost::OnPutHelper, parent_,
723 params, handles)); 721 params, base::Passed(std::move(handles))));
cmumford 2016/08/17 20:26:29 If I'm reading bind_helpers.h correctly this could
jsbell 2016/08/17 23:16:19 Done.
724 } 722 }
725 723
726 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut( 724 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut(
727 const IndexedDBHostMsg_DatabasePut_Params& params, 725 const IndexedDBHostMsg_DatabasePut_Params& params,
728 std::vector<storage::BlobDataHandle*> handles) { 726 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles) {
729 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 727 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
730 728
731 ScopedVector<storage::BlobDataHandle> scoped_handles; 729 std::vector<std::unique_ptr<storage::BlobDataHandle>> scoped_handles;
732 scoped_handles.swap(handles); 730 scoped_handles.swap(handles);
733 731
734 IndexedDBConnection* connection = 732 IndexedDBConnection* connection =
735 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 733 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
736 if (!connection || !connection->IsConnected()) 734 if (!connection || !connection->IsConnected())
737 return; 735 return;
738 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( 736 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
739 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); 737 parent_, params.ipc_thread_id, params.ipc_callbacks_id));
740 738
741 int64_t host_transaction_id = 739 int64_t host_transaction_id =
742 parent_->HostTransactionId(params.transaction_id); 740 parent_->HostTransactionId(params.transaction_id);
743 741
744 std::vector<IndexedDBBlobInfo> blob_info( 742 std::vector<IndexedDBBlobInfo> blob_info(
745 params.value.blob_or_file_info.size()); 743 params.value.blob_or_file_info.size());
746 744
747 ChildProcessSecurityPolicyImpl* policy = 745 ChildProcessSecurityPolicyImpl* policy =
748 ChildProcessSecurityPolicyImpl::GetInstance(); 746 ChildProcessSecurityPolicyImpl::GetInstance();
749 747
750 for (size_t i = 0; i < params.value.blob_or_file_info.size(); ++i) { 748 size_t i = 0;
751 const IndexedDBMsg_BlobOrFileInfo& info = params.value.blob_or_file_info[i]; 749 for (const auto& info : params.value.blob_or_file_info) {
752 if (info.is_file) { 750 if (info.is_file) {
753 base::FilePath path; 751 base::FilePath path;
754 if (!info.file_path.empty()) { 752 if (!info.file_path.empty()) {
755 path = base::FilePath::FromUTF16Unsafe(info.file_path); 753 path = base::FilePath::FromUTF16Unsafe(info.file_path);
756 if (!policy->CanReadFile(parent_->ipc_process_id_, path)) { 754 if (!policy->CanReadFile(parent_->ipc_process_id_, path)) {
757 bad_message::ReceivedBadMessage(parent_, 755 bad_message::ReceivedBadMessage(parent_,
758 bad_message::IDBDH_CAN_READ_FILE); 756 bad_message::IDBDH_CAN_READ_FILE);
759 return; 757 return;
760 } 758 }
761 } 759 }
762 blob_info[i] = 760 blob_info[i] =
763 IndexedDBBlobInfo(info.uuid, path, info.file_name, info.mime_type); 761 IndexedDBBlobInfo(info.uuid, path, info.file_name, info.mime_type);
764 if (info.size != static_cast<uint64_t>(-1)) { 762 if (info.size != static_cast<uint64_t>(-1)) {
765 blob_info[i].set_last_modified( 763 blob_info[i].set_last_modified(
766 base::Time::FromDoubleT(info.last_modified)); 764 base::Time::FromDoubleT(info.last_modified));
767 blob_info[i].set_size(info.size); 765 blob_info[i].set_size(info.size);
768 } 766 }
769 } else { 767 } else {
770 blob_info[i] = IndexedDBBlobInfo(info.uuid, info.mime_type, info.size); 768 blob_info[i] = IndexedDBBlobInfo(info.uuid, info.mime_type, info.size);
771 } 769 }
770 ++i;
772 } 771 }
773 772
774 // TODO(alecflett): Avoid a copy here. 773 // TODO(alecflett): Avoid a copy here.
775 IndexedDBValue value; 774 IndexedDBValue value;
776 value.bits = params.value.bits; 775 value.bits = params.value.bits;
777 value.blob_info.swap(blob_info); 776 value.blob_info.swap(blob_info);
778 connection->database()->Put(host_transaction_id, params.object_store_id, 777 connection->database()->Put(host_transaction_id, params.object_store_id,
779 &value, &scoped_handles, 778 &value, &scoped_handles,
780 base::MakeUnique<IndexedDBKey>(params.key), 779 base::MakeUnique<IndexedDBKey>(params.key),
781 params.put_mode, callbacks, params.index_keys); 780 params.put_mode, callbacks, params.index_keys);
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 DLOG(ERROR) << "Unable to reset prefetch"; 1085 DLOG(ERROR) << "Unable to reset prefetch";
1087 } 1086 }
1088 1087
1089 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( 1088 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed(
1090 int32_t ipc_object_id) { 1089 int32_t ipc_object_id) {
1091 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 1090 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
1092 parent_->DestroyObject(&map_, ipc_object_id); 1091 parent_->DestroyObject(&map_, ipc_object_id);
1093 } 1092 }
1094 1093
1095 } // namespace content 1094 } // 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