Chromium Code Reviews| Index: content/browser/blob_storage/blob_dispatcher_host.cc |
| diff --git a/content/browser/blob_storage/blob_dispatcher_host.cc b/content/browser/blob_storage/blob_dispatcher_host.cc |
| index 2c43055a5ecf3c7b9ff45cb2269bbfb5910aed77..54c86dae6cfb47316c42e5ee321beebecf66bf54 100644 |
| --- a/content/browser/blob_storage/blob_dispatcher_host.cc |
| +++ b/content/browser/blob_storage/blob_dispatcher_host.cc |
| @@ -12,6 +12,7 @@ |
| #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
| #include "content/common/fileapi/webblob_messages.h" |
| #include "ipc/ipc_platform_file.h" |
| +#include "storage/browser/blob/blob_data_handle.h" |
| #include "storage/browser/blob/blob_storage_context.h" |
| #include "storage/browser/blob/blob_transport_result.h" |
| #include "storage/common/blob_storage/blob_item_bytes_request.h" |
| @@ -54,8 +55,7 @@ void BlobDispatcherHost::OnChannelClosing() { |
| bool BlobDispatcherHost::OnMessageReceived(const IPC::Message& message) { |
| bool handled = true; |
| IPC_BEGIN_MESSAGE_MAP(BlobDispatcherHost, message) |
| - IPC_MESSAGE_HANDLER(BlobStorageMsg_RegisterBlobUUID, OnRegisterBlobUUID) |
| - IPC_MESSAGE_HANDLER(BlobStorageMsg_StartBuildingBlob, OnStartBuildingBlob) |
| + IPC_MESSAGE_HANDLER(BlobStorageMsg_RegisterBlob, OnRegisterBlob) |
| IPC_MESSAGE_HANDLER(BlobStorageMsg_MemoryItemResponse, OnMemoryItemResponse) |
| IPC_MESSAGE_HANDLER(BlobStorageMsg_CancelBuildingBlob, OnCancelBuildingBlob) |
| IPC_MESSAGE_HANDLER(BlobHostMsg_IncrementRefCount, OnIncrementBlobRefCount) |
| @@ -67,11 +67,11 @@ bool BlobDispatcherHost::OnMessageReceived(const IPC::Message& message) { |
| return handled; |
| } |
| -void BlobDispatcherHost::OnRegisterBlobUUID( |
| +void BlobDispatcherHost::OnRegisterBlob( |
| const std::string& uuid, |
| const std::string& content_type, |
| const std::string& content_disposition, |
| - const std::set<std::string>& referenced_blob_uuids) { |
| + const std::vector<storage::DataElement>& descriptions) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| BlobStorageContext* context = this->context(); |
| if (uuid.empty() || context->registry().HasEntry(uuid) || |
| @@ -80,67 +80,19 @@ void BlobDispatcherHost::OnRegisterBlobUUID( |
| return; |
| } |
| blobs_inuse_map_[uuid] = 1; |
| - BlobTransportResult result = async_builder_.RegisterBlobUUID( |
| - uuid, content_type, content_disposition, referenced_blob_uuids, context); |
| - switch (result) { |
| - case BlobTransportResult::BAD_IPC: |
| - blobs_inuse_map_.erase(uuid); |
| - bad_message::ReceivedBadMessage(this, |
| - bad_message::BDH_CONSTRUCTION_FAILED); |
| - break; |
| - case BlobTransportResult::CANCEL_REFERENCED_BLOB_BROKEN: |
| - // The async builder builds the blob as broken, and we just need to send |
| - // the cancel message back to the renderer. |
| - Send(new BlobStorageMsg_CancelBuildingBlob( |
| - uuid, IPCBlobCreationCancelCode::REFERENCED_BLOB_BROKEN)); |
| - break; |
| - case BlobTransportResult::DONE: |
| - break; |
| - case BlobTransportResult::CANCEL_MEMORY_FULL: |
| - case BlobTransportResult::CANCEL_FILE_ERROR: |
| - case BlobTransportResult::CANCEL_UNKNOWN: |
| - case BlobTransportResult::PENDING_RESPONSES: |
| - NOTREACHED(); |
| - break; |
| - } |
| -} |
| - |
| -void BlobDispatcherHost::OnStartBuildingBlob( |
| - const std::string& uuid, |
| - const std::vector<storage::DataElement>& descriptions) { |
| - DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| - if (uuid.empty()) { |
| - SendIPCResponse(uuid, BlobTransportResult::BAD_IPC); |
| - return; |
| - } |
| - BlobStorageContext* context = this->context(); |
| - const BlobStorageRegistry::Entry* entry = context->registry().GetEntry(uuid); |
| - if (!entry || entry->state == BlobStorageRegistry::BlobState::BROKEN) { |
| - // We ignore messages for blobs that don't exist to handle the case where |
| - // the renderer de-refs a blob that we're still constructing, and there are |
| - // no references to that blob. We ignore broken as well, in the case where |
| - // we decided to break a blob after RegisterBlobUUID is called. |
| - // Second, if the last dereference of the blob happened on a different host, |
| - // then we still haven't gotten rid of the 'building' state in the original |
| - // host. So we call cancel, and send the message just in case that happens. |
| - if (async_builder_.IsBeingBuilt(uuid)) { |
| - async_builder_.CancelBuildingBlob( |
| - uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING, |
| - context); |
| - Send(new BlobStorageMsg_CancelBuildingBlob( |
| - uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING)); |
| - } |
| - return; |
| - } |
| - if (!async_builder_.IsBeingBuilt(uuid)) { |
| - SendIPCResponse(uuid, BlobTransportResult::BAD_IPC); |
| - return; |
| - } |
| - // |this| owns async_builder_ so using base::Unretained(this) is safe. |
| - BlobTransportResult result = async_builder_.StartBuildingBlob( |
| - uuid, descriptions, context->memory_available(), context, |
| + std::unique_ptr<storage::BlobDataHandle> handle; |
|
michaeln
2016/07/07 20:05:21
Since |handle| isn't used and this is the only cal
|
| + BlobTransportResult result = async_builder_.RegisterBlob( |
| + uuid, content_type, content_disposition, descriptions, context, &handle, |
| base::Bind(&BlobDispatcherHost::SendMemoryRequest, base::Unretained(this), |
| - uuid)); |
| + uuid), |
| + base::Bind(&BlobDispatcherHost::CancelBlob, base::Unretained(this), uuid), |
| + base::Bind(&BlobDispatcherHost::SendIPCResponse, base::Unretained(this), |
| + uuid, BlobTransportResult::DONE)); |
| + if (result == BlobTransportResult::BAD_IPC) { |
| + blobs_inuse_map_.erase(uuid); |
| + } else { |
| + context->IncrementBlobRefCount(uuid); |
| + } |
| SendIPCResponse(uuid, result); |
| } |
| @@ -309,8 +261,9 @@ void BlobDispatcherHost::SendMemoryRequest( |
| std::unique_ptr<std::vector<base::File>> files) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| std::vector<IPC::PlatformFileForTransit> file_handles; |
| - // TODO(dmurph): Support file-backed blob transportation. |
| - DCHECK(files->empty()); |
| + for (base::File& file : *files) { |
| + file_handles.push_back(IPC::TakePlatformFileForTransit(std::move(file))); |
| + } |
| Send(new BlobStorageMsg_RequestMemoryItem(uuid, *requests, *memory_handles, |
| file_handles)); |
| } |
| @@ -347,6 +300,11 @@ void BlobDispatcherHost::SendIPCResponse(const std::string& uuid, |
| NOTREACHED(); |
| } |
| +void BlobDispatcherHost::CancelBlob(const std::string& uuid, |
|
michaeln
2016/07/07 20:05:21
naming consistency nit: SendCancelBlob
|
| + IPCBlobCreationCancelCode reason) { |
| + Send(new BlobStorageMsg_CancelBuildingBlob(uuid, reason)); |
| +} |
| + |
| bool BlobDispatcherHost::IsInUseInHost(const std::string& uuid) { |
| return blobs_inuse_map_.find(uuid) != blobs_inuse_map_.end(); |
| } |