| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 scoped_ptr<FileMetadata> GetFileMetadata(MetadataDatabase* database, | 66 scoped_ptr<FileMetadata> GetFileMetadata(MetadataDatabase* database, |
| 67 const std::string& file_id) { | 67 const std::string& file_id) { |
| 68 scoped_ptr<FileMetadata> metadata(new FileMetadata); | 68 scoped_ptr<FileMetadata> metadata(new FileMetadata); |
| 69 if (!database->FindFileByFileID(file_id, metadata.get())) | 69 if (!database->FindFileByFileID(file_id, metadata.get())) |
| 70 metadata.reset(); | 70 metadata.reset(); |
| 71 return metadata.Pass(); | 71 return metadata.Pass(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 } // namespace | 74 } // namespace |
| 75 | 75 |
| 76 RemoteToLocalSyncer::RemoteToLocalSyncer(SyncEngineContext* sync_context, | 76 RemoteToLocalSyncer::RemoteToLocalSyncer(SyncEngineContext* sync_context) |
| 77 int priorities) | |
| 78 : sync_context_(sync_context), | 77 : sync_context_(sync_context), |
| 79 priorities_(priorities), | |
| 80 sync_action_(SYNC_ACTION_NONE), | 78 sync_action_(SYNC_ACTION_NONE), |
| 81 weak_ptr_factory_(this) { | 79 weak_ptr_factory_(this) { |
| 82 } | 80 } |
| 83 | 81 |
| 84 RemoteToLocalSyncer::~RemoteToLocalSyncer() { | 82 RemoteToLocalSyncer::~RemoteToLocalSyncer() { |
| 85 } | 83 } |
| 86 | 84 |
| 87 void RemoteToLocalSyncer::Run(const SyncStatusCallback& callback) { | 85 void RemoteToLocalSyncer::Run(const SyncStatusCallback& callback) { |
| 88 if (!drive_service() || !metadata_database() || !remote_change_processor()) { | 86 if (!drive_service() || !metadata_database() || !remote_change_processor()) { |
| 89 NOTREACHED(); | 87 NOTREACHED(); |
| 90 callback.Run(SYNC_STATUS_FAILED); | 88 callback.Run(SYNC_STATUS_FAILED); |
| 91 return; | 89 return; |
| 92 } | 90 } |
| 93 | 91 |
| 94 SyncStatusCallback wrapped_callback = base::Bind( | 92 SyncStatusCallback wrapped_callback = base::Bind( |
| 95 &RemoteToLocalSyncer::SyncCompleted, weak_ptr_factory_.GetWeakPtr(), | 93 &RemoteToLocalSyncer::SyncCompleted, weak_ptr_factory_.GetWeakPtr(), |
| 96 callback); | 94 callback); |
| 97 | 95 |
| 98 if (priorities_ & PRIORITY_NORMAL) { | 96 dirty_tracker_ = make_scoped_ptr(new FileTracker); |
| 99 dirty_tracker_ = make_scoped_ptr(new FileTracker); | 97 if (metadata_database()->GetNormalPriorityDirtyTracker( |
| 100 if (metadata_database()->GetNormalPriorityDirtyTracker( | 98 dirty_tracker_.get())) { |
| 101 dirty_tracker_.get())) { | 99 ResolveRemoteChange(wrapped_callback); |
| 102 ResolveRemoteChange(wrapped_callback); | 100 return; |
| 103 return; | |
| 104 } | |
| 105 } | |
| 106 | |
| 107 if (priorities_ & PRIORITY_LOW) { | |
| 108 dirty_tracker_ = make_scoped_ptr(new FileTracker); | |
| 109 if (metadata_database()->GetLowPriorityDirtyTracker(dirty_tracker_.get())) { | |
| 110 ResolveRemoteChange(wrapped_callback); | |
| 111 return; | |
| 112 } | |
| 113 } | 101 } |
| 114 | 102 |
| 115 base::MessageLoopProxy::current()->PostTask( | 103 base::MessageLoopProxy::current()->PostTask( |
| 116 FROM_HERE, | 104 FROM_HERE, |
| 117 base::Bind(callback, SYNC_STATUS_NO_CHANGE_TO_SYNC)); | 105 base::Bind(callback, SYNC_STATUS_NO_CHANGE_TO_SYNC)); |
| 118 } | 106 } |
| 119 | 107 |
| 120 void RemoteToLocalSyncer::ResolveRemoteChange( | 108 void RemoteToLocalSyncer::ResolveRemoteChange( |
| 121 const SyncStatusCallback& callback) { | 109 const SyncStatusCallback& callback) { |
| 122 DCHECK(dirty_tracker_); | 110 DCHECK(dirty_tracker_); |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 return sync_context_->GetMetadataDatabase(); | 664 return sync_context_->GetMetadataDatabase(); |
| 677 } | 665 } |
| 678 | 666 |
| 679 RemoteChangeProcessor* RemoteToLocalSyncer::remote_change_processor() { | 667 RemoteChangeProcessor* RemoteToLocalSyncer::remote_change_processor() { |
| 680 DCHECK(sync_context_->GetRemoteChangeProcessor()); | 668 DCHECK(sync_context_->GetRemoteChangeProcessor()); |
| 681 return sync_context_->GetRemoteChangeProcessor(); | 669 return sync_context_->GetRemoteChangeProcessor(); |
| 682 } | 670 } |
| 683 | 671 |
| 684 } // namespace drive_backend | 672 } // namespace drive_backend |
| 685 } // namespace sync_file_system | 673 } // namespace sync_file_system |
| OLD | NEW |