Chromium Code Reviews| Index: content/child/blob_storage/blob_transport_controller.cc |
| diff --git a/content/child/blob_storage/blob_transport_controller.cc b/content/child/blob_storage/blob_transport_controller.cc |
| index cfd2c05df12e6a41eef348ca89c18d9ac05ab09e..415c6f904da501353240fefb9d6dc89a832ab6ad 100644 |
| --- a/content/child/blob_storage/blob_transport_controller.cc |
| +++ b/content/child/blob_storage/blob_transport_controller.cc |
| @@ -10,9 +10,12 @@ |
| #include "base/lazy_instance.h" |
| #include "base/memory/scoped_vector.h" |
| #include "base/memory/shared_memory.h" |
| +#include "base/single_thread_task_runner.h" |
| #include "base/stl_util.h" |
| #include "content/child/blob_storage/blob_consolidation.h" |
| +#include "content/child/child_process.h" |
| #include "content/child/thread_safe_sender.h" |
| +#include "content/common/fileapi/webblob_messages.h" |
| #include "ipc/ipc_sender.h" |
| #include "storage/common/blob_storage/blob_item_bytes_request.h" |
| #include "storage/common/blob_storage/blob_item_bytes_response.h" |
| @@ -36,6 +39,16 @@ namespace { |
| const size_t kLargeThresholdBytes = 250 * 1024; |
| static base::LazyInstance<BlobTransportController> g_controller = |
| LAZY_INSTANCE_INITIALIZER; |
| + |
| +// Must be called from main thread. |
|
michaeln
2016/03/14 20:00:19
i'd drop the comments about the main thread (which
dmurph
2016/03/14 22:39:30
Done.
|
| +void IncChildProcessRefCount() { |
| + ChildProcess::current()->AddRefProcess(); |
| +} |
| + |
| +// Must be called from main thread. |
| +void DecChildProcessRefCount() { |
| + ChildProcess::current()->ReleaseProcess(); |
| +} |
| } // namespace |
| BlobTransportController* BlobTransportController::GetInstance() { |
| @@ -46,16 +59,19 @@ BlobTransportController::~BlobTransportController() {} |
| void BlobTransportController::InitiateBlobTransfer( |
| const std::string& uuid, |
| - const std::string& type, |
| scoped_ptr<BlobConsolidation> consolidation, |
| - IPC::Sender* sender) { |
| + IPC::Sender* sender, |
| + scoped_refptr<base::SingleThreadTaskRunner> main_runner) { |
| BlobConsolidation* consolidation_ptr = consolidation.get(); |
| - blob_storage_.insert(std::make_pair(uuid, std::move(consolidation))); |
| + if (blob_storage_.empty()) { |
| + main_thread_runner_ = std::move(main_runner); |
| + main_thread_runner_->PostTask(FROM_HERE, |
| + base::Bind(&IncChildProcessRefCount)); |
| + } |
| + blob_storage_[uuid] = std::move(consolidation); |
| std::vector<storage::DataElement> descriptions; |
| GetDescriptions(consolidation_ptr, kLargeThresholdBytes, &descriptions); |
| - // TODO(dmurph): Uncomment when IPC messages are added. |
| - // sender->Send(new BlobStorageMsg_StartBuildingBlob(uuid, type, |
| - // descriptions)); |
| + sender->Send(new BlobStorageMsg_StartBuildingBlob(uuid, descriptions)); |
| } |
| void BlobTransportController::OnMemoryRequest( |
| @@ -85,8 +101,7 @@ void BlobTransportController::OnMemoryRequest( |
| break; |
| } |
| - // TODO(dmurph): Uncomment when IPC messages are added. |
| - // sender->Send(new BlobStorageMsg_MemoryItemResponse(uuid, responses)); |
| + sender->Send(new BlobStorageMsg_MemoryItemResponse(uuid, responses)); |
| } |
| void BlobTransportController::OnCancel( |
| @@ -100,8 +115,19 @@ void BlobTransportController::OnCancel( |
| case IPCBlobCreationCancelCode::OUT_OF_MEMORY: |
| DVLOG(1) << "Out of Memory."; |
| break; |
| + case IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT: |
| + DVLOG(1) |
| + << "Source died in transit. Invalid cancel reason from the Browser."; |
|
michaeln
2016/03/14 20:00:19
consider logging the numeric code instead for read
dmurph
2016/03/14 22:39:30
Done.
|
| + break; |
| case IPCBlobCreationCancelCode::FILE_WRITE_FAILED: |
| - DVLOG(1) << "File Write Failed (Invalid cancel reason!)."; |
| + DVLOG(1) << "File Write Failed."; |
| + break; |
| + case IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING: |
| + DVLOG(1) << "Blob was dereferenced before building finished, and no one " |
| + << "was waiting to read it."; |
| + break; |
| + case IPCBlobCreationCancelCode::REFERENCED_BLOB_BROKEN: |
| + DVLOG(1) << "Referenced blob was broken."; |
| break; |
| } |
| ReleaseBlobConsolidation(uuid); |
| @@ -111,20 +137,16 @@ void BlobTransportController::OnDone(const std::string& uuid) { |
| ReleaseBlobConsolidation(uuid); |
| } |
| -void BlobTransportController::Clear() { |
| +void BlobTransportController::ClearForTesting() { |
| + if (!blob_storage_.empty() && main_thread_runner_) { |
| + main_thread_runner_->PostTask(FROM_HERE, |
| + base::Bind(&DecChildProcessRefCount)); |
| + } |
| blob_storage_.clear(); |
| } |
| BlobTransportController::BlobTransportController() {} |
| -void BlobTransportController::CancelBlobTransfer(const std::string& uuid, |
| - IPCBlobCreationCancelCode code, |
| - IPC::Sender* sender) { |
| - // TODO(dmurph): Uncomment when IPC messages are added. |
| - // sender->Send(new BlobStorageMsg_CancelBuildingBlob(uuid, code)); |
| - ReleaseBlobConsolidation(uuid); |
| -} |
| - |
| void BlobTransportController::GetDescriptions( |
| BlobConsolidation* consolidation, |
| size_t max_data_population, |
| @@ -255,7 +277,13 @@ BlobTransportController::ResponsesStatus BlobTransportController::GetResponses( |
| void BlobTransportController::ReleaseBlobConsolidation( |
| const std::string& uuid) { |
| - blob_storage_.erase(uuid); |
| + // If we erased something and we're now empty, release the child process |
| + // ref count and deref the main thread runner. |
| + if (blob_storage_.erase(uuid) && blob_storage_.empty()) { |
| + main_thread_runner_->PostTask(FROM_HERE, |
| + base::Bind(&DecChildProcessRefCount)); |
| + main_thread_runner_ = nullptr; |
| + } |
| } |
| } // namespace content |