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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 } | 179 } |
180 | 180 |
181 // Routes the response of CopyEntry to a callback of CopyLocalFile() on the | 181 // Routes the response of CopyEntry to a callback of CopyLocalFile() on the |
182 // IO thread. | 182 // IO thread. |
183 void OnCopyEntry(const fileapi::AsyncFileUtil::StatusCallback& callback, | 183 void OnCopyEntry(const fileapi::AsyncFileUtil::StatusCallback& callback, |
184 base::File::Error result) { | 184 base::File::Error result) { |
185 BrowserThread::PostTask( | 185 BrowserThread::PostTask( |
186 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); | 186 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); |
187 } | 187 } |
188 | 188 |
| 189 // Executes MoveEntry on the UI thread. |
| 190 void MoveEntryOnUIThread( |
| 191 scoped_ptr<fileapi::FileSystemOperationContext> context, |
| 192 const fileapi::FileSystemURL& source_url, |
| 193 const fileapi::FileSystemURL& target_url, |
| 194 const fileapi::AsyncFileUtil::StatusCallback& callback) { |
| 195 util::FileSystemURLParser source_parser(source_url); |
| 196 util::FileSystemURLParser target_parser(target_url); |
| 197 |
| 198 if (!source_parser.Parse() || !target_parser.Parse() || |
| 199 source_parser.file_system() != target_parser.file_system()) { |
| 200 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
| 201 return; |
| 202 } |
| 203 |
| 204 target_parser.file_system()->MoveEntry( |
| 205 source_parser.file_path(), target_parser.file_path(), callback); |
| 206 } |
| 207 |
| 208 // Routes the response of CopyEntry to a callback of MoveLocalFile() on the |
| 209 // IO thread. |
| 210 void OnMoveEntry(const fileapi::AsyncFileUtil::StatusCallback& callback, |
| 211 base::File::Error result) { |
| 212 BrowserThread::PostTask( |
| 213 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); |
| 214 } |
| 215 |
189 } // namespace | 216 } // namespace |
190 | 217 |
191 ProviderAsyncFileUtil::ProviderAsyncFileUtil() {} | 218 ProviderAsyncFileUtil::ProviderAsyncFileUtil() {} |
192 | 219 |
193 ProviderAsyncFileUtil::~ProviderAsyncFileUtil() {} | 220 ProviderAsyncFileUtil::~ProviderAsyncFileUtil() {} |
194 | 221 |
195 void ProviderAsyncFileUtil::CreateOrOpen( | 222 void ProviderAsyncFileUtil::CreateOrOpen( |
196 scoped_ptr<fileapi::FileSystemOperationContext> context, | 223 scoped_ptr<fileapi::FileSystemOperationContext> context, |
197 const fileapi::FileSystemURL& url, | 224 const fileapi::FileSystemURL& url, |
198 int file_flags, | 225 int file_flags, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 base::Bind(&OnCopyEntry, callback))); | 334 base::Bind(&OnCopyEntry, callback))); |
308 } | 335 } |
309 | 336 |
310 void ProviderAsyncFileUtil::MoveFileLocal( | 337 void ProviderAsyncFileUtil::MoveFileLocal( |
311 scoped_ptr<fileapi::FileSystemOperationContext> context, | 338 scoped_ptr<fileapi::FileSystemOperationContext> context, |
312 const fileapi::FileSystemURL& src_url, | 339 const fileapi::FileSystemURL& src_url, |
313 const fileapi::FileSystemURL& dest_url, | 340 const fileapi::FileSystemURL& dest_url, |
314 CopyOrMoveOption option, | 341 CopyOrMoveOption option, |
315 const StatusCallback& callback) { | 342 const StatusCallback& callback) { |
316 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 343 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
317 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED); | 344 // TODO(mtomasz): Consier adding support for options (preserving last modified |
| 345 // time) as well as the progress callback. |
| 346 BrowserThread::PostTask(BrowserThread::UI, |
| 347 FROM_HERE, |
| 348 base::Bind(&MoveEntryOnUIThread, |
| 349 base::Passed(&context), |
| 350 src_url, |
| 351 dest_url, |
| 352 base::Bind(&OnMoveEntry, callback))); |
318 } | 353 } |
319 | 354 |
320 void ProviderAsyncFileUtil::CopyInForeignFile( | 355 void ProviderAsyncFileUtil::CopyInForeignFile( |
321 scoped_ptr<fileapi::FileSystemOperationContext> context, | 356 scoped_ptr<fileapi::FileSystemOperationContext> context, |
322 const base::FilePath& src_file_path, | 357 const base::FilePath& src_file_path, |
323 const fileapi::FileSystemURL& dest_url, | 358 const fileapi::FileSystemURL& dest_url, |
324 const StatusCallback& callback) { | 359 const StatusCallback& callback) { |
325 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 360 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
326 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED); | 361 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED); |
327 } | 362 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 NOTIMPLEMENTED(); | 411 NOTIMPLEMENTED(); |
377 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION, | 412 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION, |
378 base::File::Info(), | 413 base::File::Info(), |
379 base::FilePath(), | 414 base::FilePath(), |
380 scoped_refptr<webkit_blob::ShareableFileReference>()); | 415 scoped_refptr<webkit_blob::ShareableFileReference>()); |
381 } | 416 } |
382 | 417 |
383 } // namespace internal | 418 } // namespace internal |
384 } // namespace file_system_provider | 419 } // namespace file_system_provider |
385 } // namespace chromeos | 420 } // namespace chromeos |
OLD | NEW |