diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-30 22:15:41 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-30 22:15:41 +0000 |
commit | 6239dc641a11eeb997035a1d8f862b9781f702ed (patch) | |
tree | 7f7f0f991a791094f273439dc586cb4adcf9eeeb /chrome/common/file_system | |
parent | f4b02f03aa240394296067a3b84ecc8543133d66 (diff) | |
download | chromium_src-6239dc641a11eeb997035a1d8f862b9781f702ed.zip chromium_src-6239dc641a11eeb997035a1d8f862b9781f702ed.tar.gz chromium_src-6239dc641a11eeb997035a1d8f862b9781f702ed.tar.bz2 |
Add final part of IPC plumbing for FileSystem API.
BUG=32277
TEST=none; to be added when we have complete implementation.
Review URL: http://codereview.chromium.org/3208007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57915 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/file_system')
-rw-r--r-- | chrome/common/file_system/file_system_dispatcher.cc | 87 | ||||
-rw-r--r-- | chrome/common/file_system/file_system_dispatcher.h | 45 | ||||
-rw-r--r-- | chrome/common/file_system/webfilesystem_impl.cc | 32 |
3 files changed, 147 insertions, 17 deletions
diff --git a/chrome/common/file_system/file_system_dispatcher.cc b/chrome/common/file_system/file_system_dispatcher.cc index 81361d5..f7022e1 100644 --- a/chrome/common/file_system/file_system_dispatcher.cc +++ b/chrome/common/file_system/file_system_dispatcher.cc @@ -4,14 +4,21 @@ #include "chrome/common/file_system/file_system_dispatcher.h" +#include "base/file_util.h" #include "chrome/common/child_thread.h" #include "chrome/common/render_messages.h" +#include "chrome/common/render_messages_params.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFileInfo.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFileSystemEntry.h" #include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h" +#include "third_party/WebKit/WebKit/chromium/public/WebVector.h" #include "webkit/glue/webkit_glue.h" using WebKit::WebFileError; using WebKit::WebFileInfo; using WebKit::WebFileSystemCallbacks; +using WebKit::WebFileSystemEntry; +using WebKit::WebVector; FileSystemDispatcher::FileSystemDispatcher() { } @@ -32,8 +39,10 @@ FileSystemDispatcher::~FileSystemDispatcher() { bool FileSystemDispatcher::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(FileSystemDispatcher, msg) - IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_Succeeded, DidSucceed) - IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_Failed, DidFail) + IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidSucceed, DidSucceed) + IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidReadDirectory, DidReadDirectory) + IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidReadMetadata, DidReadMetadata) + IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidFail, DidFail) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; @@ -47,6 +56,52 @@ void FileSystemDispatcher::Move( new ViewHostMsg_FileSystem_Move(request_id, src_path, dest_path)); } +void FileSystemDispatcher::Copy( + const string16& src_path, const string16& dest_path, + WebFileSystemCallbacks* callbacks) { + int request_id = callbacks_.Add(callbacks); + ChildThread::current()->Send( + new ViewHostMsg_FileSystem_Copy(request_id, src_path, dest_path)); +} + +void FileSystemDispatcher::Remove( + const string16& path, WebFileSystemCallbacks* callbacks) { + int request_id = callbacks_.Add(callbacks); + ChildThread::current()->Send( + new ViewHostMsg_FileSystem_Remove(request_id, path)); +} + +void FileSystemDispatcher::ReadMetadata( + const string16& path, WebFileSystemCallbacks* callbacks) { + int request_id = callbacks_.Add(callbacks); + ChildThread::current()->Send( + new ViewHostMsg_FileSystem_ReadMetadata(request_id, path)); +} + +void FileSystemDispatcher::Create( + const string16& path, bool exclusive, bool is_directory, + WebFileSystemCallbacks* callbacks) { + int request_id = callbacks_.Add(callbacks); + ChildThread::current()->Send( + new ViewHostMsg_FileSystem_Create(request_id, path, exclusive, + is_directory)); +} + +void FileSystemDispatcher::Exists( + const string16& path, bool is_directory, + WebFileSystemCallbacks* callbacks) { + int request_id = callbacks_.Add(callbacks); + ChildThread::current()->Send( + new ViewHostMsg_FileSystem_Exists(request_id, path, is_directory)); +} + +void FileSystemDispatcher::ReadDirectory( + const string16& path, WebFileSystemCallbacks* callbacks) { + int request_id = callbacks_.Add(callbacks); + ChildThread::current()->Send( + new ViewHostMsg_FileSystem_ReadDirectory(request_id, path)); +} + void FileSystemDispatcher::DidSucceed(int request_id) { WebFileSystemCallbacks* callbacks = callbacks_.Lookup(request_id); DCHECK(callbacks); @@ -54,9 +109,33 @@ void FileSystemDispatcher::DidSucceed(int request_id) { callbacks->didSucceed(); } -void FileSystemDispatcher::DidFail(int request_id, int code) { +void FileSystemDispatcher::DidReadMetadata(int request_id, + const file_util::FileInfo& file_info) { + WebFileSystemCallbacks* callbacks = callbacks_.Lookup(request_id); + DCHECK(callbacks); + callbacks_.Remove(request_id); + WebFileInfo web_file_info; + web_file_info.modificationTime = file_info.last_modified.ToDoubleT(); + callbacks->didReadMetadata(web_file_info); +} + +void FileSystemDispatcher::DidReadDirectory( + const ViewMsg_FileSystem_DidReadDirectory_Params& params) { + WebFileSystemCallbacks* callbacks = callbacks_.Lookup(params.request_id); + DCHECK(callbacks); + if (!params.has_more) + callbacks_.Remove(params.request_id); + WebVector<WebFileSystemEntry> entries(params.entries.size()); + for (size_t i = 0; i < params.entries.size(); ++i) { + entries[i].name = webkit_glue::FilePathToWebString(params.entries[i].name); + entries[i].isDirectory = params.entries[i].is_directory; + } + callbacks->didReadDirectory(entries, params.has_more); +} + +void FileSystemDispatcher::DidFail(int request_id, WebFileError code) { WebFileSystemCallbacks* callbacks = callbacks_.Lookup(request_id); DCHECK(callbacks); callbacks_.Remove(request_id); - callbacks->didFail(static_cast<WebFileError>(code)); + callbacks->didFail(code); } diff --git a/chrome/common/file_system/file_system_dispatcher.h b/chrome/common/file_system/file_system_dispatcher.h index 5c854c2..70855d1 100644 --- a/chrome/common/file_system/file_system_dispatcher.h +++ b/chrome/common/file_system/file_system_dispatcher.h @@ -13,11 +13,20 @@ #include "googleurl/src/gurl.h" #include "ipc/ipc_channel.h" #include "ipc/ipc_message.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFileError.h" namespace WebKit { +struct WebFileInfo; class WebFileSystemCallbacks; +struct WebFileSystemEntry; } +namespace file_util { +struct FileInfo; +} + +struct ViewMsg_FileSystem_DidReadDirectory_Params; + // Dispatches and sends file system related messages sent to/from a child // process from/to the main browser process. There is one instance // per child process. Messages are dispatched on the main child thread. @@ -32,13 +41,39 @@ class FileSystemDispatcher { const string16& src_path, const string16& dest_path, WebKit::WebFileSystemCallbacks* callbacks); - - // TODO(kinuko): add more implementation. + void Copy( + const string16& src_path, + const string16& dest_path, + WebKit::WebFileSystemCallbacks* callbacks); + void Remove( + const string16& path, + WebKit::WebFileSystemCallbacks* callbacks); + void ReadMetadata( + const string16& path, + WebKit::WebFileSystemCallbacks* callbacks); + void Create( + const string16& path, + bool exclusive, + bool for_directory, + WebKit::WebFileSystemCallbacks* callbacks); + void Exists( + const string16& path, + bool for_directory, + WebKit::WebFileSystemCallbacks* callbacks); + void ReadDirectory( + const string16& path, + WebKit::WebFileSystemCallbacks* callbacks); private: - void DidSucceed(int32 callbacks_id); - void DidFail(int32 callbacks_id, int code); - // TODO(kinuko): add more callbacks. + void DidSucceed(int request_id); + void DidReadMetadata( + int request_id, + const file_util::FileInfo& file_info); + void DidReadDirectory( + const ViewMsg_FileSystem_DidReadDirectory_Params& params); + void DidFail( + int request_id, + WebKit::WebFileError); IDMap<WebKit::WebFileSystemCallbacks> callbacks_; diff --git a/chrome/common/file_system/webfilesystem_impl.cc b/chrome/common/file_system/webfilesystem_impl.cc index a9aa346..49a07d6 100644 --- a/chrome/common/file_system/webfilesystem_impl.cc +++ b/chrome/common/file_system/webfilesystem_impl.cc @@ -23,40 +23,56 @@ void WebFileSystemImpl::move(const WebString& src_path, void WebFileSystemImpl::copy(const WebKit::WebString& src_path, const WebKit::WebString& dest_path, WebKit::WebFileSystemCallbacks* callbacks) { - // TODO(kinuko): not implemented yet. + FileSystemDispatcher* dispatcher = + ChildThread::current()->file_system_dispatcher(); + dispatcher->Copy(src_path, dest_path, callbacks); } void WebFileSystemImpl::remove(const WebString& path, WebFileSystemCallbacks* callbacks) { - // TODO(kinuko): not implemented yet. + FileSystemDispatcher* dispatcher = + ChildThread::current()->file_system_dispatcher(); + dispatcher->Remove(path, callbacks); } void WebFileSystemImpl::readMetadata(const WebString& path, WebFileSystemCallbacks* callbacks) { - // TODO(kinuko): not implemented yet. + FileSystemDispatcher* dispatcher = + ChildThread::current()->file_system_dispatcher(); + dispatcher->ReadMetadata(path, callbacks); } void WebFileSystemImpl::createFile(const WebString& path, bool exclusive, WebFileSystemCallbacks* callbacks) { - // TODO(kinuko): not implemented yet. + FileSystemDispatcher* dispatcher = + ChildThread::current()->file_system_dispatcher(); + dispatcher->Create(path, exclusive, false, callbacks); } void WebFileSystemImpl::createDirectory(const WebString& path, bool exclusive, WebFileSystemCallbacks* callbacks) { - // TODO(kinuko): not implemented yet. + FileSystemDispatcher* dispatcher = + ChildThread::current()->file_system_dispatcher(); + dispatcher->Create(path, exclusive, true, callbacks); } void WebFileSystemImpl::fileExists(const WebString& path, WebFileSystemCallbacks* callbacks) { - // TODO(kinuko): not implemented yet. + FileSystemDispatcher* dispatcher = + ChildThread::current()->file_system_dispatcher(); + dispatcher->Exists(path, false, callbacks); } void WebFileSystemImpl::directoryExists(const WebString& path, WebFileSystemCallbacks* callbacks) { - // TODO(kinuko): not implemented yet. + FileSystemDispatcher* dispatcher = + ChildThread::current()->file_system_dispatcher(); + dispatcher->Exists(path, true, callbacks); } void WebFileSystemImpl::readDirectory(const WebString& path, WebFileSystemCallbacks* callbacks) { - // TODO(kinuko): not implemented yet. + FileSystemDispatcher* dispatcher = + ChildThread::current()->file_system_dispatcher(); + dispatcher->ReadDirectory(path, callbacks); } |