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 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 base::Bind(&LocalToRemoteSyncer::DidUploadExistingFile, | 375 base::Bind(&LocalToRemoteSyncer::DidUploadExistingFile, |
376 weak_ptr_factory_.GetWeakPtr(), | 376 weak_ptr_factory_.GetWeakPtr(), |
377 callback), | 377 callback), |
378 google_apis::ProgressCallback()); | 378 google_apis::ProgressCallback()); |
379 } | 379 } |
380 | 380 |
381 void LocalToRemoteSyncer::DidUploadExistingFile( | 381 void LocalToRemoteSyncer::DidUploadExistingFile( |
382 const SyncStatusCallback& callback, | 382 const SyncStatusCallback& callback, |
383 google_apis::GDataErrorCode error, | 383 google_apis::GDataErrorCode error, |
384 const GURL&, | 384 const GURL&, |
385 scoped_ptr<google_apis::ResourceEntry>) { | 385 scoped_ptr<google_apis::ResourceEntry> entry) { |
386 if (error == google_apis::HTTP_PRECONDITION) { | 386 if (error == google_apis::HTTP_PRECONDITION) { |
387 // The remote file has unfetched remote change. Fetch latest metadata and | 387 // The remote file has unfetched remote change. Fetch latest metadata and |
388 // update database with it. | 388 // update database with it. |
389 // TODO(tzik): Consider adding local side low-priority dirtiness handling to | 389 // TODO(tzik): Consider adding local side low-priority dirtiness handling to |
390 // handle this as ListChangesTask. | 390 // handle this as ListChangesTask. |
391 UpdateRemoteMetadata(callback); | 391 UpdateRemoteMetadata(callback); |
392 return; | 392 return; |
393 } | 393 } |
394 | 394 |
395 callback.Run(GDataErrorCodeToSyncStatusCode(error)); | 395 metadata_database()->UpdateByFileResource( |
| 396 *drive::util::ConvertResourceEntryToFileResource(*entry), |
| 397 base::Bind(&LocalToRemoteSyncer::DidUpdateDatabaseForUploadExistingFile, |
| 398 weak_ptr_factory_.GetWeakPtr(), |
| 399 callback)); |
| 400 } |
| 401 |
| 402 void LocalToRemoteSyncer::DidUpdateDatabaseForUploadExistingFile( |
| 403 const SyncStatusCallback& callback, |
| 404 SyncStatusCode status) { |
| 405 if (status != SYNC_STATUS_OK) { |
| 406 callback.Run(status); |
| 407 return; |
| 408 } |
| 409 |
| 410 FileMetadata file; |
| 411 bool should_success = metadata_database()->FindFileByFileID( |
| 412 remote_file_tracker_->file_id(), &file); |
| 413 if (!should_success) { |
| 414 NOTREACHED(); |
| 415 callback.Run(SYNC_STATUS_FAILED); |
| 416 return; |
| 417 } |
| 418 |
| 419 metadata_database()->UpdateTracker( |
| 420 remote_file_tracker_->tracker_id(), |
| 421 file.details(), |
| 422 callback); |
396 } | 423 } |
397 | 424 |
398 void LocalToRemoteSyncer::UpdateRemoteMetadata( | 425 void LocalToRemoteSyncer::UpdateRemoteMetadata( |
399 const SyncStatusCallback& callback) { | 426 const SyncStatusCallback& callback) { |
400 DCHECK(remote_file_tracker_); | 427 DCHECK(remote_file_tracker_); |
401 drive_service()->GetResourceEntry( | 428 drive_service()->GetResourceEntry( |
402 remote_file_tracker_->file_id(), | 429 remote_file_tracker_->file_id(), |
403 base::Bind(&LocalToRemoteSyncer::DidGetRemoteMetadata, | 430 base::Bind(&LocalToRemoteSyncer::DidGetRemoteMetadata, |
404 weak_ptr_factory_.GetWeakPtr(), | 431 weak_ptr_factory_.GetWeakPtr(), |
405 callback)); | 432 callback)); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 if (error != google_apis::HTTP_SUCCESS && | 496 if (error != google_apis::HTTP_SUCCESS && |
470 error != google_apis::HTTP_CREATED) { | 497 error != google_apis::HTTP_CREATED) { |
471 callback.Run(GDataErrorCodeToSyncStatusCode(error)); | 498 callback.Run(GDataErrorCodeToSyncStatusCode(error)); |
472 return; | 499 return; |
473 } | 500 } |
474 | 501 |
475 // TODO(tzik): Add a function to update both FileMetadata and FileTracker to | 502 // TODO(tzik): Add a function to update both FileMetadata and FileTracker to |
476 // MetadataDatabase. | 503 // MetadataDatabase. |
477 metadata_database()->UpdateByFileResource( | 504 metadata_database()->UpdateByFileResource( |
478 *drive::util::ConvertResourceEntryToFileResource(*entry), | 505 *drive::util::ConvertResourceEntryToFileResource(*entry), |
479 base::Bind(&LocalToRemoteSyncer::DidUpdateDatabaseForUpload, | 506 base::Bind(&LocalToRemoteSyncer::DidUpdateDatabaseForUploadNewFile, |
480 weak_ptr_factory_.GetWeakPtr(), | 507 weak_ptr_factory_.GetWeakPtr(), |
481 callback, entry->resource_id())); | 508 callback, entry->resource_id())); |
482 } | 509 } |
483 | 510 |
484 void LocalToRemoteSyncer::DidUpdateDatabaseForUpload( | 511 void LocalToRemoteSyncer::DidUpdateDatabaseForUploadNewFile( |
485 const SyncStatusCallback& callback, | 512 const SyncStatusCallback& callback, |
486 const std::string& file_id, | 513 const std::string& file_id, |
487 SyncStatusCode status) { | 514 SyncStatusCode status) { |
488 if (status != SYNC_STATUS_OK) { | 515 if (status != SYNC_STATUS_OK) { |
489 callback.Run(status); | 516 callback.Run(status); |
490 return; | 517 return; |
491 } | 518 } |
492 | 519 |
493 FileMetadata metadata; | 520 FileMetadata metadata; |
494 FileTracker tracker; | 521 FileTracker tracker; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 set_used_network(true); | 627 set_used_network(true); |
601 return sync_context_->GetDriveUploader(); | 628 return sync_context_->GetDriveUploader(); |
602 } | 629 } |
603 | 630 |
604 MetadataDatabase* LocalToRemoteSyncer::metadata_database() { | 631 MetadataDatabase* LocalToRemoteSyncer::metadata_database() { |
605 return sync_context_->GetMetadataDatabase(); | 632 return sync_context_->GetMetadataDatabase(); |
606 } | 633 } |
607 | 634 |
608 } // namespace drive_backend | 635 } // namespace drive_backend |
609 } // namespace sync_file_system | 636 } // namespace sync_file_system |
OLD | NEW |