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

Unified Diff: content/child/fileapi/webfilesystem_impl.cc

Issue 21041003: Implement Worker-MainThread bridge for FileWriter in Chrome (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
« no previous file with comments | « no previous file | content/child/fileapi/webfilewriter_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/fileapi/webfilesystem_impl.cc
diff --git a/content/child/fileapi/webfilesystem_impl.cc b/content/child/fileapi/webfilesystem_impl.cc
index e253a17ccb9a85bebf9f0bb2f1b20499df823087..090bf7d79740e3aed851a4d40ce564b622b45aea 100644
--- a/content/child/fileapi/webfilesystem_impl.cc
+++ b/content/child/fileapi/webfilesystem_impl.cc
@@ -94,19 +94,6 @@ class CallbacksMap : public WorkerTaskRunner::Observer {
DISALLOW_COPY_AND_ASSIGN(CallbacksMap);
};
-void DidReadMetadataForCreateFileWriter(
- const GURL& path,
- WebKit::WebFileWriterClient* client,
- WebKit::WebFileSystemCallbacks* callbacks,
- const base::PlatformFileInfo& file_info) {
- if (file_info.is_directory || file_info.size < 0) {
- callbacks->didFail(WebKit::WebFileErrorInvalidState);
- return;
- }
- callbacks->didCreateFileWriter(new WebFileWriterImpl(path, client),
- file_info.size);
-}
-
void DidReceiveSnapshotFile(int request_id) {
if (ChildThread::current())
ChildThread::current()->Send(
@@ -195,6 +182,37 @@ void ReadDirectoryCallbackAdapater(
MakeTuple(file_system_entries, has_more));
}
+void CreateFileWriterCallbackAdapter(
+ int thread_id, int callbacks_id,
+ base::MessageLoopProxy* main_thread_loop,
+ const GURL& path,
+ WebKit::WebFileWriterClient* client,
+ const base::PlatformFileInfo& file_info) {
+ if (thread_id != CurrentWorkerId()) {
+ WorkerTaskRunner::Instance()->PostTask(
+ thread_id,
+ base::Bind(&CreateFileWriterCallbackAdapter,
+ thread_id, callbacks_id,
+ make_scoped_refptr(main_thread_loop),
+ path, client, file_info));
+ return;
+ }
+
+ if (!CallbacksMap::Get())
+ return;
+
+ WebFileSystemCallbacks* callbacks =
+ CallbacksMap::Get()->GetAndUnregisterCallbacks(callbacks_id);
+ DCHECK(callbacks);
+
+ if (file_info.is_directory || file_info.size < 0) {
+ callbacks->didFail(WebKit::WebFileErrorInvalidState);
+ return;
+ }
+ callbacks->didCreateFileWriter(
+ new WebFileWriterImpl(path, client, main_thread_loop), file_info.size);
+}
+
void CreateSnapshotFileCallbackAdapter(
int thread_id, int callbacks_id,
base::MessageLoopProxy* main_thread_loop,
@@ -368,22 +386,23 @@ void WebFileSystemImpl::readDirectory(
WebKit::WebFileWriter* WebFileSystemImpl::createFileWriter(
const WebURL& path, WebKit::WebFileWriterClient* client) {
- return new WebFileWriterImpl(GURL(path), client);
+ return new WebFileWriterImpl(GURL(path), client, main_thread_loop_.get());
}
void WebFileSystemImpl::createFileWriter(
const WebURL& path,
WebKit::WebFileWriterClient* client,
WebKit::WebFileSystemCallbacks* callbacks) {
- // TODO(kinuko): Convert this method to use bridge model. (crbug.com/257349)
- DCHECK(main_thread_loop_->RunsTasksOnCurrentThread());
- FileSystemDispatcher* dispatcher =
- ChildThread::current()->file_system_dispatcher();
- dispatcher->ReadMetadata(
- GURL(path),
- base::Bind(&DidReadMetadataForCreateFileWriter,
- GURL(path), client, callbacks),
- base::Bind(&FileStatusCallbackAdapter, callbacks));
+ int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks);
+ CallDispatcherOnMainThread(
+ main_thread_loop_.get(),
+ &FileSystemDispatcher::ReadMetadata,
+ MakeTuple(GURL(path),
+ base::Bind(&CreateFileWriterCallbackAdapter,
+ CurrentWorkerId(), callbacks_id, main_thread_loop_,
+ GURL(path), client),
+ base::Bind(&StatusCallbackAdapter,
+ CurrentWorkerId(), callbacks_id)));
}
void WebFileSystemImpl::createSnapshotFileAndReadMetadata(
« no previous file with comments | « no previous file | content/child/fileapi/webfilewriter_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698