| 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 | |
| 9 #include <limits> | 8 #include <limits> |
| 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/format_macros.h" | 14 #include "base/format_macros.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/task_runner_util.h" | 18 #include "base/task_runner_util.h" |
| 19 #include "chrome/browser/sync_file_system/drive_backend/callback_helper.h" | 19 #include "chrome/browser/sync_file_system/drive_backend/callback_helper.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 return app_root_tracker.tracker_kind() == TRACKER_KIND_DISABLED_APP_ROOT; | 70 return app_root_tracker.tracker_kind() == TRACKER_KIND_DISABLED_APP_ROOT; |
| 71 } | 71 } |
| 72 return false; | 72 return false; |
| 73 } | 73 } |
| 74 | 74 |
| 75 scoped_ptr<FileMetadata> GetFileMetadata(MetadataDatabase* database, | 75 scoped_ptr<FileMetadata> GetFileMetadata(MetadataDatabase* database, |
| 76 const std::string& file_id) { | 76 const std::string& file_id) { |
| 77 scoped_ptr<FileMetadata> metadata(new FileMetadata); | 77 scoped_ptr<FileMetadata> metadata(new FileMetadata); |
| 78 if (!database->FindFileByFileID(file_id, metadata.get())) | 78 if (!database->FindFileByFileID(file_id, metadata.get())) |
| 79 metadata.reset(); | 79 metadata.reset(); |
| 80 return metadata.Pass(); | 80 return metadata; |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Creates a temporary file in |dir_path|. This must be called on an | 83 // 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|. | 84 // IO-allowed task runner, and the runner must be given as |file_task_runner|. |
| 85 storage::ScopedFile CreateTemporaryFile( | 85 storage::ScopedFile CreateTemporaryFile( |
| 86 const scoped_refptr<base::TaskRunner>& file_task_runner) { | 86 const scoped_refptr<base::TaskRunner>& file_task_runner) { |
| 87 base::FilePath temp_file_path; | 87 base::FilePath temp_file_path; |
| 88 if (!base::CreateTemporaryFile(&temp_file_path)) | 88 if (!base::CreateTemporaryFile(&temp_file_path)) |
| 89 return storage::ScopedFile(); | 89 return storage::ScopedFile(); |
| 90 | 90 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 105 } | 105 } |
| 106 | 106 |
| 107 RemoteToLocalSyncer::~RemoteToLocalSyncer() { | 107 RemoteToLocalSyncer::~RemoteToLocalSyncer() { |
| 108 } | 108 } |
| 109 | 109 |
| 110 void RemoteToLocalSyncer::RunPreflight(scoped_ptr<SyncTaskToken> token) { | 110 void RemoteToLocalSyncer::RunPreflight(scoped_ptr<SyncTaskToken> token) { |
| 111 token->InitializeTaskLog("Remote -> Local"); | 111 token->InitializeTaskLog("Remote -> Local"); |
| 112 | 112 |
| 113 if (!drive_service() || !metadata_database() || !remote_change_processor()) { | 113 if (!drive_service() || !metadata_database() || !remote_change_processor()) { |
| 114 token->RecordLog("Context not ready."); | 114 token->RecordLog("Context not ready."); |
| 115 SyncTaskManager::NotifyTaskDone(token.Pass(), SYNC_STATUS_FAILED); | 115 SyncTaskManager::NotifyTaskDone(std::move(token), SYNC_STATUS_FAILED); |
| 116 return; | 116 return; |
| 117 } | 117 } |
| 118 | 118 |
| 119 dirty_tracker_ = make_scoped_ptr(new FileTracker); | 119 dirty_tracker_ = make_scoped_ptr(new FileTracker); |
| 120 if (metadata_database()->GetDirtyTracker(dirty_tracker_.get())) { | 120 if (metadata_database()->GetDirtyTracker(dirty_tracker_.get())) { |
| 121 token->RecordLog(base::StringPrintf( | 121 token->RecordLog(base::StringPrintf( |
| 122 "Start: tracker_id=%" PRId64, dirty_tracker_->tracker_id())); | 122 "Start: tracker_id=%" PRId64, dirty_tracker_->tracker_id())); |
| 123 metadata_database()->DemoteTracker(dirty_tracker_->tracker_id()); | 123 metadata_database()->DemoteTracker(dirty_tracker_->tracker_id()); |
| 124 ResolveRemoteChange(token.Pass()); | 124 ResolveRemoteChange(std::move(token)); |
| 125 return; | 125 return; |
| 126 } | 126 } |
| 127 | 127 |
| 128 token->RecordLog("Nothing to do."); | 128 token->RecordLog("Nothing to do."); |
| 129 SyncTaskManager::NotifyTaskDone(token.Pass(), SYNC_STATUS_NO_CHANGE_TO_SYNC); | 129 SyncTaskManager::NotifyTaskDone(std::move(token), |
| 130 SYNC_STATUS_NO_CHANGE_TO_SYNC); |
| 130 } | 131 } |
| 131 | 132 |
| 132 void RemoteToLocalSyncer::ResolveRemoteChange(scoped_ptr<SyncTaskToken> token) { | 133 void RemoteToLocalSyncer::ResolveRemoteChange(scoped_ptr<SyncTaskToken> token) { |
| 133 DCHECK(dirty_tracker_); | 134 DCHECK(dirty_tracker_); |
| 134 remote_metadata_ = GetFileMetadata( | 135 remote_metadata_ = GetFileMetadata( |
| 135 metadata_database(), dirty_tracker_->file_id()); | 136 metadata_database(), dirty_tracker_->file_id()); |
| 136 | 137 |
| 137 if (!remote_metadata_ || !remote_metadata_->has_details()) { | 138 if (!remote_metadata_ || !remote_metadata_->has_details()) { |
| 138 if (remote_metadata_ && !remote_metadata_->has_details()) { | 139 if (remote_metadata_ && !remote_metadata_->has_details()) { |
| 139 token->RecordLog( | 140 token->RecordLog( |
| 140 "Missing details of a remote file: " + remote_metadata_->file_id()); | 141 "Missing details of a remote file: " + remote_metadata_->file_id()); |
| 141 NOTREACHED(); | 142 NOTREACHED(); |
| 142 } | 143 } |
| 143 token->RecordLog("Missing remote metadata case."); | 144 token->RecordLog("Missing remote metadata case."); |
| 144 | 145 |
| 145 MoveToBackground( | 146 MoveToBackground( |
| 146 token.Pass(), | 147 std::move(token), |
| 147 base::Bind(&RemoteToLocalSyncer::HandleMissingRemoteMetadata, | 148 base::Bind(&RemoteToLocalSyncer::HandleMissingRemoteMetadata, |
| 148 weak_ptr_factory_.GetWeakPtr())); | 149 weak_ptr_factory_.GetWeakPtr())); |
| 149 return; | 150 return; |
| 150 } | 151 } |
| 151 | 152 |
| 152 DCHECK(remote_metadata_); | 153 DCHECK(remote_metadata_); |
| 153 DCHECK(remote_metadata_->has_details()); | 154 DCHECK(remote_metadata_->has_details()); |
| 154 const FileDetails& remote_details = remote_metadata_->details(); | 155 const FileDetails& remote_details = remote_metadata_->details(); |
| 155 | 156 |
| 156 if (!dirty_tracker_->active() || | 157 if (!dirty_tracker_->active() || |
| 157 HasDisabledAppRoot(metadata_database(), *dirty_tracker_)) { | 158 HasDisabledAppRoot(metadata_database(), *dirty_tracker_)) { |
| 158 // Handle inactive tracker in SyncCompleted. | 159 // Handle inactive tracker in SyncCompleted. |
| 159 token->RecordLog("Inactive tracker case."); | 160 token->RecordLog("Inactive tracker case."); |
| 160 SyncCompleted(token.Pass(), SYNC_STATUS_OK); | 161 SyncCompleted(std::move(token), SYNC_STATUS_OK); |
| 161 return; | 162 return; |
| 162 } | 163 } |
| 163 | 164 |
| 164 DCHECK(dirty_tracker_->active()); | 165 DCHECK(dirty_tracker_->active()); |
| 165 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); | 166 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); |
| 166 | 167 |
| 167 if (!dirty_tracker_->has_synced_details()) { | 168 if (!dirty_tracker_->has_synced_details()) { |
| 168 token->RecordLog(base::StringPrintf( | 169 token->RecordLog(base::StringPrintf( |
| 169 "Missing synced_details of an active tracker: %" PRId64, | 170 "Missing synced_details of an active tracker: %" PRId64, |
| 170 dirty_tracker_->tracker_id())); | 171 dirty_tracker_->tracker_id())); |
| 171 NOTREACHED(); | 172 NOTREACHED(); |
| 172 SyncCompleted(token.Pass(), SYNC_STATUS_FAILED); | 173 SyncCompleted(std::move(token), SYNC_STATUS_FAILED); |
| 173 return; | 174 return; |
| 174 } | 175 } |
| 175 | 176 |
| 176 DCHECK(dirty_tracker_->has_synced_details()); | 177 DCHECK(dirty_tracker_->has_synced_details()); |
| 177 const FileDetails& synced_details = dirty_tracker_->synced_details(); | 178 const FileDetails& synced_details = dirty_tracker_->synced_details(); |
| 178 | 179 |
| 179 if (dirty_tracker_->tracker_id() == | 180 if (dirty_tracker_->tracker_id() == |
| 180 metadata_database()->GetSyncRootTrackerID()) { | 181 metadata_database()->GetSyncRootTrackerID()) { |
| 181 if (remote_details.missing() || | 182 if (remote_details.missing() || |
| 182 synced_details.title() != remote_details.title() || | 183 synced_details.title() != remote_details.title() || |
| 183 remote_details.parent_folder_ids_size()) { | 184 remote_details.parent_folder_ids_size()) { |
| 184 token->RecordLog("Sync-root deletion."); | 185 token->RecordLog("Sync-root deletion."); |
| 185 sync_root_deletion_ = true; | 186 sync_root_deletion_ = true; |
| 186 SyncCompleted(token.Pass(), SYNC_STATUS_OK); | 187 SyncCompleted(std::move(token), SYNC_STATUS_OK); |
| 187 return; | 188 return; |
| 188 } | 189 } |
| 189 token->RecordLog("Trivial sync-root change."); | 190 token->RecordLog("Trivial sync-root change."); |
| 190 SyncCompleted(token.Pass(), SYNC_STATUS_OK); | 191 SyncCompleted(std::move(token), SYNC_STATUS_OK); |
| 191 return; | 192 return; |
| 192 } | 193 } |
| 193 | 194 |
| 194 DCHECK_NE(dirty_tracker_->tracker_id(), | 195 DCHECK_NE(dirty_tracker_->tracker_id(), |
| 195 metadata_database()->GetSyncRootTrackerID()); | 196 metadata_database()->GetSyncRootTrackerID()); |
| 196 | 197 |
| 197 if (!BuildFileSystemURL(metadata_database(), *dirty_tracker_, &url_)) { | 198 if (!BuildFileSystemURL(metadata_database(), *dirty_tracker_, &url_)) { |
| 198 NOTREACHED(); | 199 NOTREACHED(); |
| 199 SyncCompleted(token.Pass(), SYNC_STATUS_FAILED); | 200 SyncCompleted(std::move(token), SYNC_STATUS_FAILED); |
| 200 return; | 201 return; |
| 201 } | 202 } |
| 202 | 203 |
| 203 DCHECK(url_.is_valid()); | 204 DCHECK(url_.is_valid()); |
| 204 | 205 |
| 205 if (remote_details.missing()) { | 206 if (remote_details.missing()) { |
| 206 if (!synced_details.missing()) { | 207 if (!synced_details.missing()) { |
| 207 token->RecordLog("Remote file deletion."); | 208 token->RecordLog("Remote file deletion."); |
| 208 MoveToBackground(token.Pass(), | 209 MoveToBackground(std::move(token), |
| 209 base::Bind(&RemoteToLocalSyncer::HandleDeletion, | 210 base::Bind(&RemoteToLocalSyncer::HandleDeletion, |
| 210 weak_ptr_factory_.GetWeakPtr())); | 211 weak_ptr_factory_.GetWeakPtr())); |
| 211 return; | 212 return; |
| 212 } | 213 } |
| 213 | 214 |
| 214 DCHECK(synced_details.missing()); | 215 DCHECK(synced_details.missing()); |
| 215 token->RecordLog("Found a stray missing tracker: " + | 216 token->RecordLog("Found a stray missing tracker: " + |
| 216 dirty_tracker_->file_id()); | 217 dirty_tracker_->file_id()); |
| 217 NOTREACHED(); | 218 NOTREACHED(); |
| 218 SyncCompleted(token.Pass(), SYNC_STATUS_OK); | 219 SyncCompleted(std::move(token), SYNC_STATUS_OK); |
| 219 return; | 220 return; |
| 220 } | 221 } |
| 221 | 222 |
| 222 // Most of remote_details field is valid from here. | 223 // Most of remote_details field is valid from here. |
| 223 DCHECK(!remote_details.missing()); | 224 DCHECK(!remote_details.missing()); |
| 224 | 225 |
| 225 if (synced_details.file_kind() != remote_details.file_kind()) { | 226 if (synced_details.file_kind() != remote_details.file_kind()) { |
| 226 token->RecordLog(base::StringPrintf( | 227 token->RecordLog(base::StringPrintf( |
| 227 "Found type mismatch between remote and local file: %s" | 228 "Found type mismatch between remote and local file: %s" |
| 228 " type: (local) %d vs (remote) %d", | 229 " type: (local) %d vs (remote) %d", |
| 229 dirty_tracker_->file_id().c_str(), | 230 dirty_tracker_->file_id().c_str(), |
| 230 synced_details.file_kind(), | 231 synced_details.file_kind(), |
| 231 remote_details.file_kind())); | 232 remote_details.file_kind())); |
| 232 NOTREACHED(); | 233 NOTREACHED(); |
| 233 SyncCompleted(token.Pass(), SYNC_STATUS_FAILED); | 234 SyncCompleted(std::move(token), SYNC_STATUS_FAILED); |
| 234 return; | 235 return; |
| 235 } | 236 } |
| 236 DCHECK_EQ(synced_details.file_kind(), remote_details.file_kind()); | 237 DCHECK_EQ(synced_details.file_kind(), remote_details.file_kind()); |
| 237 | 238 |
| 238 if (synced_details.file_kind() == FILE_KIND_UNSUPPORTED) { | 239 if (synced_details.file_kind() == FILE_KIND_UNSUPPORTED) { |
| 239 token->RecordLog("Found an unsupported active file: " + | 240 token->RecordLog("Found an unsupported active file: " + |
| 240 remote_metadata_->file_id()); | 241 remote_metadata_->file_id()); |
| 241 NOTREACHED(); | 242 NOTREACHED(); |
| 242 SyncCompleted(token.Pass(), SYNC_STATUS_FAILED); | 243 SyncCompleted(std::move(token), SYNC_STATUS_FAILED); |
| 243 return; | 244 return; |
| 244 } | 245 } |
| 245 DCHECK(remote_details.file_kind() == FILE_KIND_FILE || | 246 DCHECK(remote_details.file_kind() == FILE_KIND_FILE || |
| 246 remote_details.file_kind() == FILE_KIND_FOLDER); | 247 remote_details.file_kind() == FILE_KIND_FOLDER); |
| 247 | 248 |
| 248 if (synced_details.title() != remote_details.title()) { | 249 if (synced_details.title() != remote_details.title()) { |
| 249 // Handle rename as deletion + addition. | 250 // Handle rename as deletion + addition. |
| 250 token->RecordLog("Detected file rename."); | 251 token->RecordLog("Detected file rename."); |
| 251 | 252 |
| 252 MoveToBackground(token.Pass(), | 253 MoveToBackground(std::move(token), |
| 253 base::Bind(&RemoteToLocalSyncer::HandleFileMove, | 254 base::Bind(&RemoteToLocalSyncer::HandleFileMove, |
| 254 weak_ptr_factory_.GetWeakPtr())); | 255 weak_ptr_factory_.GetWeakPtr())); |
| 255 return; | 256 return; |
| 256 } | 257 } |
| 257 DCHECK_EQ(synced_details.title(), remote_details.title()); | 258 DCHECK_EQ(synced_details.title(), remote_details.title()); |
| 258 | 259 |
| 259 FileTracker parent_tracker; | 260 FileTracker parent_tracker; |
| 260 if (!metadata_database()->FindTrackerByTrackerID( | 261 if (!metadata_database()->FindTrackerByTrackerID( |
| 261 dirty_tracker_->parent_tracker_id(), &parent_tracker)) { | 262 dirty_tracker_->parent_tracker_id(), &parent_tracker)) { |
| 262 token->RecordLog("Missing parent tracker for a non sync-root tracker: " | 263 token->RecordLog("Missing parent tracker for a non sync-root tracker: " |
| 263 + dirty_tracker_->file_id()); | 264 + dirty_tracker_->file_id()); |
| 264 NOTREACHED(); | 265 NOTREACHED(); |
| 265 SyncCompleted(token.Pass(), SYNC_STATUS_FAILED); | 266 SyncCompleted(std::move(token), SYNC_STATUS_FAILED); |
| 266 return; | 267 return; |
| 267 } | 268 } |
| 268 | 269 |
| 269 if (!HasFolderAsParent(remote_details, parent_tracker.file_id())) { | 270 if (!HasFolderAsParent(remote_details, parent_tracker.file_id())) { |
| 270 // Handle reorganize as deletion + addition. | 271 // Handle reorganize as deletion + addition. |
| 271 token->RecordLog("Detected file reorganize."); | 272 token->RecordLog("Detected file reorganize."); |
| 272 | 273 |
| 273 MoveToBackground(token.Pass(), | 274 MoveToBackground(std::move(token), |
| 274 base::Bind(&RemoteToLocalSyncer::HandleFileMove, | 275 base::Bind(&RemoteToLocalSyncer::HandleFileMove, |
| 275 weak_ptr_factory_.GetWeakPtr())); | 276 weak_ptr_factory_.GetWeakPtr())); |
| 276 return; | 277 return; |
| 277 } | 278 } |
| 278 | 279 |
| 279 if (synced_details.file_kind() == FILE_KIND_FILE) { | 280 if (synced_details.file_kind() == FILE_KIND_FILE) { |
| 280 if (synced_details.md5() != remote_details.md5()) { | 281 if (synced_details.md5() != remote_details.md5()) { |
| 281 token->RecordLog("Detected file content update."); | 282 token->RecordLog("Detected file content update."); |
| 282 MoveToBackground(token.Pass(), | 283 MoveToBackground(std::move(token), |
| 283 base::Bind(&RemoteToLocalSyncer::HandleContentUpdate, | 284 base::Bind(&RemoteToLocalSyncer::HandleContentUpdate, |
| 284 weak_ptr_factory_.GetWeakPtr())); | 285 weak_ptr_factory_.GetWeakPtr())); |
| 285 return; | 286 return; |
| 286 } | 287 } |
| 287 } else { | 288 } else { |
| 288 DCHECK_EQ(FILE_KIND_FOLDER, synced_details.file_kind()); | 289 DCHECK_EQ(FILE_KIND_FOLDER, synced_details.file_kind()); |
| 289 if (synced_details.missing()) { | 290 if (synced_details.missing()) { |
| 290 token->RecordLog("Detected folder update."); | 291 token->RecordLog("Detected folder update."); |
| 291 MoveToBackground(token.Pass(), | 292 MoveToBackground(std::move(token), |
| 292 base::Bind(&RemoteToLocalSyncer::HandleFolderUpdate, | 293 base::Bind(&RemoteToLocalSyncer::HandleFolderUpdate, |
| 293 weak_ptr_factory_.GetWeakPtr())); | 294 weak_ptr_factory_.GetWeakPtr())); |
| 294 return; | 295 return; |
| 295 } | 296 } |
| 296 if (dirty_tracker_->needs_folder_listing()) { | 297 if (dirty_tracker_->needs_folder_listing()) { |
| 297 token->RecordLog("Needs listing folder."); | 298 token->RecordLog("Needs listing folder."); |
| 298 MoveToBackground(token.Pass(), | 299 MoveToBackground(std::move(token), |
| 299 base::Bind(&RemoteToLocalSyncer::ListFolderContent, | 300 base::Bind(&RemoteToLocalSyncer::ListFolderContent, |
| 300 weak_ptr_factory_.GetWeakPtr())); | 301 weak_ptr_factory_.GetWeakPtr())); |
| 301 return; | 302 return; |
| 302 } | 303 } |
| 303 SyncCompleted(token.Pass(), SYNC_STATUS_OK); | 304 SyncCompleted(std::move(token), SYNC_STATUS_OK); |
| 304 return; | 305 return; |
| 305 } | 306 } |
| 306 | 307 |
| 307 token->RecordLog("Trivial file change."); | 308 token->RecordLog("Trivial file change."); |
| 308 SyncCompleted(token.Pass(), SYNC_STATUS_OK); | 309 SyncCompleted(std::move(token), SYNC_STATUS_OK); |
| 309 } | 310 } |
| 310 | 311 |
| 311 void RemoteToLocalSyncer::MoveToBackground(scoped_ptr<SyncTaskToken> token, | 312 void RemoteToLocalSyncer::MoveToBackground(scoped_ptr<SyncTaskToken> token, |
| 312 const Continuation& continuation) { | 313 const Continuation& continuation) { |
| 313 DCHECK(dirty_tracker_); | 314 DCHECK(dirty_tracker_); |
| 314 | 315 |
| 315 scoped_ptr<TaskBlocker> blocker(new TaskBlocker); | 316 scoped_ptr<TaskBlocker> blocker(new TaskBlocker); |
| 316 blocker->app_id = dirty_tracker_->app_id(); | 317 blocker->app_id = dirty_tracker_->app_id(); |
| 317 if (url_.is_valid()) | 318 if (url_.is_valid()) |
| 318 blocker->paths.push_back(url_.path()); | 319 blocker->paths.push_back(url_.path()); |
| 319 blocker->file_ids.push_back(dirty_tracker_->file_id()); | 320 blocker->file_ids.push_back(dirty_tracker_->file_id()); |
| 320 blocker->tracker_ids.push_back(dirty_tracker_->tracker_id()); | 321 blocker->tracker_ids.push_back(dirty_tracker_->tracker_id()); |
| 321 | 322 |
| 322 SyncTaskManager::UpdateTaskBlocker( | 323 SyncTaskManager::UpdateTaskBlocker( |
| 323 token.Pass(), blocker.Pass(), | 324 std::move(token), std::move(blocker), |
| 324 base::Bind(&RemoteToLocalSyncer::ContinueAsBackgroundTask, | 325 base::Bind(&RemoteToLocalSyncer::ContinueAsBackgroundTask, |
| 325 weak_ptr_factory_.GetWeakPtr(), continuation)); | 326 weak_ptr_factory_.GetWeakPtr(), continuation)); |
| 326 } | 327 } |
| 327 | 328 |
| 328 void RemoteToLocalSyncer::ContinueAsBackgroundTask( | 329 void RemoteToLocalSyncer::ContinueAsBackgroundTask( |
| 329 const Continuation& continuation, | 330 const Continuation& continuation, |
| 330 scoped_ptr<SyncTaskToken> token) { | 331 scoped_ptr<SyncTaskToken> token) { |
| 331 DCHECK(dirty_tracker_); | 332 DCHECK(dirty_tracker_); |
| 332 | 333 |
| 333 // The SyncTask runs as a background task beyond this point. | 334 // The SyncTask runs as a background task beyond this point. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 346 // - For other RemoteToLocalSyncer, it may delete the FileTracker of parent. | 347 // - For other RemoteToLocalSyncer, it may delete the FileTracker of parent. |
| 347 // Note that since RemoteToLocalSyncer demotes the target FileTracker first, | 348 // Note that since RemoteToLocalSyncer demotes the target FileTracker first, |
| 348 // any other RemoteToLocalSyncer does not run for current |dirty_tracker_|. | 349 // any other RemoteToLocalSyncer does not run for current |dirty_tracker_|. |
| 349 // - Others, SyncEngineInitializer and RegisterAppTask doesn't affect to | 350 // - Others, SyncEngineInitializer and RegisterAppTask doesn't affect to |
| 350 | 351 |
| 351 FileTracker latest_dirty_tracker; | 352 FileTracker latest_dirty_tracker; |
| 352 if (!metadata_database()->FindTrackerByTrackerID( | 353 if (!metadata_database()->FindTrackerByTrackerID( |
| 353 dirty_tracker_->tracker_id(), &latest_dirty_tracker) || | 354 dirty_tracker_->tracker_id(), &latest_dirty_tracker) || |
| 354 dirty_tracker_->active() != latest_dirty_tracker.active() || | 355 dirty_tracker_->active() != latest_dirty_tracker.active() || |
| 355 !latest_dirty_tracker.dirty()) { | 356 !latest_dirty_tracker.dirty()) { |
| 356 SyncCompleted(token.Pass(), SYNC_STATUS_RETRY); | 357 SyncCompleted(std::move(token), SYNC_STATUS_RETRY); |
| 357 return; | 358 return; |
| 358 } | 359 } |
| 359 | 360 |
| 360 int64_t current_change_id = std::numeric_limits<int64_t>::min(); | 361 int64_t current_change_id = std::numeric_limits<int64_t>::min(); |
| 361 int64_t latest_change_id = std::numeric_limits<int64_t>::min(); | 362 int64_t latest_change_id = std::numeric_limits<int64_t>::min(); |
| 362 if (dirty_tracker_->has_synced_details()) | 363 if (dirty_tracker_->has_synced_details()) |
| 363 current_change_id = dirty_tracker_->synced_details().change_id(); | 364 current_change_id = dirty_tracker_->synced_details().change_id(); |
| 364 if (latest_dirty_tracker.has_synced_details()) | 365 if (latest_dirty_tracker.has_synced_details()) |
| 365 latest_change_id = latest_dirty_tracker.synced_details().change_id(); | 366 latest_change_id = latest_dirty_tracker.synced_details().change_id(); |
| 366 if (current_change_id != latest_change_id) { | 367 if (current_change_id != latest_change_id) { |
| 367 SyncCompleted(token.Pass(), SYNC_STATUS_RETRY); | 368 SyncCompleted(std::move(token), SYNC_STATUS_RETRY); |
| 368 return; | 369 return; |
| 369 } | 370 } |
| 370 | 371 |
| 371 FileMetadata latest_file_metadata; | 372 FileMetadata latest_file_metadata; |
| 372 if (metadata_database()->FindFileByFileID(dirty_tracker_->file_id(), | 373 if (metadata_database()->FindFileByFileID(dirty_tracker_->file_id(), |
| 373 &latest_file_metadata)) { | 374 &latest_file_metadata)) { |
| 374 if (!remote_metadata_) { | 375 if (!remote_metadata_) { |
| 375 SyncCompleted(token.Pass(), SYNC_STATUS_RETRY); | 376 SyncCompleted(std::move(token), SYNC_STATUS_RETRY); |
| 376 return; | 377 return; |
| 377 } | 378 } |
| 378 | 379 |
| 379 int64_t change_id = remote_metadata_->details().change_id(); | 380 int64_t change_id = remote_metadata_->details().change_id(); |
| 380 int64_t latest_change_id = latest_file_metadata.details().change_id(); | 381 int64_t latest_change_id = latest_file_metadata.details().change_id(); |
| 381 if (change_id != latest_change_id) { | 382 if (change_id != latest_change_id) { |
| 382 SyncCompleted(token.Pass(), SYNC_STATUS_RETRY); | 383 SyncCompleted(std::move(token), SYNC_STATUS_RETRY); |
| 383 return; | 384 return; |
| 384 } | 385 } |
| 385 } else { | 386 } else { |
| 386 if (remote_metadata_) { | 387 if (remote_metadata_) { |
| 387 SyncCompleted(token.Pass(), SYNC_STATUS_RETRY); | 388 SyncCompleted(std::move(token), SYNC_STATUS_RETRY); |
| 388 return; | 389 return; |
| 389 } | 390 } |
| 390 } | 391 } |
| 391 continuation.Run(token.Pass()); | 392 continuation.Run(std::move(token)); |
| 392 } | 393 } |
| 393 | 394 |
| 394 void RemoteToLocalSyncer::HandleMissingRemoteMetadata( | 395 void RemoteToLocalSyncer::HandleMissingRemoteMetadata( |
| 395 scoped_ptr<SyncTaskToken> token) { | 396 scoped_ptr<SyncTaskToken> token) { |
| 396 DCHECK(dirty_tracker_); | 397 DCHECK(dirty_tracker_); |
| 397 | 398 |
| 398 drive_service()->GetFileResource( | 399 drive_service()->GetFileResource( |
| 399 dirty_tracker_->file_id(), | 400 dirty_tracker_->file_id(), |
| 400 base::Bind(&RemoteToLocalSyncer::DidGetRemoteMetadata, | 401 base::Bind(&RemoteToLocalSyncer::DidGetRemoteMetadata, |
| 401 weak_ptr_factory_.GetWeakPtr(), | 402 weak_ptr_factory_.GetWeakPtr(), |
| 402 base::Passed(&token))); | 403 base::Passed(&token))); |
| 403 } | 404 } |
| 404 | 405 |
| 405 void RemoteToLocalSyncer::DidGetRemoteMetadata( | 406 void RemoteToLocalSyncer::DidGetRemoteMetadata( |
| 406 scoped_ptr<SyncTaskToken> token, | 407 scoped_ptr<SyncTaskToken> token, |
| 407 google_apis::DriveApiErrorCode error, | 408 google_apis::DriveApiErrorCode error, |
| 408 scoped_ptr<google_apis::FileResource> entry) { | 409 scoped_ptr<google_apis::FileResource> entry) { |
| 409 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread()); | 410 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread()); |
| 410 | 411 |
| 411 SyncStatusCode status = DriveApiErrorCodeToSyncStatusCode(error); | 412 SyncStatusCode status = DriveApiErrorCodeToSyncStatusCode(error); |
| 412 if (status != SYNC_STATUS_OK && | 413 if (status != SYNC_STATUS_OK && |
| 413 error != google_apis::HTTP_NOT_FOUND) { | 414 error != google_apis::HTTP_NOT_FOUND) { |
| 414 SyncCompleted(token.Pass(), status); | 415 SyncCompleted(std::move(token), status); |
| 415 return; | 416 return; |
| 416 } | 417 } |
| 417 | 418 |
| 418 if (error == google_apis::HTTP_NOT_FOUND) { | 419 if (error == google_apis::HTTP_NOT_FOUND) { |
| 419 status = metadata_database()->UpdateByDeletedRemoteFile( | 420 status = metadata_database()->UpdateByDeletedRemoteFile( |
| 420 dirty_tracker_->file_id()); | 421 dirty_tracker_->file_id()); |
| 421 SyncCompleted(token.Pass(), status); | 422 SyncCompleted(std::move(token), status); |
| 422 return; | 423 return; |
| 423 } | 424 } |
| 424 | 425 |
| 425 if (!entry) { | 426 if (!entry) { |
| 426 NOTREACHED(); | 427 NOTREACHED(); |
| 427 SyncCompleted(token.Pass(), SYNC_STATUS_FAILED); | 428 SyncCompleted(std::move(token), SYNC_STATUS_FAILED); |
| 428 return; | 429 return; |
| 429 } | 430 } |
| 430 | 431 |
| 431 status = metadata_database()->UpdateByFileResource(*entry); | 432 status = metadata_database()->UpdateByFileResource(*entry); |
| 432 if (status != SYNC_STATUS_OK) { | 433 if (status != SYNC_STATUS_OK) { |
| 433 SyncCompleted(token.Pass(), status); | 434 SyncCompleted(std::move(token), status); |
| 434 return; | 435 return; |
| 435 } | 436 } |
| 436 | 437 |
| 437 metadata_database()->PromoteDemotedTracker(dirty_tracker_->tracker_id()); | 438 metadata_database()->PromoteDemotedTracker(dirty_tracker_->tracker_id()); |
| 438 | 439 |
| 439 // Do not update |dirty_tracker_|. | 440 // Do not update |dirty_tracker_|. |
| 440 SyncCompleted(token.Pass(), SYNC_STATUS_RETRY); | 441 SyncCompleted(std::move(token), SYNC_STATUS_RETRY); |
| 441 } | 442 } |
| 442 | 443 |
| 443 void RemoteToLocalSyncer::DidPrepareForAddOrUpdateFile( | 444 void RemoteToLocalSyncer::DidPrepareForAddOrUpdateFile( |
| 444 scoped_ptr<SyncTaskToken> token, | 445 scoped_ptr<SyncTaskToken> token, |
| 445 SyncStatusCode status) { | 446 SyncStatusCode status) { |
| 446 if (status != SYNC_STATUS_OK) { | 447 if (status != SYNC_STATUS_OK) { |
| 447 SyncCompleted(token.Pass(), status); | 448 SyncCompleted(std::move(token), status); |
| 448 return; | 449 return; |
| 449 } | 450 } |
| 450 | 451 |
| 451 DCHECK(url_.is_valid()); | 452 DCHECK(url_.is_valid()); |
| 452 DCHECK(local_metadata_); | 453 DCHECK(local_metadata_); |
| 453 DCHECK(local_changes_); | 454 DCHECK(local_changes_); |
| 454 | 455 |
| 455 // Check if the local file exists. | 456 // Check if the local file exists. |
| 456 if (local_metadata_->file_type == SYNC_FILE_TYPE_UNKNOWN || | 457 if (local_metadata_->file_type == SYNC_FILE_TYPE_UNKNOWN || |
| 457 (!local_changes_->empty() && local_changes_->back().IsDelete())) { | 458 (!local_changes_->empty() && local_changes_->back().IsDelete())) { |
| 458 file_type_ = SYNC_FILE_TYPE_FILE; | 459 file_type_ = SYNC_FILE_TYPE_FILE; |
| 459 sync_action_ = SYNC_ACTION_ADDED; | 460 sync_action_ = SYNC_ACTION_ADDED; |
| 460 // Missing local file case. | 461 // Missing local file case. |
| 461 // Download the file and add it to local as a new file. | 462 // Download the file and add it to local as a new file. |
| 462 DownloadFile(token.Pass()); | 463 DownloadFile(std::move(token)); |
| 463 return; | 464 return; |
| 464 } | 465 } |
| 465 | 466 |
| 466 DCHECK(local_changes_->empty() || local_changes_->back().IsAddOrUpdate()); | 467 DCHECK(local_changes_->empty() || local_changes_->back().IsAddOrUpdate()); |
| 467 if (local_changes_->empty()) { | 468 if (local_changes_->empty()) { |
| 468 if (local_metadata_->file_type == SYNC_FILE_TYPE_FILE) { | 469 if (local_metadata_->file_type == SYNC_FILE_TYPE_FILE) { |
| 469 file_type_ = SYNC_FILE_TYPE_FILE; | 470 file_type_ = SYNC_FILE_TYPE_FILE; |
| 470 sync_action_ = SYNC_ACTION_UPDATED; | 471 sync_action_ = SYNC_ACTION_UPDATED; |
| 471 // Download the file and overwrite the existing local file. | 472 // Download the file and overwrite the existing local file. |
| 472 DownloadFile(token.Pass()); | 473 DownloadFile(std::move(token)); |
| 473 return; | 474 return; |
| 474 } | 475 } |
| 475 | 476 |
| 476 DCHECK_EQ(SYNC_FILE_TYPE_DIRECTORY, local_metadata_->file_type); | 477 DCHECK_EQ(SYNC_FILE_TYPE_DIRECTORY, local_metadata_->file_type); |
| 477 | 478 |
| 478 // Got a remote regular file modification for existing local folder. | 479 // Got a remote regular file modification for existing local folder. |
| 479 // Our policy prioritize folders in this case. | 480 // Our policy prioritize folders in this case. |
| 480 // Let local-to-remote sync phase process this change. | 481 // Let local-to-remote sync phase process this change. |
| 481 remote_change_processor()->RecordFakeLocalChange( | 482 remote_change_processor()->RecordFakeLocalChange( |
| 482 url_, | 483 url_, FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
| 483 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 484 local_metadata_->file_type), |
| 484 local_metadata_->file_type), | 485 SyncCompletedCallback(std::move(token))); |
| 485 SyncCompletedCallback(token.Pass())); | |
| 486 return; | 486 return; |
| 487 } | 487 } |
| 488 | 488 |
| 489 DCHECK(local_changes_->back().IsAddOrUpdate()); | 489 DCHECK(local_changes_->back().IsAddOrUpdate()); |
| 490 // Conflict case. | 490 // Conflict case. |
| 491 // Do nothing for the change now, and handle this in LocalToRemoteSync phase. | 491 // Do nothing for the change now, and handle this in LocalToRemoteSync phase. |
| 492 SyncCompleted(token.Pass(), SYNC_STATUS_RETRY); | 492 SyncCompleted(std::move(token), SYNC_STATUS_RETRY); |
| 493 } | 493 } |
| 494 | 494 |
| 495 void RemoteToLocalSyncer::HandleFolderUpdate( | 495 void RemoteToLocalSyncer::HandleFolderUpdate( |
| 496 scoped_ptr<SyncTaskToken> token) { | 496 scoped_ptr<SyncTaskToken> token) { |
| 497 DCHECK(dirty_tracker_); | 497 DCHECK(dirty_tracker_); |
| 498 DCHECK(dirty_tracker_->active()); | 498 DCHECK(dirty_tracker_->active()); |
| 499 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); | 499 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); |
| 500 | 500 |
| 501 DCHECK(remote_metadata_); | 501 DCHECK(remote_metadata_); |
| 502 DCHECK(remote_metadata_->has_details()); | 502 DCHECK(remote_metadata_->has_details()); |
| 503 DCHECK(!remote_metadata_->details().missing()); | 503 DCHECK(!remote_metadata_->details().missing()); |
| 504 DCHECK_EQ(FILE_KIND_FOLDER, remote_metadata_->details().file_kind()); | 504 DCHECK_EQ(FILE_KIND_FOLDER, remote_metadata_->details().file_kind()); |
| 505 | 505 |
| 506 Prepare(base::Bind(&RemoteToLocalSyncer::DidPrepareForFolderUpdate, | 506 Prepare(base::Bind(&RemoteToLocalSyncer::DidPrepareForFolderUpdate, |
| 507 weak_ptr_factory_.GetWeakPtr(), | 507 weak_ptr_factory_.GetWeakPtr(), |
| 508 base::Passed(&token))); | 508 base::Passed(&token))); |
| 509 } | 509 } |
| 510 | 510 |
| 511 void RemoteToLocalSyncer::DidPrepareForFolderUpdate( | 511 void RemoteToLocalSyncer::DidPrepareForFolderUpdate( |
| 512 scoped_ptr<SyncTaskToken> token, | 512 scoped_ptr<SyncTaskToken> token, |
| 513 SyncStatusCode status) { | 513 SyncStatusCode status) { |
| 514 if (status != SYNC_STATUS_OK) { | 514 if (status != SYNC_STATUS_OK) { |
| 515 SyncCompleted(token.Pass(), status); | 515 SyncCompleted(std::move(token), status); |
| 516 return; | 516 return; |
| 517 } | 517 } |
| 518 | 518 |
| 519 DCHECK(url_.is_valid()); | 519 DCHECK(url_.is_valid()); |
| 520 DCHECK(local_metadata_); | 520 DCHECK(local_metadata_); |
| 521 DCHECK(local_changes_); | 521 DCHECK(local_changes_); |
| 522 | 522 |
| 523 // Check if the local file exists. | 523 // Check if the local file exists. |
| 524 if (local_metadata_->file_type == SYNC_FILE_TYPE_UNKNOWN || | 524 if (local_metadata_->file_type == SYNC_FILE_TYPE_UNKNOWN || |
| 525 (!local_changes_->empty() && local_changes_->back().IsDelete())) { | 525 (!local_changes_->empty() && local_changes_->back().IsDelete())) { |
| 526 file_type_ = SYNC_FILE_TYPE_DIRECTORY; | 526 file_type_ = SYNC_FILE_TYPE_DIRECTORY; |
| 527 sync_action_ = SYNC_ACTION_ADDED; | 527 sync_action_ = SYNC_ACTION_ADDED; |
| 528 // No local file exists at the path. | 528 // No local file exists at the path. |
| 529 CreateFolder(token.Pass()); | 529 CreateFolder(std::move(token)); |
| 530 return; | 530 return; |
| 531 } | 531 } |
| 532 | 532 |
| 533 if (local_metadata_->file_type == SYNC_FILE_TYPE_DIRECTORY) { | 533 if (local_metadata_->file_type == SYNC_FILE_TYPE_DIRECTORY) { |
| 534 // There already exists a folder, nothing left to do. | 534 // There already exists a folder, nothing left to do. |
| 535 if (dirty_tracker_->needs_folder_listing() && | 535 if (dirty_tracker_->needs_folder_listing() && |
| 536 !dirty_tracker_->synced_details().missing()) { | 536 !dirty_tracker_->synced_details().missing()) { |
| 537 ListFolderContent(token.Pass()); | 537 ListFolderContent(std::move(token)); |
| 538 } else { | 538 } else { |
| 539 SyncCompleted(token.Pass(), SYNC_STATUS_OK); | 539 SyncCompleted(std::move(token), SYNC_STATUS_OK); |
| 540 } | 540 } |
| 541 return; | 541 return; |
| 542 } | 542 } |
| 543 | 543 |
| 544 DCHECK_EQ(SYNC_FILE_TYPE_FILE, local_metadata_->file_type); | 544 DCHECK_EQ(SYNC_FILE_TYPE_FILE, local_metadata_->file_type); |
| 545 file_type_ = SYNC_FILE_TYPE_DIRECTORY; | 545 file_type_ = SYNC_FILE_TYPE_DIRECTORY; |
| 546 sync_action_ = SYNC_ACTION_ADDED; | 546 sync_action_ = SYNC_ACTION_ADDED; |
| 547 // Got a remote folder for existing local file. | 547 // Got a remote folder for existing local file. |
| 548 // Our policy prioritize folders in this case. | 548 // Our policy prioritize folders in this case. |
| 549 CreateFolder(token.Pass()); | 549 CreateFolder(std::move(token)); |
| 550 } | 550 } |
| 551 | 551 |
| 552 void RemoteToLocalSyncer::HandleDeletion( | 552 void RemoteToLocalSyncer::HandleDeletion( |
| 553 scoped_ptr<SyncTaskToken> token) { | 553 scoped_ptr<SyncTaskToken> token) { |
| 554 DCHECK(dirty_tracker_); | 554 DCHECK(dirty_tracker_); |
| 555 DCHECK(dirty_tracker_->active()); | 555 DCHECK(dirty_tracker_->active()); |
| 556 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); | 556 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); |
| 557 DCHECK(dirty_tracker_->has_synced_details()); | 557 DCHECK(dirty_tracker_->has_synced_details()); |
| 558 DCHECK(!dirty_tracker_->synced_details().missing()); | 558 DCHECK(!dirty_tracker_->synced_details().missing()); |
| 559 | 559 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 578 | 578 |
| 579 Prepare(base::Bind(&RemoteToLocalSyncer::DidPrepareForDeletion, | 579 Prepare(base::Bind(&RemoteToLocalSyncer::DidPrepareForDeletion, |
| 580 weak_ptr_factory_.GetWeakPtr(), | 580 weak_ptr_factory_.GetWeakPtr(), |
| 581 base::Passed(&token))); | 581 base::Passed(&token))); |
| 582 } | 582 } |
| 583 | 583 |
| 584 void RemoteToLocalSyncer::DidPrepareForDeletion( | 584 void RemoteToLocalSyncer::DidPrepareForDeletion( |
| 585 scoped_ptr<SyncTaskToken> token, | 585 scoped_ptr<SyncTaskToken> token, |
| 586 SyncStatusCode status) { | 586 SyncStatusCode status) { |
| 587 if (status != SYNC_STATUS_OK) { | 587 if (status != SYNC_STATUS_OK) { |
| 588 SyncCompleted(token.Pass(), status); | 588 SyncCompleted(std::move(token), status); |
| 589 return; | 589 return; |
| 590 } | 590 } |
| 591 | 591 |
| 592 DCHECK(url_.is_valid()); | 592 DCHECK(url_.is_valid()); |
| 593 DCHECK(local_metadata_); | 593 DCHECK(local_metadata_); |
| 594 DCHECK(local_changes_); | 594 DCHECK(local_changes_); |
| 595 | 595 |
| 596 // Check if the local file exists. | 596 // Check if the local file exists. |
| 597 if (local_metadata_->file_type == SYNC_FILE_TYPE_UNKNOWN || | 597 if (local_metadata_->file_type == SYNC_FILE_TYPE_UNKNOWN || |
| 598 (!local_changes_->empty() && local_changes_->back().IsDelete())) { | 598 (!local_changes_->empty() && local_changes_->back().IsDelete())) { |
| 599 // No local file exists at the path. | 599 // No local file exists at the path. |
| 600 SyncCompleted(token.Pass(), SYNC_STATUS_OK); | 600 SyncCompleted(std::move(token), SYNC_STATUS_OK); |
| 601 return; | 601 return; |
| 602 } | 602 } |
| 603 | 603 |
| 604 DCHECK(local_changes_->empty() || local_changes_->back().IsAddOrUpdate()); | 604 DCHECK(local_changes_->empty() || local_changes_->back().IsAddOrUpdate()); |
| 605 if (local_changes_->empty()) { | 605 if (local_changes_->empty()) { |
| 606 file_type_ = local_metadata_->file_type; | 606 file_type_ = local_metadata_->file_type; |
| 607 sync_action_ = SYNC_ACTION_DELETED; | 607 sync_action_ = SYNC_ACTION_DELETED; |
| 608 DeleteLocalFile(token.Pass()); | 608 DeleteLocalFile(std::move(token)); |
| 609 return; | 609 return; |
| 610 } | 610 } |
| 611 | 611 |
| 612 DCHECK(local_changes_->back().IsAddOrUpdate()); | 612 DCHECK(local_changes_->back().IsAddOrUpdate()); |
| 613 // File is remotely deleted and locally updated. | 613 // File is remotely deleted and locally updated. |
| 614 // Ignore the remote deletion and handle it as if applied successfully. | 614 // Ignore the remote deletion and handle it as if applied successfully. |
| 615 SyncCompleted(token.Pass(), SYNC_STATUS_OK); | 615 SyncCompleted(std::move(token), SYNC_STATUS_OK); |
| 616 } | 616 } |
| 617 | 617 |
| 618 void RemoteToLocalSyncer::HandleContentUpdate( | 618 void RemoteToLocalSyncer::HandleContentUpdate( |
| 619 scoped_ptr<SyncTaskToken> token) { | 619 scoped_ptr<SyncTaskToken> token) { |
| 620 DCHECK(dirty_tracker_); | 620 DCHECK(dirty_tracker_); |
| 621 DCHECK(dirty_tracker_->active()); | 621 DCHECK(dirty_tracker_->active()); |
| 622 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); | 622 DCHECK(!HasDisabledAppRoot(metadata_database(), *dirty_tracker_)); |
| 623 DCHECK(dirty_tracker_->has_synced_details()); | 623 DCHECK(dirty_tracker_->has_synced_details()); |
| 624 DCHECK_EQ(FILE_KIND_FILE, dirty_tracker_->synced_details().file_kind()); | 624 DCHECK_EQ(FILE_KIND_FILE, dirty_tracker_->synced_details().file_kind()); |
| 625 | 625 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 base::Passed(make_scoped_ptr(new FileIDList)))); | 657 base::Passed(make_scoped_ptr(new FileIDList)))); |
| 658 } | 658 } |
| 659 | 659 |
| 660 void RemoteToLocalSyncer::DidListFolderContent( | 660 void RemoteToLocalSyncer::DidListFolderContent( |
| 661 scoped_ptr<SyncTaskToken> token, | 661 scoped_ptr<SyncTaskToken> token, |
| 662 scoped_ptr<FileIDList> children, | 662 scoped_ptr<FileIDList> children, |
| 663 google_apis::DriveApiErrorCode error, | 663 google_apis::DriveApiErrorCode error, |
| 664 scoped_ptr<google_apis::FileList> file_list) { | 664 scoped_ptr<google_apis::FileList> file_list) { |
| 665 SyncStatusCode status = DriveApiErrorCodeToSyncStatusCode(error); | 665 SyncStatusCode status = DriveApiErrorCodeToSyncStatusCode(error); |
| 666 if (status != SYNC_STATUS_OK) { | 666 if (status != SYNC_STATUS_OK) { |
| 667 SyncCompleted(token.Pass(), status); | 667 SyncCompleted(std::move(token), status); |
| 668 return; | 668 return; |
| 669 } | 669 } |
| 670 | 670 |
| 671 if (!file_list) { | 671 if (!file_list) { |
| 672 NOTREACHED(); | 672 NOTREACHED(); |
| 673 SyncCompleted(token.Pass(), SYNC_STATUS_FAILED); | 673 SyncCompleted(std::move(token), SYNC_STATUS_FAILED); |
| 674 return; | 674 return; |
| 675 } | 675 } |
| 676 | 676 |
| 677 children->reserve(children->size() + file_list->items().size()); | 677 children->reserve(children->size() + file_list->items().size()); |
| 678 for (ScopedVector<google_apis::FileResource>::const_iterator itr = | 678 for (ScopedVector<google_apis::FileResource>::const_iterator itr = |
| 679 file_list->items().begin(); | 679 file_list->items().begin(); |
| 680 itr != file_list->items().end(); | 680 itr != file_list->items().end(); |
| 681 ++itr) { | 681 ++itr) { |
| 682 children->push_back((*itr)->file_id()); | 682 children->push_back((*itr)->file_id()); |
| 683 } | 683 } |
| 684 | 684 |
| 685 if (!file_list->next_link().is_empty()) { | 685 if (!file_list->next_link().is_empty()) { |
| 686 drive_service()->GetRemainingFileList( | 686 drive_service()->GetRemainingFileList( |
| 687 file_list->next_link(), | 687 file_list->next_link(), |
| 688 base::Bind(&RemoteToLocalSyncer::DidListFolderContent, | 688 base::Bind(&RemoteToLocalSyncer::DidListFolderContent, |
| 689 weak_ptr_factory_.GetWeakPtr(), | 689 weak_ptr_factory_.GetWeakPtr(), |
| 690 base::Passed(&token), base::Passed(&children))); | 690 base::Passed(&token), base::Passed(&children))); |
| 691 return; | 691 return; |
| 692 } | 692 } |
| 693 | 693 |
| 694 status = metadata_database()->PopulateFolderByChildList( | 694 status = metadata_database()->PopulateFolderByChildList( |
| 695 dirty_tracker_->file_id(), *children); | 695 dirty_tracker_->file_id(), *children); |
| 696 SyncCompleted(token.Pass(), status); | 696 SyncCompleted(std::move(token), status); |
| 697 } | 697 } |
| 698 | 698 |
| 699 void RemoteToLocalSyncer::SyncCompleted(scoped_ptr<SyncTaskToken> token, | 699 void RemoteToLocalSyncer::SyncCompleted(scoped_ptr<SyncTaskToken> token, |
| 700 SyncStatusCode status) { | 700 SyncStatusCode status) { |
| 701 token->RecordLog(base::StringPrintf( | 701 token->RecordLog(base::StringPrintf( |
| 702 "[Remote -> Local]: Finished: action=%s, tracker=%" PRId64 " status=%s", | 702 "[Remote -> Local]: Finished: action=%s, tracker=%" PRId64 " status=%s", |
| 703 SyncActionToString(sync_action_), dirty_tracker_->tracker_id(), | 703 SyncActionToString(sync_action_), dirty_tracker_->tracker_id(), |
| 704 SyncStatusCodeToString(status))); | 704 SyncStatusCodeToString(status))); |
| 705 | 705 |
| 706 if (sync_root_deletion_) { | 706 if (sync_root_deletion_) { |
| 707 FinalizeSync(token.Pass(), SYNC_STATUS_OK); | 707 FinalizeSync(std::move(token), SYNC_STATUS_OK); |
| 708 return; | 708 return; |
| 709 } | 709 } |
| 710 | 710 |
| 711 if (status == SYNC_STATUS_RETRY) { | 711 if (status == SYNC_STATUS_RETRY) { |
| 712 FinalizeSync(token.Pass(), SYNC_STATUS_OK); | 712 FinalizeSync(std::move(token), SYNC_STATUS_OK); |
| 713 return; | 713 return; |
| 714 } | 714 } |
| 715 | 715 |
| 716 if (status != SYNC_STATUS_OK) { | 716 if (status != SYNC_STATUS_OK) { |
| 717 FinalizeSync(token.Pass(), status); | 717 FinalizeSync(std::move(token), status); |
| 718 return; | 718 return; |
| 719 } | 719 } |
| 720 | 720 |
| 721 DCHECK(dirty_tracker_); | 721 DCHECK(dirty_tracker_); |
| 722 DCHECK(remote_metadata_); | 722 DCHECK(remote_metadata_); |
| 723 DCHECK(remote_metadata_->has_details()); | 723 DCHECK(remote_metadata_->has_details()); |
| 724 | 724 |
| 725 FileDetails updated_details = remote_metadata_->details(); | 725 FileDetails updated_details = remote_metadata_->details(); |
| 726 if (!dirty_tracker_->active() || | 726 if (!dirty_tracker_->active() || |
| 727 HasDisabledAppRoot(metadata_database(), *dirty_tracker_)) { | 727 HasDisabledAppRoot(metadata_database(), *dirty_tracker_)) { |
| 728 // Operations for an inactive tracker don't update file content. | 728 // Operations for an inactive tracker don't update file content. |
| 729 if (dirty_tracker_->has_synced_details()) | 729 if (dirty_tracker_->has_synced_details()) |
| 730 updated_details.set_md5(dirty_tracker_->synced_details().md5()); | 730 updated_details.set_md5(dirty_tracker_->synced_details().md5()); |
| 731 if (!dirty_tracker_->active()) { | 731 if (!dirty_tracker_->active()) { |
| 732 // Keep missing true, as the change hasn't been synced to local. | 732 // Keep missing true, as the change hasn't been synced to local. |
| 733 updated_details.clear_md5(); | 733 updated_details.clear_md5(); |
| 734 updated_details.set_missing(true); | 734 updated_details.set_missing(true); |
| 735 } | 735 } |
| 736 } | 736 } |
| 737 | 737 |
| 738 status = metadata_database()->UpdateTracker( | 738 status = metadata_database()->UpdateTracker( |
| 739 dirty_tracker_->tracker_id(), updated_details); | 739 dirty_tracker_->tracker_id(), updated_details); |
| 740 FinalizeSync(token.Pass(), status); | 740 FinalizeSync(std::move(token), status); |
| 741 } | 741 } |
| 742 | 742 |
| 743 void RemoteToLocalSyncer::FinalizeSync(scoped_ptr<SyncTaskToken> token, | 743 void RemoteToLocalSyncer::FinalizeSync(scoped_ptr<SyncTaskToken> token, |
| 744 SyncStatusCode status) { | 744 SyncStatusCode status) { |
| 745 if (prepared_) { | 745 if (prepared_) { |
| 746 remote_change_processor()->FinalizeRemoteSync( | 746 remote_change_processor()->FinalizeRemoteSync( |
| 747 url_, false /* clear_local_change */, | 747 url_, false /* clear_local_change */, |
| 748 base::Bind(SyncTaskManager::NotifyTaskDone, | 748 base::Bind(SyncTaskManager::NotifyTaskDone, |
| 749 base::Passed(&token), status)); | 749 base::Passed(&token), status)); |
| 750 return; | 750 return; |
| 751 } | 751 } |
| 752 | 752 |
| 753 SyncTaskManager::NotifyTaskDone(token.Pass(), status); | 753 SyncTaskManager::NotifyTaskDone(std::move(token), status); |
| 754 } | 754 } |
| 755 | 755 |
| 756 void RemoteToLocalSyncer::Prepare(const SyncStatusCallback& callback) { | 756 void RemoteToLocalSyncer::Prepare(const SyncStatusCallback& callback) { |
| 757 DCHECK(url_.is_valid()); | 757 DCHECK(url_.is_valid()); |
| 758 remote_change_processor()->PrepareForProcessRemoteChange( | 758 remote_change_processor()->PrepareForProcessRemoteChange( |
| 759 url_, | 759 url_, |
| 760 base::Bind(&RemoteToLocalSyncer::DidPrepare, | 760 base::Bind(&RemoteToLocalSyncer::DidPrepare, |
| 761 weak_ptr_factory_.GetWeakPtr(), | 761 weak_ptr_factory_.GetWeakPtr(), |
| 762 callback)); | 762 callback)); |
| 763 } | 763 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 774 | 774 |
| 775 local_metadata_.reset(new SyncFileMetadata(local_metadata)); | 775 local_metadata_.reset(new SyncFileMetadata(local_metadata)); |
| 776 local_changes_.reset(new FileChangeList(local_changes)); | 776 local_changes_.reset(new FileChangeList(local_changes)); |
| 777 | 777 |
| 778 callback.Run(status); | 778 callback.Run(status); |
| 779 } | 779 } |
| 780 | 780 |
| 781 void RemoteToLocalSyncer::DeleteLocalFile(scoped_ptr<SyncTaskToken> token) { | 781 void RemoteToLocalSyncer::DeleteLocalFile(scoped_ptr<SyncTaskToken> token) { |
| 782 remote_change_processor()->ApplyRemoteChange( | 782 remote_change_processor()->ApplyRemoteChange( |
| 783 FileChange(FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_UNKNOWN), | 783 FileChange(FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_UNKNOWN), |
| 784 base::FilePath(), | 784 base::FilePath(), url_, SyncCompletedCallback(std::move(token))); |
| 785 url_, | |
| 786 SyncCompletedCallback(token.Pass())); | |
| 787 } | 785 } |
| 788 | 786 |
| 789 void RemoteToLocalSyncer::DownloadFile(scoped_ptr<SyncTaskToken> token) { | 787 void RemoteToLocalSyncer::DownloadFile(scoped_ptr<SyncTaskToken> token) { |
| 790 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread()); | 788 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread()); |
| 791 | 789 |
| 792 storage::ScopedFile file = CreateTemporaryFile( | 790 storage::ScopedFile file = CreateTemporaryFile( |
| 793 make_scoped_refptr(sync_context_->GetWorkerTaskRunner())); | 791 make_scoped_refptr(sync_context_->GetWorkerTaskRunner())); |
| 794 | 792 |
| 795 base::FilePath path = file.path(); | 793 base::FilePath path = file.path(); |
| 796 drive_service()->DownloadFile( | 794 drive_service()->DownloadFile( |
| 797 path, remote_metadata_->file_id(), | 795 path, remote_metadata_->file_id(), |
| 798 base::Bind(&RemoteToLocalSyncer::DidDownloadFile, | 796 base::Bind(&RemoteToLocalSyncer::DidDownloadFile, |
| 799 weak_ptr_factory_.GetWeakPtr(), | 797 weak_ptr_factory_.GetWeakPtr(), |
| 800 base::Passed(&token), base::Passed(&file)), | 798 base::Passed(&token), base::Passed(&file)), |
| 801 google_apis::GetContentCallback(), | 799 google_apis::GetContentCallback(), |
| 802 google_apis::ProgressCallback()); | 800 google_apis::ProgressCallback()); |
| 803 } | 801 } |
| 804 | 802 |
| 805 void RemoteToLocalSyncer::DidDownloadFile(scoped_ptr<SyncTaskToken> token, | 803 void RemoteToLocalSyncer::DidDownloadFile(scoped_ptr<SyncTaskToken> token, |
| 806 storage::ScopedFile file, | 804 storage::ScopedFile file, |
| 807 google_apis::DriveApiErrorCode error, | 805 google_apis::DriveApiErrorCode error, |
| 808 const base::FilePath&) { | 806 const base::FilePath&) { |
| 809 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread()); | 807 DCHECK(sync_context_->GetWorkerTaskRunner()->RunsTasksOnCurrentThread()); |
| 810 | 808 |
| 811 SyncStatusCode status = DriveApiErrorCodeToSyncStatusCode(error); | 809 SyncStatusCode status = DriveApiErrorCodeToSyncStatusCode(error); |
| 812 if (status != SYNC_STATUS_OK) { | 810 if (status != SYNC_STATUS_OK) { |
| 813 SyncCompleted(token.Pass(), status); | 811 SyncCompleted(std::move(token), status); |
| 814 return; | 812 return; |
| 815 } | 813 } |
| 816 | 814 |
| 817 base::FilePath path = file.path(); | 815 base::FilePath path = file.path(); |
| 818 const std::string md5 = drive::util::GetMd5Digest(path, nullptr); | 816 const std::string md5 = drive::util::GetMd5Digest(path, nullptr); |
| 819 if (md5.empty()) { | 817 if (md5.empty()) { |
| 820 SyncCompleted(token.Pass(), SYNC_FILE_ERROR_NOT_FOUND); | 818 SyncCompleted(std::move(token), SYNC_FILE_ERROR_NOT_FOUND); |
| 821 return; | 819 return; |
| 822 } | 820 } |
| 823 | 821 |
| 824 if (md5 != remote_metadata_->details().md5()) { | 822 if (md5 != remote_metadata_->details().md5()) { |
| 825 // File has been modified since last metadata retrieval. | 823 // File has been modified since last metadata retrieval. |
| 826 SyncCompleted(token.Pass(), SYNC_STATUS_RETRY); | 824 SyncCompleted(std::move(token), SYNC_STATUS_RETRY); |
| 827 return; | 825 return; |
| 828 } | 826 } |
| 829 | 827 |
| 830 remote_change_processor()->ApplyRemoteChange( | 828 remote_change_processor()->ApplyRemoteChange( |
| 831 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE), | 829 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE), |
| 832 path, url_, | 830 path, url_, |
| 833 base::Bind(&RemoteToLocalSyncer::DidApplyDownload, | 831 base::Bind(&RemoteToLocalSyncer::DidApplyDownload, |
| 834 weak_ptr_factory_.GetWeakPtr(), | 832 weak_ptr_factory_.GetWeakPtr(), |
| 835 base::Passed(&token), base::Passed(&file))); | 833 base::Passed(&token), base::Passed(&file))); |
| 836 } | 834 } |
| 837 | 835 |
| 838 void RemoteToLocalSyncer::DidApplyDownload(scoped_ptr<SyncTaskToken> token, | 836 void RemoteToLocalSyncer::DidApplyDownload(scoped_ptr<SyncTaskToken> token, |
| 839 storage::ScopedFile, | 837 storage::ScopedFile, |
| 840 SyncStatusCode status) { | 838 SyncStatusCode status) { |
| 841 SyncCompleted(token.Pass(), status); | 839 SyncCompleted(std::move(token), status); |
| 842 } | 840 } |
| 843 | 841 |
| 844 void RemoteToLocalSyncer::CreateFolder(scoped_ptr<SyncTaskToken> token) { | 842 void RemoteToLocalSyncer::CreateFolder(scoped_ptr<SyncTaskToken> token) { |
| 845 remote_change_processor()->ApplyRemoteChange( | 843 remote_change_processor()->ApplyRemoteChange( |
| 846 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 844 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
| 847 SYNC_FILE_TYPE_DIRECTORY), | 845 SYNC_FILE_TYPE_DIRECTORY), |
| 848 base::FilePath(), url_, | 846 base::FilePath(), url_, SyncCompletedCallback(std::move(token))); |
| 849 SyncCompletedCallback(token.Pass())); | |
| 850 } | 847 } |
| 851 | 848 |
| 852 drive::DriveServiceInterface* RemoteToLocalSyncer::drive_service() { | 849 drive::DriveServiceInterface* RemoteToLocalSyncer::drive_service() { |
| 853 return sync_context_->GetDriveService(); | 850 return sync_context_->GetDriveService(); |
| 854 } | 851 } |
| 855 | 852 |
| 856 MetadataDatabase* RemoteToLocalSyncer::metadata_database() { | 853 MetadataDatabase* RemoteToLocalSyncer::metadata_database() { |
| 857 return sync_context_->GetMetadataDatabase(); | 854 return sync_context_->GetMetadataDatabase(); |
| 858 } | 855 } |
| 859 | 856 |
| 860 RemoteChangeProcessor* RemoteToLocalSyncer::remote_change_processor() { | 857 RemoteChangeProcessor* RemoteToLocalSyncer::remote_change_processor() { |
| 861 DCHECK(sync_context_->GetRemoteChangeProcessor()); | 858 DCHECK(sync_context_->GetRemoteChangeProcessor()); |
| 862 return sync_context_->GetRemoteChangeProcessor(); | 859 return sync_context_->GetRemoteChangeProcessor(); |
| 863 } | 860 } |
| 864 | 861 |
| 865 SyncStatusCallback RemoteToLocalSyncer::SyncCompletedCallback( | 862 SyncStatusCallback RemoteToLocalSyncer::SyncCompletedCallback( |
| 866 scoped_ptr<SyncTaskToken> token) { | 863 scoped_ptr<SyncTaskToken> token) { |
| 867 return base::Bind(&RemoteToLocalSyncer::SyncCompleted, | 864 return base::Bind(&RemoteToLocalSyncer::SyncCompleted, |
| 868 weak_ptr_factory_.GetWeakPtr(), | 865 weak_ptr_factory_.GetWeakPtr(), |
| 869 base::Passed(&token)); | 866 base::Passed(&token)); |
| 870 } | 867 } |
| 871 | 868 |
| 872 } // namespace drive_backend | 869 } // namespace drive_backend |
| 873 } // namespace sync_file_system | 870 } // namespace sync_file_system |
| OLD | NEW |