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

Unified Diff: content/browser/blob_storage/blob_dispatcher_host.cc

Issue 2055053003: [BlobAsync] Disk support for blob storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: half of comments Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
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 4f2ed8439f15ee20201f45bef45f5b836ccfb62f..10f55bbe44c79b4aa90a6332437255e9cdc6f734 100644
--- a/content/browser/blob_storage/blob_dispatcher_host.cc
+++ b/content/browser/blob_storage/blob_dispatcher_host.cc
@@ -14,10 +14,11 @@
#include "content/browser/fileapi/browser_file_system_helper.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/browser/fileapi/file_system_context.h"
#include "storage/browser/fileapi/file_system_url.h"
+#include "storage/browser/blob/internal_blob_data.h"
#include "storage/common/blob_storage/blob_item_bytes_request.h"
#include "storage/common/blob_storage/blob_item_bytes_response.h"
#include "storage/common/data_element.h"
@@ -25,9 +26,8 @@
using storage::BlobStorageContext;
using storage::BlobStorageRegistry;
-using storage::BlobTransportResult;
+using storage::BlobStatus;
using storage::DataElement;
-using storage::IPCBlobCreationCancelCode;
using storage::FileSystemURL;
namespace content {
@@ -64,10 +64,9 @@ 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(BlobStorageMsg_SendBlobStatus, OnCancelBuildingBob)
IPC_MESSAGE_HANDLER(BlobHostMsg_IncrementRefCount, OnIncrementBlobRefCount)
IPC_MESSAGE_HANDLER(BlobHostMsg_DecrementRefCount, OnDecrementBlobRefCount)
IPC_MESSAGE_HANDLER(BlobHostMsg_RegisterPublicURL, OnRegisterPublicBlobURL)
@@ -77,11 +76,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) ||
@@ -89,63 +88,6 @@ void BlobDispatcherHost::OnRegisterBlobUUID(
bad_message::ReceivedBadMessage(this, bad_message::BDH_UUID_REGISTERED);
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;
- }
ChildProcessSecurityPolicyImpl* security_policy =
ChildProcessSecurityPolicyImpl::GetInstance();
@@ -156,29 +98,24 @@ void BlobDispatcherHost::OnStartBuildingBlob(
if (!FileSystemURLIsValid(file_system_context_.get(), filesystem_url) ||
!security_policy->CanReadFileSystemFile(process_id_,
filesystem_url)) {
- async_builder_.CancelBuildingBlob(
- uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED, context);
- Send(new BlobStorageMsg_CancelBuildingBlob(
- uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED));
+ SendFinalBlobStatus(uuid, BlobStatus::ERR_FILE_WRITE_FAILED);
return;
}
}
if (item.type() == storage::DataElement::TYPE_FILE &&
!security_policy->CanReadFile(process_id_, item.path())) {
- async_builder_.CancelBuildingBlob(
- uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED, context);
- Send(new BlobStorageMsg_CancelBuildingBlob(
- uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED));
+ SendFinalBlobStatus(uuid, BlobStatus::ERR_FILE_WRITE_FAILED);
return;
}
}
+ blobs_inuse_map_[uuid] = 1;
- // |this| owns async_builder_ so using base::Unretained(this) is safe.
- BlobTransportResult result = async_builder_.StartBuildingBlob(
- uuid, descriptions, context->memory_available(), context,
+ async_builder_.RegisterBlob(
+ uuid, content_type, content_disposition, descriptions, context,
base::Bind(&BlobDispatcherHost::SendMemoryRequest, base::Unretained(this),
- uuid));
- SendIPCResponse(uuid, result);
+ uuid),
+ base::Bind(&BlobDispatcherHost::SendFinalBlobStatus,
+ base::Unretained(this), uuid));
}
void BlobDispatcherHost::OnMemoryItemResponse(
@@ -186,12 +123,12 @@ void BlobDispatcherHost::OnMemoryItemResponse(
const std::vector<storage::BlobItemBytesResponse>& responses) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (uuid.empty()) {
- SendIPCResponse(uuid, BlobTransportResult::BAD_IPC);
+ bad_message::ReceivedBadMessage(this, bad_message::BDH_CONSTRUCTION_FAILED);
return;
}
BlobStorageContext* context = this->context();
- const BlobStorageRegistry::Entry* entry = context->registry().GetEntry(uuid);
- if (!entry || entry->state == BlobStorageRegistry::BlobState::BROKEN) {
+ const storage::InternalBlobData* entry = context->registry().GetEntry(uuid);
+ if (!entry || BlobStatusIsError(entry->status())) {
// 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
@@ -202,33 +139,31 @@ void BlobDispatcherHost::OnMemoryItemResponse(
// 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));
+ uuid, BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING, context);
+ SendFinalBlobStatus(uuid,
+ BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING);
}
return;
}
if (!async_builder_.IsBeingBuilt(uuid)) {
- SendIPCResponse(uuid, BlobTransportResult::BAD_IPC);
+ bad_message::ReceivedBadMessage(this, bad_message::BDH_CONSTRUCTION_FAILED);
return;
}
- BlobTransportResult result =
+ BlobStatus result =
async_builder_.OnMemoryResponses(uuid, responses, context);
- SendIPCResponse(uuid, result);
+ SendFinalBlobStatus(uuid, result);
michaeln 2016/08/23 01:31:55 I thought that in some cases the result can still
}
-void BlobDispatcherHost::OnCancelBuildingBlob(
- const std::string& uuid,
- const storage::IPCBlobCreationCancelCode code) {
+void BlobDispatcherHost::OnCancelBuildingBob(const std::string& uuid,
+ const storage::BlobStatus code) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (uuid.empty()) {
- SendIPCResponse(uuid, BlobTransportResult::BAD_IPC);
+ bad_message::ReceivedBadMessage(this, bad_message::BDH_CONSTRUCTION_FAILED);
return;
}
BlobStorageContext* context = this->context();
- const BlobStorageRegistry::Entry* entry = context->registry().GetEntry(uuid);
- if (!entry || entry->state == BlobStorageRegistry::BlobState::BROKEN) {
+ const storage::InternalBlobData* entry = context->registry().GetEntry(uuid);
+ if (!entry || BlobStatusIsError(entry->status())) {
// 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
@@ -239,13 +174,13 @@ void BlobDispatcherHost::OnCancelBuildingBlob(
// host. So we call cancel just in case this happens.
if (async_builder_.IsBeingBuilt(uuid)) {
async_builder_.CancelBuildingBlob(
- uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING,
- context);
+ uuid, BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING, context);
}
return;
}
- if (!async_builder_.IsBeingBuilt(uuid)) {
- SendIPCResponse(uuid, BlobTransportResult::BAD_IPC);
+ // We should only get these messages for errors.
+ if (!async_builder_.IsBeingBuilt(uuid) || !storage::BlobStatusIsError(code)) {
+ bad_message::ReceivedBadMessage(this, bad_message::BDH_CONSTRUCTION_FAILED);
return;
}
VLOG(1) << "Blob construction of " << uuid << " cancelled by renderer. "
@@ -293,10 +228,9 @@ void BlobDispatcherHost::OnDecrementBlobRefCount(const std::string& uuid) {
if (async_builder_.IsBeingBuilt(uuid) &&
!context->registry().HasEntry(uuid)) {
michaeln 2016/08/23 01:31:55 If the final ref is dropped from a different rende
async_builder_.CancelBuildingBlob(
- uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING,
- context);
- Send(new BlobStorageMsg_CancelBuildingBlob(
- uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING));
+ uuid, BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING, context);
+ SendFinalBlobStatus(
+ uuid, BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING);
}
}
}
@@ -341,47 +275,27 @@ storage::BlobStorageContext* BlobDispatcherHost::context() {
void BlobDispatcherHost::SendMemoryRequest(
const std::string& uuid,
- std::unique_ptr<std::vector<storage::BlobItemBytesRequest>> requests,
- std::unique_ptr<std::vector<base::SharedMemoryHandle>> memory_handles,
- std::unique_ptr<std::vector<base::File>> files) {
+ std::vector<storage::BlobItemBytesRequest> requests,
+ std::vector<base::SharedMemoryHandle> memory_handles,
+ 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());
- Send(new BlobStorageMsg_RequestMemoryItem(uuid, *requests, *memory_handles,
+ for (base::File& file : files) {
+ file_handles.push_back(IPC::TakePlatformFileForTransit(std::move(file)));
+ }
+ Send(new BlobStorageMsg_RequestMemoryItem(uuid, requests, memory_handles,
file_handles));
}
-void BlobDispatcherHost::SendIPCResponse(const std::string& uuid,
- storage::BlobTransportResult result) {
- switch (result) {
- case BlobTransportResult::BAD_IPC:
- bad_message::ReceivedBadMessage(this,
- bad_message::BDH_CONSTRUCTION_FAILED);
- return;
- case BlobTransportResult::CANCEL_MEMORY_FULL:
- Send(new BlobStorageMsg_CancelBuildingBlob(
- uuid, IPCBlobCreationCancelCode::OUT_OF_MEMORY));
- return;
- case BlobTransportResult::CANCEL_FILE_ERROR:
- Send(new BlobStorageMsg_CancelBuildingBlob(
- uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED));
- return;
- case BlobTransportResult::CANCEL_REFERENCED_BLOB_BROKEN:
- Send(new BlobStorageMsg_CancelBuildingBlob(
- uuid, IPCBlobCreationCancelCode::REFERENCED_BLOB_BROKEN));
- return;
- case BlobTransportResult::CANCEL_UNKNOWN:
- Send(new BlobStorageMsg_CancelBuildingBlob(
- uuid, IPCBlobCreationCancelCode::UNKNOWN));
- return;
- case BlobTransportResult::PENDING_RESPONSES:
- return;
- case BlobTransportResult::DONE:
- Send(new BlobStorageMsg_DoneBuildingBlob(uuid));
- return;
+void BlobDispatcherHost::SendFinalBlobStatus(const std::string& uuid,
+ BlobStatus status) {
+ if (storage::BlobStatusIsBadIPC(status)) {
+ blobs_inuse_map_.erase(uuid);
+ bad_message::ReceivedBadMessage(this, bad_message::BDH_CONSTRUCTION_FAILED);
+ return;
}
- NOTREACHED();
+ DCHECK(status != BlobStatus::PENDING);
+ Send(new BlobStorageMsg_SendBlobStatus(uuid, status));
}
bool BlobDispatcherHost::IsInUseInHost(const std::string& uuid) {

Powered by Google App Engine
This is Rietveld 408576698