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/local_to_remote_syncer.h
" | 5 #include "chrome/browser/sync_file_system/drive_backend/local_to_remote_syncer.h
" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 return; | 170 return; |
171 } | 171 } |
172 | 172 |
173 DCHECK(active_ancestor_details.file_kind() == FILE_KIND_FILE); | 173 DCHECK(active_ancestor_details.file_kind() == FILE_KIND_FILE); |
174 remote_parent_folder_tracker_ = | 174 remote_parent_folder_tracker_ = |
175 FindTrackerByID(metadata_database(), | 175 FindTrackerByID(metadata_database(), |
176 active_ancestor_tracker->parent_tracker_id()); | 176 active_ancestor_tracker->parent_tracker_id()); |
177 remote_file_tracker_ = active_ancestor_tracker.Pass(); | 177 remote_file_tracker_ = active_ancestor_tracker.Pass(); |
178 target_path_ = active_ancestor_path; | 178 target_path_ = active_ancestor_path; |
179 token->RecordLog("Detected non-folder file in its path."); | 179 token->RecordLog("Detected non-folder file in its path."); |
180 DeleteRemoteFile(base::Bind(&LocalToRemoteSyncer::DidDeleteForCreateFolder, | 180 DeleteRemoteFile(base::Bind(&LocalToRemoteSyncer::CompleteWithRetryStatus, |
181 weak_ptr_factory_.GetWeakPtr(), | 181 weak_ptr_factory_.GetWeakPtr(), |
182 base::Passed(&token))); | 182 base::Passed(&token))); |
183 return; | 183 return; |
184 } | 184 } |
185 | 185 |
186 if (missing_components.empty()) { | 186 if (missing_components.empty()) { |
187 // The original target has remote active file/folder. | 187 // The original target has remote active file/folder. |
188 remote_parent_folder_tracker_ = | 188 remote_parent_folder_tracker_ = |
189 FindTrackerByID(metadata_database(), | 189 FindTrackerByID(metadata_database(), |
190 active_ancestor_tracker->parent_tracker_id()); | 190 active_ancestor_tracker->parent_tracker_id()); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 if (synced_details.file_kind() == FILE_KIND_FILE) { | 311 if (synced_details.file_kind() == FILE_KIND_FILE) { |
312 // Non-conflicting local file update to existing remote regular file. | 312 // Non-conflicting local file update to existing remote regular file. |
313 UploadExistingFile(token.Pass()); | 313 UploadExistingFile(token.Pass()); |
314 return; | 314 return; |
315 } | 315 } |
316 | 316 |
317 DCHECK_EQ(FILE_KIND_FOLDER, synced_details.file_kind()); | 317 DCHECK_EQ(FILE_KIND_FOLDER, synced_details.file_kind()); |
318 // Non-conflicting local file update to existing remote *folder*. | 318 // Non-conflicting local file update to existing remote *folder*. |
319 // Assuming this case as local folder deletion + local file creation, delete | 319 // Assuming this case as local folder deletion + local file creation, delete |
320 // the remote folder and upload the file. | 320 // the remote folder and upload the file. |
321 DeleteRemoteFile(base::Bind(&LocalToRemoteSyncer::DidDeleteForUploadNewFile, | 321 DeleteRemoteFile(base::Bind(&LocalToRemoteSyncer::CompleteWithRetryStatus, |
322 weak_ptr_factory_.GetWeakPtr(), | 322 weak_ptr_factory_.GetWeakPtr(), |
323 base::Passed(&token))); | 323 base::Passed(&token))); |
324 return; | 324 return; |
325 } | 325 } |
326 | 326 |
327 DCHECK(local_change_.IsDirectory()); | 327 DCHECK(local_change_.IsDirectory()); |
328 if (synced_details.file_kind() == FILE_KIND_FILE) { | 328 if (synced_details.file_kind() == FILE_KIND_FILE) { |
329 // Non-conflicting local folder creation to existing remote *file*. | 329 // Non-conflicting local folder creation to existing remote *file*. |
330 // Assuming this case as local file deletion + local folder creation, delete | 330 // Assuming this case as local file deletion + local folder creation, delete |
331 // the remote file and create a remote folder. | 331 // the remote file and create a remote folder. |
332 DeleteRemoteFile(base::Bind(&LocalToRemoteSyncer::DidDeleteForCreateFolder, | 332 DeleteRemoteFile(base::Bind(&LocalToRemoteSyncer::CompleteWithRetryStatus, |
333 weak_ptr_factory_.GetWeakPtr(), | 333 weak_ptr_factory_.GetWeakPtr(), |
334 base::Passed(&token))); | 334 base::Passed(&token))); |
335 return; | 335 return; |
336 } | 336 } |
337 | 337 |
338 // Non-conflicting local folder creation to existing remote folder. | 338 // Non-conflicting local folder creation to existing remote folder. |
339 DCHECK_EQ(FILE_KIND_FOLDER, synced_details.file_kind()); | 339 DCHECK_EQ(FILE_KIND_FOLDER, synced_details.file_kind()); |
340 SyncCompleted(token.Pass(), SYNC_STATUS_OK); | 340 SyncCompleted(token.Pass(), SYNC_STATUS_OK); |
341 } | 341 } |
342 | 342 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 return; | 534 return; |
535 } | 535 } |
536 | 536 |
537 metadata_database()->UpdateByFileResource( | 537 metadata_database()->UpdateByFileResource( |
538 *entry, | 538 *entry, |
539 base::Bind(&LocalToRemoteSyncer::CompleteWithRetryStatus, | 539 base::Bind(&LocalToRemoteSyncer::CompleteWithRetryStatus, |
540 weak_ptr_factory_.GetWeakPtr(), | 540 weak_ptr_factory_.GetWeakPtr(), |
541 base::Passed(&token))); | 541 base::Passed(&token))); |
542 } | 542 } |
543 | 543 |
544 void LocalToRemoteSyncer::DidDeleteForUploadNewFile( | |
545 scoped_ptr<SyncTaskToken> token, | |
546 SyncStatusCode status) { | |
547 if (status == SYNC_STATUS_HAS_CONFLICT) { | |
548 UpdateRemoteMetadata( | |
549 remote_file_tracker_->file_id(), | |
550 token.Pass()); | |
551 return; | |
552 } | |
553 | |
554 if (status != SYNC_STATUS_OK) { | |
555 SyncCompleted(token.Pass(), status); | |
556 return; | |
557 } | |
558 | |
559 UploadNewFile(token.Pass()); | |
560 } | |
561 | |
562 void LocalToRemoteSyncer::DidDeleteForCreateFolder( | |
563 scoped_ptr<SyncTaskToken> token, | |
564 SyncStatusCode status) { | |
565 if (status == SYNC_STATUS_HAS_CONFLICT) { | |
566 UpdateRemoteMetadata(remote_file_tracker_->file_id(), token.Pass()); | |
567 return; | |
568 } | |
569 | |
570 if (status != SYNC_STATUS_OK) { | |
571 SyncCompleted(token.Pass(), status); | |
572 return; | |
573 } | |
574 | |
575 CreateRemoteFolder(token.Pass()); | |
576 } | |
577 | |
578 void LocalToRemoteSyncer::UploadNewFile(scoped_ptr<SyncTaskToken> token) { | 544 void LocalToRemoteSyncer::UploadNewFile(scoped_ptr<SyncTaskToken> token) { |
579 DCHECK(remote_parent_folder_tracker_); | 545 DCHECK(remote_parent_folder_tracker_); |
580 | 546 |
581 sync_action_ = SYNC_ACTION_ADDED; | 547 sync_action_ = SYNC_ACTION_ADDED; |
582 base::FilePath title = fileapi::VirtualPath::BaseName(target_path_); | 548 base::FilePath title = fileapi::VirtualPath::BaseName(target_path_); |
583 drive_uploader()->UploadNewFile( | 549 drive_uploader()->UploadNewFile( |
584 remote_parent_folder_tracker_->file_id(), | 550 remote_parent_folder_tracker_->file_id(), |
585 local_path_, | 551 local_path_, |
586 title.AsUTF8Unsafe(), | 552 title.AsUTF8Unsafe(), |
587 GetMimeTypeFromTitle(title), | 553 GetMimeTypeFromTitle(title), |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 void LocalToRemoteSyncer::CompleteWithRetryStatus( | 679 void LocalToRemoteSyncer::CompleteWithRetryStatus( |
714 scoped_ptr<SyncTaskToken> token, | 680 scoped_ptr<SyncTaskToken> token, |
715 SyncStatusCode status) { | 681 SyncStatusCode status) { |
716 if (status == SYNC_STATUS_OK) | 682 if (status == SYNC_STATUS_OK) |
717 status = SYNC_STATUS_RETRY; | 683 status = SYNC_STATUS_RETRY; |
718 SyncCompleted(token.Pass(), status); | 684 SyncCompleted(token.Pass(), status); |
719 } | 685 } |
720 | 686 |
721 } // namespace drive_backend | 687 } // namespace drive_backend |
722 } // namespace sync_file_system | 688 } // namespace sync_file_system |
OLD | NEW |