| 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/drive_backend/remote_to_local_syncer.h
" | 5 #include "chrome/browser/sync_file_system/drive_backend/remote_to_local_syncer.h
" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 |
| 8 #include <limits> | 9 #include <limits> |
| 9 #include <utility> | 10 #include <utility> |
| 10 | 11 |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/callback.h" | 13 #include "base/callback.h" |
| 13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 14 #include "base/format_macros.h" | 15 #include "base/format_macros.h" |
| 15 #include "base/location.h" | 16 #include "base/location.h" |
| 16 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/memory/ptr_util.h" |
| 17 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 18 #include "base/task_runner_util.h" | 20 #include "base/task_runner_util.h" |
| 19 #include "chrome/browser/sync_file_system/drive_backend/callback_helper.h" | 21 #include "chrome/browser/sync_file_system/drive_backend/callback_helper.h" |
| 20 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_util.h" | 22 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_util.h" |
| 21 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" | 23 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" |
| 22 #include "chrome/browser/sync_file_system/drive_backend/sync_engine_context.h" | 24 #include "chrome/browser/sync_file_system/drive_backend/sync_engine_context.h" |
| 23 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h" | 25 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h" |
| 24 #include "chrome/browser/sync_file_system/drive_backend/sync_task_token.h" | 26 #include "chrome/browser/sync_file_system/drive_backend/sync_task_token.h" |
| 25 #include "chrome/browser/sync_file_system/drive_backend/task_dependency_manager.
h" | 27 #include "chrome/browser/sync_file_system/drive_backend/task_dependency_manager.
h" |
| 26 #include "chrome/browser/sync_file_system/logger.h" | 28 #include "chrome/browser/sync_file_system/logger.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 DCHECK(tracker.active()); | 67 DCHECK(tracker.active()); |
| 66 FileTracker app_root_tracker; | 68 FileTracker app_root_tracker; |
| 67 if (database->FindAppRootTracker(tracker.app_id(), &app_root_tracker)) { | 69 if (database->FindAppRootTracker(tracker.app_id(), &app_root_tracker)) { |
| 68 DCHECK(app_root_tracker.tracker_kind() == TRACKER_KIND_APP_ROOT || | 70 DCHECK(app_root_tracker.tracker_kind() == TRACKER_KIND_APP_ROOT || |
| 69 app_root_tracker.tracker_kind() == TRACKER_KIND_DISABLED_APP_ROOT); | 71 app_root_tracker.tracker_kind() == TRACKER_KIND_DISABLED_APP_ROOT); |
| 70 return app_root_tracker.tracker_kind() == TRACKER_KIND_DISABLED_APP_ROOT; | 72 return app_root_tracker.tracker_kind() == TRACKER_KIND_DISABLED_APP_ROOT; |
| 71 } | 73 } |
| 72 return false; | 74 return false; |
| 73 } | 75 } |
| 74 | 76 |
| 75 scoped_ptr<FileMetadata> GetFileMetadata(MetadataDatabase* database, | 77 std::unique_ptr<FileMetadata> GetFileMetadata(MetadataDatabase* database, |
| 76 const std::string& file_id) { | 78 const std::string& file_id) { |
| 77 scoped_ptr<FileMetadata> metadata(new FileMetadata); | 79 std::unique_ptr<FileMetadata> metadata(new FileMetadata); |
| 78 if (!database->FindFileByFileID(file_id, metadata.get())) | 80 if (!database->FindFileByFileID(file_id, metadata.get())) |
| 79 metadata.reset(); | 81 metadata.reset(); |
| 80 return metadata; | 82 return metadata; |
| 81 } | 83 } |
| 82 | 84 |
| 83 // Creates a temporary file in |dir_path|. This must be called on an | 85 // Creates a temporary file in |dir_path|. This must be called on an |
| 84 // IO-allowed task runner, and the runner must be given as |file_task_runner|. | 86 // IO-allowed task runner, and the runner must be given as |file_task_runner|. |
| 85 storage::ScopedFile CreateTemporaryFile( | 87 storage::ScopedFile CreateTemporaryFile( |
| 86 const scoped_refptr<base::TaskRunner>& file_task_runner) { | 88 const scoped_refptr<base::TaskRunner>& file_task_runner) { |
| 87 base::FilePath temp_file_path; | 89 base::FilePath temp_file_path; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 100 file_type_(SYNC_FILE_TYPE_UNKNOWN), | 102 file_type_(SYNC_FILE_TYPE_UNKNOWN), |
| 101 sync_action_(SYNC_ACTION_NONE), | 103 sync_action_(SYNC_ACTION_NONE), |
| 102 prepared_(false), | 104 prepared_(false), |
| 103 sync_root_deletion_(false), | 105 sync_root_deletion_(false), |
| 104 weak_ptr_factory_(this) { | 106 weak_ptr_factory_(this) { |
| 105 } | 107 } |
| 106 | 108 |
| 107 RemoteToLocalSyncer::~RemoteToLocalSyncer() { | 109 RemoteToLocalSyncer::~RemoteToLocalSyncer() { |
| 108 } | 110 } |
| 109 | 111 |
| 110 void RemoteToLocalSyncer::RunPreflight(scoped_ptr<SyncTaskToken> token) { | 112 void RemoteToLocalSyncer::RunPreflight(std::unique_ptr<SyncTaskToken> token) { |
| 111 token->InitializeTaskLog("Remote -> Local"); | 113 token->InitializeTaskLog("Remote -> Local"); |
| 112 | 114 |
| 113 if (!drive_service() || !metadata_database() || !remote_change_processor()) { | 115 if (!drive_service() || !metadata_database() || !remote_change_processor()) { |
| 114 token->RecordLog("Context not ready."); | 116 token->RecordLog("Context not ready."); |
| 115 SyncTaskManager::NotifyTaskDone(std::move(token), SYNC_STATUS_FAILED); | 117 SyncTaskManager::NotifyTaskDone(std::move(token), SYNC_STATUS_FAILED); |
| 116 return; | 118 return; |
| 117 } | 119 } |
| 118 | 120 |
| 119 dirty_tracker_ = make_scoped_ptr(new FileTracker); | 121 dirty_tracker_ = base::WrapUnique(new FileTracker); |
| 120 if (metadata_database()->GetDirtyTracker(dirty_tracker_.get())) { | 122 if (metadata_database()->GetDirtyTracker(dirty_tracker_.get())) { |
| 121 token->RecordLog(base::StringPrintf( | 123 token->RecordLog(base::StringPrintf( |
| 122 "Start: tracker_id=%" PRId64, dirty_tracker_->tracker_id())); | 124 "Start: tracker_id=%" PRId64, dirty_tracker_->tracker_id())); |
| 123 metadata_database()->DemoteTracker(dirty_tracker_->tracker_id()); | 125 metadata_database()->DemoteTracker(dirty_tracker_->tracker_id()); |
| 124 ResolveRemoteChange(std::move(token)); | 126 ResolveRemoteChange(std::move(token)); |
| 125 return; | 127 return; |
| 126 } | 128 } |
| 127 | 129 |
| 128 token->RecordLog("Nothing to do."); | 130 token->RecordLog("Nothing to do."); |
| 129 SyncTaskManager::NotifyTaskDone(std::move(token), | 131 SyncTaskManager::NotifyTaskDone(std::move(token), |
| 130 SYNC_STATUS_NO_CHANGE_TO_SYNC); | 132 SYNC_STATUS_NO_CHANGE_TO_SYNC); |
| 131 } | 133 } |
| 132 | 134 |
| 133 void RemoteToLocalSyncer::ResolveRemoteChange(scoped_ptr<SyncTaskToken> token) { | 135 void RemoteToLocalSyncer::ResolveRemoteChange( |
| 136 std::unique_ptr<SyncTaskToken> token) { |
| 134 DCHECK(dirty_tracker_); | 137 DCHECK(dirty_tracker_); |
| 135 remote_metadata_ = GetFileMetadata( | 138 remote_metadata_ = GetFileMetadata( |
| 136 metadata_database(), dirty_tracker_->file_id()); | 139 metadata_database(), dirty_tracker_->file_id()); |
| 137 | 140 |
| 138 if (!remote_metadata_ || !remote_metadata_->has_details()) { | 141 if (!remote_metadata_ || !remote_metadata_->has_details()) { |
| 139 if (remote_metadata_ && !remote_metadata_->has_details()) { | 142 if (remote_metadata_ && !remote_metadata_->has_details()) { |
| 140 token->RecordLog( | 143 token->RecordLog( |
| 141 "Missing details of a remote file: " + remote_metadata_->file_id()); | 144 "Missing details of a remote file: " + remote_metadata_->file_id()); |
| 142 NOTREACHED(); | 145 NOTREACHED(); |
| 143 } | 146 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 return; | 305 return; |
| 303 } | 306 } |
| 304 SyncCompleted(std::move(token), SYNC_STATUS_OK); | 307 SyncCompleted(std::move(token), SYNC_STATUS_OK); |
| 305 return; | 308 return; |
| 306 } | 309 } |
| 307 | 310 |
| 308 token->RecordLog("Trivial file change."); | 311 token->RecordLog("Trivial file change."); |
| 309 SyncCompleted(std::move(token), SYNC_STATUS_OK); | 312 SyncCompleted(std::move(token), SYNC_STATUS_OK); |
| 310 } | 313 } |
| 311 | 314 |
| 312 void RemoteToLocalSyncer::MoveToBackground(scoped_ptr<SyncTaskToken> token, | 315 void RemoteToLocalSyncer::MoveToBackground(std::unique_ptr<SyncTaskToken> token, |
| 313 const Continuation& continuation) { | 316 const Continuation& continuation) { |
| 314 DCHECK(dirty_tracker_); | 317 DCHECK(dirty_tracker_); |
| 315 | 318 |
| 316 scoped_ptr<TaskBlocker> blocker(new TaskBlocker); | 319 std::unique_ptr<TaskBlocker> blocker(new TaskBlocker); |
| 317 blocker->app_id = dirty_tracker_->app_id(); | 320 blocker->app_id = dirty_tracker_->app_id(); |
| 318 if (url_.is_valid()) | 321 if (url_.is_valid()) |
| 319 blocker->paths.push_back(url_.path()); | 322 blocker->paths.push_back(url_.path()); |
| 320 blocker->file_ids.push_back(dirty_tracker_->file_id()); | 323 blocker->file_ids.push_back(dirty_tracker_->file_id()); |
| 321 blocker->tracker_ids.push_back(dirty_tracker_->tracker_id()); | 324 blocker->tracker_ids.push_back(dirty_tracker_->tracker_id()); |
| 322 | 325 |
| 323 SyncTaskManager::UpdateTaskBlocker( | 326 SyncTaskManager::UpdateTaskBlocker( |
| 324 std::move(token), std::move(blocker), | 327 std::move(token), std::move(blocker), |
| 325 base::Bind(&RemoteToLocalSyncer::ContinueAsBackgroundTask, | 328 base::Bind(&RemoteToLocalSyncer::ContinueAsBackgroundTask, |
| 326 weak_ptr_factory_.GetWeakPtr(), continuation)); | 329 weak_ptr_factory_.GetWeakPtr(), continuation)); |
| 327 } | 330 } |
| 328 | 331 |
| 329 void RemoteToLocalSyncer::ContinueAsBackgroundTask( | 332 void RemoteToLocalSyncer::ContinueAsBackgroundTask( |
| 330 const Continuation& continuation, | 333 const Continuation& continuation, |
| 331 scoped_ptr<SyncTaskToken> token) { | 334 std::unique_ptr<SyncTaskToken> token) { |
| 332 DCHECK(dirty_tracker_); | 335 DCHECK(dirty_tracker_); |
| 333 | 336 |
| 334 // The SyncTask runs as a background task beyond this point. | 337 // The SyncTask runs as a background task beyond this point. |
| 335 // Not that any task can run between MoveToBackground() and | 338 // Not that any task can run between MoveToBackground() and |
| 336 // ContinueAsBackgroundTask(), so we need to make sure other tasks didn't | 339 // ContinueAsBackgroundTask(), so we need to make sure other tasks didn't |
| 337 // affect to the current RemoteToLocalSyncer task. | 340 // affect to the current RemoteToLocalSyncer task. |
| 338 // | 341 // |
| 339 // - For LocalToRemoteSyncer, it may update or delete any of FileTracker and | 342 // - For LocalToRemoteSyncer, it may update or delete any of FileTracker and |
| 340 // FileMetadata. When it updates FileMetadata or FileDetails in FileTracker, | 343 // FileMetadata. When it updates FileMetadata or FileDetails in FileTracker, |
| 341 // it also updates |change_id|. So, ensure the target FileTracker and | 344 // it also updates |change_id|. So, ensure the target FileTracker and |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 } else { | 389 } else { |
| 387 if (remote_metadata_) { | 390 if (remote_metadata_) { |
| 388 SyncCompleted(std::move(token), SYNC_STATUS_RETRY); | 391 SyncCompleted(std::move(token), SYNC_STATUS_RETRY); |
| 389 return; | 392 return; |
| 390 } | 393 } |
| 391 } | 394 } |
| 392 continuation.Run(std::move(token)); | 395 continuation.Run(std::move(token)); |
| 393 } | 396 } |
| 394 | 397 |
| 395 void RemoteToLocalSyncer::HandleMissingRemoteMetadata( | 398 void RemoteToLocalSyncer::HandleMissingRemoteMetadata( |
| 396 scoped_ptr<SyncTaskToken> token) { | 399 std::unique_ptr<SyncTaskToken> token) { |
| 397 DCHECK(dirty_tracker_); | 400 DCHECK(dirty_tracker_); |
| 398 | 401 |
| 399 drive_service()->GetFileResource( | 402 drive_service()->GetFileResource( |
| 400 dirty_tracker_->file_id(), | 403 dirty_tracker_->file_id(), |
| 401 base::Bind(&RemoteToLocalSyncer::DidGetRemoteMetadata, | 404 base::Bind(&RemoteToLocalSyncer::DidGetRemoteMetadata, |
| 402 weak_ptr_factory_.GetWeakPtr(), | 405 weak_ptr_factory_.GetWeakPtr(), |
| 403 base::Passed(&token))); | 406 base::Passed(&token))); |
| 404 } | 407 } |
| 405 | 408 |
| 406 void RemoteToLocalSyncer::DidGetRemoteMetadata( | 409 void RemoteToLocalSyncer::DidGetRemoteMetadata( |
| 407 scoped_ptr<SyncTaskToken> token, | 410 std::unique_ptr<SyncTaskToken> token, |
| 408 google_apis::DriveApiErrorCode error, | 411 google_apis::DriveApiErrorCode error, |
| 409 scoped_ptr<google_apis::FileResource> entry) { | 412 std::unique_ptr<google_apis::FileResource> entry) { |
| 410 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread()); | 413 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread()); |
| 411 | 414 |
| 412 SyncStatusCode status = DriveApiErrorCodeToSyncStatusCode(error); | 415 SyncStatusCode status = DriveApiErrorCodeToSyncStatusCode(error); |
| 413 if (status != SYNC_STATUS_OK && | 416 if (status != SYNC_STATUS_OK && |
| 414 error != google_apis::HTTP_NOT_FOUND) { | 417 error != google_apis::HTTP_NOT_FOUND) { |
| 415 SyncCompleted(std::move(token), status); | 418 SyncCompleted(std::move(token), status); |
| 416 return; | 419 return; |
| 417 } | 420 } |
| 418 | 421 |
| 419 if (error == google_apis::HTTP_NOT_FOUND) { | 422 if (error == google_apis::HTTP_NOT_FOUND) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 435 return; | 438 return; |
| 436 } | 439 } |
| 437 | 440 |
| 438 metadata_database()->PromoteDemotedTracker(dirty_tracker_->tracker_id()); | 441 metadata_database()->PromoteDemotedTracker(dirty_tracker_->tracker_id()); |
| 439 | 442 |
| 440 // Do not update |dirty_tracker_|. | 443 // Do not update |dirty_tracker_|. |
| 441 SyncCompleted(std::move(token), SYNC_STATUS_RETRY); | 444 SyncCompleted(std::move(token), SYNC_STATUS_RETRY); |
| 442 } | 445 } |
| 443 | 446 |
| 444 void RemoteToLocalSyncer::DidPrepareForAddOrUpdateFile( | 447 void RemoteToLocalSyncer::DidPrepareForAddOrUpdateFile( |
| 445 scoped_ptr<SyncTaskToken> token, | 448 std::unique_ptr<SyncTaskToken> token, |
| 446 SyncStatusCode status) { | 449 SyncStatusCode status) { |
| 447 if (status != SYNC_STATUS_OK) { | 450 if (status != SYNC_STATUS_OK) { |
| 448 SyncCompleted(std::move(token), status); | 451 SyncCompleted(std::move(token), status); |
| 449 return; | 452 return; |
| 450 } | 453 } |
| 451 | 454 |
| 452 DCHECK(url_.is_valid()); | 455 DCHECK(url_.is_valid()); |
| 453 DCHECK(local_metadata_); | 456 DCHECK(local_metadata_); |
| 454 DCHECK(local_changes_); | 457 DCHECK(local_changes_); |
| 455 | 458 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 486 return; | 489 return; |
| 487 } | 490 } |
| 488 | 491 |
| 489 DCHECK(local_changes_->back().IsAddOrUpdate()); | 492 DCHECK(local_changes_->back().IsAddOrUpdate()); |
| 490 // Conflict case. | 493 // Conflict case. |
| 491 // Do nothing for the change now, and handle this in LocalToRemoteSync phase. | 494 // Do nothing for the change now, and handle this in LocalToRemoteSync phase. |
| 492 SyncCompleted(std::move(token), SYNC_STATUS_RETRY); | 495 SyncCompleted(std::move(token), SYNC_STATUS_RETRY); |
| 493 } | 496 } |
| 494 | 497 |
| 495 void RemoteToLocalSyncer::HandleFolderUpdate( | 498 void RemoteToLocalSyncer::HandleFolderUpdate( |
| 496 scoped_ptr<SyncTaskToken> token) { | 499 std::unique_ptr<SyncTaskToken> token) { |
| 497 DCHECK(dirty_tracker_); | 500 DCHECK(dirty_tracker_); |
| 498 DCHECK(dirty_tracker_->active()); | 501 DCHECK(dirty_tracker_->active()); |
| 499 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); | 502 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); |
| 500 | 503 |
| 501 DCHECK(remote_metadata_); | 504 DCHECK(remote_metadata_); |
| 502 DCHECK(remote_metadata_->has_details()); | 505 DCHECK(remote_metadata_->has_details()); |
| 503 DCHECK(!remote_metadata_->details().missing()); | 506 DCHECK(!remote_metadata_->details().missing()); |
| 504 DCHECK_EQ(FILE_KIND_FOLDER, remote_metadata_->details().file_kind()); | 507 DCHECK_EQ(FILE_KIND_FOLDER, remote_metadata_->details().file_kind()); |
| 505 | 508 |
| 506 Prepare(base::Bind(&RemoteToLocalSyncer::DidPrepareForFolderUpdate, | 509 Prepare(base::Bind(&RemoteToLocalSyncer::DidPrepareForFolderUpdate, |
| 507 weak_ptr_factory_.GetWeakPtr(), | 510 weak_ptr_factory_.GetWeakPtr(), |
| 508 base::Passed(&token))); | 511 base::Passed(&token))); |
| 509 } | 512 } |
| 510 | 513 |
| 511 void RemoteToLocalSyncer::DidPrepareForFolderUpdate( | 514 void RemoteToLocalSyncer::DidPrepareForFolderUpdate( |
| 512 scoped_ptr<SyncTaskToken> token, | 515 std::unique_ptr<SyncTaskToken> token, |
| 513 SyncStatusCode status) { | 516 SyncStatusCode status) { |
| 514 if (status != SYNC_STATUS_OK) { | 517 if (status != SYNC_STATUS_OK) { |
| 515 SyncCompleted(std::move(token), status); | 518 SyncCompleted(std::move(token), status); |
| 516 return; | 519 return; |
| 517 } | 520 } |
| 518 | 521 |
| 519 DCHECK(url_.is_valid()); | 522 DCHECK(url_.is_valid()); |
| 520 DCHECK(local_metadata_); | 523 DCHECK(local_metadata_); |
| 521 DCHECK(local_changes_); | 524 DCHECK(local_changes_); |
| 522 | 525 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 542 } | 545 } |
| 543 | 546 |
| 544 DCHECK_EQ(SYNC_FILE_TYPE_FILE, local_metadata_->file_type); | 547 DCHECK_EQ(SYNC_FILE_TYPE_FILE, local_metadata_->file_type); |
| 545 file_type_ = SYNC_FILE_TYPE_DIRECTORY; | 548 file_type_ = SYNC_FILE_TYPE_DIRECTORY; |
| 546 sync_action_ = SYNC_ACTION_ADDED; | 549 sync_action_ = SYNC_ACTION_ADDED; |
| 547 // Got a remote folder for existing local file. | 550 // Got a remote folder for existing local file. |
| 548 // Our policy prioritize folders in this case. | 551 // Our policy prioritize folders in this case. |
| 549 CreateFolder(std::move(token)); | 552 CreateFolder(std::move(token)); |
| 550 } | 553 } |
| 551 | 554 |
| 552 void RemoteToLocalSyncer::HandleDeletion( | 555 void RemoteToLocalSyncer::HandleDeletion(std::unique_ptr<SyncTaskToken> token) { |
| 553 scoped_ptr<SyncTaskToken> token) { | |
| 554 DCHECK(dirty_tracker_); | 556 DCHECK(dirty_tracker_); |
| 555 DCHECK(dirty_tracker_->active()); | 557 DCHECK(dirty_tracker_->active()); |
| 556 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); | 558 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); |
| 557 DCHECK(dirty_tracker_->has_synced_details()); | 559 DCHECK(dirty_tracker_->has_synced_details()); |
| 558 DCHECK(!dirty_tracker_->synced_details().missing()); | 560 DCHECK(!dirty_tracker_->synced_details().missing()); |
| 559 | 561 |
| 560 DCHECK(remote_metadata_); | 562 DCHECK(remote_metadata_); |
| 561 DCHECK(remote_metadata_->has_details()); | 563 DCHECK(remote_metadata_->has_details()); |
| 562 DCHECK(remote_metadata_->details().missing()); | 564 DCHECK(remote_metadata_->details().missing()); |
| 563 | 565 |
| 564 Prepare(base::Bind(&RemoteToLocalSyncer::DidPrepareForDeletion, | 566 Prepare(base::Bind(&RemoteToLocalSyncer::DidPrepareForDeletion, |
| 565 weak_ptr_factory_.GetWeakPtr(), | 567 weak_ptr_factory_.GetWeakPtr(), |
| 566 base::Passed(&token))); | 568 base::Passed(&token))); |
| 567 } | 569 } |
| 568 | 570 |
| 569 void RemoteToLocalSyncer::HandleFileMove(scoped_ptr<SyncTaskToken> token) { | 571 void RemoteToLocalSyncer::HandleFileMove(std::unique_ptr<SyncTaskToken> token) { |
| 570 DCHECK(dirty_tracker_); | 572 DCHECK(dirty_tracker_); |
| 571 DCHECK(dirty_tracker_->active()); | 573 DCHECK(dirty_tracker_->active()); |
| 572 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); | 574 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); |
| 573 DCHECK(dirty_tracker_->has_synced_details()); | 575 DCHECK(dirty_tracker_->has_synced_details()); |
| 574 | 576 |
| 575 DCHECK(remote_metadata_); | 577 DCHECK(remote_metadata_); |
| 576 DCHECK(remote_metadata_->has_details()); | 578 DCHECK(remote_metadata_->has_details()); |
| 577 DCHECK(!remote_metadata_->details().missing()); | 579 DCHECK(!remote_metadata_->details().missing()); |
| 578 | 580 |
| 579 Prepare(base::Bind(&RemoteToLocalSyncer::DidPrepareForDeletion, | 581 Prepare(base::Bind(&RemoteToLocalSyncer::DidPrepareForDeletion, |
| 580 weak_ptr_factory_.GetWeakPtr(), | 582 weak_ptr_factory_.GetWeakPtr(), |
| 581 base::Passed(&token))); | 583 base::Passed(&token))); |
| 582 } | 584 } |
| 583 | 585 |
| 584 void RemoteToLocalSyncer::DidPrepareForDeletion( | 586 void RemoteToLocalSyncer::DidPrepareForDeletion( |
| 585 scoped_ptr<SyncTaskToken> token, | 587 std::unique_ptr<SyncTaskToken> token, |
| 586 SyncStatusCode status) { | 588 SyncStatusCode status) { |
| 587 if (status != SYNC_STATUS_OK) { | 589 if (status != SYNC_STATUS_OK) { |
| 588 SyncCompleted(std::move(token), status); | 590 SyncCompleted(std::move(token), status); |
| 589 return; | 591 return; |
| 590 } | 592 } |
| 591 | 593 |
| 592 DCHECK(url_.is_valid()); | 594 DCHECK(url_.is_valid()); |
| 593 DCHECK(local_metadata_); | 595 DCHECK(local_metadata_); |
| 594 DCHECK(local_changes_); | 596 DCHECK(local_changes_); |
| 595 | 597 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 609 return; | 611 return; |
| 610 } | 612 } |
| 611 | 613 |
| 612 DCHECK(local_changes_->back().IsAddOrUpdate()); | 614 DCHECK(local_changes_->back().IsAddOrUpdate()); |
| 613 // File is remotely deleted and locally updated. | 615 // File is remotely deleted and locally updated. |
| 614 // Ignore the remote deletion and handle it as if applied successfully. | 616 // Ignore the remote deletion and handle it as if applied successfully. |
| 615 SyncCompleted(std::move(token), SYNC_STATUS_OK); | 617 SyncCompleted(std::move(token), SYNC_STATUS_OK); |
| 616 } | 618 } |
| 617 | 619 |
| 618 void RemoteToLocalSyncer::HandleContentUpdate( | 620 void RemoteToLocalSyncer::HandleContentUpdate( |
| 619 scoped_ptr<SyncTaskToken> token) { | 621 std::unique_ptr<SyncTaskToken> token) { |
| 620 DCHECK(dirty_tracker_); | 622 DCHECK(dirty_tracker_); |
| 621 DCHECK(dirty_tracker_->active()); | 623 DCHECK(dirty_tracker_->active()); |
| 622 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); | 624 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); |
| 623 DCHECK(dirty_tracker_->has_synced_details()); | 625 DCHECK(dirty_tracker_->has_synced_details()); |
| 624 DCHECK_EQ(FILE_KIND_FILE, dirty_tracker_->synced_details().file_kind()); | 626 DCHECK_EQ(FILE_KIND_FILE, dirty_tracker_->synced_details().file_kind()); |
| 625 | 627 |
| 626 DCHECK(remote_metadata_); | 628 DCHECK(remote_metadata_); |
| 627 DCHECK(remote_metadata_->has_details()); | 629 DCHECK(remote_metadata_->has_details()); |
| 628 DCHECK(!remote_metadata_->details().missing()); | 630 DCHECK(!remote_metadata_->details().missing()); |
| 629 | 631 |
| 630 DCHECK_NE(dirty_tracker_->synced_details().md5(), | 632 DCHECK_NE(dirty_tracker_->synced_details().md5(), |
| 631 remote_metadata_->details().md5()); | 633 remote_metadata_->details().md5()); |
| 632 | 634 |
| 633 Prepare(base::Bind(&RemoteToLocalSyncer::DidPrepareForAddOrUpdateFile, | 635 Prepare(base::Bind(&RemoteToLocalSyncer::DidPrepareForAddOrUpdateFile, |
| 634 weak_ptr_factory_.GetWeakPtr(), base::Passed(&token))); | 636 weak_ptr_factory_.GetWeakPtr(), base::Passed(&token))); |
| 635 } | 637 } |
| 636 | 638 |
| 637 void RemoteToLocalSyncer::ListFolderContent( | 639 void RemoteToLocalSyncer::ListFolderContent( |
| 638 scoped_ptr<SyncTaskToken> token) { | 640 std::unique_ptr<SyncTaskToken> token) { |
| 639 DCHECK(dirty_tracker_); | 641 DCHECK(dirty_tracker_); |
| 640 DCHECK(dirty_tracker_->active()); | 642 DCHECK(dirty_tracker_->active()); |
| 641 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); | 643 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); |
| 642 DCHECK(dirty_tracker_->has_synced_details()); | 644 DCHECK(dirty_tracker_->has_synced_details()); |
| 643 DCHECK(!dirty_tracker_->synced_details().missing()); | 645 DCHECK(!dirty_tracker_->synced_details().missing()); |
| 644 DCHECK_EQ(FILE_KIND_FOLDER, dirty_tracker_->synced_details().file_kind()); | 646 DCHECK_EQ(FILE_KIND_FOLDER, dirty_tracker_->synced_details().file_kind()); |
| 645 DCHECK(dirty_tracker_->needs_folder_listing()); | 647 DCHECK(dirty_tracker_->needs_folder_listing()); |
| 646 | 648 |
| 647 DCHECK(remote_metadata_); | 649 DCHECK(remote_metadata_); |
| 648 DCHECK(remote_metadata_->has_details()); | 650 DCHECK(remote_metadata_->has_details()); |
| 649 DCHECK(!remote_metadata_->details().missing()); | 651 DCHECK(!remote_metadata_->details().missing()); |
| 650 | 652 |
| 651 // TODO(tzik): Replace this call with ChildList version. | 653 // TODO(tzik): Replace this call with ChildList version. |
| 652 drive_service()->GetFileListInDirectory( | 654 drive_service()->GetFileListInDirectory( |
| 653 dirty_tracker_->file_id(), | 655 dirty_tracker_->file_id(), |
| 654 base::Bind(&RemoteToLocalSyncer::DidListFolderContent, | 656 base::Bind(&RemoteToLocalSyncer::DidListFolderContent, |
| 655 weak_ptr_factory_.GetWeakPtr(), | 657 weak_ptr_factory_.GetWeakPtr(), base::Passed(&token), |
| 656 base::Passed(&token), | 658 base::Passed(base::WrapUnique(new FileIDList)))); |
| 657 base::Passed(make_scoped_ptr(new FileIDList)))); | |
| 658 } | 659 } |
| 659 | 660 |
| 660 void RemoteToLocalSyncer::DidListFolderContent( | 661 void RemoteToLocalSyncer::DidListFolderContent( |
| 661 scoped_ptr<SyncTaskToken> token, | 662 std::unique_ptr<SyncTaskToken> token, |
| 662 scoped_ptr<FileIDList> children, | 663 std::unique_ptr<FileIDList> children, |
| 663 google_apis::DriveApiErrorCode error, | 664 google_apis::DriveApiErrorCode error, |
| 664 scoped_ptr<google_apis::FileList> file_list) { | 665 std::unique_ptr<google_apis::FileList> file_list) { |
| 665 SyncStatusCode status = DriveApiErrorCodeToSyncStatusCode(error); | 666 SyncStatusCode status = DriveApiErrorCodeToSyncStatusCode(error); |
| 666 if (status != SYNC_STATUS_OK) { | 667 if (status != SYNC_STATUS_OK) { |
| 667 SyncCompleted(std::move(token), status); | 668 SyncCompleted(std::move(token), status); |
| 668 return; | 669 return; |
| 669 } | 670 } |
| 670 | 671 |
| 671 if (!file_list) { | 672 if (!file_list) { |
| 672 NOTREACHED(); | 673 NOTREACHED(); |
| 673 SyncCompleted(std::move(token), SYNC_STATUS_FAILED); | 674 SyncCompleted(std::move(token), SYNC_STATUS_FAILED); |
| 674 return; | 675 return; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 689 weak_ptr_factory_.GetWeakPtr(), | 690 weak_ptr_factory_.GetWeakPtr(), |
| 690 base::Passed(&token), base::Passed(&children))); | 691 base::Passed(&token), base::Passed(&children))); |
| 691 return; | 692 return; |
| 692 } | 693 } |
| 693 | 694 |
| 694 status = metadata_database()->PopulateFolderByChildList( | 695 status = metadata_database()->PopulateFolderByChildList( |
| 695 dirty_tracker_->file_id(), *children); | 696 dirty_tracker_->file_id(), *children); |
| 696 SyncCompleted(std::move(token), status); | 697 SyncCompleted(std::move(token), status); |
| 697 } | 698 } |
| 698 | 699 |
| 699 void RemoteToLocalSyncer::SyncCompleted(scoped_ptr<SyncTaskToken> token, | 700 void RemoteToLocalSyncer::SyncCompleted(std::unique_ptr<SyncTaskToken> token, |
| 700 SyncStatusCode status) { | 701 SyncStatusCode status) { |
| 701 token->RecordLog(base::StringPrintf( | 702 token->RecordLog(base::StringPrintf( |
| 702 "[Remote -> Local]: Finished: action=%s, tracker=%" PRId64 " status=%s", | 703 "[Remote -> Local]: Finished: action=%s, tracker=%" PRId64 " status=%s", |
| 703 SyncActionToString(sync_action_), dirty_tracker_->tracker_id(), | 704 SyncActionToString(sync_action_), dirty_tracker_->tracker_id(), |
| 704 SyncStatusCodeToString(status))); | 705 SyncStatusCodeToString(status))); |
| 705 | 706 |
| 706 if (sync_root_deletion_) { | 707 if (sync_root_deletion_) { |
| 707 FinalizeSync(std::move(token), SYNC_STATUS_OK); | 708 FinalizeSync(std::move(token), SYNC_STATUS_OK); |
| 708 return; | 709 return; |
| 709 } | 710 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 733 updated_details.clear_md5(); | 734 updated_details.clear_md5(); |
| 734 updated_details.set_missing(true); | 735 updated_details.set_missing(true); |
| 735 } | 736 } |
| 736 } | 737 } |
| 737 | 738 |
| 738 status = metadata_database()->UpdateTracker( | 739 status = metadata_database()->UpdateTracker( |
| 739 dirty_tracker_->tracker_id(), updated_details); | 740 dirty_tracker_->tracker_id(), updated_details); |
| 740 FinalizeSync(std::move(token), status); | 741 FinalizeSync(std::move(token), status); |
| 741 } | 742 } |
| 742 | 743 |
| 743 void RemoteToLocalSyncer::FinalizeSync(scoped_ptr<SyncTaskToken> token, | 744 void RemoteToLocalSyncer::FinalizeSync(std::unique_ptr<SyncTaskToken> token, |
| 744 SyncStatusCode status) { | 745 SyncStatusCode status) { |
| 745 if (prepared_) { | 746 if (prepared_) { |
| 746 remote_change_processor()->FinalizeRemoteSync( | 747 remote_change_processor()->FinalizeRemoteSync( |
| 747 url_, false /* clear_local_change */, | 748 url_, false /* clear_local_change */, |
| 748 base::Bind(SyncTaskManager::NotifyTaskDone, | 749 base::Bind(SyncTaskManager::NotifyTaskDone, |
| 749 base::Passed(&token), status)); | 750 base::Passed(&token), status)); |
| 750 return; | 751 return; |
| 751 } | 752 } |
| 752 | 753 |
| 753 SyncTaskManager::NotifyTaskDone(std::move(token), status); | 754 SyncTaskManager::NotifyTaskDone(std::move(token), status); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 771 return; | 772 return; |
| 772 } | 773 } |
| 773 prepared_ = true; | 774 prepared_ = true; |
| 774 | 775 |
| 775 local_metadata_.reset(new SyncFileMetadata(local_metadata)); | 776 local_metadata_.reset(new SyncFileMetadata(local_metadata)); |
| 776 local_changes_.reset(new FileChangeList(local_changes)); | 777 local_changes_.reset(new FileChangeList(local_changes)); |
| 777 | 778 |
| 778 callback.Run(status); | 779 callback.Run(status); |
| 779 } | 780 } |
| 780 | 781 |
| 781 void RemoteToLocalSyncer::DeleteLocalFile(scoped_ptr<SyncTaskToken> token) { | 782 void RemoteToLocalSyncer::DeleteLocalFile( |
| 783 std::unique_ptr<SyncTaskToken> token) { |
| 782 remote_change_processor()->ApplyRemoteChange( | 784 remote_change_processor()->ApplyRemoteChange( |
| 783 FileChange(FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_UNKNOWN), | 785 FileChange(FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_UNKNOWN), |
| 784 base::FilePath(), url_, SyncCompletedCallback(std::move(token))); | 786 base::FilePath(), url_, SyncCompletedCallback(std::move(token))); |
| 785 } | 787 } |
| 786 | 788 |
| 787 void RemoteToLocalSyncer::DownloadFile(scoped_ptr<SyncTaskToken> token) { | 789 void RemoteToLocalSyncer::DownloadFile(std::unique_ptr<SyncTaskToken> token) { |
| 788 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread()); | 790 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread()); |
| 789 | 791 |
| 790 storage::ScopedFile file = CreateTemporaryFile( | 792 storage::ScopedFile file = CreateTemporaryFile( |
| 791 make_scoped_refptr(sync_context_->GetWorkerTaskRunner())); | 793 make_scoped_refptr(sync_context_->GetWorkerTaskRunner())); |
| 792 | 794 |
| 793 base::FilePath path = file.path(); | 795 base::FilePath path = file.path(); |
| 794 drive_service()->DownloadFile( | 796 drive_service()->DownloadFile( |
| 795 path, remote_metadata_->file_id(), | 797 path, remote_metadata_->file_id(), |
| 796 base::Bind(&RemoteToLocalSyncer::DidDownloadFile, | 798 base::Bind(&RemoteToLocalSyncer::DidDownloadFile, |
| 797 weak_ptr_factory_.GetWeakPtr(), | 799 weak_ptr_factory_.GetWeakPtr(), |
| 798 base::Passed(&token), base::Passed(&file)), | 800 base::Passed(&token), base::Passed(&file)), |
| 799 google_apis::GetContentCallback(), | 801 google_apis::GetContentCallback(), |
| 800 google_apis::ProgressCallback()); | 802 google_apis::ProgressCallback()); |
| 801 } | 803 } |
| 802 | 804 |
| 803 void RemoteToLocalSyncer::DidDownloadFile(scoped_ptr<SyncTaskToken> token, | 805 void RemoteToLocalSyncer::DidDownloadFile(std::unique_ptr<SyncTaskToken> token, |
| 804 storage::ScopedFile file, | 806 storage::ScopedFile file, |
| 805 google_apis::DriveApiErrorCode error, | 807 google_apis::DriveApiErrorCode error, |
| 806 const base::FilePath&) { | 808 const base::FilePath&) { |
| 807 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread()); | 809 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread()); |
| 808 | 810 |
| 809 SyncStatusCode status = DriveApiErrorCodeToSyncStatusCode(error); | 811 SyncStatusCode status = DriveApiErrorCodeToSyncStatusCode(error); |
| 810 if (status != SYNC_STATUS_OK) { | 812 if (status != SYNC_STATUS_OK) { |
| 811 SyncCompleted(std::move(token), status); | 813 SyncCompleted(std::move(token), status); |
| 812 return; | 814 return; |
| 813 } | 815 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 826 } | 828 } |
| 827 | 829 |
| 828 remote_change_processor()->ApplyRemoteChange( | 830 remote_change_processor()->ApplyRemoteChange( |
| 829 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE), | 831 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE), |
| 830 path, url_, | 832 path, url_, |
| 831 base::Bind(&RemoteToLocalSyncer::DidApplyDownload, | 833 base::Bind(&RemoteToLocalSyncer::DidApplyDownload, |
| 832 weak_ptr_factory_.GetWeakPtr(), | 834 weak_ptr_factory_.GetWeakPtr(), |
| 833 base::Passed(&token), base::Passed(&file))); | 835 base::Passed(&token), base::Passed(&file))); |
| 834 } | 836 } |
| 835 | 837 |
| 836 void RemoteToLocalSyncer::DidApplyDownload(scoped_ptr<SyncTaskToken> token, | 838 void RemoteToLocalSyncer::DidApplyDownload(std::unique_ptr<SyncTaskToken> token, |
| 837 storage::ScopedFile, | 839 storage::ScopedFile, |
| 838 SyncStatusCode status) { | 840 SyncStatusCode status) { |
| 839 SyncCompleted(std::move(token), status); | 841 SyncCompleted(std::move(token), status); |
| 840 } | 842 } |
| 841 | 843 |
| 842 void RemoteToLocalSyncer::CreateFolder(scoped_ptr<SyncTaskToken> token) { | 844 void RemoteToLocalSyncer::CreateFolder(std::unique_ptr<SyncTaskToken> token) { |
| 843 remote_change_processor()->ApplyRemoteChange( | 845 remote_change_processor()->ApplyRemoteChange( |
| 844 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 846 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
| 845 SYNC_FILE_TYPE_DIRECTORY), | 847 SYNC_FILE_TYPE_DIRECTORY), |
| 846 base::FilePath(), url_, SyncCompletedCallback(std::move(token))); | 848 base::FilePath(), url_, SyncCompletedCallback(std::move(token))); |
| 847 } | 849 } |
| 848 | 850 |
| 849 drive::DriveServiceInterface* RemoteToLocalSyncer::drive_service() { | 851 drive::DriveServiceInterface* RemoteToLocalSyncer::drive_service() { |
| 850 return sync_context_->GetDriveService(); | 852 return sync_context_->GetDriveService(); |
| 851 } | 853 } |
| 852 | 854 |
| 853 MetadataDatabase* RemoteToLocalSyncer::metadata_database() { | 855 MetadataDatabase* RemoteToLocalSyncer::metadata_database() { |
| 854 return sync_context_->GetMetadataDatabase(); | 856 return sync_context_->GetMetadataDatabase(); |
| 855 } | 857 } |
| 856 | 858 |
| 857 RemoteChangeProcessor* RemoteToLocalSyncer::remote_change_processor() { | 859 RemoteChangeProcessor* RemoteToLocalSyncer::remote_change_processor() { |
| 858 DCHECK(sync_context_->GetRemoteChangeProcessor()); | 860 DCHECK(sync_context_->GetRemoteChangeProcessor()); |
| 859 return sync_context_->GetRemoteChangeProcessor(); | 861 return sync_context_->GetRemoteChangeProcessor(); |
| 860 } | 862 } |
| 861 | 863 |
| 862 SyncStatusCallback RemoteToLocalSyncer::SyncCompletedCallback( | 864 SyncStatusCallback RemoteToLocalSyncer::SyncCompletedCallback( |
| 863 scoped_ptr<SyncTaskToken> token) { | 865 std::unique_ptr<SyncTaskToken> token) { |
| 864 return base::Bind(&RemoteToLocalSyncer::SyncCompleted, | 866 return base::Bind(&RemoteToLocalSyncer::SyncCompleted, |
| 865 weak_ptr_factory_.GetWeakPtr(), | 867 weak_ptr_factory_.GetWeakPtr(), |
| 866 base::Passed(&token)); | 868 base::Passed(&token)); |
| 867 } | 869 } |
| 868 | 870 |
| 869 } // namespace drive_backend | 871 } // namespace drive_backend |
| 870 } // namespace sync_file_system | 872 } // namespace sync_file_system |
| OLD | NEW |