| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_COMMON_FILEAPI_FILE_SYSTEM_DISPATCHER_H_ | 5 #ifndef CONTENT_COMMON_FILEAPI_FILE_SYSTEM_DISPATCHER_H_ |
| 6 #define CONTENT_COMMON_FILEAPI_FILE_SYSTEM_DISPATCHER_H_ | 6 #define CONTENT_COMMON_FILEAPI_FILE_SYSTEM_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback_forward.h" |
| 12 #include "base/files/file_util_proxy.h" | 13 #include "base/files/file_util_proxy.h" |
| 13 #include "base/id_map.h" | 14 #include "base/id_map.h" |
| 14 #include "base/process.h" | 15 #include "base/process.h" |
| 15 #include "ipc/ipc_listener.h" | 16 #include "ipc/ipc_listener.h" |
| 16 #include "ipc/ipc_platform_file.h" | 17 #include "ipc/ipc_platform_file.h" |
| 17 #include "webkit/fileapi/file_system_callback_dispatcher.h" | |
| 18 #include "webkit/fileapi/file_system_types.h" | 18 #include "webkit/fileapi/file_system_types.h" |
| 19 #include "webkit/quota/quota_types.h" | 19 #include "webkit/quota/quota_types.h" |
| 20 | 20 |
| 21 namespace base { | 21 namespace base { |
| 22 class FilePath; | 22 class FilePath; |
| 23 struct PlatformFileInfo; | 23 struct PlatformFileInfo; |
| 24 } | 24 } |
| 25 | 25 |
| 26 class GURL; | 26 class GURL; |
| 27 | 27 |
| 28 namespace content { | 28 namespace content { |
| 29 | 29 |
| 30 // Dispatches and sends file system related messages sent to/from a child | 30 // Dispatches and sends file system related messages sent to/from a child |
| 31 // process from/to the main browser process. There is one instance | 31 // process from/to the main browser process. There is one instance |
| 32 // per child process. Messages are dispatched on the main child thread. | 32 // per child process. Messages are dispatched on the main child thread. |
| 33 class FileSystemDispatcher : public IPC::Listener { | 33 class FileSystemDispatcher : public IPC::Listener { |
| 34 public: | 34 public: |
| 35 typedef base::Callback<void(base::PlatformFileError error)> StatusCallback; |
| 36 typedef base::Callback<void( |
| 37 const base::PlatformFileInfo& file_info, |
| 38 const base::FilePath& platform_path)> MetadataCallback; |
| 39 typedef MetadataCallback CreateSnapshotFileCallback; |
| 40 typedef base::Callback<void( |
| 41 const std::vector<base::FileUtilProxy::Entry>& entries, |
| 42 bool has_more)> ReadDirectoryCallback; |
| 43 typedef base::Callback<void( |
| 44 const std::string& name, |
| 45 const GURL& root)> OpenFileSystemCallback; |
| 46 typedef base::Callback<void( |
| 47 int64 bytes, |
| 48 bool complete)> WriteCallback; |
| 49 typedef base::Callback<void( |
| 50 base::PlatformFile file, |
| 51 int file_open_id, |
| 52 quota::QuotaLimitType quota_policy)> OpenFileCallback; |
| 53 |
| 35 FileSystemDispatcher(); | 54 FileSystemDispatcher(); |
| 36 virtual ~FileSystemDispatcher(); | 55 virtual ~FileSystemDispatcher(); |
| 37 | 56 |
| 38 // IPC::Listener implementation. | 57 // IPC::Listener implementation. |
| 39 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 58 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
| 40 | 59 |
| 41 bool OpenFileSystem(const GURL& origin_url, | 60 bool OpenFileSystem(const GURL& origin_url, |
| 42 fileapi::FileSystemType type, | 61 fileapi::FileSystemType type, |
| 43 long long size, | 62 long long size, |
| 44 bool create, | 63 bool create, |
| 45 fileapi::FileSystemCallbackDispatcher* dispatcher); | 64 const OpenFileSystemCallback& success_callback, |
| 65 const StatusCallback& error_callback); |
| 46 bool DeleteFileSystem(const GURL& origin_url, | 66 bool DeleteFileSystem(const GURL& origin_url, |
| 47 fileapi::FileSystemType type, | 67 fileapi::FileSystemType type, |
| 48 fileapi::FileSystemCallbackDispatcher* dispatcher); | 68 const StatusCallback& callback); |
| 49 bool Move(const GURL& src_path, | 69 bool Move(const GURL& src_path, |
| 50 const GURL& dest_path, | 70 const GURL& dest_path, |
| 51 fileapi::FileSystemCallbackDispatcher* dispatcher); | 71 const StatusCallback& callback); |
| 52 bool Copy(const GURL& src_path, | 72 bool Copy(const GURL& src_path, |
| 53 const GURL& dest_path, | 73 const GURL& dest_path, |
| 54 fileapi::FileSystemCallbackDispatcher* dispatcher); | 74 const StatusCallback& callback); |
| 55 bool Remove(const GURL& path, | 75 bool Remove(const GURL& path, |
| 56 bool recursive, | 76 bool recursive, |
| 57 fileapi::FileSystemCallbackDispatcher* dispatcher); | 77 const StatusCallback& callback); |
| 58 bool ReadMetadata(const GURL& path, | 78 bool ReadMetadata(const GURL& path, |
| 59 fileapi::FileSystemCallbackDispatcher* dispatcher); | 79 const MetadataCallback& success_callback, |
| 80 const StatusCallback& error_callback); |
| 60 bool Create(const GURL& path, | 81 bool Create(const GURL& path, |
| 61 bool exclusive, | 82 bool exclusive, |
| 62 bool is_directory, | 83 bool is_directory, |
| 63 bool recursive, | 84 bool recursive, |
| 64 fileapi::FileSystemCallbackDispatcher* dispatcher); | 85 const StatusCallback& callback); |
| 65 bool Exists(const GURL& path, | 86 bool Exists(const GURL& path, |
| 66 bool for_directory, | 87 bool for_directory, |
| 67 fileapi::FileSystemCallbackDispatcher* dispatcher); | 88 const StatusCallback& callback); |
| 68 bool ReadDirectory(const GURL& path, | 89 bool ReadDirectory(const GURL& path, |
| 69 fileapi::FileSystemCallbackDispatcher* dispatcher); | 90 const ReadDirectoryCallback& success_callback, |
| 91 const StatusCallback& error_callback); |
| 70 bool Truncate(const GURL& path, | 92 bool Truncate(const GURL& path, |
| 71 int64 offset, | 93 int64 offset, |
| 72 int* request_id_out, | 94 int* request_id_out, |
| 73 fileapi::FileSystemCallbackDispatcher* dispatcher); | 95 const StatusCallback& callback); |
| 74 bool Write(const GURL& path, | 96 bool Write(const GURL& path, |
| 75 const GURL& blob_url, | 97 const GURL& blob_url, |
| 76 int64 offset, | 98 int64 offset, |
| 77 int* request_id_out, | 99 int* request_id_out, |
| 78 fileapi::FileSystemCallbackDispatcher* dispatcher); | 100 const WriteCallback& success_callback, |
| 101 const StatusCallback& error_callback); |
| 79 bool Cancel(int request_id_to_cancel, | 102 bool Cancel(int request_id_to_cancel, |
| 80 fileapi::FileSystemCallbackDispatcher* dispatcher); | 103 const StatusCallback& callback); |
| 81 bool TouchFile(const GURL& file_path, | 104 bool TouchFile(const GURL& file_path, |
| 82 const base::Time& last_access_time, | 105 const base::Time& last_access_time, |
| 83 const base::Time& last_modified_time, | 106 const base::Time& last_modified_time, |
| 84 fileapi::FileSystemCallbackDispatcher* dispatcher); | 107 const StatusCallback& callback); |
| 85 | 108 |
| 86 // This returns a raw open PlatformFile, unlike the above, which are | 109 // This returns a raw open PlatformFile, unlike the above, which are |
| 87 // self-contained operations. | 110 // self-contained operations. |
| 88 bool OpenFile(const GURL& file_path, | 111 bool OpenFile(const GURL& file_path, |
| 89 int file_flags, // passed to FileUtilProxy::CreateOrOpen | 112 int file_flags, // passed to FileUtilProxy::CreateOrOpen |
| 90 fileapi::FileSystemCallbackDispatcher* dispatcher); | 113 const OpenFileCallback& success_callback, |
| 114 const StatusCallback& error_callback); |
| 91 // This must be paired with OpenFile, and called after finished using the | 115 // This must be paired with OpenFile, and called after finished using the |
| 92 // raw PlatformFile returned from OpenFile. | 116 // raw PlatformFile returned from OpenFile. |
| 93 bool NotifyCloseFile(int file_open_id); | 117 bool NotifyCloseFile(int file_open_id); |
| 94 | 118 |
| 95 bool CreateSnapshotFile(const GURL& file_path, | 119 bool CreateSnapshotFile(const GURL& file_path, |
| 96 fileapi::FileSystemCallbackDispatcher* dispatcher); | 120 const CreateSnapshotFileCallback& success_callback, |
| 121 const StatusCallback& error_callback); |
| 97 | 122 |
| 98 private: | 123 private: |
| 124 class CallbackDispatcher; |
| 125 |
| 99 // Message handlers. | 126 // Message handlers. |
| 100 void OnDidOpenFileSystem(int request_id, | 127 void OnDidOpenFileSystem(int request_id, |
| 101 const std::string& name, | 128 const std::string& name, |
| 102 const GURL& root); | 129 const GURL& root); |
| 103 void OnDidSucceed(int request_id); | 130 void OnDidSucceed(int request_id); |
| 104 void OnDidReadMetadata(int request_id, | 131 void OnDidReadMetadata(int request_id, |
| 105 const base::PlatformFileInfo& file_info, | 132 const base::PlatformFileInfo& file_info, |
| 106 const base::FilePath& platform_path); | 133 const base::FilePath& platform_path); |
| 107 void OnDidCreateSnapshotFile(int request_id, | 134 void OnDidCreateSnapshotFile(int request_id, |
| 108 const base::PlatformFileInfo& file_info, | 135 const base::PlatformFileInfo& file_info, |
| 109 const base::FilePath& platform_path); | 136 const base::FilePath& platform_path); |
| 110 void OnDidReadDirectory( | 137 void OnDidReadDirectory( |
| 111 int request_id, | 138 int request_id, |
| 112 const std::vector<base::FileUtilProxy::Entry>& entries, | 139 const std::vector<base::FileUtilProxy::Entry>& entries, |
| 113 bool has_more); | 140 bool has_more); |
| 114 void OnDidFail(int request_id, base::PlatformFileError error_code); | 141 void OnDidFail(int request_id, base::PlatformFileError error_code); |
| 115 void OnDidWrite(int request_id, int64 bytes, bool complete); | 142 void OnDidWrite(int request_id, int64 bytes, bool complete); |
| 116 void OnDidOpenFile( | 143 void OnDidOpenFile( |
| 117 int request_id, | 144 int request_id, |
| 118 IPC::PlatformFileForTransit file, | 145 IPC::PlatformFileForTransit file, |
| 119 int file_open_id, | 146 int file_open_id, |
| 120 quota::QuotaLimitType quota_policy); | 147 quota::QuotaLimitType quota_policy); |
| 121 | 148 |
| 122 IDMap<fileapi::FileSystemCallbackDispatcher, IDMapOwnPointer> dispatchers_; | 149 IDMap<CallbackDispatcher, IDMapOwnPointer> dispatchers_; |
| 123 | 150 |
| 124 DISALLOW_COPY_AND_ASSIGN(FileSystemDispatcher); | 151 DISALLOW_COPY_AND_ASSIGN(FileSystemDispatcher); |
| 125 }; | 152 }; |
| 126 | 153 |
| 127 } // namespace content | 154 } // namespace content |
| 128 | 155 |
| 129 #endif // CONTENT_COMMON_FILEAPI_FILE_SYSTEM_DISPATCHER_H_ | 156 #endif // CONTENT_COMMON_FILEAPI_FILE_SYSTEM_DISPATCHER_H_ |
| OLD | NEW |