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 #include "content/common/fileapi/file_system_dispatcher.h" | 5 #include "content/common/fileapi/file_system_dispatcher.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/process.h" | 8 #include "base/process.h" |
9 #include "content/common/child_thread.h" | 9 #include "content/common/child_thread.h" |
10 #include "content/common/fileapi/file_system_messages.h" | 10 #include "content/common/fileapi/file_system_messages.h" |
11 | 11 |
12 namespace { | |
13 | |
14 // Dummy dispatcher used only for issuing a request_id. | |
15 class CloseFileDispatcher : public fileapi::FileSystemCallbackDispatcher { | |
kinuko
2012/06/13 06:38:29
We usually put these dispatchers on the caller's s
kinaba
2012/06/25 11:14:02
Sounds good. I made it into a send-only message.
| |
16 public: | |
17 virtual void DidSucceed() {} | |
18 virtual void DidFail(base::PlatformFileError error_code) {} | |
19 | |
20 virtual void DidReadMetadata(const base::PlatformFileInfo& file_info, | |
21 const FilePath& platform_path) { | |
22 NOTREACHED(); | |
23 } | |
24 virtual void DidReadDirectory( | |
25 const std::vector<base::FileUtilProxy::Entry>& entries, | |
26 bool has_more) { | |
27 NOTREACHED(); | |
28 } | |
29 virtual void DidOpenFileSystem(const std::string& name, | |
30 const GURL& root) { | |
31 NOTREACHED(); | |
32 } | |
33 virtual void DidWrite(int64 bytes, bool complete) { | |
34 NOTREACHED(); | |
35 } | |
36 virtual void DidOpenFile(base::PlatformFile file) { | |
37 NOTREACHED(); | |
38 } | |
39 }; | |
40 | |
41 } // namespace | |
42 | |
12 FileSystemDispatcher::FileSystemDispatcher() { | 43 FileSystemDispatcher::FileSystemDispatcher() { |
13 } | 44 } |
14 | 45 |
15 FileSystemDispatcher::~FileSystemDispatcher() { | 46 FileSystemDispatcher::~FileSystemDispatcher() { |
16 // Make sure we fire all the remaining callbacks. | 47 // Make sure we fire all the remaining callbacks. |
17 for (IDMap<fileapi::FileSystemCallbackDispatcher, IDMapOwnPointer>::iterator | 48 for (IDMap<fileapi::FileSystemCallbackDispatcher, IDMapOwnPointer>::iterator |
18 iter(&dispatchers_); !iter.IsAtEnd(); iter.Advance()) { | 49 iter(&dispatchers_); !iter.IsAtEnd(); iter.Advance()) { |
19 int request_id = iter.GetCurrentKey(); | 50 int request_id = iter.GetCurrentKey(); |
20 fileapi::FileSystemCallbackDispatcher* dispatcher = iter.GetCurrentValue(); | 51 fileapi::FileSystemCallbackDispatcher* dispatcher = iter.GetCurrentValue(); |
21 DCHECK(dispatcher); | 52 DCHECK(dispatcher); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 if (!ChildThread::current()->Send( | 254 if (!ChildThread::current()->Send( |
224 new FileSystemHostMsg_OpenFile( | 255 new FileSystemHostMsg_OpenFile( |
225 request_id, file_path, file_flags))) { | 256 request_id, file_path, file_flags))) { |
226 dispatchers_.Remove(request_id); // destroys |dispatcher| | 257 dispatchers_.Remove(request_id); // destroys |dispatcher| |
227 return false; | 258 return false; |
228 } | 259 } |
229 | 260 |
230 return true; | 261 return true; |
231 } | 262 } |
232 | 263 |
264 bool FileSystemDispatcher::NotifyCloseFile(const GURL& file_path) { | |
265 fileapi::FileSystemCallbackDispatcher* dispatcher = new CloseFileDispatcher; | |
266 int request_id = dispatchers_.Add(dispatcher); | |
267 if (!ChildThread::current()->Send( | |
268 new FileSystemHostMsg_NotifyCloseFile(request_id, file_path))) { | |
269 dispatchers_.Remove(request_id); // destroys |dispatcher| | |
270 return false; | |
271 } | |
272 return true; | |
273 } | |
274 | |
233 bool FileSystemDispatcher::CreateSnapshotFile( | 275 bool FileSystemDispatcher::CreateSnapshotFile( |
234 const GURL& blob_url, | 276 const GURL& blob_url, |
235 const GURL& file_path, | 277 const GURL& file_path, |
236 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 278 fileapi::FileSystemCallbackDispatcher* dispatcher) { |
237 int request_id = dispatchers_.Add(dispatcher); | 279 int request_id = dispatchers_.Add(dispatcher); |
238 if (!ChildThread::current()->Send( | 280 if (!ChildThread::current()->Send( |
239 new FileSystemHostMsg_CreateSnapshotFile( | 281 new FileSystemHostMsg_CreateSnapshotFile( |
240 request_id, blob_url, file_path))) { | 282 request_id, blob_url, file_path))) { |
241 dispatchers_.Remove(request_id); // destroys |dispatcher| | 283 dispatchers_.Remove(request_id); // destroys |dispatcher| |
242 return false; | 284 return false; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 } | 346 } |
305 | 347 |
306 void FileSystemDispatcher::OnDidOpenFile( | 348 void FileSystemDispatcher::OnDidOpenFile( |
307 int request_id, IPC::PlatformFileForTransit file) { | 349 int request_id, IPC::PlatformFileForTransit file) { |
308 fileapi::FileSystemCallbackDispatcher* dispatcher = | 350 fileapi::FileSystemCallbackDispatcher* dispatcher = |
309 dispatchers_.Lookup(request_id); | 351 dispatchers_.Lookup(request_id); |
310 DCHECK(dispatcher); | 352 DCHECK(dispatcher); |
311 dispatcher->DidOpenFile(IPC::PlatformFileForTransitToPlatformFile(file)); | 353 dispatcher->DidOpenFile(IPC::PlatformFileForTransitToPlatformFile(file)); |
312 dispatchers_.Remove(request_id); | 354 dispatchers_.Remove(request_id); |
313 } | 355 } |
OLD | NEW |