Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1043)

Side by Side Diff: content/common/fileapi/file_system_dispatcher.cc

Issue 14796018: Cleanup: Deprecate FileSystemCallbackDispatcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "content/common/fileapi/file_system_dispatcher.h" 5 #include "content/common/fileapi/file_system_dispatcher.h"
6 6
7 #include "base/callback.h"
8 #include "base/file_util.h"
7 #include "base/process.h" 9 #include "base/process.h"
8 #include "content/common/child_thread.h" 10 #include "content/common/child_thread.h"
9 #include "content/common/fileapi/file_system_messages.h" 11 #include "content/common/fileapi/file_system_messages.h"
10 12
11 namespace content { 13 namespace content {
12 14
15 class FileSystemDispatcher::CallbackDispatcher {
16 public:
17 typedef CallbackDispatcher self;
18 typedef FileSystemDispatcher::StatusCallback StatusCallback;
19 typedef FileSystemDispatcher::MetadataCallback MetadataCallback;
20 typedef FileSystemDispatcher::ReadDirectoryCallback ReadDirectoryCallback;
21 typedef FileSystemDispatcher::OpenFileSystemCallback OpenFileSystemCallback;
22 typedef FileSystemDispatcher::WriteCallback WriteCallback;
23 typedef FileSystemDispatcher::OpenFileCallback OpenFileCallback;
24
25 static CallbackDispatcher* Create(const StatusCallback& callback) {
26 CallbackDispatcher* dispatcher = new CallbackDispatcher;
27 dispatcher->status_callback_ = callback;
28 dispatcher->error_callback_ = callback;
29 return dispatcher;
30 }
31 static CallbackDispatcher* Create(const MetadataCallback& callback,
32 const StatusCallback& error_callback) {
33 CallbackDispatcher* dispatcher = new CallbackDispatcher;
34 dispatcher->metadata_callback_ = callback;
35 dispatcher->error_callback_ = error_callback;
36 return dispatcher;
37 }
38 static CallbackDispatcher* Create(const ReadDirectoryCallback& callback,
39 const StatusCallback& error_callback) {
40 CallbackDispatcher* dispatcher = new CallbackDispatcher;
41 dispatcher->directory_callback_ = callback;
42 dispatcher->error_callback_ = error_callback;
43 return dispatcher;
44 }
45 static CallbackDispatcher* Create(const OpenFileSystemCallback& callback,
46 const StatusCallback& error_callback) {
47 CallbackDispatcher* dispatcher = new CallbackDispatcher;
48 dispatcher->filesystem_callback_ = callback;
49 dispatcher->error_callback_ = error_callback;
50 return dispatcher;
51 }
52 static CallbackDispatcher* Create(const WriteCallback& callback,
53 const StatusCallback& error_callback) {
54 CallbackDispatcher* dispatcher = new CallbackDispatcher;
55 dispatcher->write_callback_ = callback;
56 dispatcher->error_callback_ = error_callback;
57 return dispatcher;
58 }
59 static CallbackDispatcher* Create(const OpenFileCallback& callback,
60 const StatusCallback& error_callback) {
61 CallbackDispatcher* dispatcher = new CallbackDispatcher;
62 dispatcher->open_callback_ = callback;
63 dispatcher->error_callback_ = error_callback;
64 return dispatcher;
65 }
66
67 ~CallbackDispatcher() {}
68
69 void DidSucceed() {
70 status_callback_.Run(base::PLATFORM_FILE_OK);
71 }
72
73 void DidFail(base::PlatformFileError error_code) {
74 error_callback_.Run(error_code);
75 }
76
77 void DidReadMetadata(
78 const base::PlatformFileInfo& file_info,
79 const base::FilePath& platform_path) {
80 metadata_callback_.Run(file_info, platform_path);
81 }
82
83 void DidCreateSnapshotFile(
84 const base::PlatformFileInfo& file_info,
85 const base::FilePath& platform_path) {
86 metadata_callback_.Run(file_info, platform_path);
87 }
88
89 void DidReadDirectory(
90 const std::vector<base::FileUtilProxy::Entry>& entries,
91 bool has_more) {
92 directory_callback_.Run(entries, has_more);
93 }
94
95 void DidOpenFileSystem(const std::string& name,
96 const GURL& root) {
97 filesystem_callback_.Run(name, root);
98 }
99
100 void DidWrite(int64 bytes, bool complete) {
101 write_callback_.Run(bytes, complete);
102 }
103
104 void DidOpenFile(base::PlatformFile file,
105 int file_open_id,
106 quota::QuotaLimitType quota_policy) {
107 open_callback_.Run(file, file_open_id, quota_policy);
108 }
109
110 private:
111 CallbackDispatcher() {}
112
113 StatusCallback status_callback_;
114 MetadataCallback metadata_callback_;
115 ReadDirectoryCallback directory_callback_;
116 OpenFileSystemCallback filesystem_callback_;
117 WriteCallback write_callback_;
118 OpenFileCallback open_callback_;
119
120 StatusCallback error_callback_;
121
122 DISALLOW_COPY_AND_ASSIGN(CallbackDispatcher);
123 };
124
13 FileSystemDispatcher::FileSystemDispatcher() { 125 FileSystemDispatcher::FileSystemDispatcher() {
14 } 126 }
15 127
16 FileSystemDispatcher::~FileSystemDispatcher() { 128 FileSystemDispatcher::~FileSystemDispatcher() {
17 // Make sure we fire all the remaining callbacks. 129 // Make sure we fire all the remaining callbacks.
18 for (IDMap<fileapi::FileSystemCallbackDispatcher, IDMapOwnPointer>::iterator 130 for (IDMap<CallbackDispatcher, IDMapOwnPointer>::iterator
19 iter(&dispatchers_); !iter.IsAtEnd(); iter.Advance()) { 131 iter(&dispatchers_); !iter.IsAtEnd(); iter.Advance()) {
20 int request_id = iter.GetCurrentKey(); 132 int request_id = iter.GetCurrentKey();
21 fileapi::FileSystemCallbackDispatcher* dispatcher = iter.GetCurrentValue(); 133 CallbackDispatcher* dispatcher = iter.GetCurrentValue();
22 DCHECK(dispatcher); 134 DCHECK(dispatcher);
23 dispatcher->DidFail(base::PLATFORM_FILE_ERROR_ABORT); 135 dispatcher->DidFail(base::PLATFORM_FILE_ERROR_ABORT);
24 dispatchers_.Remove(request_id); 136 dispatchers_.Remove(request_id);
25 } 137 }
26 } 138 }
27 139
28 bool FileSystemDispatcher::OnMessageReceived(const IPC::Message& msg) { 140 bool FileSystemDispatcher::OnMessageReceived(const IPC::Message& msg) {
29 bool handled = true; 141 bool handled = true;
30 IPC_BEGIN_MESSAGE_MAP(FileSystemDispatcher, msg) 142 IPC_BEGIN_MESSAGE_MAP(FileSystemDispatcher, msg)
31 IPC_MESSAGE_HANDLER(FileSystemMsg_DidOpenFileSystem, OnDidOpenFileSystem) 143 IPC_MESSAGE_HANDLER(FileSystemMsg_DidOpenFileSystem, OnDidOpenFileSystem)
32 IPC_MESSAGE_HANDLER(FileSystemMsg_DidSucceed, OnDidSucceed) 144 IPC_MESSAGE_HANDLER(FileSystemMsg_DidSucceed, OnDidSucceed)
33 IPC_MESSAGE_HANDLER(FileSystemMsg_DidReadDirectory, OnDidReadDirectory) 145 IPC_MESSAGE_HANDLER(FileSystemMsg_DidReadDirectory, OnDidReadDirectory)
34 IPC_MESSAGE_HANDLER(FileSystemMsg_DidReadMetadata, OnDidReadMetadata) 146 IPC_MESSAGE_HANDLER(FileSystemMsg_DidReadMetadata, OnDidReadMetadata)
35 IPC_MESSAGE_HANDLER(FileSystemMsg_DidCreateSnapshotFile, 147 IPC_MESSAGE_HANDLER(FileSystemMsg_DidCreateSnapshotFile,
36 OnDidCreateSnapshotFile) 148 OnDidCreateSnapshotFile)
37 IPC_MESSAGE_HANDLER(FileSystemMsg_DidFail, OnDidFail) 149 IPC_MESSAGE_HANDLER(FileSystemMsg_DidFail, OnDidFail)
38 IPC_MESSAGE_HANDLER(FileSystemMsg_DidWrite, OnDidWrite) 150 IPC_MESSAGE_HANDLER(FileSystemMsg_DidWrite, OnDidWrite)
39 IPC_MESSAGE_HANDLER(FileSystemMsg_DidOpenFile, OnDidOpenFile) 151 IPC_MESSAGE_HANDLER(FileSystemMsg_DidOpenFile, OnDidOpenFile)
40 IPC_MESSAGE_UNHANDLED(handled = false) 152 IPC_MESSAGE_UNHANDLED(handled = false)
41 IPC_END_MESSAGE_MAP() 153 IPC_END_MESSAGE_MAP()
42 return handled; 154 return handled;
43 } 155 }
44 156
45 bool FileSystemDispatcher::OpenFileSystem( 157 bool FileSystemDispatcher::OpenFileSystem(
46 const GURL& origin_url, fileapi::FileSystemType type, 158 const GURL& origin_url, fileapi::FileSystemType type,
47 long long size, bool create, 159 long long size, bool create,
48 fileapi::FileSystemCallbackDispatcher* dispatcher) { 160 const OpenFileSystemCallback& success_callback,
49 int request_id = dispatchers_.Add(dispatcher); 161 const StatusCallback& error_callback) {
162 int request_id = dispatchers_.Add(
163 CallbackDispatcher::Create(success_callback, error_callback));
50 if (!ChildThread::current()->Send(new FileSystemHostMsg_Open( 164 if (!ChildThread::current()->Send(new FileSystemHostMsg_Open(
51 request_id, origin_url, type, size, create))) { 165 request_id, origin_url, type, size, create))) {
52 dispatchers_.Remove(request_id); // destroys |dispatcher| 166 dispatchers_.Remove(request_id); // destroys |dispatcher|
53 return false; 167 return false;
54 } 168 }
55 169
56 return true; 170 return true;
57 } 171 }
58 172
59 bool FileSystemDispatcher::DeleteFileSystem( 173 bool FileSystemDispatcher::DeleteFileSystem(
60 const GURL& origin_url, 174 const GURL& origin_url,
61 fileapi::FileSystemType type, 175 fileapi::FileSystemType type,
62 fileapi::FileSystemCallbackDispatcher* dispatcher) { 176 const StatusCallback& callback) {
63 int request_id = dispatchers_.Add(dispatcher); 177 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
64 if (!ChildThread::current()->Send(new FileSystemHostMsg_DeleteFileSystem( 178 if (!ChildThread::current()->Send(new FileSystemHostMsg_DeleteFileSystem(
65 request_id, origin_url, type))) { 179 request_id, origin_url, type))) {
66 dispatchers_.Remove(request_id); 180 dispatchers_.Remove(request_id);
67 return false; 181 return false;
68 } 182 }
69 return true; 183 return true;
70 } 184 }
71 185
72 bool FileSystemDispatcher::Move( 186 bool FileSystemDispatcher::Move(
73 const GURL& src_path, 187 const GURL& src_path,
74 const GURL& dest_path, 188 const GURL& dest_path,
75 fileapi::FileSystemCallbackDispatcher* dispatcher) { 189 const StatusCallback& callback) {
76 int request_id = dispatchers_.Add(dispatcher); 190 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
77 if (!ChildThread::current()->Send(new FileSystemHostMsg_Move( 191 if (!ChildThread::current()->Send(new FileSystemHostMsg_Move(
78 request_id, src_path, dest_path))) { 192 request_id, src_path, dest_path))) {
79 dispatchers_.Remove(request_id); // destroys |dispatcher| 193 dispatchers_.Remove(request_id); // destroys |dispatcher|
80 return false; 194 return false;
81 } 195 }
82 196
83 return true; 197 return true;
84 } 198 }
85 199
86 bool FileSystemDispatcher::Copy( 200 bool FileSystemDispatcher::Copy(
87 const GURL& src_path, 201 const GURL& src_path,
88 const GURL& dest_path, 202 const GURL& dest_path,
89 fileapi::FileSystemCallbackDispatcher* dispatcher) { 203 const StatusCallback& callback) {
90 int request_id = dispatchers_.Add(dispatcher); 204 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
91 if (!ChildThread::current()->Send(new FileSystemHostMsg_Copy( 205 if (!ChildThread::current()->Send(new FileSystemHostMsg_Copy(
92 request_id, src_path, dest_path))) { 206 request_id, src_path, dest_path))) {
93 dispatchers_.Remove(request_id); // destroys |dispatcher| 207 dispatchers_.Remove(request_id); // destroys |dispatcher|
94 return false; 208 return false;
95 } 209 }
96 210
97 return true; 211 return true;
98 } 212 }
99 213
100 bool FileSystemDispatcher::Remove( 214 bool FileSystemDispatcher::Remove(
101 const GURL& path, 215 const GURL& path,
102 bool recursive, 216 bool recursive,
103 fileapi::FileSystemCallbackDispatcher* dispatcher) { 217 const StatusCallback& callback) {
104 int request_id = dispatchers_.Add(dispatcher); 218 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
105 if (!ChildThread::current()->Send( 219 if (!ChildThread::current()->Send(
106 new FileSystemMsg_Remove(request_id, path, recursive))) { 220 new FileSystemMsg_Remove(request_id, path, recursive))) {
107 dispatchers_.Remove(request_id); // destroys |dispatcher| 221 dispatchers_.Remove(request_id); // destroys |dispatcher|
108 return false; 222 return false;
109 } 223 }
110 224
111 return true; 225 return true;
112 } 226 }
113 227
114 bool FileSystemDispatcher::ReadMetadata( 228 bool FileSystemDispatcher::ReadMetadata(
115 const GURL& path, 229 const GURL& path,
116 fileapi::FileSystemCallbackDispatcher* dispatcher) { 230 const MetadataCallback& success_callback,
117 int request_id = dispatchers_.Add(dispatcher); 231 const StatusCallback& error_callback) {
232 int request_id = dispatchers_.Add(
233 CallbackDispatcher::Create(success_callback, error_callback));
118 if (!ChildThread::current()->Send( 234 if (!ChildThread::current()->Send(
119 new FileSystemHostMsg_ReadMetadata(request_id, path))) { 235 new FileSystemHostMsg_ReadMetadata(request_id, path))) {
120 dispatchers_.Remove(request_id); // destroys |dispatcher| 236 dispatchers_.Remove(request_id); // destroys |dispatcher|
121 return false; 237 return false;
122 } 238 }
123 239
124 return true; 240 return true;
125 } 241 }
126 242
127 bool FileSystemDispatcher::Create( 243 bool FileSystemDispatcher::Create(
128 const GURL& path, 244 const GURL& path,
129 bool exclusive, 245 bool exclusive,
130 bool is_directory, 246 bool is_directory,
131 bool recursive, 247 bool recursive,
132 fileapi::FileSystemCallbackDispatcher* dispatcher) { 248 const StatusCallback& callback) {
133 int request_id = dispatchers_.Add(dispatcher); 249 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
134 if (!ChildThread::current()->Send(new FileSystemHostMsg_Create( 250 if (!ChildThread::current()->Send(new FileSystemHostMsg_Create(
135 request_id, path, exclusive, is_directory, recursive))) { 251 request_id, path, exclusive, is_directory, recursive))) {
136 dispatchers_.Remove(request_id); // destroys |dispatcher| 252 dispatchers_.Remove(request_id); // destroys |dispatcher|
137 return false; 253 return false;
138 } 254 }
139 255
140 return true; 256 return true;
141 } 257 }
142 258
143 bool FileSystemDispatcher::Exists( 259 bool FileSystemDispatcher::Exists(
144 const GURL& path, 260 const GURL& path,
145 bool is_directory, 261 bool is_directory,
146 fileapi::FileSystemCallbackDispatcher* dispatcher) { 262 const StatusCallback& callback) {
147 int request_id = dispatchers_.Add(dispatcher); 263 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
148 if (!ChildThread::current()->Send( 264 if (!ChildThread::current()->Send(
149 new FileSystemHostMsg_Exists(request_id, path, is_directory))) { 265 new FileSystemHostMsg_Exists(request_id, path, is_directory))) {
150 dispatchers_.Remove(request_id); // destroys |dispatcher| 266 dispatchers_.Remove(request_id); // destroys |dispatcher|
151 return false; 267 return false;
152 } 268 }
153 269
154 return true; 270 return true;
155 } 271 }
156 272
157 bool FileSystemDispatcher::ReadDirectory( 273 bool FileSystemDispatcher::ReadDirectory(
158 const GURL& path, 274 const GURL& path,
159 fileapi::FileSystemCallbackDispatcher* dispatcher) { 275 const ReadDirectoryCallback& success_callback,
160 int request_id = dispatchers_.Add(dispatcher); 276 const StatusCallback& error_callback) {
277 int request_id = dispatchers_.Add(
278 CallbackDispatcher::Create(success_callback, error_callback));
161 if (!ChildThread::current()->Send( 279 if (!ChildThread::current()->Send(
162 new FileSystemHostMsg_ReadDirectory(request_id, path))) { 280 new FileSystemHostMsg_ReadDirectory(request_id, path))) {
163 dispatchers_.Remove(request_id); // destroys |dispatcher| 281 dispatchers_.Remove(request_id); // destroys |dispatcher|
164 return false; 282 return false;
165 } 283 }
166 284
167 return true; 285 return true;
168 } 286 }
169 287
170 bool FileSystemDispatcher::Truncate( 288 bool FileSystemDispatcher::Truncate(
171 const GURL& path, 289 const GURL& path,
172 int64 offset, 290 int64 offset,
173 int* request_id_out, 291 int* request_id_out,
174 fileapi::FileSystemCallbackDispatcher* dispatcher) { 292 const StatusCallback& callback) {
175 int request_id = dispatchers_.Add(dispatcher); 293 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
176 if (!ChildThread::current()->Send( 294 if (!ChildThread::current()->Send(
177 new FileSystemHostMsg_Truncate(request_id, path, offset))) { 295 new FileSystemHostMsg_Truncate(request_id, path, offset))) {
178 dispatchers_.Remove(request_id); // destroys |dispatcher| 296 dispatchers_.Remove(request_id); // destroys |dispatcher|
179 return false; 297 return false;
180 } 298 }
181 299
182 if (request_id_out) 300 if (request_id_out)
183 *request_id_out = request_id; 301 *request_id_out = request_id;
184 return true; 302 return true;
185 } 303 }
186 304
187 bool FileSystemDispatcher::Write( 305 bool FileSystemDispatcher::Write(
188 const GURL& path, 306 const GURL& path,
189 const GURL& blob_url, 307 const GURL& blob_url,
190 int64 offset, 308 int64 offset,
191 int* request_id_out, 309 int* request_id_out,
192 fileapi::FileSystemCallbackDispatcher* dispatcher) { 310 const WriteCallback& success_callback,
193 int request_id = dispatchers_.Add(dispatcher); 311 const StatusCallback& error_callback) {
312 int request_id = dispatchers_.Add(
313 CallbackDispatcher::Create(success_callback, error_callback));
194 if (!ChildThread::current()->Send( 314 if (!ChildThread::current()->Send(
195 new FileSystemHostMsg_Write(request_id, path, blob_url, offset))) { 315 new FileSystemHostMsg_Write(request_id, path, blob_url, offset))) {
196 dispatchers_.Remove(request_id); // destroys |dispatcher| 316 dispatchers_.Remove(request_id); // destroys |dispatcher|
197 return false; 317 return false;
198 } 318 }
199 319
200 if (request_id_out) 320 if (request_id_out)
201 *request_id_out = request_id; 321 *request_id_out = request_id;
202 return true; 322 return true;
203 } 323 }
204 324
205 bool FileSystemDispatcher::Cancel( 325 bool FileSystemDispatcher::Cancel(
206 int request_id_to_cancel, 326 int request_id_to_cancel,
207 fileapi::FileSystemCallbackDispatcher* dispatcher) { 327 const StatusCallback& callback) {
208 int request_id = dispatchers_.Add(dispatcher); 328 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
209 if (!ChildThread::current()->Send(new FileSystemHostMsg_CancelWrite( 329 if (!ChildThread::current()->Send(new FileSystemHostMsg_CancelWrite(
210 request_id, request_id_to_cancel))) { 330 request_id, request_id_to_cancel))) {
211 dispatchers_.Remove(request_id); // destroys |dispatcher| 331 dispatchers_.Remove(request_id); // destroys |dispatcher|
212 return false; 332 return false;
213 } 333 }
214 334
215 return true; 335 return true;
216 } 336 }
217 337
218 bool FileSystemDispatcher::TouchFile( 338 bool FileSystemDispatcher::TouchFile(
219 const GURL& path, 339 const GURL& path,
220 const base::Time& last_access_time, 340 const base::Time& last_access_time,
221 const base::Time& last_modified_time, 341 const base::Time& last_modified_time,
222 fileapi::FileSystemCallbackDispatcher* dispatcher) { 342 const StatusCallback& callback) {
223 int request_id = dispatchers_.Add(dispatcher); 343 int request_id = dispatchers_.Add(CallbackDispatcher::Create(callback));
224 if (!ChildThread::current()->Send( 344 if (!ChildThread::current()->Send(
225 new FileSystemHostMsg_TouchFile( 345 new FileSystemHostMsg_TouchFile(
226 request_id, path, last_access_time, last_modified_time))) { 346 request_id, path, last_access_time, last_modified_time))) {
227 dispatchers_.Remove(request_id); // destroys |dispatcher| 347 dispatchers_.Remove(request_id); // destroys |dispatcher|
228 return false; 348 return false;
229 } 349 }
230 350
231 return true; 351 return true;
232 } 352 }
233 353
234 bool FileSystemDispatcher::OpenFile( 354 bool FileSystemDispatcher::OpenFile(
235 const GURL& file_path, 355 const GURL& file_path,
236 int file_flags, 356 int file_flags,
237 fileapi::FileSystemCallbackDispatcher* dispatcher) { 357 const OpenFileCallback& success_callback,
238 int request_id = dispatchers_.Add(dispatcher); 358 const StatusCallback& error_callback) {
359 int request_id = dispatchers_.Add(
360 CallbackDispatcher::Create(success_callback, error_callback));
239 if (!ChildThread::current()->Send( 361 if (!ChildThread::current()->Send(
240 new FileSystemHostMsg_OpenFile( 362 new FileSystemHostMsg_OpenFile(
241 request_id, file_path, file_flags))) { 363 request_id, file_path, file_flags))) {
242 dispatchers_.Remove(request_id); // destroys |dispatcher| 364 dispatchers_.Remove(request_id); // destroys |dispatcher|
243 return false; 365 return false;
244 } 366 }
245 367
246 return true; 368 return true;
247 } 369 }
248 370
249 bool FileSystemDispatcher::NotifyCloseFile(int file_open_id) { 371 bool FileSystemDispatcher::NotifyCloseFile(int file_open_id) {
250 return ChildThread::current()->Send( 372 return ChildThread::current()->Send(
251 new FileSystemHostMsg_NotifyCloseFile(file_open_id)); 373 new FileSystemHostMsg_NotifyCloseFile(file_open_id));
252 } 374 }
253 375
254 bool FileSystemDispatcher::CreateSnapshotFile( 376 bool FileSystemDispatcher::CreateSnapshotFile(
255 const GURL& file_path, 377 const GURL& file_path,
256 fileapi::FileSystemCallbackDispatcher* dispatcher) { 378 const CreateSnapshotFileCallback& success_callback,
257 int request_id = dispatchers_.Add(dispatcher); 379 const StatusCallback& error_callback) {
380 int request_id = dispatchers_.Add(
381 CallbackDispatcher::Create(success_callback, error_callback));
258 if (!ChildThread::current()->Send( 382 if (!ChildThread::current()->Send(
259 new FileSystemHostMsg_CreateSnapshotFile( 383 new FileSystemHostMsg_CreateSnapshotFile(
260 request_id, file_path))) { 384 request_id, file_path))) {
261 dispatchers_.Remove(request_id); // destroys |dispatcher| 385 dispatchers_.Remove(request_id); // destroys |dispatcher|
262 return false; 386 return false;
263 } 387 }
264 return true; 388 return true;
265 } 389 }
266 390
267 void FileSystemDispatcher::OnDidOpenFileSystem(int request_id, 391 void FileSystemDispatcher::OnDidOpenFileSystem(int request_id,
268 const std::string& name, 392 const std::string& name,
269 const GURL& root) { 393 const GURL& root) {
270 DCHECK(root.is_valid()); 394 DCHECK(root.is_valid());
271 fileapi::FileSystemCallbackDispatcher* dispatcher = 395 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id);
272 dispatchers_.Lookup(request_id);
273 DCHECK(dispatcher); 396 DCHECK(dispatcher);
274 dispatcher->DidOpenFileSystem(name, root); 397 dispatcher->DidOpenFileSystem(name, root);
275 dispatchers_.Remove(request_id); 398 dispatchers_.Remove(request_id);
276 } 399 }
277 400
278 void FileSystemDispatcher::OnDidSucceed(int request_id) { 401 void FileSystemDispatcher::OnDidSucceed(int request_id) {
279 fileapi::FileSystemCallbackDispatcher* dispatcher = 402 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id);
280 dispatchers_.Lookup(request_id);
281 DCHECK(dispatcher); 403 DCHECK(dispatcher);
282 dispatcher->DidSucceed(); 404 dispatcher->DidSucceed();
283 dispatchers_.Remove(request_id); 405 dispatchers_.Remove(request_id);
284 } 406 }
285 407
286 void FileSystemDispatcher::OnDidReadMetadata( 408 void FileSystemDispatcher::OnDidReadMetadata(
287 int request_id, const base::PlatformFileInfo& file_info, 409 int request_id, const base::PlatformFileInfo& file_info,
288 const base::FilePath& platform_path) { 410 const base::FilePath& platform_path) {
289 fileapi::FileSystemCallbackDispatcher* dispatcher = 411 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id);
290 dispatchers_.Lookup(request_id);
291 DCHECK(dispatcher); 412 DCHECK(dispatcher);
292 dispatcher->DidReadMetadata(file_info, platform_path); 413 dispatcher->DidReadMetadata(file_info, platform_path);
293 dispatchers_.Remove(request_id); 414 dispatchers_.Remove(request_id);
294 } 415 }
295 416
296 void FileSystemDispatcher::OnDidCreateSnapshotFile( 417 void FileSystemDispatcher::OnDidCreateSnapshotFile(
297 int request_id, const base::PlatformFileInfo& file_info, 418 int request_id, const base::PlatformFileInfo& file_info,
298 const base::FilePath& platform_path) { 419 const base::FilePath& platform_path) {
299 fileapi::FileSystemCallbackDispatcher* dispatcher = 420 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id);
300 dispatchers_.Lookup(request_id);
301 DCHECK(dispatcher); 421 DCHECK(dispatcher);
302 dispatcher->DidCreateSnapshotFile(file_info, platform_path); 422 dispatcher->DidCreateSnapshotFile(file_info, platform_path);
303 dispatchers_.Remove(request_id); 423 dispatchers_.Remove(request_id);
304 ChildThread::current()->Send( 424 ChildThread::current()->Send(
305 new FileSystemHostMsg_DidReceiveSnapshotFile(request_id)); 425 new FileSystemHostMsg_DidReceiveSnapshotFile(request_id));
306 } 426 }
307 427
308 void FileSystemDispatcher::OnDidReadDirectory( 428 void FileSystemDispatcher::OnDidReadDirectory(
309 int request_id, 429 int request_id,
310 const std::vector<base::FileUtilProxy::Entry>& entries, 430 const std::vector<base::FileUtilProxy::Entry>& entries,
311 bool has_more) { 431 bool has_more) {
312 fileapi::FileSystemCallbackDispatcher* dispatcher = 432 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id);
313 dispatchers_.Lookup(request_id);
314 DCHECK(dispatcher); 433 DCHECK(dispatcher);
315 dispatcher->DidReadDirectory(entries, has_more); 434 dispatcher->DidReadDirectory(entries, has_more);
316 dispatchers_.Remove(request_id); 435 dispatchers_.Remove(request_id);
317 } 436 }
318 437
319 void FileSystemDispatcher::OnDidFail( 438 void FileSystemDispatcher::OnDidFail(
320 int request_id, base::PlatformFileError error_code) { 439 int request_id, base::PlatformFileError error_code) {
321 fileapi::FileSystemCallbackDispatcher* dispatcher = 440 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id);
322 dispatchers_.Lookup(request_id);
323 DCHECK(dispatcher); 441 DCHECK(dispatcher);
324 dispatcher->DidFail(error_code); 442 dispatcher->DidFail(error_code);
325 dispatchers_.Remove(request_id); 443 dispatchers_.Remove(request_id);
326 } 444 }
327 445
328 void FileSystemDispatcher::OnDidWrite( 446 void FileSystemDispatcher::OnDidWrite(
329 int request_id, int64 bytes, bool complete) { 447 int request_id, int64 bytes, bool complete) {
330 fileapi::FileSystemCallbackDispatcher* dispatcher = 448 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id);
331 dispatchers_.Lookup(request_id);
332 DCHECK(dispatcher); 449 DCHECK(dispatcher);
333 dispatcher->DidWrite(bytes, complete); 450 dispatcher->DidWrite(bytes, complete);
334 if (complete) 451 if (complete)
335 dispatchers_.Remove(request_id); 452 dispatchers_.Remove(request_id);
336 } 453 }
337 454
338 void FileSystemDispatcher::OnDidOpenFile( 455 void FileSystemDispatcher::OnDidOpenFile(
339 int request_id, 456 int request_id,
340 IPC::PlatformFileForTransit file, 457 IPC::PlatformFileForTransit file,
341 int file_open_id, 458 int file_open_id,
342 quota::QuotaLimitType quota_policy) { 459 quota::QuotaLimitType quota_policy) {
343 fileapi::FileSystemCallbackDispatcher* dispatcher = 460 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id);
344 dispatchers_.Lookup(request_id);
345 DCHECK(dispatcher); 461 DCHECK(dispatcher);
346 dispatcher->DidOpenFile(IPC::PlatformFileForTransitToPlatformFile(file), 462 dispatcher->DidOpenFile(IPC::PlatformFileForTransitToPlatformFile(file),
347 file_open_id, 463 file_open_id,
348 quota_policy); 464 quota_policy);
349 dispatchers_.Remove(request_id); 465 dispatchers_.Remove(request_id);
350 } 466 }
351 467
352 } // namespace content 468 } // namespace content
OLDNEW
« no previous file with comments | « content/common/fileapi/file_system_dispatcher.h ('k') | content/common/fileapi/webfilesystem_callback_adapters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698