| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_file_sync_service.h" | 5 #include "chrome/browser/sync_file_system/drive_file_sync_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "webkit/fileapi/syncable/sync_file_type.h" | 23 #include "webkit/fileapi/syncable/sync_file_type.h" |
| 24 #include "webkit/fileapi/syncable/syncable_file_system_util.h" | 24 #include "webkit/fileapi/syncable/syncable_file_system_util.h" |
| 25 | 25 |
| 26 namespace sync_file_system { | 26 namespace sync_file_system { |
| 27 | 27 |
| 28 const char DriveFileSyncService::kServiceName[] = "drive"; | 28 const char DriveFileSyncService::kServiceName[] = "drive"; |
| 29 | 29 |
| 30 class DriveFileSyncService::TaskToken { | 30 class DriveFileSyncService::TaskToken { |
| 31 public: | 31 public: |
| 32 explicit TaskToken(const base::WeakPtr<DriveFileSyncService>& sync_service) | 32 explicit TaskToken(const base::WeakPtr<DriveFileSyncService>& sync_service) |
| 33 : sync_service_(sync_service) { | 33 : sync_service_(sync_service), |
| 34 task_type_(TASK_TYPE_NONE) { |
| 34 } | 35 } |
| 35 | 36 |
| 36 void set_location(const tracked_objects::Location& from_here) { | 37 void ResetTask(const tracked_objects::Location& location) { |
| 37 from_here_ = from_here; | 38 location_ = location; |
| 39 task_type_ = TASK_TYPE_NONE; |
| 40 description_.clear(); |
| 38 } | 41 } |
| 39 | 42 |
| 43 void UpdateTask(const tracked_objects::Location& location, |
| 44 TaskType task_type, |
| 45 const std::string& description) { |
| 46 location_ = location; |
| 47 task_type_ = task_type; |
| 48 description_ = description; |
| 49 } |
| 50 |
| 51 const tracked_objects::Location& location() const { return location_; } |
| 52 TaskType task_type() const { return task_type_; } |
| 53 const std::string& description() const { return description_; } |
| 54 |
| 40 ~TaskToken() { | 55 ~TaskToken() { |
| 41 // All task on DriveFileSyncService must hold TaskToken instance to ensure | 56 // All task on DriveFileSyncService must hold TaskToken instance to ensure |
| 42 // no other tasks are running. Also, as soon as a task finishes to work, | 57 // no other tasks are running. Also, as soon as a task finishes to work, |
| 43 // it must return the token to DriveFileSyncService. | 58 // it must return the token to DriveFileSyncService. |
| 44 // Destroying a token with valid |sync_service_| indicates the token was | 59 // Destroying a token with valid |sync_service_| indicates the token was |
| 45 // dropped by a task without returning. | 60 // dropped by a task without returning. |
| 46 DCHECK(!sync_service_); | 61 DCHECK(!sync_service_); |
| 47 if (sync_service_) { | 62 if (sync_service_) { |
| 48 LOG(ERROR) << "Unexpected TaskToken deletion from: " | 63 LOG(ERROR) << "Unexpected TaskToken deletion from: " |
| 49 << from_here_.ToString(); | 64 << location_.ToString() << " while: " << description_; |
| 50 } | 65 } |
| 51 } | 66 } |
| 52 | 67 |
| 53 private: | 68 private: |
| 54 tracked_objects::Location from_here_; | |
| 55 base::WeakPtr<DriveFileSyncService> sync_service_; | 69 base::WeakPtr<DriveFileSyncService> sync_service_; |
| 70 tracked_objects::Location location_; |
| 71 TaskType task_type_; |
| 72 std::string description_; |
| 56 | 73 |
| 57 DISALLOW_COPY_AND_ASSIGN(TaskToken); | 74 DISALLOW_COPY_AND_ASSIGN(TaskToken); |
| 58 }; | 75 }; |
| 59 | 76 |
| 60 DriveFileSyncService::DriveFileSyncService(Profile* profile) | 77 DriveFileSyncService::DriveFileSyncService(Profile* profile) |
| 61 : status_(fileapi::SYNC_STATUS_OK), | 78 : last_operation_status_(fileapi::SYNC_STATUS_OK), |
| 79 state_(REMOTE_SERVICE_OK), |
| 62 largest_changestamp_(0), | 80 largest_changestamp_(0), |
| 63 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 81 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 64 token_.reset(new TaskToken(weak_factory_.GetWeakPtr())); | 82 token_.reset(new TaskToken(weak_factory_.GetWeakPtr())); |
| 65 | 83 |
| 66 sync_client_.reset(new DriveFileSyncClient(profile)); | 84 sync_client_.reset(new DriveFileSyncClient(profile)); |
| 67 | 85 |
| 68 metadata_store_.reset(new DriveMetadataStore( | 86 metadata_store_.reset(new DriveMetadataStore( |
| 69 profile->GetPath(), | 87 profile->GetPath(), |
| 70 content::BrowserThread::GetMessageLoopProxyForThread( | 88 content::BrowserThread::GetMessageLoopProxyForThread( |
| 71 content::BrowserThread::FILE))); | 89 content::BrowserThread::FILE))); |
| 72 | 90 |
| 73 metadata_store_->Initialize( | 91 metadata_store_->Initialize( |
| 74 base::Bind(&DriveFileSyncService::DidInitializeMetadataStore, | 92 base::Bind(&DriveFileSyncService::DidInitializeMetadataStore, |
| 75 weak_factory_.GetWeakPtr(), | 93 weak_factory_.GetWeakPtr(), |
| 76 base::Passed(GetToken(FROM_HERE)))); | 94 base::Passed(GetToken(FROM_HERE, TASK_TYPE_DATABASE, |
| 95 "Metadata database initialization")))); |
| 77 } | 96 } |
| 78 | 97 |
| 79 // static | 98 // static |
| 80 scoped_ptr<DriveFileSyncService> DriveFileSyncService::CreateForTesting( | 99 scoped_ptr<DriveFileSyncService> DriveFileSyncService::CreateForTesting( |
| 81 scoped_ptr<DriveFileSyncClient> sync_client, | 100 scoped_ptr<DriveFileSyncClient> sync_client, |
| 82 scoped_ptr<DriveMetadataStore> metadata_store) { | 101 scoped_ptr<DriveMetadataStore> metadata_store) { |
| 83 return make_scoped_ptr(new DriveFileSyncService( | 102 return make_scoped_ptr(new DriveFileSyncService( |
| 84 sync_client.Pass(), metadata_store.Pass())); | 103 sync_client.Pass(), metadata_store.Pass())); |
| 85 } | 104 } |
| 86 | 105 |
| 87 // Called by CreateForTesting. | 106 // Called by CreateForTesting. |
| 88 DriveFileSyncService::DriveFileSyncService( | 107 DriveFileSyncService::DriveFileSyncService( |
| 89 scoped_ptr<DriveFileSyncClient> sync_client, | 108 scoped_ptr<DriveFileSyncClient> sync_client, |
| 90 scoped_ptr<DriveMetadataStore> metadata_store) | 109 scoped_ptr<DriveMetadataStore> metadata_store) |
| 91 : status_(fileapi::SYNC_STATUS_OK), | 110 : last_operation_status_(fileapi::SYNC_STATUS_OK), |
| 111 state_(REMOTE_SERVICE_OK), |
| 92 largest_changestamp_(0), | 112 largest_changestamp_(0), |
| 93 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 113 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 94 token_.reset(new TaskToken(weak_factory_.GetWeakPtr())); | 114 token_.reset(new TaskToken(weak_factory_.GetWeakPtr())); |
| 95 sync_client_ = sync_client.Pass(); | 115 sync_client_ = sync_client.Pass(); |
| 96 metadata_store_ = metadata_store.Pass(); | 116 metadata_store_ = metadata_store.Pass(); |
| 97 | 117 |
| 98 DidInitializeMetadataStore(GetToken(FROM_HERE), | 118 DidInitializeMetadataStore( |
| 99 fileapi::SYNC_STATUS_OK, false); | 119 GetToken(FROM_HERE, TASK_TYPE_NONE, "Drive initialization for testing"), |
| 120 fileapi::SYNC_STATUS_OK, false); |
| 100 } | 121 } |
| 101 | 122 |
| 102 DriveFileSyncService::~DriveFileSyncService() { | 123 DriveFileSyncService::~DriveFileSyncService() { |
| 103 } | 124 } |
| 104 | 125 |
| 105 void DriveFileSyncService::DidInitializeMetadataStore( | 126 void DriveFileSyncService::DidInitializeMetadataStore( |
| 106 scoped_ptr<TaskToken> token, | 127 scoped_ptr<TaskToken> token, |
| 107 fileapi::SyncStatusCode status, | 128 fileapi::SyncStatusCode status, |
| 108 bool created) { | 129 bool created) { |
| 109 if (status != fileapi::SYNC_STATUS_OK) { | 130 if (status != fileapi::SYNC_STATUS_OK) { |
| 110 NotifyTaskDone(status, token.Pass()); | 131 NotifyTaskDone(status, token.Pass()); |
| 111 return; | 132 return; |
| 112 } | 133 } |
| 113 | 134 |
| 114 if (metadata_store_->sync_root_directory().empty()) { | 135 if (metadata_store_->sync_root_directory().empty()) { |
| 115 DCHECK(metadata_store_->batch_sync_origins().empty()); | 136 DCHECK(metadata_store_->batch_sync_origins().empty()); |
| 116 DCHECK(metadata_store_->incremental_sync_origins().empty()); | 137 DCHECK(metadata_store_->incremental_sync_origins().empty()); |
| 117 | 138 |
| 139 token->UpdateTask(FROM_HERE, TASK_TYPE_DRIVE, "Retrieving drive root"); |
| 118 sync_client_->GetDriveDirectoryForSyncRoot( | 140 sync_client_->GetDriveDirectoryForSyncRoot( |
| 119 base::Bind(&DriveFileSyncService::DidGetSyncRootDirectory, | 141 base::Bind(&DriveFileSyncService::DidGetSyncRootDirectory, |
| 120 weak_factory_.GetWeakPtr(), | 142 weak_factory_.GetWeakPtr(), |
| 121 base::Passed(&token))); | 143 base::Passed(&token))); |
| 122 return; | 144 return; |
| 123 } | 145 } |
| 124 NotifyTaskDone(status, token.Pass()); | 146 NotifyTaskDone(status, token.Pass()); |
| 125 | 147 |
| 126 for (std::map<GURL, std::string>::const_iterator itr = | 148 for (std::map<GURL, std::string>::const_iterator itr = |
| 127 metadata_store_->batch_sync_origins().begin(); | 149 metadata_store_->batch_sync_origins().begin(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 139 error != google_apis::HTTP_CREATED) { | 161 error != google_apis::HTTP_CREATED) { |
| 140 NotifyTaskDone(GDataErrorCodeToSyncStatusCode(error), token.Pass()); | 162 NotifyTaskDone(GDataErrorCodeToSyncStatusCode(error), token.Pass()); |
| 141 return; | 163 return; |
| 142 } | 164 } |
| 143 | 165 |
| 144 metadata_store_->SetSyncRootDirectory(resource_id); | 166 metadata_store_->SetSyncRootDirectory(resource_id); |
| 145 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); | 167 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); |
| 146 } | 168 } |
| 147 | 169 |
| 148 scoped_ptr<DriveFileSyncService::TaskToken> DriveFileSyncService::GetToken( | 170 scoped_ptr<DriveFileSyncService::TaskToken> DriveFileSyncService::GetToken( |
| 149 const tracked_objects::Location& from_here) { | 171 const tracked_objects::Location& from_here, |
| 172 TaskType task_type, |
| 173 const std::string& description) { |
| 150 if (!token_) | 174 if (!token_) |
| 151 return scoped_ptr<TaskToken>(); | 175 return scoped_ptr<TaskToken>(); |
| 152 token_->set_location(from_here); | 176 token_->UpdateTask(from_here, task_type, description); |
| 153 return token_.Pass(); | 177 return token_.Pass(); |
| 154 } | 178 } |
| 155 | 179 |
| 156 void DriveFileSyncService::NotifyTaskDone(fileapi::SyncStatusCode status, | 180 void DriveFileSyncService::NotifyTaskDone(fileapi::SyncStatusCode status, |
| 157 scoped_ptr<TaskToken> token) { | 181 scoped_ptr<TaskToken> token) { |
| 158 DCHECK(token); | 182 DCHECK(token); |
| 159 bool status_changed = status_ != status; | 183 last_operation_status_ = status; |
| 160 status_ = status; | |
| 161 token_ = token.Pass(); | 184 token_ = token.Pass(); |
| 162 token_->set_location(tracked_objects::Location()); | |
| 163 | 185 |
| 186 if (token_->task_type() != TASK_TYPE_NONE) { |
| 187 RemoteServiceState old_state = state_; |
| 188 UpdateServiceState(); |
| 189 |
| 190 // Notify remote sync service state for healthy running updates (OK to OK |
| 191 // state transition) and for any state changes. |
| 192 if ((state_ == REMOTE_SERVICE_OK && !token_->description().empty()) || |
| 193 old_state != state_) { |
| 194 FOR_EACH_OBSERVER(Observer, observers_, |
| 195 OnRemoteServiceStateUpdated(state_, |
| 196 token_->description())); |
| 197 } |
| 198 } |
| 199 |
| 200 token_->ResetTask(FROM_HERE); |
| 164 if (status == fileapi::SYNC_STATUS_OK && !pending_tasks_.empty()) { | 201 if (status == fileapi::SYNC_STATUS_OK && !pending_tasks_.empty()) { |
| 165 base::Closure closure = pending_tasks_.front(); | 202 base::Closure closure = pending_tasks_.front(); |
| 166 pending_tasks_.pop_front(); | 203 pending_tasks_.pop_front(); |
| 167 closure.Run(); | 204 closure.Run(); |
| 168 } | 205 } |
| 206 } |
| 169 | 207 |
| 170 if (status_changed) { | 208 void DriveFileSyncService::UpdateServiceState() { |
| 171 // TODO(tzik): Refine the status to track the error. | 209 switch (last_operation_status_) { |
| 172 FOR_EACH_OBSERVER(Observer, observers_, OnRemoteSyncStatusChanged(status)); | 210 // Possible regular operation errors. |
| 211 case fileapi::SYNC_STATUS_OK: |
| 212 case fileapi::SYNC_STATUS_FILE_BUSY: |
| 213 case fileapi::SYNC_STATUS_HAS_CONFLICT: |
| 214 case fileapi::SYNC_STATUS_NOT_A_CONFLICT: |
| 215 case fileapi::SYNC_STATUS_NO_CHANGE_TO_SYNC: |
| 216 case fileapi::SYNC_FILE_ERROR_NOT_FOUND: |
| 217 case fileapi::SYNC_FILE_ERROR_FAILED: |
| 218 case fileapi::SYNC_FILE_ERROR_NO_SPACE: |
| 219 // If the service type was DRIVE and the status was ok, the state |
| 220 // should be migrated to OK state. |
| 221 if (token_->task_type() == TASK_TYPE_DRIVE) |
| 222 state_ = REMOTE_SERVICE_OK; |
| 223 break; |
| 224 |
| 225 // Errors which could make the service temporarily unavailable. |
| 226 case fileapi::SYNC_STATUS_RETRY: |
| 227 case fileapi::SYNC_STATUS_NETWORK_ERROR: |
| 228 case fileapi::SYNC_STATUS_AUTHENTICATION_FAILED: |
| 229 state_ = REMOTE_SERVICE_TEMPORARY_UNAVAILABLE; |
| 230 break; |
| 231 |
| 232 // Errors which would require manual user intervention to resolve. |
| 233 case fileapi::SYNC_DATABASE_ERROR_CORRUPTION: |
| 234 case fileapi::SYNC_DATABASE_ERROR_IO_ERROR: |
| 235 case fileapi::SYNC_DATABASE_ERROR_FAILED: |
| 236 case fileapi::SYNC_STATUS_ABORT: |
| 237 case fileapi::SYNC_STATUS_FAILED: |
| 238 state_ = REMOTE_SERVICE_DISABLED; |
| 239 break; |
| 240 |
| 241 // Unexpected status code. They should be explicitly added to one of the |
| 242 // above three cases. |
| 243 default: |
| 244 NOTREACHED(); |
| 245 state_ = REMOTE_SERVICE_DISABLED; |
| 246 break; |
| 173 } | 247 } |
| 174 } | 248 } |
| 175 | 249 |
| 176 void DriveFileSyncService::AddObserver(Observer* observer) { | 250 void DriveFileSyncService::AddObserver(Observer* observer) { |
| 177 observers_.AddObserver(observer); | 251 observers_.AddObserver(observer); |
| 178 } | 252 } |
| 179 | 253 |
| 180 void DriveFileSyncService::RemoveObserver(Observer* observer) { | 254 void DriveFileSyncService::RemoveObserver(Observer* observer) { |
| 181 observers_.RemoveObserver(observer); | 255 observers_.RemoveObserver(observer); |
| 182 } | 256 } |
| 183 | 257 |
| 184 void DriveFileSyncService::RegisterOriginForTrackingChanges( | 258 void DriveFileSyncService::RegisterOriginForTrackingChanges( |
| 185 const GURL& origin, | 259 const GURL& origin, |
| 186 const fileapi::SyncStatusCallback& callback) { | 260 const fileapi::SyncStatusCallback& callback) { |
| 187 scoped_ptr<TaskToken> token(GetToken(FROM_HERE)); | 261 scoped_ptr<TaskToken> token(GetToken( |
| 262 FROM_HERE, TASK_TYPE_DRIVE, "Retrieving origin metadata")); |
| 188 if (!token) { | 263 if (!token) { |
| 189 pending_tasks_.push_back(base::Bind( | 264 pending_tasks_.push_back(base::Bind( |
| 190 &DriveFileSyncService::RegisterOriginForTrackingChanges, | 265 &DriveFileSyncService::RegisterOriginForTrackingChanges, |
| 191 weak_factory_.GetWeakPtr(), origin, callback)); | 266 weak_factory_.GetWeakPtr(), origin, callback)); |
| 192 return; | 267 return; |
| 193 } | 268 } |
| 194 | 269 |
| 195 if (status_ != fileapi::SYNC_STATUS_OK) { | 270 if (state_ == REMOTE_SERVICE_DISABLED) { |
| 196 NotifyTaskDone(status_, token.Pass()); | 271 token->ResetTask(FROM_HERE); |
| 197 callback.Run(status_); | 272 NotifyTaskDone(last_operation_status_, token.Pass()); |
| 273 callback.Run(last_operation_status_); |
| 198 return; | 274 return; |
| 199 } | 275 } |
| 200 | 276 |
| 201 if (metadata_store_->IsIncrementalSyncOrigin(origin) || | 277 if (metadata_store_->IsIncrementalSyncOrigin(origin) || |
| 202 metadata_store_->IsBatchSyncOrigin(origin)) { | 278 metadata_store_->IsBatchSyncOrigin(origin)) { |
| 279 token->ResetTask(FROM_HERE); |
| 203 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); | 280 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); |
| 204 callback.Run(fileapi::SYNC_STATUS_OK); | 281 callback.Run(fileapi::SYNC_STATUS_OK); |
| 205 return; | 282 return; |
| 206 } | 283 } |
| 207 | 284 |
| 208 DCHECK(!metadata_store_->sync_root_directory().empty()); | 285 DCHECK(!metadata_store_->sync_root_directory().empty()); |
| 209 sync_client_->GetDriveDirectoryForOrigin( | 286 sync_client_->GetDriveDirectoryForOrigin( |
| 210 metadata_store_->sync_root_directory(), origin, | 287 metadata_store_->sync_root_directory(), origin, |
| 211 base::Bind(&DriveFileSyncService::DidGetDirectoryForOrigin, | 288 base::Bind(&DriveFileSyncService::DidGetDirectoryForOrigin, |
| 212 weak_factory_.GetWeakPtr(), base::Passed(&token), | 289 weak_factory_.GetWeakPtr(), base::Passed(&token), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 231 | 308 |
| 232 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); | 309 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); |
| 233 callback.Run(fileapi::SYNC_STATUS_OK); | 310 callback.Run(fileapi::SYNC_STATUS_OK); |
| 234 | 311 |
| 235 StartBatchSyncForOrigin(origin, resource_id); | 312 StartBatchSyncForOrigin(origin, resource_id); |
| 236 } | 313 } |
| 237 | 314 |
| 238 void DriveFileSyncService::UnregisterOriginForTrackingChanges( | 315 void DriveFileSyncService::UnregisterOriginForTrackingChanges( |
| 239 const GURL& origin, | 316 const GURL& origin, |
| 240 const fileapi::SyncStatusCallback& callback) { | 317 const fileapi::SyncStatusCallback& callback) { |
| 241 scoped_ptr<TaskToken> token(GetToken(FROM_HERE)); | 318 scoped_ptr<TaskToken> token(GetToken(FROM_HERE, TASK_TYPE_DATABASE, "")); |
| 242 if (!token) { | 319 if (!token) { |
| 243 pending_tasks_.push_back(base::Bind( | 320 pending_tasks_.push_back(base::Bind( |
| 244 &DriveFileSyncService::UnregisterOriginForTrackingChanges, | 321 &DriveFileSyncService::UnregisterOriginForTrackingChanges, |
| 245 weak_factory_.GetWeakPtr(), origin, callback)); | 322 weak_factory_.GetWeakPtr(), origin, callback)); |
| 246 return; | 323 return; |
| 247 } | 324 } |
| 248 | 325 |
| 249 changestamp_map_.erase(origin); | 326 changestamp_map_.erase(origin); |
| 250 | 327 |
| 251 std::vector<RemoteChange> new_queue; | 328 std::vector<RemoteChange> new_queue; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 const FilePath& local_path, | 379 const FilePath& local_path, |
| 303 const fileapi::FileSystemURL& url, | 380 const fileapi::FileSystemURL& url, |
| 304 const fileapi::SyncStatusCallback& callback) { | 381 const fileapi::SyncStatusCallback& callback) { |
| 305 NOTIMPLEMENTED(); | 382 NOTIMPLEMENTED(); |
| 306 callback.Run(fileapi::SYNC_STATUS_FAILED); | 383 callback.Run(fileapi::SYNC_STATUS_FAILED); |
| 307 } | 384 } |
| 308 | 385 |
| 309 void DriveFileSyncService::StartBatchSyncForOrigin( | 386 void DriveFileSyncService::StartBatchSyncForOrigin( |
| 310 const GURL& origin, | 387 const GURL& origin, |
| 311 const std::string& resource_id) { | 388 const std::string& resource_id) { |
| 312 scoped_ptr<TaskToken> token(GetToken(FROM_HERE)); | 389 scoped_ptr<TaskToken> token( |
| 390 GetToken(FROM_HERE, TASK_TYPE_DRIVE, "Retrieving largest changestamp")); |
| 313 if (!token) { | 391 if (!token) { |
| 314 pending_tasks_.push_back(base::Bind( | 392 pending_tasks_.push_back(base::Bind( |
| 315 &DriveFileSyncService::StartBatchSyncForOrigin, | 393 &DriveFileSyncService::StartBatchSyncForOrigin, |
| 316 weak_factory_.GetWeakPtr(), origin, resource_id)); | 394 weak_factory_.GetWeakPtr(), origin, resource_id)); |
| 317 return; | 395 return; |
| 318 } | 396 } |
| 319 | 397 |
| 320 sync_client_->GetLargestChangeStamp( | 398 sync_client_->GetLargestChangeStamp( |
| 321 base::Bind(&DriveFileSyncService::DidGetLargestChangeStampForBatchSync, | 399 base::Bind(&DriveFileSyncService::DidGetLargestChangeStampForBatchSync, |
| 322 weak_factory_.GetWeakPtr(), | 400 weak_factory_.GetWeakPtr(), |
| 323 base::Passed(&token), origin, resource_id)); | 401 base::Passed(&token), origin, resource_id)); |
| 324 } | 402 } |
| 325 | 403 |
| 326 void DriveFileSyncService::DidGetLargestChangeStampForBatchSync( | 404 void DriveFileSyncService::DidGetLargestChangeStampForBatchSync( |
| 327 scoped_ptr<TaskToken> token, | 405 scoped_ptr<TaskToken> token, |
| 328 const GURL& origin, | 406 const GURL& origin, |
| 329 const std::string& resource_id, | 407 const std::string& resource_id, |
| 330 google_apis::GDataErrorCode error, | 408 google_apis::GDataErrorCode error, |
| 331 int64 largest_changestamp) { | 409 int64 largest_changestamp) { |
| 332 if (error != google_apis::HTTP_SUCCESS) { | 410 if (error != google_apis::HTTP_SUCCESS) { |
| 333 // TODO(tzik): Refine this error code. | 411 // TODO(tzik): Refine this error code. |
| 334 NotifyTaskDone(GDataErrorCodeToSyncStatusCode(error), token.Pass()); | 412 NotifyTaskDone(GDataErrorCodeToSyncStatusCode(error), token.Pass()); |
| 335 return; | 413 return; |
| 336 } | 414 } |
| 337 | 415 |
| 416 DCHECK(token); |
| 417 token->UpdateTask(FROM_HERE, TASK_TYPE_DRIVE, "Retrieving remote files"); |
| 338 sync_client_->ListFiles( | 418 sync_client_->ListFiles( |
| 339 resource_id, | 419 resource_id, |
| 340 base::Bind(&DriveFileSyncService::DidGetDirectoryContentForBatchSync, | 420 base::Bind(&DriveFileSyncService::DidGetDirectoryContentForBatchSync, |
| 341 weak_factory_.GetWeakPtr(), | 421 weak_factory_.GetWeakPtr(), |
| 342 base::Passed(&token), origin, largest_changestamp)); | 422 base::Passed(&token), origin, largest_changestamp)); |
| 343 } | 423 } |
| 344 | 424 |
| 345 void DriveFileSyncService::DidGetDirectoryContentForBatchSync( | 425 void DriveFileSyncService::DidGetDirectoryContentForBatchSync( |
| 346 scoped_ptr<TaskToken> token, | 426 scoped_ptr<TaskToken> token, |
| 347 const GURL& origin, | 427 const GURL& origin, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 const RemoteChange& right) { | 514 const RemoteChange& right) { |
| 435 // This should return true if |right| has higher priority than |left|. | 515 // This should return true if |right| has higher priority than |left|. |
| 436 // Smaller changestamps have higher priorities (i.e. need to be processed | 516 // Smaller changestamps have higher priorities (i.e. need to be processed |
| 437 // earlier). | 517 // earlier). |
| 438 if (left.changestamp != right.changestamp) | 518 if (left.changestamp != right.changestamp) |
| 439 return left.changestamp > right.changestamp; | 519 return left.changestamp > right.changestamp; |
| 440 return false; | 520 return false; |
| 441 } | 521 } |
| 442 | 522 |
| 443 } // namespace sync_file_system | 523 } // namespace sync_file_system |
| OLD | NEW |