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