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
3 // found in the LICENSE file.
5 #ifndef CONTENT_CHILD_FILEAPI_FILE_SYSTEM_DISPATCHER_H_
6 #define CONTENT_CHILD_FILEAPI_FILE_SYSTEM_DISPATCHER_H_
11 #include "base/basictypes.h"
12 #include "base/callback_forward.h"
13 #include "base/id_map.h"
14 #include "base/process/process.h"
15 #include "ipc/ipc_listener.h"
16 #include "ipc/ipc_platform_file.h"
17 #include "webkit/common/fileapi/file_system_types.h"
18 #include "webkit/common/quota/quota_types.h"
22 struct PlatformFileInfo;
26 struct DirectoryEntry;
27 struct FileSystemInfo;
34 // Dispatches and sends file system related messages sent to/from a child
35 // process from/to the main browser process. There is one instance
36 // per child process. Messages are dispatched on the main child thread.
37 class FileSystemDispatcher : public IPC::Listener {
39 typedef base::Callback<void(base::PlatformFileError error)> StatusCallback;
40 typedef base::Callback<void(
41 const base::PlatformFileInfo& file_info)> MetadataCallback;
42 typedef base::Callback<void(
43 const base::PlatformFileInfo& file_info,
44 const base::FilePath& platform_path,
45 int request_id)> CreateSnapshotFileCallback;
46 typedef base::Callback<void(
47 const std::vector<fileapi::DirectoryEntry>& entries,
48 bool has_more)> ReadDirectoryCallback;
49 typedef base::Callback<void(
50 const std::string& name,
51 const GURL& root)> OpenFileSystemCallback;
52 typedef base::Callback<void(
53 const fileapi::FileSystemInfo& info,
54 const base::FilePath& file_path,
55 bool is_directory)> ResolveURLCallback;
56 typedef base::Callback<void(
58 bool complete)> WriteCallback;
59 typedef base::Callback<void(
60 base::PlatformFile file,
62 quota::QuotaLimitType quota_policy)> OpenFileCallback;
64 FileSystemDispatcher();
65 virtual ~FileSystemDispatcher();
67 // IPC::Listener implementation.
68 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
70 void OpenFileSystem(const GURL& origin_url,
71 fileapi::FileSystemType type,
72 const OpenFileSystemCallback& success_callback,
73 const StatusCallback& error_callback);
74 void ResolveURL(const GURL& filesystem_url,
75 const ResolveURLCallback& success_callback,
76 const StatusCallback& error_callback);
77 void DeleteFileSystem(const GURL& origin_url,
78 fileapi::FileSystemType type,
79 const StatusCallback& callback);
80 void Move(const GURL& src_path,
81 const GURL& dest_path,
82 const StatusCallback& callback);
83 void Copy(const GURL& src_path,
84 const GURL& dest_path,
85 const StatusCallback& callback);
86 void Remove(const GURL& path,
88 const StatusCallback& callback);
89 void ReadMetadata(const GURL& path,
90 const MetadataCallback& success_callback,
91 const StatusCallback& error_callback);
92 void CreateFile(const GURL& path,
94 const StatusCallback& callback);
95 void CreateDirectory(const GURL& path,
98 const StatusCallback& callback);
99 void Exists(const GURL& path,
101 const StatusCallback& callback);
102 void ReadDirectory(const GURL& path,
103 const ReadDirectoryCallback& success_callback,
104 const StatusCallback& error_callback);
105 void Truncate(const GURL& path,
108 const StatusCallback& callback);
109 void WriteDeprecated(
111 const GURL& blob_url,
114 const WriteCallback& success_callback,
115 const StatusCallback& error_callback);
116 void Write(const GURL& path,
117 const std::string& blob_id,
120 const WriteCallback& success_callback,
121 const StatusCallback& error_callback);
122 void Cancel(int request_id_to_cancel,
123 const StatusCallback& callback);
124 void TouchFile(const GURL& file_path,
125 const base::Time& last_access_time,
126 const base::Time& last_modified_time,
127 const StatusCallback& callback);
129 // This returns a raw open PlatformFile, unlike the above, which are
130 // self-contained operations.
131 void OpenPepperFile(const GURL& file_path,
133 const OpenFileCallback& success_callback,
134 const StatusCallback& error_callback);
135 // This must be paired with OpenFile, and called after finished using the
136 // raw PlatformFile returned from OpenFile.
137 void NotifyCloseFile(int file_open_id);
139 // The caller must send FileSystemHostMsg_DidReceiveSnapshot message
140 // with |request_id| passed to |success_callback| after the snapshot file
141 // is successfully received.
142 void CreateSnapshotFile(const GURL& file_path,
143 const CreateSnapshotFileCallback& success_callback,
144 const StatusCallback& error_callback);
147 class CallbackDispatcher;
150 void OnDidOpenFileSystem(int request_id,
151 const std::string& name,
153 void OnDidResolveURL(int request_id,
154 const fileapi::FileSystemInfo& info,
155 const base::FilePath& file_path,
157 void OnDidSucceed(int request_id);
158 void OnDidReadMetadata(int request_id,
159 const base::PlatformFileInfo& file_info);
160 void OnDidCreateSnapshotFile(int request_id,
161 const base::PlatformFileInfo& file_info,
162 const base::FilePath& platform_path);
163 void OnDidReadDirectory(int request_id,
164 const std::vector<fileapi::DirectoryEntry>& entries,
166 void OnDidFail(int request_id, base::PlatformFileError error_code);
167 void OnDidWrite(int request_id, int64 bytes, bool complete);
170 IPC::PlatformFileForTransit file,
172 quota::QuotaLimitType quota_policy);
174 IDMap<CallbackDispatcher, IDMapOwnPointer> dispatchers_;
176 DISALLOW_COPY_AND_ASSIGN(FileSystemDispatcher);
179 } // namespace content
181 #endif // CONTENT_CHILD_FILEAPI_FILE_SYSTEM_DISPATCHER_H_