summaryrefslogtreecommitdiffstats
path: root/chrome/common/file_system
diff options
context:
space:
mode:
authordumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-22 03:29:14 +0000
committerdumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-22 03:29:14 +0000
commit5746640f419fe2b493ed4e97aa473e96f73c8d73 (patch)
tree63b222962eb9c5ea5d230d8add24fe72e6281386 /chrome/common/file_system
parentae236193f7b64659caf81ba2a009f8ff4e947693 (diff)
downloadchromium_src-5746640f419fe2b493ed4e97aa473e96f73c8d73.zip
chromium_src-5746640f419fe2b493ed4e97aa473e96f73c8d73.tar.gz
chromium_src-5746640f419fe2b493ed4e97aa473e96f73c8d73.tar.bz2
Refactor some file_system classes to use chromium types instead of
WebKit API types. BUG=none TEST=none Review URL: http://codereview.chromium.org/3406008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60152 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/file_system')
-rw-r--r--chrome/common/file_system/file_system_dispatcher.cc177
-rw-r--r--chrome/common/file_system/file_system_dispatcher.h70
-rw-r--r--chrome/common/file_system/webfilesystem_impl.cc133
3 files changed, 223 insertions, 157 deletions
diff --git a/chrome/common/file_system/file_system_dispatcher.cc b/chrome/common/file_system/file_system_dispatcher.cc
index 89a2de4..8ae0c16 100644
--- a/chrome/common/file_system/file_system_dispatcher.cc
+++ b/chrome/common/file_system/file_system_dispatcher.cc
@@ -8,31 +8,20 @@
#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() {
}
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);
+ for (IDMap<fileapi::FileSystemCallbackDispatcher, IDMapOwnPointer>::iterator
+ iter(&dispatchers_); !iter.IsAtEnd(); iter.Advance()) {
+ int request_id = iter.GetCurrentKey();
+ fileapi::FileSystemCallbackDispatcher* dispatcher = iter.GetCurrentValue();
+ DCHECK(dispatcher);
+ dispatcher->DidFail(base::PLATFORM_FILE_ERROR_ABORT);
+ dispatchers_.Remove(request_id);
}
}
@@ -48,103 +37,101 @@ bool FileSystemDispatcher::OnMessageReceived(const IPC::Message& msg) {
return handled;
}
-void FileSystemDispatcher::Move(
- const string16& src_path, const string16& dest_path,
- WebFileSystemCallbacks* callbacks) {
- FilePath src_file_path = webkit_glue::WebStringToFilePath(src_path);
- FilePath dest_file_path = webkit_glue::WebStringToFilePath(dest_path);
- int request_id = callbacks_.Add(callbacks);
- ChildThread::current()->Send(new ViewHostMsg_FileSystem_Move(
- request_id, src_file_path, dest_file_path));
+bool FileSystemDispatcher::Move(
+ const FilePath& src_path,
+ const FilePath& dest_path,
+ fileapi::FileSystemCallbackDispatcher* dispatcher) {
+ int request_id = dispatchers_.Add(dispatcher);
+ return ChildThread::current()->Send(new ViewHostMsg_FileSystem_Move(
+ request_id, src_path, dest_path));
}
-void FileSystemDispatcher::Copy(
- const string16& src_path, const string16& dest_path,
- WebFileSystemCallbacks* callbacks) {
- FilePath src_file_path = webkit_glue::WebStringToFilePath(src_path);
- FilePath dest_file_path = webkit_glue::WebStringToFilePath(dest_path);
- int request_id = callbacks_.Add(callbacks);
- ChildThread::current()->Send(new ViewHostMsg_FileSystem_Copy(
- request_id, src_file_path, dest_file_path));
+bool FileSystemDispatcher::Copy(
+ const FilePath& src_path,
+ const FilePath& dest_path,
+ fileapi::FileSystemCallbackDispatcher* dispatcher) {
+ int request_id = dispatchers_.Add(dispatcher);
+ return ChildThread::current()->Send(new ViewHostMsg_FileSystem_Copy(
+ request_id, src_path, dest_path));
}
-void FileSystemDispatcher::Remove(
- const string16& path, WebFileSystemCallbacks* callbacks) {
- FilePath file_path = webkit_glue::WebStringToFilePath(path);
- int request_id = callbacks_.Add(callbacks);
- ChildThread::current()->Send(
- new ViewHostMsg_FileSystem_Remove(request_id, file_path));
+bool FileSystemDispatcher::Remove(
+ const FilePath& path,
+ fileapi::FileSystemCallbackDispatcher* dispatcher) {
+ int request_id = dispatchers_.Add(dispatcher);
+ return ChildThread::current()->Send(
+ new ViewHostMsg_FileSystem_Remove(request_id, path));
}
-void FileSystemDispatcher::ReadMetadata(
- const string16& path, WebFileSystemCallbacks* callbacks) {
- FilePath file_path = webkit_glue::WebStringToFilePath(path);
- int request_id = callbacks_.Add(callbacks);
- ChildThread::current()->Send(
- new ViewHostMsg_FileSystem_ReadMetadata(request_id, file_path));
+bool FileSystemDispatcher::ReadMetadata(
+ const FilePath& path,
+ fileapi::FileSystemCallbackDispatcher* dispatcher) {
+ int request_id = dispatchers_.Add(dispatcher);
+ return ChildThread::current()->Send(
+ new ViewHostMsg_FileSystem_ReadMetadata(request_id, path));
}
-void FileSystemDispatcher::Create(
- const string16& path, bool exclusive, bool is_directory,
- WebFileSystemCallbacks* callbacks) {
- FilePath file_path = webkit_glue::WebStringToFilePath(path);
- int request_id = callbacks_.Add(callbacks);
- ChildThread::current()->Send(new ViewHostMsg_FileSystem_Create(
- request_id, file_path, exclusive, is_directory));
+bool FileSystemDispatcher::Create(
+ const FilePath& path,
+ bool exclusive,
+ bool is_directory,
+ bool recursive,
+ fileapi::FileSystemCallbackDispatcher* dispatcher) {
+ int request_id = dispatchers_.Add(dispatcher);
+ return ChildThread::current()->Send(new ViewHostMsg_FileSystem_Create(
+ request_id, path, exclusive, is_directory, recursive));
}
-void FileSystemDispatcher::Exists(
- const string16& path, bool is_directory,
- WebFileSystemCallbacks* callbacks) {
- FilePath file_path = webkit_glue::WebStringToFilePath(path);
- int request_id = callbacks_.Add(callbacks);
- ChildThread::current()->Send(
- new ViewHostMsg_FileSystem_Exists(request_id, file_path, is_directory));
+bool FileSystemDispatcher::Exists(
+ const FilePath& path,
+ bool is_directory,
+ fileapi::FileSystemCallbackDispatcher* dispatcher) {
+ int request_id = dispatchers_.Add(dispatcher);
+ return ChildThread::current()->Send(
+ new ViewHostMsg_FileSystem_Exists(request_id, path, is_directory));
}
-void FileSystemDispatcher::ReadDirectory(
- const string16& path, WebFileSystemCallbacks* callbacks) {
- FilePath file_path = webkit_glue::WebStringToFilePath(path);
- int request_id = callbacks_.Add(callbacks);
- ChildThread::current()->Send(
- new ViewHostMsg_FileSystem_ReadDirectory(request_id, file_path));
+bool FileSystemDispatcher::ReadDirectory(
+ const FilePath& path,
+ fileapi::FileSystemCallbackDispatcher* dispatcher) {
+ int request_id = dispatchers_.Add(dispatcher);
+ return ChildThread::current()->Send(
+ new ViewHostMsg_FileSystem_ReadDirectory(request_id, path));
}
void FileSystemDispatcher::DidSucceed(int request_id) {
- WebFileSystemCallbacks* callbacks = callbacks_.Lookup(request_id);
- DCHECK(callbacks);
- callbacks_.Remove(request_id);
- callbacks->didSucceed();
+ fileapi::FileSystemCallbackDispatcher* dispatcher =
+ dispatchers_.Lookup(request_id);
+ DCHECK(dispatcher);
+ dispatcher->DidSucceed();
+ dispatchers_.Remove(request_id);
}
-void FileSystemDispatcher::DidReadMetadata(int request_id,
- const base::PlatformFileInfo& 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::DidReadMetadata(
+ int request_id, const base::PlatformFileInfo& file_info) {
+ fileapi::FileSystemCallbackDispatcher* dispatcher =
+ dispatchers_.Lookup(request_id);
+ DCHECK(dispatcher);
+ dispatcher->DidReadMetadata(file_info);
+ dispatchers_.Remove(request_id);
}
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::FilePathStringToWebString(
- params.entries[i].name);
- entries[i].isDirectory = params.entries[i].is_directory;
- }
- callbacks->didReadDirectory(entries, params.has_more);
+ int request_id,
+ const std::vector<base::file_util_proxy::Entry>& entries,
+ bool has_more) {
+ fileapi::FileSystemCallbackDispatcher* dispatcher =
+ dispatchers_.Lookup(request_id);
+ DCHECK(dispatcher);
+ dispatcher->DidReadDirectory(entries, has_more);
+ dispatchers_.Remove(request_id);
}
-void FileSystemDispatcher::DidFail(int request_id, WebFileError code) {
- WebFileSystemCallbacks* callbacks = callbacks_.Lookup(request_id);
- DCHECK(callbacks);
- callbacks_.Remove(request_id);
- callbacks->didFail(code);
+void FileSystemDispatcher::DidFail(
+ int request_id, base::PlatformFileError error_code) {
+ fileapi::FileSystemCallbackDispatcher* dispatcher =
+ dispatchers_.Lookup(request_id);
+ DCHECK(dispatcher);
+ dispatcher->DidFail(error_code);
+ dispatchers_.Remove(request_id);
}
diff --git a/chrome/common/file_system/file_system_dispatcher.h b/chrome/common/file_system/file_system_dispatcher.h
index 6fb9db5..8214b1c 100644
--- a/chrome/common/file_system/file_system_dispatcher.h
+++ b/chrome/common/file_system/file_system_dispatcher.h
@@ -8,24 +8,19 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/file_util_proxy.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"
-#include "third_party/WebKit/WebKit/chromium/public/WebFileError.h"
-
-namespace WebKit {
-struct WebFileInfo;
-class WebFileSystemCallbacks;
-struct WebFileSystemEntry;
-}
+#include "webkit/fileapi/file_system_callback_dispatcher.h"
namespace base {
struct PlatformFileInfo;
}
-struct ViewMsg_FileSystem_DidReadDirectory_Params;
+class FilePath;
// Dispatches and sends file system related messages sent to/from a child
// process from/to the main browser process. There is one instance
@@ -37,45 +32,38 @@ class FileSystemDispatcher {
bool OnMessageReceived(const IPC::Message& msg);
- void Move(
- const string16& src_path,
- const string16& dest_path,
- WebKit::WebFileSystemCallbacks* callbacks);
- 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);
+ bool Move(const FilePath& src_path,
+ const FilePath& dest_path,
+ fileapi::FileSystemCallbackDispatcher* dispatcher);
+ bool Copy(const FilePath& src_path,
+ const FilePath& dest_path,
+ fileapi::FileSystemCallbackDispatcher* dispatcher);
+ bool Remove(const FilePath& path,
+ fileapi::FileSystemCallbackDispatcher* dispatcher);
+ bool ReadMetadata(const FilePath& path,
+ fileapi::FileSystemCallbackDispatcher* dispatcher);
+ bool Create(const FilePath& path,
+ bool exclusive,
+ bool is_directory,
+ bool recursive,
+ fileapi::FileSystemCallbackDispatcher* dispatcher);
+ bool Exists(const FilePath& path,
+ bool for_directory,
+ fileapi::FileSystemCallbackDispatcher* dispatcher);
+ bool ReadDirectory(const FilePath& path,
+ fileapi::FileSystemCallbackDispatcher* dispatcher);
private:
void DidSucceed(int request_id);
- void DidReadMetadata(
- int request_id,
- const base::PlatformFileInfo& file_info);
+ void DidReadMetadata(int request_id,
+ const base::PlatformFileInfo& file_info);
void DidReadDirectory(
- const ViewMsg_FileSystem_DidReadDirectory_Params& params);
- void DidFail(
int request_id,
- WebKit::WebFileError);
+ const std::vector<base::file_util_proxy::Entry>& entries,
+ bool has_more);
+ void DidFail(int request_id, base::PlatformFileError error_code);
- IDMap<WebKit::WebFileSystemCallbacks> callbacks_;
+ IDMap<fileapi::FileSystemCallbackDispatcher, IDMapOwnPointer> dispatchers_;
DISALLOW_COPY_AND_ASSIGN(FileSystemDispatcher);
};
diff --git a/chrome/common/file_system/webfilesystem_impl.cc b/chrome/common/file_system/webfilesystem_impl.cc
index 49a07d6..546ed25 100644
--- a/chrome/common/file_system/webfilesystem_impl.cc
+++ b/chrome/common/file_system/webfilesystem_impl.cc
@@ -6,73 +6,164 @@
#include "chrome/common/file_system/file_system_dispatcher.h"
#include "chrome/common/child_thread.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebFileInfo.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
+#include "webkit/glue/webkit_glue.h"
-using WebKit::WebString;
+using WebKit::WebFileInfo;
using WebKit::WebFileSystemCallbacks;
+using WebKit::WebFileSystemEntry;
+using WebKit::WebString;
+using WebKit::WebVector;
+
+namespace {
+
+WebKit::WebFileError PlatformFileErrorToWebFileError(
+ base::PlatformFileError error_code) {
+ switch (error_code) {
+ case base::PLATFORM_FILE_ERROR_NOT_FOUND:
+ return WebKit::WebFileErrorNotFound;
+ case base::PLATFORM_FILE_ERROR_INVALID_OPERATION:
+ case base::PLATFORM_FILE_ERROR_EXISTS:
+ case base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY:
+ return WebKit::WebFileErrorInvalidModification;
+ case base::PLATFORM_FILE_ERROR_ACCESS_DENIED:
+ return WebKit::WebFileErrorNoModificationAllowed;
+ case base::PLATFORM_FILE_ERROR_FAILED:
+ return WebKit::WebFileErrorInvalidState;
+ case base::PLATFORM_FILE_ERROR_ABORT:
+ return WebKit::WebFileErrorAbort;
+ default:
+ return WebKit::WebFileErrorInvalidModification;
+ }
+}
+
+class WebFileSystemCallbackDispatcherImpl
+ : public fileapi::FileSystemCallbackDispatcher {
+ public:
+ explicit WebFileSystemCallbackDispatcherImpl(
+ WebFileSystemCallbacks* callbacks)
+ : callbacks_(callbacks) {
+ DCHECK(callbacks_);
+ }
+
+ virtual ~WebFileSystemCallbackDispatcherImpl() {
+ }
+
+ // FileSystemCallbackDispatcher implementation
+ virtual void DidSucceed() {
+ callbacks_->didSucceed();
+ }
+
+ virtual void DidReadMetadata(const base::PlatformFileInfo& file_info) {
+ WebFileInfo web_file_info;
+ web_file_info.modificationTime = file_info.last_modified.ToDoubleT();
+ callbacks_->didReadMetadata(web_file_info);
+ }
+
+ virtual void DidReadDirectory(
+ const std::vector<base::file_util_proxy::Entry>& entries, bool has_more) {
+ WebVector<WebFileSystemEntry> file_system_entries(entries.size());
+ for (size_t i = 0; i < entries.size(); i++) {
+ file_system_entries[i].name =
+ webkit_glue::FilePathStringToWebString(entries[i].name);
+ file_system_entries[i].isDirectory = entries[i].is_directory;
+ }
+ callbacks_->didReadDirectory(file_system_entries, has_more);
+ }
+
+ virtual void DidOpenFileSystem(const string16&, const FilePath&) {
+ NOTREACHED();
+ }
+
+ virtual void DidFail(base::PlatformFileError error_code) {
+ callbacks_->didFail(PlatformFileErrorToWebFileError(error_code));
+ }
+
+ private:
+ WebFileSystemCallbacks* callbacks_;
+};
+
+} // namespace
WebFileSystemImpl::WebFileSystemImpl() {
}
void WebFileSystemImpl::move(const WebString& src_path,
- const WebString& dest_path, WebFileSystemCallbacks* callbacks) {
+ const WebString& dest_path,
+ WebFileSystemCallbacks* callbacks) {
FileSystemDispatcher* dispatcher =
ChildThread::current()->file_system_dispatcher();
- dispatcher->Move(src_path, dest_path, callbacks);
+ dispatcher->Move(webkit_glue::WebStringToFilePath(src_path),
+ webkit_glue::WebStringToFilePath(dest_path),
+ new WebFileSystemCallbackDispatcherImpl(callbacks));
}
-void WebFileSystemImpl::copy(const WebKit::WebString& src_path,
- const WebKit::WebString& dest_path,
- WebKit::WebFileSystemCallbacks* callbacks) {
+void WebFileSystemImpl::copy(const WebString& src_path,
+ const WebString& dest_path,
+ WebFileSystemCallbacks* callbacks) {
FileSystemDispatcher* dispatcher =
ChildThread::current()->file_system_dispatcher();
- dispatcher->Copy(src_path, dest_path, callbacks);
+ dispatcher->Copy(webkit_glue::WebStringToFilePath(src_path),
+ webkit_glue::WebStringToFilePath(dest_path),
+ new WebFileSystemCallbackDispatcherImpl(callbacks));
}
void WebFileSystemImpl::remove(const WebString& path,
- WebFileSystemCallbacks* callbacks) {
+ WebFileSystemCallbacks* callbacks) {
FileSystemDispatcher* dispatcher =
ChildThread::current()->file_system_dispatcher();
- dispatcher->Remove(path, callbacks);
+ dispatcher->Remove(webkit_glue::WebStringToFilePath(path),
+ new WebFileSystemCallbackDispatcherImpl(callbacks));
}
void WebFileSystemImpl::readMetadata(const WebString& path,
- WebFileSystemCallbacks* callbacks) {
+ WebFileSystemCallbacks* callbacks) {
FileSystemDispatcher* dispatcher =
ChildThread::current()->file_system_dispatcher();
- dispatcher->ReadMetadata(path, callbacks);
+ dispatcher->ReadMetadata(webkit_glue::WebStringToFilePath(path),
+ new WebFileSystemCallbackDispatcherImpl(callbacks));
}
void WebFileSystemImpl::createFile(const WebString& path,
- bool exclusive, WebFileSystemCallbacks* callbacks) {
+ bool exclusive,
+ WebFileSystemCallbacks* callbacks) {
FileSystemDispatcher* dispatcher =
ChildThread::current()->file_system_dispatcher();
- dispatcher->Create(path, exclusive, false, callbacks);
+ dispatcher->Create(webkit_glue::WebStringToFilePath(path), exclusive, false,
+ false, new WebFileSystemCallbackDispatcherImpl(callbacks));
}
void WebFileSystemImpl::createDirectory(const WebString& path,
- bool exclusive, WebFileSystemCallbacks* callbacks) {
+ bool exclusive,
+ WebFileSystemCallbacks* callbacks) {
FileSystemDispatcher* dispatcher =
ChildThread::current()->file_system_dispatcher();
- dispatcher->Create(path, exclusive, true, callbacks);
+ dispatcher->Create(webkit_glue::WebStringToFilePath(path), exclusive, true,
+ false, new WebFileSystemCallbackDispatcherImpl(callbacks));
}
void WebFileSystemImpl::fileExists(const WebString& path,
- WebFileSystemCallbacks* callbacks) {
+ WebFileSystemCallbacks* callbacks) {
FileSystemDispatcher* dispatcher =
ChildThread::current()->file_system_dispatcher();
- dispatcher->Exists(path, false, callbacks);
+ dispatcher->Exists(webkit_glue::WebStringToFilePath(path), false,
+ new WebFileSystemCallbackDispatcherImpl(callbacks));
}
void WebFileSystemImpl::directoryExists(const WebString& path,
- WebFileSystemCallbacks* callbacks) {
+ WebFileSystemCallbacks* callbacks) {
FileSystemDispatcher* dispatcher =
ChildThread::current()->file_system_dispatcher();
- dispatcher->Exists(path, true, callbacks);
+ dispatcher->Exists(webkit_glue::WebStringToFilePath(path), true,
+ new WebFileSystemCallbackDispatcherImpl(callbacks));
}
void WebFileSystemImpl::readDirectory(const WebString& path,
- WebFileSystemCallbacks* callbacks) {
+ WebFileSystemCallbacks* callbacks) {
FileSystemDispatcher* dispatcher =
ChildThread::current()->file_system_dispatcher();
- dispatcher->ReadDirectory(path, callbacks);
+ dispatcher->ReadDirectory(webkit_glue::WebStringToFilePath(path),
+ new WebFileSystemCallbackDispatcherImpl(callbacks));
}