OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_fi
le_util.h" | 5 #include "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_fi
le_util.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 bool exclusive, | 90 bool exclusive, |
91 bool recursive, | 91 bool recursive, |
92 const storage::AsyncFileUtil::StatusCallback& callback) { | 92 const storage::AsyncFileUtil::StatusCallback& callback) { |
93 util::FileSystemURLParser parser(url); | 93 util::FileSystemURLParser parser(url); |
94 if (!parser.Parse()) { | 94 if (!parser.Parse()) { |
95 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); | 95 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
96 return; | 96 return; |
97 } | 97 } |
98 | 98 |
99 parser.file_system()->CreateDirectory( | 99 parser.file_system()->CreateDirectory( |
100 parser.file_path(), exclusive, recursive, callback); | 100 parser.file_path(), recursive, callback); |
101 } | 101 } |
102 | 102 |
103 // Routes the response of CreateDirectory back to the IO thread. | 103 // Routes the response of CreateDirectory back to the IO thread. |
104 void OnCreateDirectory(const storage::AsyncFileUtil::StatusCallback& callback, | 104 void OnCreateDirectory(bool exclusive, |
| 105 const storage::AsyncFileUtil::StatusCallback& callback, |
105 base::File::Error result) { | 106 base::File::Error result) { |
| 107 // If the directory already existed and the operation wasn't exclusive, then |
| 108 // return success anyway, since it is not an error. |
| 109 const base::File::Error error = |
| 110 (result == base::File::FILE_ERROR_EXISTS && !exclusive) |
| 111 ? base::File::FILE_OK |
| 112 : result; |
| 113 |
106 BrowserThread::PostTask( | 114 BrowserThread::PostTask( |
107 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); | 115 BrowserThread::IO, FROM_HERE, base::Bind(callback, error)); |
108 } | 116 } |
109 | 117 |
110 // Executes DeleteEntry on the UI thread. | 118 // Executes DeleteEntry on the UI thread. |
111 void DeleteEntryOnUIThread( | 119 void DeleteEntryOnUIThread( |
112 scoped_ptr<storage::FileSystemOperationContext> context, | 120 scoped_ptr<storage::FileSystemOperationContext> context, |
113 const storage::FileSystemURL& url, | 121 const storage::FileSystemURL& url, |
114 bool recursive, | 122 bool recursive, |
115 const storage::AsyncFileUtil::StatusCallback& callback) { | 123 const storage::AsyncFileUtil::StatusCallback& callback) { |
116 util::FileSystemURLParser parser(url); | 124 util::FileSystemURLParser parser(url); |
117 if (!parser.Parse()) { | 125 if (!parser.Parse()) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 base::Bind(&OnCreateFileForEnsureFileExists, callback))); | 283 base::Bind(&OnCreateFileForEnsureFileExists, callback))); |
276 } | 284 } |
277 | 285 |
278 void ProviderAsyncFileUtil::CreateDirectory( | 286 void ProviderAsyncFileUtil::CreateDirectory( |
279 scoped_ptr<storage::FileSystemOperationContext> context, | 287 scoped_ptr<storage::FileSystemOperationContext> context, |
280 const storage::FileSystemURL& url, | 288 const storage::FileSystemURL& url, |
281 bool exclusive, | 289 bool exclusive, |
282 bool recursive, | 290 bool recursive, |
283 const StatusCallback& callback) { | 291 const StatusCallback& callback) { |
284 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 292 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
285 BrowserThread::PostTask(BrowserThread::UI, | 293 BrowserThread::PostTask( |
286 FROM_HERE, | 294 BrowserThread::UI, |
287 base::Bind(&CreateDirectoryOnUIThread, | 295 FROM_HERE, |
288 base::Passed(&context), | 296 base::Bind(&CreateDirectoryOnUIThread, |
289 url, | 297 base::Passed(&context), |
290 exclusive, | 298 url, |
291 recursive, | 299 exclusive, |
292 base::Bind(&OnCreateDirectory, callback))); | 300 recursive, |
| 301 base::Bind(&OnCreateDirectory, exclusive, callback))); |
293 } | 302 } |
294 | 303 |
295 void ProviderAsyncFileUtil::GetFileInfo( | 304 void ProviderAsyncFileUtil::GetFileInfo( |
296 scoped_ptr<storage::FileSystemOperationContext> context, | 305 scoped_ptr<storage::FileSystemOperationContext> context, |
297 const storage::FileSystemURL& url, | 306 const storage::FileSystemURL& url, |
298 const GetFileInfoCallback& callback) { | 307 const GetFileInfoCallback& callback) { |
299 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 308 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
300 BrowserThread::PostTask(BrowserThread::UI, | 309 BrowserThread::PostTask(BrowserThread::UI, |
301 FROM_HERE, | 310 FROM_HERE, |
302 base::Bind(&GetFileInfoOnUIThread, | 311 base::Bind(&GetFileInfoOnUIThread, |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 NOTIMPLEMENTED(); | 448 NOTIMPLEMENTED(); |
440 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION, | 449 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION, |
441 base::File::Info(), | 450 base::File::Info(), |
442 base::FilePath(), | 451 base::FilePath(), |
443 scoped_refptr<storage::ShareableFileReference>()); | 452 scoped_refptr<storage::ShareableFileReference>()); |
444 } | 453 } |
445 | 454 |
446 } // namespace internal | 455 } // namespace internal |
447 } // namespace file_system_provider | 456 } // namespace file_system_provider |
448 } // namespace chromeos | 457 } // namespace chromeos |
OLD | NEW |