Chromium Code Reviews| 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/child/fileapi/file_system_dispatcher.h" | 5 #include "content/child/fileapi/file_system_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | |
| 9 #include "base/process.h" | 10 #include "base/process.h" |
| 10 #include "content/child/child_thread.h" | 11 #include "content/child/child_thread.h" |
| 11 #include "content/common/fileapi/file_system_messages.h" | 12 #include "content/common/fileapi/file_system_messages.h" |
| 12 | 13 |
| 13 namespace content { | 14 namespace content { |
| 14 | 15 |
| 16 namespace { | |
| 17 | |
| 18 void DidReceiveSnapshotFile( | |
| 19 int request_id, | |
| 20 base::MessageLoopProxy* message_loop) { | |
|
michaeln
2013/07/24 00:54:08
You might be able to use the ThreadSafeSender here
kinuko
2013/07/24 09:29:09
Done.
| |
| 21 if (!message_loop->RunsTasksOnCurrentThread()) { | |
| 22 message_loop->PostTask(FROM_HERE, | |
| 23 base::Bind(&DidReceiveSnapshotFile, request_id, | |
| 24 make_scoped_refptr(message_loop))); | |
| 25 return; | |
| 26 } | |
| 27 if (ChildThread::current()) { | |
| 28 ChildThread::current()->Send( | |
| 29 new FileSystemHostMsg_DidReceiveSnapshotFile(request_id)); | |
| 30 } | |
| 31 } | |
| 32 | |
| 33 } // namespace | |
| 34 | |
| 15 class FileSystemDispatcher::CallbackDispatcher { | 35 class FileSystemDispatcher::CallbackDispatcher { |
| 16 public: | 36 public: |
| 17 typedef CallbackDispatcher self; | 37 typedef CallbackDispatcher self; |
| 18 typedef FileSystemDispatcher::StatusCallback StatusCallback; | 38 typedef FileSystemDispatcher::StatusCallback StatusCallback; |
| 19 typedef FileSystemDispatcher::MetadataCallback MetadataCallback; | 39 typedef FileSystemDispatcher::MetadataCallback MetadataCallback; |
| 20 typedef FileSystemDispatcher::ReadDirectoryCallback ReadDirectoryCallback; | 40 typedef FileSystemDispatcher::ReadDirectoryCallback ReadDirectoryCallback; |
| 21 typedef FileSystemDispatcher::OpenFileSystemCallback OpenFileSystemCallback; | 41 typedef FileSystemDispatcher::OpenFileSystemCallback OpenFileSystemCallback; |
| 22 typedef FileSystemDispatcher::WriteCallback WriteCallback; | 42 typedef FileSystemDispatcher::WriteCallback WriteCallback; |
| 23 typedef FileSystemDispatcher::OpenFileCallback OpenFileCallback; | 43 typedef FileSystemDispatcher::OpenFileCallback OpenFileCallback; |
| 24 | 44 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 error_callback_.Run(error_code); | 101 error_callback_.Run(error_code); |
| 82 } | 102 } |
| 83 | 103 |
| 84 void DidReadMetadata( | 104 void DidReadMetadata( |
| 85 const base::PlatformFileInfo& file_info) { | 105 const base::PlatformFileInfo& file_info) { |
| 86 metadata_callback_.Run(file_info); | 106 metadata_callback_.Run(file_info); |
| 87 } | 107 } |
| 88 | 108 |
| 89 void DidCreateSnapshotFile( | 109 void DidCreateSnapshotFile( |
| 90 const base::PlatformFileInfo& file_info, | 110 const base::PlatformFileInfo& file_info, |
| 91 const base::FilePath& platform_path) { | 111 const base::FilePath& platform_path, |
| 92 snapshot_callback_.Run(file_info, platform_path); | 112 const base::Closure& did_receive_snapshot) { |
| 113 snapshot_callback_.Run(file_info, platform_path, did_receive_snapshot); | |
|
michaeln
2013/07/24 01:38:58
What method/function is snapshot_callback_ this wi
kinuko
2013/07/24 09:29:09
I thought returning a closure is clearer about wha
| |
| 93 } | 114 } |
| 94 | 115 |
| 95 void DidReadDirectory( | 116 void DidReadDirectory( |
| 96 const std::vector<fileapi::DirectoryEntry>& entries, | 117 const std::vector<fileapi::DirectoryEntry>& entries, |
| 97 bool has_more) { | 118 bool has_more) { |
| 98 directory_callback_.Run(entries, has_more); | 119 directory_callback_.Run(entries, has_more); |
| 99 } | 120 } |
| 100 | 121 |
| 101 void DidOpenFileSystem(const std::string& name, | 122 void DidOpenFileSystem(const std::string& name, |
| 102 const GURL& root) { | 123 const GURL& root) { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 132 FileSystemDispatcher::FileSystemDispatcher() { | 153 FileSystemDispatcher::FileSystemDispatcher() { |
| 133 } | 154 } |
| 134 | 155 |
| 135 FileSystemDispatcher::~FileSystemDispatcher() { | 156 FileSystemDispatcher::~FileSystemDispatcher() { |
| 136 // Make sure we fire all the remaining callbacks. | 157 // Make sure we fire all the remaining callbacks. |
| 137 for (IDMap<CallbackDispatcher, IDMapOwnPointer>::iterator | 158 for (IDMap<CallbackDispatcher, IDMapOwnPointer>::iterator |
| 138 iter(&dispatchers_); !iter.IsAtEnd(); iter.Advance()) { | 159 iter(&dispatchers_); !iter.IsAtEnd(); iter.Advance()) { |
| 139 int request_id = iter.GetCurrentKey(); | 160 int request_id = iter.GetCurrentKey(); |
| 140 CallbackDispatcher* dispatcher = iter.GetCurrentValue(); | 161 CallbackDispatcher* dispatcher = iter.GetCurrentValue(); |
| 141 DCHECK(dispatcher); | 162 DCHECK(dispatcher); |
| 142 dispatcher->DidFail(base::PLATFORM_FILE_ERROR_ABORT); | 163 dispatcher->DidFail(base::PLATFORM_FILE_ERROR_ABORT); |
|
michaeln
2013/07/24 00:54:08
O/T for this CL, but similarly we're shutting down
kinuko
2013/07/24 09:29:09
Current API contract expects it to be called in th
| |
| 143 dispatchers_.Remove(request_id); | 164 dispatchers_.Remove(request_id); |
| 144 } | 165 } |
| 145 } | 166 } |
| 146 | 167 |
| 147 bool FileSystemDispatcher::OnMessageReceived(const IPC::Message& msg) { | 168 bool FileSystemDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 148 bool handled = true; | 169 bool handled = true; |
| 149 IPC_BEGIN_MESSAGE_MAP(FileSystemDispatcher, msg) | 170 IPC_BEGIN_MESSAGE_MAP(FileSystemDispatcher, msg) |
| 150 IPC_MESSAGE_HANDLER(FileSystemMsg_DidOpenFileSystem, OnDidOpenFileSystem) | 171 IPC_MESSAGE_HANDLER(FileSystemMsg_DidOpenFileSystem, OnDidOpenFileSystem) |
| 151 IPC_MESSAGE_HANDLER(FileSystemMsg_DidSucceed, OnDidSucceed) | 172 IPC_MESSAGE_HANDLER(FileSystemMsg_DidSucceed, OnDidSucceed) |
| 152 IPC_MESSAGE_HANDLER(FileSystemMsg_DidReadDirectory, OnDidReadDirectory) | 173 IPC_MESSAGE_HANDLER(FileSystemMsg_DidReadDirectory, OnDidReadDirectory) |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 DCHECK(dispatcher); | 377 DCHECK(dispatcher); |
| 357 dispatcher->DidReadMetadata(file_info); | 378 dispatcher->DidReadMetadata(file_info); |
| 358 dispatchers_.Remove(request_id); | 379 dispatchers_.Remove(request_id); |
| 359 } | 380 } |
| 360 | 381 |
| 361 void FileSystemDispatcher::OnDidCreateSnapshotFile( | 382 void FileSystemDispatcher::OnDidCreateSnapshotFile( |
| 362 int request_id, const base::PlatformFileInfo& file_info, | 383 int request_id, const base::PlatformFileInfo& file_info, |
| 363 const base::FilePath& platform_path) { | 384 const base::FilePath& platform_path) { |
| 364 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); | 385 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); |
| 365 DCHECK(dispatcher); | 386 DCHECK(dispatcher); |
| 366 dispatcher->DidCreateSnapshotFile(file_info, platform_path); | 387 dispatcher->DidCreateSnapshotFile( |
| 388 file_info, platform_path, | |
| 389 base::Bind(&DidReceiveSnapshotFile, request_id, | |
| 390 base::MessageLoopProxy::current())); | |
| 367 dispatchers_.Remove(request_id); | 391 dispatchers_.Remove(request_id); |
| 368 ChildThread::current()->Send( | |
| 369 new FileSystemHostMsg_DidReceiveSnapshotFile(request_id)); | |
| 370 } | 392 } |
| 371 | 393 |
| 372 void FileSystemDispatcher::OnDidReadDirectory( | 394 void FileSystemDispatcher::OnDidReadDirectory( |
| 373 int request_id, | 395 int request_id, |
| 374 const std::vector<fileapi::DirectoryEntry>& entries, | 396 const std::vector<fileapi::DirectoryEntry>& entries, |
| 375 bool has_more) { | 397 bool has_more) { |
| 376 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); | 398 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); |
| 377 DCHECK(dispatcher); | 399 DCHECK(dispatcher); |
| 378 dispatcher->DidReadDirectory(entries, has_more); | 400 dispatcher->DidReadDirectory(entries, has_more); |
| 379 dispatchers_.Remove(request_id); | 401 dispatchers_.Remove(request_id); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 403 quota::QuotaLimitType quota_policy) { | 425 quota::QuotaLimitType quota_policy) { |
| 404 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); | 426 CallbackDispatcher* dispatcher = dispatchers_.Lookup(request_id); |
| 405 DCHECK(dispatcher); | 427 DCHECK(dispatcher); |
| 406 dispatcher->DidOpenFile(IPC::PlatformFileForTransitToPlatformFile(file), | 428 dispatcher->DidOpenFile(IPC::PlatformFileForTransitToPlatformFile(file), |
| 407 file_open_id, | 429 file_open_id, |
| 408 quota_policy); | 430 quota_policy); |
| 409 dispatchers_.Remove(request_id); | 431 dispatchers_.Remove(request_id); |
| 410 } | 432 } |
| 411 | 433 |
| 412 } // namespace content | 434 } // namespace content |
| OLD | NEW |