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