diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-25 19:44:49 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-25 19:44:49 +0000 |
commit | 52785d4c507c7c1f997d8bac300d0e9c13ac6391 (patch) | |
tree | ccf53ad81ffece1e3c036661e41e4e7befc0ceed | |
parent | 7c9ae8ce124cf730b0ef45b43a3b0bba8d284998 (diff) | |
download | chromium_src-52785d4c507c7c1f997d8bac300d0e9c13ac6391.zip chromium_src-52785d4c507c7c1f997d8bac300d0e9c13ac6391.tar.gz chromium_src-52785d4c507c7c1f997d8bac300d0e9c13ac6391.tar.bz2 |
Add WebFileSystemImpl and 2nd cut of IPC plumbing code for Move operation.
Plumbing code for the remaining operations (Copy, Remove etc) will come later in a separate patch once this one becomes to look good.
BUG=32277
TESTS=none, will be added later
Review URL: http://codereview.chromium.org/3165040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57365 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/file_system/file_system_dispatcher_host.cc | 18 | ||||
-rw-r--r-- | chrome/browser/file_system/file_system_dispatcher_host.h | 7 | ||||
-rw-r--r-- | chrome/chrome_common.gypi | 5 | ||||
-rw-r--r-- | chrome/common/child_thread.cc | 4 | ||||
-rw-r--r-- | chrome/common/child_thread.h | 7 | ||||
-rw-r--r-- | chrome/common/file_system/file_system_dispatcher.cc | 62 | ||||
-rw-r--r-- | chrome/common/file_system/file_system_dispatcher.h | 48 | ||||
-rw-r--r-- | chrome/common/file_system/file_system_dispatcher_dummy.cc | 21 | ||||
-rw-r--r-- | chrome/common/file_system/webfilesystem_impl.cc | 62 | ||||
-rw-r--r-- | chrome/common/file_system/webfilesystem_impl.h | 57 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 13 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 2 | ||||
-rw-r--r-- | chrome/renderer/renderer_webkitclient_impl.cc | 10 | ||||
-rw-r--r-- | chrome/renderer/renderer_webkitclient_impl.h | 4 |
14 files changed, 315 insertions, 5 deletions
diff --git a/chrome/browser/file_system/file_system_dispatcher_host.cc b/chrome/browser/file_system/file_system_dispatcher_host.cc index 8b4b42c..3e23695 100644 --- a/chrome/browser/file_system/file_system_dispatcher_host.cc +++ b/chrome/browser/file_system/file_system_dispatcher_host.cc @@ -13,6 +13,7 @@ #include "chrome/common/render_messages.h" #include "chrome/common/render_messages_params.h" #include "googleurl/src/gurl.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFileError.h" FileSystemDispatcherHost::FileSystemDispatcherHost( IPC::Message::Sender* sender, @@ -44,6 +45,7 @@ bool FileSystemDispatcherHost::OnMessageReceived( bool handled = true; IPC_BEGIN_MESSAGE_MAP_EX(FileSystemDispatcherHost, message, *message_was_ok) IPC_MESSAGE_HANDLER(ViewHostMsg_OpenFileSystemRequest, OnOpenFileSystem) + IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Move, OnMove) // TODO(kinuko): add more. IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP_EX() @@ -58,10 +60,18 @@ void FileSystemDispatcherHost::OnOpenFileSystem( // TODO(kinuko): not implemented yet. Send(new ViewMsg_OpenFileSystemRequest_Complete( - params.routing_id, - params.request_id, - false, - name, root_path)); + params.routing_id, + params.request_id, + false, + name, root_path)); +} + +void FileSystemDispatcherHost::OnMove( + int request_id, const string16& src_path, const string16& dest_path) { + // TODO(kinuko): not implemented yet. + + Send(new ViewMsg_FileSystem_Failed( + request_id, WebKit::WebFileErrorAbort)); } void FileSystemDispatcherHost::Send(IPC::Message* message) { diff --git a/chrome/browser/file_system/file_system_dispatcher_host.h b/chrome/browser/file_system/file_system_dispatcher_host.h index dbe18a8..f756ebe 100644 --- a/chrome/browser/file_system/file_system_dispatcher_host.h +++ b/chrome/browser/file_system/file_system_dispatcher_host.h @@ -26,11 +26,18 @@ class FileSystemDispatcherHost bool OnMessageReceived(const IPC::Message& message, bool* message_was_ok); void OnOpenFileSystem(const ViewHostMsg_OpenFileSystemRequest_Params&); + void OnMove( + int request_id, + const string16& src_path, + const string16& dest_path); + // TODO(kinuko): add more methods. void Send(IPC::Message* message); private: + void Move(const string16& src, const string16& dest, int operation_id); + // The sender to be used for sending out IPC messages. IPC::Message::Sender* message_sender_; diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index 1f37f86..958d99e 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -52,6 +52,8 @@ 'common/devtools_messages.cc', 'common/devtools_messages.h', 'common/devtools_messages_internal.h', + 'common/file_system/webfilesystem_impl.cc', + 'common/file_system/webfilesystem_impl.h', 'common/font_descriptor_mac.h', 'common/font_descriptor_mac.mm', 'common/geoposition.cc', @@ -287,6 +289,8 @@ 'common/deprecated/event_sys-inl.h', 'common/deprecated/event_sys.h', 'common/dom_storage_common.h', + 'common/file_system/file_system_dispatcher.cc', + 'common/file_system/file_system_dispatcher.h', 'common/font_loader_mac.h', 'common/font_loader_mac.mm', 'common/gears_api.h', @@ -490,6 +494,7 @@ ], 'sources': [ '../webkit/glue/webkit_glue_dummy.cc', + 'common/file_system/file_system_dispatcher_dummy.cc', 'common/resource_dispatcher_dummy.cc', 'common/socket_stream_dispatcher_dummy.cc', 'common/url_constants.cc', diff --git a/chrome/common/child_thread.cc b/chrome/common/child_thread.cc index 126fc2b..8e6fbce 100644 --- a/chrome/common/child_thread.cc +++ b/chrome/common/child_thread.cc @@ -9,6 +9,7 @@ #include "base/command_line.h" #include "chrome/common/child_process.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/file_system/file_system_dispatcher.h" #include "chrome/common/notification_service.h" #include "chrome/common/plugin_messages.h" #include "chrome/common/resource_dispatcher.h" @@ -51,6 +52,7 @@ void ChildThread::Init() { resource_dispatcher_.reset(new ResourceDispatcher(this)); socket_stream_dispatcher_.reset(new SocketStreamDispatcher()); + file_system_dispatcher_.reset(new FileSystemDispatcher()); sync_message_filter_ = new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); @@ -138,6 +140,8 @@ void ChildThread::OnMessageReceived(const IPC::Message& msg) { return; if (socket_stream_dispatcher_->OnMessageReceived(msg)) return; + if (file_system_dispatcher_->OnMessageReceived(msg)) + return; bool handled = true; IPC_BEGIN_MESSAGE_MAP(ChildThread, msg) diff --git a/chrome/common/child_thread.h b/chrome/common/child_thread.h index 7f9c3f8..337a7f8 100644 --- a/chrome/common/child_thread.h +++ b/chrome/common/child_thread.h @@ -12,6 +12,7 @@ #include "ipc/ipc_message.h" #include "webkit/glue/resource_loader_bridge.h" +class FileSystemDispatcher; class MessageLoop; class NotificationService; class ResourceDispatcher; @@ -54,6 +55,10 @@ class ChildThread : public IPC::Channel::Listener, return socket_stream_dispatcher_.get(); } + FileSystemDispatcher* file_system_dispatcher() const { + return file_system_dispatcher_.get(); + } + // Safe to call on any thread, as long as it's guaranteed that the thread's // lifetime is less than the main thread. IPC::SyncMessageFilter* sync_message_filter(); @@ -118,6 +123,8 @@ class ChildThread : public IPC::Channel::Listener, scoped_ptr<NotificationService> notification_service_; + scoped_ptr<FileSystemDispatcher> file_system_dispatcher_; + DISALLOW_COPY_AND_ASSIGN(ChildThread); }; diff --git a/chrome/common/file_system/file_system_dispatcher.cc b/chrome/common/file_system/file_system_dispatcher.cc new file mode 100644 index 0000000..81361d5 --- /dev/null +++ b/chrome/common/file_system/file_system_dispatcher.cc @@ -0,0 +1,62 @@ +// Copyright (c) 2010 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 "chrome/common/file_system/file_system_dispatcher.h" + +#include "chrome/common/child_thread.h" +#include "chrome/common/render_messages.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h" +#include "webkit/glue/webkit_glue.h" + +using WebKit::WebFileError; +using WebKit::WebFileInfo; +using WebKit::WebFileSystemCallbacks; + +FileSystemDispatcher::FileSystemDispatcher() { +} + +FileSystemDispatcher::~FileSystemDispatcher() { + // Make sure we fire all the remaining callbacks. + for (IDMap<WebFileSystemCallbacks>::iterator iter(&callbacks_); + !iter.IsAtEnd(); + iter.Advance()) { + int callbacks_id = iter.GetCurrentKey(); + WebFileSystemCallbacks* callbacks = iter.GetCurrentValue(); + DCHECK(callbacks); + callbacks_.Remove(callbacks_id); + callbacks->didFail(WebKit::WebFileErrorAbort); + } +} + +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_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void FileSystemDispatcher::Move( + const string16& src_path, const string16& dest_path, + WebFileSystemCallbacks* callbacks) { + int request_id = callbacks_.Add(callbacks); + ChildThread::current()->Send( + new ViewHostMsg_FileSystem_Move(request_id, src_path, dest_path)); +} + +void FileSystemDispatcher::DidSucceed(int request_id) { + WebFileSystemCallbacks* callbacks = callbacks_.Lookup(request_id); + DCHECK(callbacks); + callbacks_.Remove(request_id); + callbacks->didSucceed(); +} + +void FileSystemDispatcher::DidFail(int request_id, int code) { + WebFileSystemCallbacks* callbacks = callbacks_.Lookup(request_id); + DCHECK(callbacks); + callbacks_.Remove(request_id); + callbacks->didFail(static_cast<WebFileError>(code)); +} diff --git a/chrome/common/file_system/file_system_dispatcher.h b/chrome/common/file_system/file_system_dispatcher.h new file mode 100644 index 0000000..5c854c2 --- /dev/null +++ b/chrome/common/file_system/file_system_dispatcher.h @@ -0,0 +1,48 @@ +// Copyright (c) 2010 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. + +#ifndef CHROME_COMMON_FILE_SYSTEM_FILE_SYSTEM_DISPATCHER_H_ +#define CHROME_COMMON_FILE_SYSTEM_FILE_SYSTEM_DISPATCHER_H_ + +#include <vector> + +#include "base/basictypes.h" +#include "base/id_map.h" +#include "base/nullable_string16.h" +#include "googleurl/src/gurl.h" +#include "ipc/ipc_channel.h" +#include "ipc/ipc_message.h" + +namespace WebKit { +class WebFileSystemCallbacks; +} + +// 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. +class FileSystemDispatcher { + public: + FileSystemDispatcher(); + ~FileSystemDispatcher(); + + bool OnMessageReceived(const IPC::Message& msg); + + void Move( + const string16& src_path, + const string16& dest_path, + WebKit::WebFileSystemCallbacks* callbacks); + + // TODO(kinuko): add more implementation. + + private: + void DidSucceed(int32 callbacks_id); + void DidFail(int32 callbacks_id, int code); + // TODO(kinuko): add more callbacks. + + IDMap<WebKit::WebFileSystemCallbacks> callbacks_; + + DISALLOW_COPY_AND_ASSIGN(FileSystemDispatcher); +}; + +#endif // CHROME_COMMON_FILE_SYSTEM_FILE_SYSTEM_DISPATCHER_H_ diff --git a/chrome/common/file_system/file_system_dispatcher_dummy.cc b/chrome/common/file_system/file_system_dispatcher_dummy.cc new file mode 100644 index 0000000..a7c8c71 --- /dev/null +++ b/chrome/common/file_system/file_system_dispatcher_dummy.cc @@ -0,0 +1,21 @@ +// Copyright (c) 2010 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 "chrome/common/file_system/file_system_dispatcher.h" + +#include "base/compiler_specific.h" + +// FileSystemDispatcher -------------------------------------------------------- + +FileSystemDispatcher::FileSystemDispatcher() { +} + +FileSystemDispatcher::~FileSystemDispatcher() { +} + +// FileSystemDispatcher implementation ----------------------------------------- + +bool FileSystemDispatcher::OnMessageReceived(const IPC::Message& message) { + return false; +} diff --git a/chrome/common/file_system/webfilesystem_impl.cc b/chrome/common/file_system/webfilesystem_impl.cc new file mode 100644 index 0000000..a9aa346 --- /dev/null +++ b/chrome/common/file_system/webfilesystem_impl.cc @@ -0,0 +1,62 @@ +// Copyright (c) 2010 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 "chrome/common/file_system/webfilesystem_impl.h" + +#include "chrome/common/file_system/file_system_dispatcher.h" +#include "chrome/common/child_thread.h" + +using WebKit::WebString; +using WebKit::WebFileSystemCallbacks; + +WebFileSystemImpl::WebFileSystemImpl() { +} + +void WebFileSystemImpl::move(const WebString& src_path, + const WebString& dest_path, WebFileSystemCallbacks* callbacks) { + FileSystemDispatcher* dispatcher = + ChildThread::current()->file_system_dispatcher(); + dispatcher->Move(src_path, dest_path, callbacks); +} + +void WebFileSystemImpl::copy(const WebKit::WebString& src_path, + const WebKit::WebString& dest_path, + WebKit::WebFileSystemCallbacks* callbacks) { + // TODO(kinuko): not implemented yet. +} + +void WebFileSystemImpl::remove(const WebString& path, + WebFileSystemCallbacks* callbacks) { + // TODO(kinuko): not implemented yet. +} + +void WebFileSystemImpl::readMetadata(const WebString& path, + WebFileSystemCallbacks* callbacks) { + // TODO(kinuko): not implemented yet. +} + +void WebFileSystemImpl::createFile(const WebString& path, + bool exclusive, WebFileSystemCallbacks* callbacks) { + // TODO(kinuko): not implemented yet. +} + +void WebFileSystemImpl::createDirectory(const WebString& path, + bool exclusive, WebFileSystemCallbacks* callbacks) { + // TODO(kinuko): not implemented yet. +} + +void WebFileSystemImpl::fileExists(const WebString& path, + WebFileSystemCallbacks* callbacks) { + // TODO(kinuko): not implemented yet. +} + +void WebFileSystemImpl::directoryExists(const WebString& path, + WebFileSystemCallbacks* callbacks) { + // TODO(kinuko): not implemented yet. +} + +void WebFileSystemImpl::readDirectory(const WebString& path, + WebFileSystemCallbacks* callbacks) { + // TODO(kinuko): not implemented yet. +} diff --git a/chrome/common/file_system/webfilesystem_impl.h b/chrome/common/file_system/webfilesystem_impl.h new file mode 100644 index 0000000..8ca67ab --- /dev/null +++ b/chrome/common/file_system/webfilesystem_impl.h @@ -0,0 +1,57 @@ +// Copyright (c) 2010 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. + +#ifndef CHROME_COMMON_FILE_SYSTEM_WEBFILESYSTEM_IMPL_H_ +#define CHROME_COMMON_FILE_SYSTEM_WEBFILESYSTEM_IMPL_H_ + +#include "base/basictypes.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" + +class WebFileSystemImpl : public WebKit::WebFileSystem { + public: + WebFileSystemImpl(); + virtual ~WebFileSystemImpl() { } + + virtual void move( + const WebKit::WebString& src_path, + const WebKit::WebString& dest_path, + WebKit::WebFileSystemCallbacks*); + + virtual void copy( + const WebKit::WebString& src_path, + const WebKit::WebString& dest_path, + WebKit::WebFileSystemCallbacks*); + + virtual void remove( + const WebKit::WebString& path, + WebKit::WebFileSystemCallbacks*); + + virtual void readMetadata( + const WebKit::WebString& path, + WebKit::WebFileSystemCallbacks*); + + virtual void createFile( + const WebKit::WebString& path, + bool exclusive, + WebKit::WebFileSystemCallbacks*); + + virtual void createDirectory( + const WebKit::WebString& path, + bool exclusive, + WebKit::WebFileSystemCallbacks*); + + virtual void fileExists( + const WebKit::WebString& path, + WebKit::WebFileSystemCallbacks*); + + virtual void directoryExists( + const WebKit::WebString& path, + WebKit::WebFileSystemCallbacks*); + + virtual void readDirectory( + const WebKit::WebString& path, + WebKit::WebFileSystemCallbacks*); +}; + +#endif // CHROME_COMMON_FILE_SYSTEM_WEBFILESYSTEM_IMPL_H_ diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 1527854..14e1166 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -1009,6 +1009,13 @@ IPC_BEGIN_MESSAGES(View) string16 /* name */, string16 /* root_path */) + // WebFileSystem response messages. + IPC_MESSAGE_CONTROL1(ViewMsg_FileSystem_Succeeded, + int /* request_id */) + IPC_MESSAGE_CONTROL2(ViewMsg_FileSystem_Failed, + int /* request_id */, + int /* error_code */) + IPC_END_MESSAGES(View) @@ -2696,4 +2703,10 @@ IPC_BEGIN_MESSAGES(ViewHost) IPC_MESSAGE_CONTROL1(ViewHostMsg_OpenFileSystemRequest, ViewHostMsg_OpenFileSystemRequest_Params) + // WebFileSystem::move() message. + IPC_MESSAGE_CONTROL3(ViewHostMsg_FileSystem_Move, + int /* request_id */, + string16 /* src path */, + string16 /* dest path */) + IPC_END_MESSAGES(ViewHost) diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index eb8a0ff..326acac 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -551,7 +551,7 @@ class RenderView : public RenderWidget, const WebKit::WebRect& sel); virtual void openFileSystem(WebKit::WebFrame* frame, - WebKit::WebFileSystem::Type, + WebKit::WebFileSystem::Type type, long long size, WebKit::WebFileSystemCallbacks* callbacks); diff --git a/chrome/renderer/renderer_webkitclient_impl.cc b/chrome/renderer/renderer_webkitclient_impl.cc index b87c19d..0eaef37 100644 --- a/chrome/renderer/renderer_webkitclient_impl.cc +++ b/chrome/renderer/renderer_webkitclient_impl.cc @@ -11,6 +11,7 @@ #include "base/utf_string_conversions.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/database_util.h" +#include "chrome/common/file_system/webfilesystem_impl.h" #include "chrome/common/render_messages.h" #include "chrome/common/webmessageportchannel_impl.h" #include "chrome/plugin/npobject_util.h" @@ -59,6 +60,7 @@ #include "base/file_descriptor_posix.h" #endif +using WebKit::WebFileSystem; using WebKit::WebFrame; using WebKit::WebIDBFactory; using WebKit::WebKitClient; @@ -282,6 +284,14 @@ WebIDBFactory* RendererWebKitClientImpl::idbFactory() { //------------------------------------------------------------------------------ +WebFileSystem* RendererWebKitClientImpl::fileSystem() { + if (!web_file_system_.get()) + web_file_system_.reset(new WebFileSystemImpl()); + return web_file_system_.get(); +} + +//------------------------------------------------------------------------------ + WebString RendererWebKitClientImpl::MimeRegistry::mimeTypeForExtension( const WebString& file_extension) { if (IsPluginProcess()) diff --git a/chrome/renderer/renderer_webkitclient_impl.h b/chrome/renderer/renderer_webkitclient_impl.h index 5af8815..cc1149c 100644 --- a/chrome/renderer/renderer_webkitclient_impl.h +++ b/chrome/renderer/renderer_webkitclient_impl.h @@ -11,6 +11,7 @@ #include "webkit/glue/webkitclient_impl.h" class WebSharedWorkerRepositoryImpl; +class WebFileSystemImpl; namespace IPC { class SyncMessage; @@ -61,6 +62,7 @@ class RendererWebKitClientImpl : public webkit_glue::WebKitClientImpl { const WebKit::WebString& challenge, const WebKit::WebURL& url); virtual WebKit::WebIDBFactory* idbFactory(); + virtual WebKit::WebFileSystem* fileSystem(); virtual WebKit::WebSharedWorkerRepository* sharedWorkerRepository(); virtual WebKit::WebGraphicsContext3D* createGraphicsContext3D(); @@ -94,6 +96,8 @@ class RendererWebKitClientImpl : public webkit_glue::WebKitClientImpl { scoped_ptr<WebSharedWorkerRepositoryImpl> shared_worker_repository_; scoped_ptr<WebKit::WebIDBFactory> web_idb_factory_; + + scoped_ptr<WebFileSystemImpl> web_file_system_; }; #endif // CHROME_RENDERER_RENDERER_WEBKITCLIENT_IMPL_H_ |