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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..21f95d370d3f8e21eac2334675a3b856cf4e2932 |
| --- /dev/null |
| +++ b/content/browser/blob_storage/blob_dispatcher_host.cc |
| @@ -0,0 +1,132 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/blob_storage/blob_dispatcher_host.h" |
| + |
| +#include "base/bind.h" |
| +#include "content/browser/fileapi/blob_storage_host.h" |
| +#include "content/browser/fileapi/chrome_blob_storage_context.h" |
| +#include "content/common/fileapi/webblob_messages.h" |
| +#include "storage/browser/blob/blob_storage_context.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" |
| +#include "url/gurl.h" |
| + |
| +namespace content { |
| + |
| +BlobDispatcherHost::BlobDispatcherHost( |
| + int process_id, |
| + ChromeBlobStorageContext* blob_storage_context) |
| + : BrowserMessageFilter(BlobMsgStart), |
| + process_id_(process_id), |
| + blob_storage_context_(blob_storage_context) {} |
| + |
| +BlobDispatcherHost::~BlobDispatcherHost() {} |
| + |
| +void BlobDispatcherHost::OnChannelConnected(int32 peer_pid) { |
| + blob_storage_host_.reset( |
| + new BlobStorageHost(blob_storage_context_->context())); |
| +} |
| + |
| +void BlobDispatcherHost::OnChannelClosing() { |
| + // Unregister all the blobs that are previously registered in this process. |
| + blob_storage_host_.reset(); |
| +} |
| + |
| +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) |
| + IPC_MESSAGE_HANDLER(BlobHostMsg_RevokePublicURL, OnRevokePublicBlobURL) |
| + IPC_MESSAGE_UNHANDLED(handled = false) |
| + IPC_END_MESSAGE_MAP() |
| + return handled; |
| +} |
| + |
| +void BlobDispatcherHost::OnRegisterBlobUUID(const std::string& uuid) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + blob_storage_host_->RegisterBlobUUID(uuid); |
| +} |
| + |
| +void BlobDispatcherHost::OnStartBuildingBlob( |
| + const std::string& uuid, |
| + const std::string& type, |
| + const std::vector<storage::DataElement>& descriptions) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + blob_storage_host_->StartBuildingBlob( |
| + uuid, type, descriptions, |
| + base::Bind(&BlobDispatcherHost::SendMemoryRequest, this, uuid), |
| + base::Bind(&BlobDispatcherHost::BlobDoneBuilding, this, uuid), |
| + base::Bind(&BlobDispatcherHost::CancelBlob, this, uuid)); |
| +} |
| + |
| +void BlobDispatcherHost::OnMemoryItemResponse( |
| + const std::string& uuid, |
| + const std::vector<storage::BlobItemBytesResponse>& responses) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + blob_storage_host_->OnBlobMemoryResponses(uuid, responses); |
| +} |
| + |
| +void BlobDispatcherHost::OnCancelBuildingBlob( |
| + const std::string& uuid, |
| + const storage::IPCBlobCreationCancelCode code) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + VLOG(1) << "Blob construction of " << uuid << " cancelled by renderer. " |
| + << " Reason: " << static_cast<int>(code) << "."; |
| + blob_storage_host_->CancelBuildingBlob(uuid); |
| +} |
| + |
| +void BlobDispatcherHost::OnIncrementBlobRefCount(const std::string& uuid) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + blob_storage_host_->IncrementBlobRefCount(uuid); |
| +} |
| + |
| +void BlobDispatcherHost::OnDecrementBlobRefCount(const std::string& uuid) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + blob_storage_host_->DecrementBlobRefCount(uuid); |
| +} |
| + |
| +void BlobDispatcherHost::OnRegisterPublicBlobURL(const GURL& public_url, |
| + const std::string& uuid) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + blob_storage_host_->RegisterPublicBlobURL(public_url, uuid); |
| +} |
| + |
| +void BlobDispatcherHost::OnRevokePublicBlobURL(const GURL& public_url) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + blob_storage_host_->RevokePublicBlobURL(public_url); |
| +} |
| + |
| +void BlobDispatcherHost::SendMemoryRequest( |
| + const std::string& uuid, |
| + const std::vector<storage::BlobItemBytesRequest>& requests, |
| + const std::vector<base::SharedMemoryHandle>& memory_handles, |
| + const std::vector<IPC::PlatformFileForTransit>& file_handles) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + Send(new BlobStorageMsg_RequestMemoryItem(uuid, requests, memory_handles, |
| + file_handles)); |
| +} |
| + |
| +void BlobDispatcherHost::CancelBlob( |
| + const std::string& uuid, |
| + const storage::IPCBlobCreationCancelCode code) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + // Ensure we don't have any state lying around (if we cancelled the build) |
| + blob_storage_host_->CancelBuildingBlob(uuid); |
| + Send(new BlobStorageMsg_CancelBuildingBlob(uuid, code)); |
| +} |
| + |
| +void BlobDispatcherHost::BlobDoneBuilding(const std::string& uuid) { |
|
kinuko
2015/12/13 08:41:44
nit: DoneBuildingBlob ?
dmurph
2015/12/18 03:22:49
Removed.
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + Send(new BlobStorageMsg_DoneBuildingBlob(uuid)); |
| +} |
| + |
| +} // namespace content |