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

Unified Diff: content/browser/fileapi/fileapi_message_filter.cc

Issue 15817013: Add Stream support to WebBlobRegistry and FileAPIMessageFilter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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/fileapi/fileapi_message_filter.cc
diff --git a/content/browser/fileapi/fileapi_message_filter.cc b/content/browser/fileapi/fileapi_message_filter.cc
index 312e04dd4fd479c19c911cdf6cfa195e574d5308..368e55f7b6d993ea5c4986bd759c39935a4744bb 100644
--- a/content/browser/fileapi/fileapi_message_filter.cc
+++ b/content/browser/fileapi/fileapi_message_filter.cc
@@ -9,14 +9,17 @@
#include "base/bind.h"
#include "base/files/file_path.h"
+#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/platform_file.h"
#include "base/sequenced_task_runner.h"
+#include "base/strings/string_util.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/fileapi/browser_file_system_helper.h"
#include "content/browser/fileapi/chrome_blob_storage_context.h"
+#include "content/browser/streams/stream_registry.h"
#include "content/common/fileapi/file_system_messages.h"
#include "content/common/fileapi/webblob_messages.h"
#include "content/public/browser/user_metrics.h"
@@ -64,29 +67,35 @@ FileAPIMessageFilter::FileAPIMessageFilter(
int process_id,
net::URLRequestContextGetter* request_context_getter,
fileapi::FileSystemContext* file_system_context,
- ChromeBlobStorageContext* blob_storage_context)
+ ChromeBlobStorageContext* blob_storage_context,
+ StreamContext* stream_context)
: process_id_(process_id),
context_(file_system_context),
request_context_getter_(request_context_getter),
request_context_(NULL),
- blob_storage_context_(blob_storage_context) {
+ blob_storage_context_(blob_storage_context),
+ stream_context_(stream_context) {
DCHECK(context_);
DCHECK(request_context_getter_.get());
DCHECK(blob_storage_context);
+ DCHECK(stream_context);
}
FileAPIMessageFilter::FileAPIMessageFilter(
int process_id,
net::URLRequestContext* request_context,
fileapi::FileSystemContext* file_system_context,
- ChromeBlobStorageContext* blob_storage_context)
+ ChromeBlobStorageContext* blob_storage_context,
+ StreamContext* stream_context)
: process_id_(process_id),
context_(file_system_context),
request_context_(request_context),
- blob_storage_context_(blob_storage_context) {
+ blob_storage_context_(blob_storage_context),
+ stream_context_(stream_context) {
DCHECK(context_);
DCHECK(request_context_);
DCHECK(blob_storage_context);
+ DCHECK(stream_context);
}
void FileAPIMessageFilter::OnChannelConnected(int32 peer_pid) {
@@ -103,12 +112,16 @@ void FileAPIMessageFilter::OnChannelConnected(int32 peer_pid) {
void FileAPIMessageFilter::OnChannelClosing() {
BrowserMessageFilter::OnChannelClosing();
- // Unregister all the blob URLs that are previously registered in this
- // process.
+ // Unregister all the blob and stream URLs that are previously registered in
+ // this process.
for (base::hash_set<std::string>::const_iterator iter = blob_urls_.begin();
iter != blob_urls_.end(); ++iter) {
blob_storage_context_->controller()->RemoveBlob(GURL(*iter));
}
+ for (base::hash_set<std::string>::const_iterator iter = stream_urls_.begin();
+ iter != stream_urls_.end(); ++iter) {
+ stream_context_->registry()->UnregisterStream(GURL(*iter));
+ }
in_transit_snapshot_files_.clear();
@@ -167,13 +180,22 @@ bool FileAPIMessageFilter::OnMessageReceived(
IPC_MESSAGE_HANDLER(FileSystemHostMsg_DidUpdate, OnDidUpdate)
IPC_MESSAGE_HANDLER(FileSystemHostMsg_SyncGetPlatformPath,
OnSyncGetPlatformPath)
- IPC_MESSAGE_HANDLER(BlobHostMsg_StartBuildingBlob, OnStartBuildingBlob)
- IPC_MESSAGE_HANDLER(BlobHostMsg_AppendBlobDataItem, OnAppendBlobDataItem)
+ IPC_MESSAGE_HANDLER(BlobHostMsg_StartBuilding, OnStartBuildingBlob)
+ IPC_MESSAGE_HANDLER(BlobHostMsg_AppendBlobDataItem,
+ OnAppendBlobDataItemToBlob)
IPC_MESSAGE_HANDLER(BlobHostMsg_SyncAppendSharedMemory,
- OnAppendSharedMemory)
- IPC_MESSAGE_HANDLER(BlobHostMsg_FinishBuildingBlob, OnFinishBuildingBlob)
- IPC_MESSAGE_HANDLER(BlobHostMsg_CloneBlob, OnCloneBlob)
- IPC_MESSAGE_HANDLER(BlobHostMsg_RemoveBlob, OnRemoveBlob)
+ OnAppendSharedMemoryToBlob)
+ IPC_MESSAGE_HANDLER(BlobHostMsg_FinishBuilding, OnFinishBuildingBlob)
+ IPC_MESSAGE_HANDLER(BlobHostMsg_Clone, OnCloneBlob)
+ IPC_MESSAGE_HANDLER(BlobHostMsg_Remove, OnRemoveBlob)
+ IPC_MESSAGE_HANDLER(StreamHostMsg_StartBuilding, OnStartBuildingStream)
+ IPC_MESSAGE_HANDLER(StreamHostMsg_AppendBlobDataItem,
+ OnAppendBlobDataItemToStream)
+ IPC_MESSAGE_HANDLER(StreamHostMsg_SyncAppendSharedMemory,
+ OnAppendSharedMemoryToStream)
+ IPC_MESSAGE_HANDLER(StreamHostMsg_FinishBuilding, OnFinishBuildingStream)
+ IPC_MESSAGE_HANDLER(StreamHostMsg_Clone, OnCloneStream)
+ IPC_MESSAGE_HANDLER(StreamHostMsg_Remove, OnRemoveStream)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP_EX()
return handled;
@@ -519,7 +541,7 @@ void FileAPIMessageFilter::OnStartBuildingBlob(const GURL& url) {
blob_urls_.insert(url.spec());
}
-void FileAPIMessageFilter::OnAppendBlobDataItem(
+void FileAPIMessageFilter::OnAppendBlobDataItemToBlob(
const GURL& url, const BlobData::Item& item) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (item.type() == BlobData::Item::TYPE_FILE_FILESYSTEM) {
@@ -544,7 +566,7 @@ void FileAPIMessageFilter::OnAppendBlobDataItem(
blob_storage_context_->controller()->AppendBlobDataItem(url, item);
}
-void FileAPIMessageFilter::OnAppendSharedMemory(
+void FileAPIMessageFilter::OnAppendSharedMemoryToBlob(
const GURL& url, base::SharedMemoryHandle handle, size_t buffer_size) {
DCHECK(base::SharedMemory::IsHandleValid(handle));
if (!buffer_size) {
@@ -586,6 +608,105 @@ void FileAPIMessageFilter::OnRemoveBlob(const GURL& url) {
blob_urls_.erase(url.spec());
}
+// Currently |content_type| is ignored inside Chromium.
+//
+// TODO(tyoshino): Set |content_type| to the stream.
kinuko 2013/07/24 13:11:05 nit: I think common comment style is to have metho
tyoshino (SeeGerritForStatus) 2013/07/24 13:56:22 Moved to .h thanks
tyoshino (SeeGerritForStatus) 2013/07/25 04:03:52 Oops. Removal was not applied yet. Done again.
+void FileAPIMessageFilter::OnStartBuildingStream(
+ const GURL& url, const std::string& content_type) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ // Only an internal Blob URL is expected here. See the BlobURL of the Blink.
+ if (!StartsWithASCII(
+ url.path(), "blobinternal%3A///", true /* case_sensitive */)) {
+ NOTREACHED() << "Malformed Stream URL: " << url.path();
+ BadMessageReceived();
+ return;
+ }
+ // Use an empty security origin for now. Stream accepts a security origin
+ // but how it's handled is not fixed yet.
+ new Stream(stream_context_->registry(),
+ NULL /* write_observer */,
+ GURL(),
+ url);
+ stream_urls_.insert(url.spec());
+}
+
+void FileAPIMessageFilter::OnAppendBlobDataItemToStream(
+ const GURL& url, const BlobData::Item& item) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ scoped_refptr<Stream> stream(GetStreamForURL(url));
+ if (!stream.get()) {
+ NOTREACHED();
+ return;
+ }
+
+ // Data for stream is delivered as TYPE_BYTES item.
+ if (item.type() != BlobData::Item::TYPE_BYTES) {
+ BadMessageReceived();
+ return;
+ }
+ stream->AddData(item.bytes(), item.length());
+}
+
+void FileAPIMessageFilter::OnAppendSharedMemoryToStream(
+ const GURL& url, base::SharedMemoryHandle handle, size_t buffer_size) {
+ DCHECK(base::SharedMemory::IsHandleValid(handle));
+ if (!buffer_size) {
+ BadMessageReceived();
+ return;
+ }
+#if defined(OS_WIN)
+ base::SharedMemory shared_memory(handle, true, PeerHandle());
+#else
+ base::SharedMemory shared_memory(handle, true);
+#endif
+ if (!shared_memory.Map(buffer_size)) {
+ OnRemoveStream(url);
+ return;
+ }
+
+ scoped_refptr<Stream> stream(GetStreamForURL(url));
+ if (!stream.get()) {
+ NOTREACHED();
+ return;
+ }
+
+ stream->AddData(static_cast<char*>(shared_memory.memory()), buffer_size);
+}
+
+void FileAPIMessageFilter::OnFinishBuildingStream(const GURL& url) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ scoped_refptr<Stream> stream(GetStreamForURL(url));
+ if (stream.get())
+ stream->Finalize();
+ else
+ NOTREACHED();
+}
+
+void FileAPIMessageFilter::OnCloneStream(
+ const GURL& url, const GURL& src_url) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ if (!GetStreamForURL(src_url)) {
+ NOTREACHED();
+ return;
+ }
+
+ stream_context_->registry()->CloneStream(url, src_url);
+ stream_urls_.insert(url.spec());
+}
+
+void FileAPIMessageFilter::OnRemoveStream(const GURL& url) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ if (!GetStreamForURL(url).get()) {
+ NOTREACHED();
+ return;
+ }
+
+ stream_context_->registry()->UnregisterStream(url);
+ stream_urls_.erase(url.spec());
+}
+
void FileAPIMessageFilter::DidFinish(int request_id,
base::PlatformFileError result) {
if (result == base::PLATFORM_FILE_OK)
@@ -738,6 +859,10 @@ bool FileAPIMessageFilter::HasPermissionsForFile(
permissions, error);
}
+scoped_refptr<Stream> FileAPIMessageFilter::GetStreamForURL(const GURL& url) {
+ return stream_context_->registry()->GetStream(url);
+}
+
fileapi::FileSystemOperationRunner* FileAPIMessageFilter::operation_runner() {
return context_->operation_runner();
}
« no previous file with comments | « content/browser/fileapi/fileapi_message_filter.h ('k') | content/browser/fileapi/fileapi_message_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698