summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorericu@google.com <ericu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-24 01:06:00 +0000
committerericu@google.com <ericu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-24 01:06:00 +0000
commitac716267efc98d9fcdf9c3c22b10e6a9d8a9dbc8 (patch)
tree83a2b5f323ab94ae9ce25eea6f3b50c87f3b1353
parent09618270d0997bd325786d19182202ccb80fa945 (diff)
downloadchromium_src-ac716267efc98d9fcdf9c3c22b10e6a9d8a9dbc8.zip
chromium_src-ac716267efc98d9fcdf9c3c22b10e6a9d8a9dbc8.tar.gz
chromium_src-ac716267efc98d9fcdf9c3c22b10e6a9d8a9dbc8.tar.bz2
This is the IPC and bits of the browser backend for FileWriter. The rest of
it's too tied together to include a small amount; this is the most-significant chunk that I could put up without making too big a changelist. The backend isn't complete, but you can see where it's going from here. BUG=none TEST=none Review URL: http://codereview.chromium.org/3440021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60396 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/file_system/browser_file_system_callback_dispatcher.cc9
-rw-r--r--chrome/browser/file_system/browser_file_system_callback_dispatcher.h1
-rw-r--r--chrome/browser/file_system/file_system_dispatcher_host.cc36
-rw-r--r--chrome/browser/file_system/file_system_dispatcher_host.h7
-rw-r--r--chrome/common/render_messages_internal.h24
-rw-r--r--webkit/fileapi/file_system_operation.cc48
-rw-r--r--webkit/fileapi/file_system_operation.h16
-rw-r--r--webkit/tools/test_shell/simple_file_system.cc4
8 files changed, 144 insertions, 1 deletions
diff --git a/chrome/browser/file_system/browser_file_system_callback_dispatcher.cc b/chrome/browser/file_system/browser_file_system_callback_dispatcher.cc
index 107515e..129d4a7 100644
--- a/chrome/browser/file_system/browser_file_system_callback_dispatcher.cc
+++ b/chrome/browser/file_system/browser_file_system_callback_dispatcher.cc
@@ -43,3 +43,12 @@ void BrowserFileSystemCallbackDispatcher::DidFail(
request_id_, error_code));
dispatcher_host_->RemoveCompletedOperation(request_id_);
}
+
+void BrowserFileSystemCallbackDispatcher::DidWrite(
+ int64 bytes,
+ bool complete) {
+ dispatcher_host_->Send(new ViewMsg_FileSystem_DidWrite(
+ request_id_, bytes, complete));
+ if (complete)
+ dispatcher_host_->RemoveCompletedOperation(request_id_);
+}
diff --git a/chrome/browser/file_system/browser_file_system_callback_dispatcher.h b/chrome/browser/file_system/browser_file_system_callback_dispatcher.h
index 0372e09..075ae30 100644
--- a/chrome/browser/file_system/browser_file_system_callback_dispatcher.h
+++ b/chrome/browser/file_system/browser_file_system_callback_dispatcher.h
@@ -24,6 +24,7 @@ class BrowserFileSystemCallbackDispatcher
virtual void DidOpenFileSystem(const string16& name,
const FilePath& root_path);
virtual void DidFail(base::PlatformFileError error_code);
+ virtual void DidWrite(int64 bytes, bool complete);
private:
scoped_refptr<FileSystemDispatcherHost> dispatcher_host_;
diff --git a/chrome/browser/file_system/file_system_dispatcher_host.cc b/chrome/browser/file_system/file_system_dispatcher_host.cc
index 385f2a4..5cfa5be 100644
--- a/chrome/browser/file_system/file_system_dispatcher_host.cc
+++ b/chrome/browser/file_system/file_system_dispatcher_host.cc
@@ -115,6 +115,9 @@ bool FileSystemDispatcherHost::OnMessageReceived(
IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Create, OnCreate)
IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Exists, OnExists)
IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_ReadDirectory, OnReadDirectory)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Write, OnWrite)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Truncate, OnTruncate)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_CancelWrite, OnCancel)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP_EX()
return handled;
@@ -206,6 +209,39 @@ void FileSystemDispatcherHost::OnReadDirectory(
GetNewOperation(request_id)->ReadDirectory(path);
}
+void FileSystemDispatcherHost::OnWrite(
+ int request_id,
+ const FilePath& path,
+ const GURL& blob_url,
+ int64 offset) {
+ if (!CheckValidFileSystemPath(path, request_id))
+ return;
+ GetNewOperation(request_id)->Write(path, blob_url, offset);
+}
+
+void FileSystemDispatcherHost::OnTruncate(
+ int request_id,
+ const FilePath& path,
+ int64 length) {
+ if (!CheckValidFileSystemPath(path, request_id))
+ return;
+ GetNewOperation(request_id)->Truncate(path, length);
+}
+
+void FileSystemDispatcherHost::OnCancel(
+ int request_id,
+ int request_id_to_cancel) {
+ fileapi::FileSystemOperation* write =
+ operations_.Lookup(request_id_to_cancel);
+ if (write) {
+ write->Cancel();
+ Send(new ViewMsg_FileSystem_DidSucceed(request_id));
+ } else {
+ Send(new ViewMsg_FileSystem_DidFail(
+ request_id, base::PLATFORM_FILE_ERROR_INVALID_OPERATION));
+ }
+}
+
void FileSystemDispatcherHost::Send(IPC::Message* message) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
if (!shutdown_ && message_sender_)
diff --git a/chrome/browser/file_system/file_system_dispatcher_host.h b/chrome/browser/file_system/file_system_dispatcher_host.h
index ac22255..561350c 100644
--- a/chrome/browser/file_system/file_system_dispatcher_host.h
+++ b/chrome/browser/file_system/file_system_dispatcher_host.h
@@ -17,6 +17,7 @@
#include "webkit/fileapi/file_system_operation.h"
class FileSystemHostContext;
+class GURL;
class HostContentSettingsMap;
class Receiver;
class ResourceMessageFilter;
@@ -49,6 +50,12 @@ class FileSystemDispatcherHost
bool recursive);
void OnExists(int request_id, const FilePath& path, bool is_directory);
void OnReadDirectory(int request_id, const FilePath& path);
+ void OnWrite(int request_id,
+ const FilePath& path,
+ const GURL& blob_url,
+ int64 offset);
+ void OnTruncate(int request_id, const FilePath& path, int64 length);
+ void OnCancel(int request_id, int request_to_cancel);
void Send(IPC::Message* message);
void RemoveCompletedOperation(int request_id);
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index 6437c05..9662d1c 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -1046,6 +1046,10 @@ IPC_BEGIN_MESSAGES(View)
std::vector<base::file_util_proxy::Entry> /* entries */,
bool /* has_more */)
+ IPC_MESSAGE_CONTROL3(ViewMsg_FileSystem_DidWrite,
+ int /* request_id */,
+ int64 /* byte count */,
+ bool /* complete */)
IPC_MESSAGE_CONTROL2(ViewMsg_FileSystem_DidFail,
int /* request_id */,
base::PlatformFileError /* error_code */)
@@ -2184,7 +2188,7 @@ IPC_BEGIN_MESSAGES(ViewHost)
// processes (SharedWorkers are shut down when their last associated document
// is detached).
IPC_MESSAGE_CONTROL1(ViewHostMsg_DocumentDetached,
- unsigned long long /* document_id */)
+ uint64 /* document_id */)
// A message sent to the browser on behalf of a renderer which wants to show
// a desktop notification.
@@ -2856,6 +2860,24 @@ IPC_BEGIN_MESSAGES(ViewHost)
int /* request_id */,
FilePath /* path */)
+ // WebFileWriter::write() message.
+ IPC_MESSAGE_CONTROL4(ViewHostMsg_FileSystem_Write,
+ int /* request id */,
+ FilePath /* file path */,
+ GURL /* blob URL */,
+ int64 /* position */)
+
+ // WebFileWriter::truncate() message.
+ IPC_MESSAGE_CONTROL3(ViewHostMsg_FileSystem_Truncate,
+ int /* request id */,
+ FilePath /* file path */,
+ int64 /* length */)
+
+ // WebFileWriter::cancel() message.
+ IPC_MESSAGE_CONTROL2(ViewHostMsg_FileSystem_CancelWrite,
+ int /* request id */,
+ int /* id of request to cancel */)
+
//---------------------------------------------------------------------------
// Blob messages:
diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc
index dba9881..ffe5e5f 100644
--- a/webkit/fileapi/file_system_operation.cc
+++ b/webkit/fileapi/file_system_operation.cc
@@ -4,6 +4,7 @@
#include "webkit/fileapi/file_system_operation.h"
+#include "googleurl/src/gurl.h"
#include "webkit/fileapi/file_system_callback_dispatcher.h"
namespace fileapi {
@@ -125,6 +126,43 @@ void FileSystemOperation::Remove(const FilePath& path) {
&FileSystemOperation::DidFinishFileOperation));
}
+
+void FileSystemOperation::Write(
+ const FilePath&,
+ const GURL&,
+ int64) {
+#ifndef NDEBUG
+ DCHECK(!operation_pending_);
+ operation_pending_ = true;
+#endif
+ NOTREACHED();
+ // TODO(ericu):
+ // Set up a loop that, via multiple callback invocations, reads from a
+ // URLRequest wrapping blob_url, writes the bytes to the file, reports
+ // progress events no more frequently than some set rate, and periodically
+ // checks to see if it's been cancelled.
+}
+
+void FileSystemOperation::Truncate(const FilePath& path, int64 length) {
+#ifndef NDEBUG
+ DCHECK(!operation_pending_);
+ operation_pending_ = true;
+#endif
+ // TODO(ericu):
+ NOTREACHED();
+}
+
+void FileSystemOperation::Cancel() {
+#ifndef NDEBUG
+ DCHECK(operation_pending_);
+#endif
+ NOTREACHED();
+ // TODO(ericu):
+ // Make sure this was done on a FileSystemOperation used for a Write.
+ // Then set a flag that ensures that the Write loop will exit without
+ // reporting any more progress, with a failure notification.
+}
+
void FileSystemOperation::DidCreateFileExclusive(
base::PlatformFileError rv,
base::PassPlatformFile file,
@@ -194,4 +232,14 @@ void FileSystemOperation::DidReadDirectory(
dispatcher_->DidFail(rv);
}
+void FileSystemOperation::DidWrite(
+ base::PlatformFileError rv,
+ int64 bytes,
+ bool complete) {
+ if (rv == base::PLATFORM_FILE_OK)
+ /* dispatcher_->DidWrite(bytes, complete) TODO(ericu): Coming soon. */ {}
+ else
+ dispatcher_->DidFail(rv);
+}
+
} // namespace fileapi
diff --git a/webkit/fileapi/file_system_operation.h b/webkit/fileapi/file_system_operation.h
index 5df4d4d..e1058a3 100644
--- a/webkit/fileapi/file_system_operation.h
+++ b/webkit/fileapi/file_system_operation.h
@@ -15,6 +15,8 @@
#include "base/scoped_callback_factory.h"
#include "base/scoped_ptr.h"
+class GURL;
+
namespace fileapi {
class FileSystemCallbackDispatcher;
@@ -55,6 +57,15 @@ class FileSystemOperation {
void Remove(const FilePath& path);
+ void Write(
+ const FilePath& path, const GURL& blob_url, int64 offset);
+
+ void Truncate(const FilePath& path, int64 length);
+
+ // Used to attempt to cancel the current operation. This currently does
+ // nothing for any operation other than Write().
+ void Cancel();
+
protected:
// Proxy for calling file_util_proxy methods.
scoped_refptr<base::MessageLoopProxy> proxy_;
@@ -84,6 +95,11 @@ class FileSystemOperation {
base::PlatformFileError rv,
const std::vector<base::file_util_proxy::Entry>& entries);
+ void DidWrite(
+ base::PlatformFileError rv,
+ int64 bytes,
+ bool complete);
+
scoped_ptr<FileSystemCallbackDispatcher> dispatcher_;
base::ScopedCallbackFactory<FileSystemOperation> callback_factory_;
diff --git a/webkit/tools/test_shell/simple_file_system.cc b/webkit/tools/test_shell/simple_file_system.cc
index 0b76758..370c8d4 100644
--- a/webkit/tools/test_shell/simple_file_system.cc
+++ b/webkit/tools/test_shell/simple_file_system.cc
@@ -92,6 +92,10 @@ class TestShellFileSystemCallbackDispatcher
file_system_->RemoveCompletedOperation(request_id_);
}
+ virtual void DidWrite(int64, bool, fileapi::FileSystemOperation*) {
+ NOTREACHED();
+ }
+
private:
SimpleFileSystem* file_system_;
WebFileSystemCallbacks* callbacks_;