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

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

Issue 1988293002: [BlobAsync] Fixed race between IPC messages and IO task queue (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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; 75 // TODO(dmurph): handle racy io thread scheduling, so we can send both
76 // messages ASAP.
76 std::set<std::string> referenced_blobs = consolidation->referenced_blobs(); 77 std::set<std::string> referenced_blobs = consolidation->referenced_blobs();
77 BlobTransportController::GetDescriptions( 78 sender->Send(new BlobStorageMsg_RegisterBlobUUID(uuid, content_type, "",
78 consolidation.get(), kBlobStorageIPCThresholdBytes, &descriptions); 79 referenced_blobs));
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( 80 io_runner->PostTask(
82 FROM_HERE, 81 FROM_HERE,
83 base::Bind(&BlobTransportController::StoreBlobDataForRequests, 82 base::Bind(&BlobTransportController::StoreBlobDataAndStart,
84 base::Unretained(BlobTransportController::GetInstance()), uuid, 83 base::Unretained(BlobTransportController::GetInstance()), uuid,
85 base::Passed(std::move(consolidation)), 84 base::Passed(&consolidation),
86 base::Passed(std::move(main_runner)))); 85 base::Passed(&sender),
87 // TODO(dmurph): Merge register and start messages. 86 base::Passed(&main_runner)));
88 sender->Send(new BlobStorageMsg_RegisterBlobUUID(uuid, content_type, "",
89 referenced_blobs));
90 sender->Send(new BlobStorageMsg_StartBuildingBlob(uuid, descriptions));
91 } 87 }
92 88
93 void BlobTransportController::OnMemoryRequest( 89 void BlobTransportController::OnMemoryRequest(
94 const std::string& uuid, 90 const std::string& uuid,
95 const std::vector<storage::BlobItemBytesRequest>& requests, 91 const std::vector<storage::BlobItemBytesRequest>& requests,
96 std::vector<base::SharedMemoryHandle>* memory_handles, 92 std::vector<base::SharedMemoryHandle>* memory_handles,
97 const std::vector<IPC::PlatformFileForTransit>& file_handles, 93 const std::vector<IPC::PlatformFileForTransit>& file_handles,
98 IPC::Sender* sender) { 94 IPC::Sender* sender) {
99 std::vector<storage::BlobItemBytesResponse> responses; 95 std::vector<storage::BlobItemBytesResponse> responses;
100 ResponsesStatus status = 96 ResponsesStatus status =
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 BlobTransportController::~BlobTransportController() {} 187 BlobTransportController::~BlobTransportController() {}
192 188
193 void BlobTransportController::ClearForTesting() { 189 void BlobTransportController::ClearForTesting() {
194 if (!blob_storage_.empty() && main_thread_runner_) { 190 if (!blob_storage_.empty() && main_thread_runner_) {
195 main_thread_runner_->PostTask(FROM_HERE, 191 main_thread_runner_->PostTask(FROM_HERE,
196 base::Bind(&DecChildProcessRefCount)); 192 base::Bind(&DecChildProcessRefCount));
197 } 193 }
198 blob_storage_.clear(); 194 blob_storage_.clear();
199 } 195 }
200 196
201 void BlobTransportController::StoreBlobDataForRequests( 197 void BlobTransportController::StoreBlobDataAndStart(
202 const std::string& uuid, 198 const std::string& uuid,
203 std::unique_ptr<BlobConsolidation> consolidation, 199 std::unique_ptr<BlobConsolidation> consolidation,
200 scoped_refptr<ThreadSafeSender> sender,
204 scoped_refptr<base::SingleThreadTaskRunner> main_runner) { 201 scoped_refptr<base::SingleThreadTaskRunner> main_runner) {
202 std::vector<storage::DataElement> descriptions;
203 BlobTransportController::GetDescriptions(
204 consolidation.get(), kBlobStorageIPCThresholdBytes, &descriptions);
205 sender->Send(new BlobStorageMsg_StartBuildingBlob(uuid, descriptions));
206
205 if (!main_thread_runner_.get()) { 207 if (!main_thread_runner_.get()) {
206 main_thread_runner_ = std::move(main_runner); 208 main_thread_runner_ = std::move(main_runner);
207 } 209 }
208 blob_storage_[uuid] = std::move(consolidation); 210 blob_storage_[uuid] = std::move(consolidation);
209 } 211 }
210 212
211 BlobTransportController::ResponsesStatus BlobTransportController::GetResponses( 213 BlobTransportController::ResponsesStatus BlobTransportController::GetResponses(
212 const std::string& uuid, 214 const std::string& uuid,
213 const std::vector<BlobItemBytesRequest>& requests, 215 const std::vector<BlobItemBytesRequest>& requests,
214 std::vector<SharedMemoryHandle>* memory_handles, 216 std::vector<SharedMemoryHandle>* memory_handles,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 287
286 void BlobTransportController::ReleaseBlobConsolidation( 288 void BlobTransportController::ReleaseBlobConsolidation(
287 const std::string& uuid) { 289 const std::string& uuid) {
288 if (blob_storage_.erase(uuid)) { 290 if (blob_storage_.erase(uuid)) {
289 main_thread_runner_->PostTask(FROM_HERE, 291 main_thread_runner_->PostTask(FROM_HERE,
290 base::Bind(&DecChildProcessRefCount)); 292 base::Bind(&DecChildProcessRefCount));
291 } 293 }
292 } 294 }
293 295
294 } // namespace content 296 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698