| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/sync_file_system/local/syncable_file_system_operation.h
" | 5 #include "chrome/browser/sync_file_system/local/syncable_file_system_operation.h
" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" | 8 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" |
| 9 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" | 9 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" |
| 10 #include "chrome/browser/sync_file_system/local/syncable_file_operation_runner.h
" | 10 #include "chrome/browser/sync_file_system/local/syncable_file_operation_runner.h
" |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 DCHECK(CalledOnValidThread()); | 297 DCHECK(CalledOnValidThread()); |
| 298 if (!operation_runner_.get()) { | 298 if (!operation_runner_.get()) { |
| 299 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); | 299 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
| 300 return; | 300 return; |
| 301 } | 301 } |
| 302 DCHECK(operation_runner_.get()); | 302 DCHECK(operation_runner_.get()); |
| 303 target_paths_.push_back(dest_url); | 303 target_paths_.push_back(dest_url); |
| 304 completion_callback_ = callback; | 304 completion_callback_ = callback; |
| 305 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 305 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
| 306 AsWeakPtr(), | 306 AsWeakPtr(), |
| 307 base::Bind(&FileSystemOperationImpl::CopyInForeignFile, | 307 base::Bind(&FileSystemOperation::CopyInForeignFile, |
| 308 NewOperation()->AsWeakPtr(), | 308 NewOperation()->AsWeakPtr(), |
| 309 src_local_disk_path, dest_url, | 309 src_local_disk_path, dest_url, |
| 310 base::Bind(&self::DidFinish, AsWeakPtr())))); | 310 base::Bind(&self::DidFinish, AsWeakPtr())))); |
| 311 operation_runner_->PostOperationTask(task.Pass()); | 311 operation_runner_->PostOperationTask(task.Pass()); |
| 312 } | 312 } |
| 313 | 313 |
| 314 void SyncableFileSystemOperation::RemoveFile( |
| 315 const FileSystemURL& url, |
| 316 const StatusCallback& callback) { |
| 317 DCHECK(CalledOnValidThread()); |
| 318 NewOperation()->RemoveFile(url, callback); |
| 319 } |
| 320 |
| 321 void SyncableFileSystemOperation::RemoveDirectory( |
| 322 const FileSystemURL& url, |
| 323 const StatusCallback& callback) { |
| 324 DCHECK(CalledOnValidThread()); |
| 325 NewOperation()->RemoveDirectory(url, callback); |
| 326 } |
| 327 |
| 328 void SyncableFileSystemOperation::CopyFileLocal( |
| 329 const FileSystemURL& src_url, |
| 330 const FileSystemURL& dest_url, |
| 331 const StatusCallback& callback) { |
| 332 DCHECK(CalledOnValidThread()); |
| 333 NewOperation()->CopyFileLocal(src_url, dest_url, callback); |
| 334 } |
| 335 |
| 336 void SyncableFileSystemOperation::MoveFileLocal( |
| 337 const FileSystemURL& src_url, |
| 338 const FileSystemURL& dest_url, |
| 339 const StatusCallback& callback) { |
| 340 DCHECK(CalledOnValidThread()); |
| 341 NewOperation()->MoveFileLocal(src_url, dest_url, callback); |
| 342 } |
| 343 |
| 344 base::PlatformFileError SyncableFileSystemOperation::SyncGetPlatformPath( |
| 345 const FileSystemURL& url, |
| 346 base::FilePath* platform_path) { |
| 347 return NewOperation()->SyncGetPlatformPath(url, platform_path); |
| 348 } |
| 349 |
| 314 SyncableFileSystemOperation::SyncableFileSystemOperation( | 350 SyncableFileSystemOperation::SyncableFileSystemOperation( |
| 315 const FileSystemURL& url, | 351 const FileSystemURL& url, |
| 316 fileapi::FileSystemContext* file_system_context, | 352 fileapi::FileSystemContext* file_system_context, |
| 317 scoped_ptr<FileSystemOperationContext> operation_context) | 353 scoped_ptr<FileSystemOperationContext> operation_context) |
| 318 : FileSystemOperationImpl(url, file_system_context, | 354 : url_(url), |
| 319 operation_context.Pass()), | 355 file_system_context_(file_system_context), |
| 320 url_(url) { | 356 operation_context_(operation_context.Pass()) { |
| 321 DCHECK(file_system_context); | 357 DCHECK(file_system_context); |
| 322 SyncFileSystemBackend* backend = | 358 SyncFileSystemBackend* backend = |
| 323 SyncFileSystemBackend::GetBackend(file_system_context); | 359 SyncFileSystemBackend::GetBackend(file_system_context); |
| 324 DCHECK(backend); | 360 DCHECK(backend); |
| 325 if (!backend->sync_context()) { | 361 if (!backend->sync_context()) { |
| 326 // Syncable FileSystem is opened in a file system context which doesn't | 362 // Syncable FileSystem is opened in a file system context which doesn't |
| 327 // support (or is not initialized for) the API. | 363 // support (or is not initialized for) the API. |
| 328 // Returning here to leave operation_runner_ as NULL. | 364 // Returning here to leave operation_runner_ as NULL. |
| 329 return; | 365 return; |
| 330 } | 366 } |
| 331 operation_runner_ = backend->sync_context()->operation_runner(); | 367 operation_runner_ = backend->sync_context()->operation_runner(); |
| 332 is_directory_operation_enabled_ = IsSyncFSDirectoryOperationEnabled(); | 368 is_directory_operation_enabled_ = IsSyncFSDirectoryOperationEnabled(); |
| 333 } | 369 } |
| 334 | 370 |
| 335 FileSystemOperationImpl* SyncableFileSystemOperation::NewOperation() { | 371 FileSystemOperationImpl* SyncableFileSystemOperation::NewOperation() { |
| 336 DCHECK(operation_context_); | 372 DCHECK(operation_context_); |
| 337 inflight_operation_.reset(new FileSystemOperationImpl( | 373 inflight_operation_.reset(new FileSystemOperationImpl( |
| 338 url_, file_system_context(), operation_context_.Pass())); | 374 url_, file_system_context_, operation_context_.Pass())); |
| 339 DCHECK(inflight_operation_); | 375 DCHECK(inflight_operation_); |
| 340 return inflight_operation_.get(); | 376 return inflight_operation_.get(); |
| 341 } | 377 } |
| 342 | 378 |
| 343 void SyncableFileSystemOperation::DidFinish(base::PlatformFileError status) { | 379 void SyncableFileSystemOperation::DidFinish(base::PlatformFileError status) { |
| 344 DCHECK(CalledOnValidThread()); | 380 DCHECK(CalledOnValidThread()); |
| 345 DCHECK(!completion_callback_.is_null()); | 381 DCHECK(!completion_callback_.is_null()); |
| 346 if (operation_runner_.get()) | 382 if (operation_runner_.get()) |
| 347 operation_runner_->OnOperationCompleted(target_paths_); | 383 operation_runner_->OnOperationCompleted(target_paths_); |
| 348 completion_callback_.Run(status); | 384 completion_callback_.Run(status); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 362 operation_runner_->OnOperationCompleted(target_paths_); | 398 operation_runner_->OnOperationCompleted(target_paths_); |
| 363 callback.Run(result, bytes, complete); | 399 callback.Run(result, bytes, complete); |
| 364 } | 400 } |
| 365 | 401 |
| 366 void SyncableFileSystemOperation::OnCancelled() { | 402 void SyncableFileSystemOperation::OnCancelled() { |
| 367 DCHECK(!completion_callback_.is_null()); | 403 DCHECK(!completion_callback_.is_null()); |
| 368 completion_callback_.Run(base::PLATFORM_FILE_ERROR_ABORT); | 404 completion_callback_.Run(base::PLATFORM_FILE_ERROR_ABORT); |
| 369 } | 405 } |
| 370 | 406 |
| 371 } // namespace sync_file_system | 407 } // namespace sync_file_system |
| OLD | NEW |