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

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

Issue 2340133006: [WIP] Hack on Blob mojom (Closed)
Patch Set: Created 4 years, 3 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..3b87f1dd9aee1499ee78ea1781aeb4df586e2360 100644
--- a/content/browser/blob_storage/blob_dispatcher_host.cc
+++ b/content/browser/blob_storage/blob_dispatcher_host.cc
@@ -47,9 +47,11 @@ BlobDispatcherHost::BlobDispatcherHost(
scoped_refptr<ChromeBlobStorageContext> blob_storage_context,
scoped_refptr<storage::FileSystemContext> file_system_context)
: BrowserMessageFilter(BlobMsgStart),
+ BrowserAssociatedInterface<mojom::BlobFactory>(this, this),
process_id_(process_id),
file_system_context_(std::move(file_system_context)),
- blob_storage_context_(std::move(blob_storage_context)) {}
+ blob_storage_context_(std::move(blob_storage_context)),
+ blob_bindings_(mojo::BindingSetDispatchMode::WITH_CONTEXT) {}
BlobDispatcherHost::~BlobDispatcherHost() {
ClearHostFromBlobStorageContext();
@@ -64,10 +66,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_MemoryItemResponse, OnMemoryItemResponse)
- IPC_MESSAGE_HANDLER(BlobStorageMsg_CancelBuildingBlob, OnCancelBuildingBlob)
IPC_MESSAGE_HANDLER(BlobHostMsg_IncrementRefCount, OnIncrementBlobRefCount)
IPC_MESSAGE_HANDLER(BlobHostMsg_DecrementRefCount, OnDecrementBlobRefCount)
IPC_MESSAGE_HANDLER(BlobHostMsg_RegisterPublicURL, OnRegisterPublicBlobURL)
@@ -77,12 +76,15 @@ bool BlobDispatcherHost::OnMessageReceived(const IPC::Message& message) {
return handled;
}
-void BlobDispatcherHost::OnRegisterBlobUUID(
+void BlobDispatcherHost::BuildBlob(
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<std::string>& referenced_blob_uuids,
+ const std::vector<storage::DataElement>& item_descriptions,
+ const BuildBlobCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
BlobStorageContext* context = this->context();
if (uuid.empty() || context->registry().HasEntry(uuid) ||
async_builder_.IsBeingBuilt(uuid)) {
@@ -90,8 +92,13 @@ void BlobDispatcherHost::OnRegisterBlobUUID(
return;
}
blobs_inuse_map_[uuid] = 1;
+ std::set<std::string> referenced_blob_uuid_set;
+ std::copy(referenced_blob_uuids.begin(), referenced_blob_uuids.end(),
+ std::inserter(referenced_blob_uuid_set,
+ referenced_blob_uuid_set.end()));
BlobTransportResult result = async_builder_.RegisterBlobUUID(
- uuid, content_type, content_disposition, referenced_blob_uuids, context);
+ uuid, content_type, content_disposition, referenced_blob_uuid_set,
+ context);
switch (result) {
case BlobTransportResult::BAD_IPC:
blobs_inuse_map_.erase(uuid);
@@ -101,9 +108,9 @@ void BlobDispatcherHost::OnRegisterBlobUUID(
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;
+ callback.Run(
+ nullptr, mojom::BlobCreationCancelCode::REFERENCED_BLOB_BROKEN);
+ return;
case BlobTransportResult::DONE:
break;
case BlobTransportResult::CANCEL_MEMORY_FULL:
@@ -113,14 +120,9 @@ void BlobDispatcherHost::OnRegisterBlobUUID(
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);
+ SendIPCResponse(callback, BlobTransportResult::BAD_IPC);
return;
}
BlobStorageContext* context = this->context();
@@ -137,13 +139,14 @@ void BlobDispatcherHost::OnStartBuildingBlob(
async_builder_.CancelBuildingBlob(
uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING,
context);
- Send(new BlobStorageMsg_CancelBuildingBlob(
- uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING));
+ callback.Run(
+ nullptr,
+ mojom::BlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING);
}
return;
}
if (!async_builder_.IsBeingBuilt(uuid)) {
- SendIPCResponse(uuid, BlobTransportResult::BAD_IPC);
+ SendIPCResponse(callback, BlobTransportResult::BAD_IPC);
return;
}
@@ -158,8 +161,7 @@ void BlobDispatcherHost::OnStartBuildingBlob(
filesystem_url)) {
async_builder_.CancelBuildingBlob(
uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED, context);
- Send(new BlobStorageMsg_CancelBuildingBlob(
- uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED));
+ callback.Run(nullptr, mojom::BlobCreationCancelCode::FILE_WRITE_FAILED);
return;
}
}
@@ -167,8 +169,7 @@ void BlobDispatcherHost::OnStartBuildingBlob(
!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));
+ callback.Run(nullptr, mojom::BlobCreationCancelCode::FILE_WRITE_FAILED);
return;
}
}
@@ -178,7 +179,7 @@ void BlobDispatcherHost::OnStartBuildingBlob(
uuid, descriptions, context->memory_available(), context,
base::Bind(&BlobDispatcherHost::SendMemoryRequest, base::Unretained(this),
uuid));
- SendIPCResponse(uuid, result);
+ SendIPCResponse(callback, result);
}
void BlobDispatcherHost::OnMemoryItemResponse(
@@ -352,36 +353,40 @@ void BlobDispatcherHost::SendMemoryRequest(
file_handles));
}
-void BlobDispatcherHost::SendIPCResponse(const std::string& uuid,
+void BlobDispatcherHost::SendIPCResponse(const BuildBlobCallback& callback,
storage::BlobTransportResult result) {
+ mojom::BlobAssociatedPtr new_blob;
+ mojom::BlobCreationCancelCode cancel_code =
+ mojom:BlobCreationCancelCode::UNKNOWN;
switch (result) {
case BlobTransportResult::BAD_IPC:
bad_message::ReceivedBadMessage(this,
bad_message::BDH_CONSTRUCTION_FAILED);
- return;
+ cancel_code = mojom::BlobCreationCancelCode::UNKNOWN;
+ break;
case BlobTransportResult::CANCEL_MEMORY_FULL:
- Send(new BlobStorageMsg_CancelBuildingBlob(
- uuid, IPCBlobCreationCancelCode::OUT_OF_MEMORY));
- return;
+ cancel_code = mojom::BlobCreationCancelCode::OUT_OF_MEMORY;
+ break;
case BlobTransportResult::CANCEL_FILE_ERROR:
- Send(new BlobStorageMsg_CancelBuildingBlob(
- uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED));
- return;
+ cancel_code = mojom::BlobCreationCancelCode::FILE_WRITE_FAILED;
+ break;
case BlobTransportResult::CANCEL_REFERENCED_BLOB_BROKEN:
- Send(new BlobStorageMsg_CancelBuildingBlob(
- uuid, IPCBlobCreationCancelCode::REFERENCED_BLOB_BROKEN));
- return;
+ cancel_code = mojom::BlobCreationCancelCode::REFERENCED_BLOB_BROKEN;
+ break;
case BlobTransportResult::CANCEL_UNKNOWN:
- Send(new BlobStorageMsg_CancelBuildingBlob(
- uuid, IPCBlobCreationCancelCode::UNKNOWN));
- return;
+ cancel_code = mojom::BlobCreationCancelCode::UNKNOWN;
+ break;
case BlobTransportResult::PENDING_RESPONSES:
return;
case BlobTransportResult::DONE:
- Send(new BlobStorageMsg_DoneBuildingBlob(uuid));
- return;
+ new_blob = blob_bindings_.CreateInterfacePtrAndBind(this);
+ break;
+ default:
+ NOTREACHED();
+ break;
}
- NOTREACHED();
+
+ callback.Run(std::move(new_blob), cancel_code);
}
bool BlobDispatcherHost::IsInUseInHost(const std::string& uuid) {
« no previous file with comments | « content/browser/blob_storage/blob_dispatcher_host.h ('k') | content/child/blob_storage/blob_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698