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

Side by Side Diff: content/child/blob_storage/blob_transport_controller.cc

Issue 1988983003: [BlobStorage] Fix IPC race in sending IPC and posting to IO thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix one test Created 4 years, 7 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/blob_storage/blob_transport_controller.h" 5 #include "content/child/blob_storage/blob_transport_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 std::unique_ptr<BlobConsolidation> consolidation, 65 std::unique_ptr<BlobConsolidation> consolidation,
66 scoped_refptr<ThreadSafeSender> sender, 66 scoped_refptr<ThreadSafeSender> sender,
67 base::SingleThreadTaskRunner* io_runner, 67 base::SingleThreadTaskRunner* io_runner,
68 scoped_refptr<base::SingleThreadTaskRunner> main_runner) { 68 scoped_refptr<base::SingleThreadTaskRunner> main_runner) {
69 if (main_runner->BelongsToCurrentThread()) { 69 if (main_runner->BelongsToCurrentThread()) {
70 IncChildProcessRefCount(); 70 IncChildProcessRefCount();
71 } else { 71 } else {
72 main_runner->PostTask(FROM_HERE, base::Bind(&IncChildProcessRefCount)); 72 main_runner->PostTask(FROM_HERE, base::Bind(&IncChildProcessRefCount));
73 } 73 }
74 74
75 std::vector<storage::DataElement> descriptions;
76 std::set<std::string> referenced_blobs = consolidation->referenced_blobs();
77 BlobTransportController::GetDescriptions(
78 consolidation.get(), kBlobStorageIPCThresholdBytes, &descriptions);
79 // I post the task first to make sure that we store our consolidation before
80 // we get a request back from the browser.
81 io_runner->PostTask( 75 io_runner->PostTask(
82 FROM_HERE, 76 FROM_HERE,
83 base::Bind(&BlobTransportController::StoreBlobDataForRequests, 77 base::Bind(&BlobTransportController::InitiateBlobTransferOnIOThread, uuid,
84 base::Unretained(BlobTransportController::GetInstance()), uuid, 78 content_type, base::Passed(std::move(consolidation)),
85 base::Passed(std::move(consolidation)), 79 base::Passed(std::move(sender)),
86 base::Passed(std::move(main_runner)))); 80 base::Passed(std::move(main_runner))));
87 // TODO(dmurph): Merge register and start messages.
88 sender->Send(new BlobStorageMsg_RegisterBlobUUID(uuid, content_type, "",
89 referenced_blobs));
90 sender->Send(new BlobStorageMsg_StartBuildingBlob(uuid, descriptions));
91 } 81 }
92 82
93 void BlobTransportController::OnMemoryRequest( 83 void BlobTransportController::OnMemoryRequest(
94 const std::string& uuid, 84 const std::string& uuid,
95 const std::vector<storage::BlobItemBytesRequest>& requests, 85 const std::vector<storage::BlobItemBytesRequest>& requests,
96 std::vector<base::SharedMemoryHandle>* memory_handles, 86 std::vector<base::SharedMemoryHandle>* memory_handles,
97 const std::vector<IPC::PlatformFileForTransit>& file_handles, 87 const std::vector<IPC::PlatformFileForTransit>& file_handles,
98 IPC::Sender* sender) { 88 IPC::Sender* sender) {
99 std::vector<storage::BlobItemBytesResponse> responses; 89 std::vector<storage::BlobItemBytesResponse> responses;
100 ResponsesStatus status = 90 ResponsesStatus status =
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 BlobTransportController::~BlobTransportController() {} 181 BlobTransportController::~BlobTransportController() {}
192 182
193 void BlobTransportController::ClearForTesting() { 183 void BlobTransportController::ClearForTesting() {
194 if (!blob_storage_.empty() && main_thread_runner_) { 184 if (!blob_storage_.empty() && main_thread_runner_) {
195 main_thread_runner_->PostTask(FROM_HERE, 185 main_thread_runner_->PostTask(FROM_HERE,
196 base::Bind(&DecChildProcessRefCount)); 186 base::Bind(&DecChildProcessRefCount));
197 } 187 }
198 blob_storage_.clear(); 188 blob_storage_.clear();
199 } 189 }
200 190
191 // static
192 void BlobTransportController::InitiateBlobTransferOnIOThread(
193 const std::string& uuid,
194 const std::string& content_type,
195 std::unique_ptr<BlobConsolidation> consolidation,
196 scoped_refptr<ThreadSafeSender> sender,
197 scoped_refptr<base::SingleThreadTaskRunner> main_runner) {
198 std::vector<storage::DataElement> descriptions;
199 std::set<std::string> referenced_blobs = consolidation->referenced_blobs();
200 BlobTransportController::GetDescriptions(
201 consolidation.get(), kBlobStorageIPCThresholdBytes, &descriptions);
202 BlobTransportController::GetInstance()->StoreBlobDataForRequests(
203 uuid, std::move(consolidation), std::move(main_runner));
204
205 // TODO(dmurph): Merge register and start messages.
206 sender->Send(new BlobStorageMsg_RegisterBlobUUID(uuid, content_type, "",
207 referenced_blobs));
208 sender->Send(new BlobStorageMsg_StartBuildingBlob(uuid, descriptions));
209 }
210
201 void BlobTransportController::StoreBlobDataForRequests( 211 void BlobTransportController::StoreBlobDataForRequests(
202 const std::string& uuid, 212 const std::string& uuid,
203 std::unique_ptr<BlobConsolidation> consolidation, 213 std::unique_ptr<BlobConsolidation> consolidation,
204 scoped_refptr<base::SingleThreadTaskRunner> main_runner) { 214 scoped_refptr<base::SingleThreadTaskRunner> main_runner) {
205 if (!main_thread_runner_.get()) { 215 if (!main_thread_runner_.get()) {
206 main_thread_runner_ = std::move(main_runner); 216 main_thread_runner_ = std::move(main_runner);
207 } 217 }
208 blob_storage_[uuid] = std::move(consolidation); 218 blob_storage_[uuid] = std::move(consolidation);
209 } 219 }
210 220
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 295
286 void BlobTransportController::ReleaseBlobConsolidation( 296 void BlobTransportController::ReleaseBlobConsolidation(
287 const std::string& uuid) { 297 const std::string& uuid) {
288 if (blob_storage_.erase(uuid)) { 298 if (blob_storage_.erase(uuid)) {
289 main_thread_runner_->PostTask(FROM_HERE, 299 main_thread_runner_->PostTask(FROM_HERE,
290 base::Bind(&DecChildProcessRefCount)); 300 base::Bind(&DecChildProcessRefCount));
291 } 301 }
292 } 302 }
293 303
294 } // namespace content 304 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698