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