| 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 | |
| 61 DriveFileSyncService::RemoteChange::RemoteChange() | 77 DriveFileSyncService::RemoteChange::RemoteChange() |
| 62 : changestamp(0), | 78 : changestamp(0), |
| 63 change(fileapi::FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 79 change(fileapi::FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
| 64 fileapi::SYNC_FILE_TYPE_UNKNOWN) { | 80 fileapi::SYNC_FILE_TYPE_UNKNOWN) { |
| 65 } | 81 } |
| 66 | 82 |
| 67 DriveFileSyncService::RemoteChange::RemoteChange( | 83 DriveFileSyncService::RemoteChange::RemoteChange( |
| 68 int64 changestamp, | 84 int64 changestamp, |
| 69 const std::string& resource_id, | 85 const std::string& resource_id, |
| 70 const fileapi::FileSystemURL& url, | 86 const fileapi::FileSystemURL& url, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 82 const RemoteChange& left, | 98 const RemoteChange& left, |
| 83 const RemoteChange& right) { | 99 const RemoteChange& right) { |
| 84 // This should return true if |right| has higher priority than |left|. | 100 // This should return true if |right| has higher priority than |left|. |
| 85 // Smaller changestamps have higher priorities (i.e. need to be processed | 101 // Smaller changestamps have higher priorities (i.e. need to be processed |
| 86 // earlier). | 102 // earlier). |
| 87 if (left.changestamp != right.changestamp) | 103 if (left.changestamp != right.changestamp) |
| 88 return left.changestamp > right.changestamp; | 104 return left.changestamp > right.changestamp; |
| 89 return false; | 105 return false; |
| 90 } | 106 } |
| 91 | 107 |
| 92 // Called by CreateForTesting. | 108 DriveFileSyncService::DriveFileSyncService(Profile* profile) |
| 93 DriveFileSyncService::DriveFileSyncService( | 109 : last_operation_status_(fileapi::SYNC_STATUS_OK), |
| 94 scoped_ptr<DriveFileSyncClient> sync_client, | 110 state_(REMOTE_SERVICE_OK), |
| 95 scoped_ptr<DriveMetadataStore> metadata_store) | |
| 96 : status_(fileapi::SYNC_STATUS_OK), | |
| 97 largest_changestamp_(0), | 111 largest_changestamp_(0), |
| 98 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 112 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 99 token_.reset(new TaskToken(weak_factory_.GetWeakPtr())); | 113 token_.reset(new TaskToken(weak_factory_.GetWeakPtr())); |
| 100 sync_client_ = sync_client.Pass(); | |
| 101 metadata_store_ = metadata_store.Pass(); | |
| 102 | |
| 103 DidInitializeMetadataStore(GetToken(FROM_HERE), | |
| 104 fileapi::SYNC_STATUS_OK, false); | |
| 105 } | |
| 106 | |
| 107 DriveFileSyncService::DriveFileSyncService(Profile* profile) | |
| 108 : status_(fileapi::SYNC_STATUS_OK), | |
| 109 largest_changestamp_(0), | |
| 110 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
| 111 token_.reset(new TaskToken(weak_factory_.GetWeakPtr())); | |
| 112 | 114 |
| 113 sync_client_.reset(new DriveFileSyncClient(profile)); | 115 sync_client_.reset(new DriveFileSyncClient(profile)); |
| 114 | 116 |
| 115 metadata_store_.reset(new DriveMetadataStore( | 117 metadata_store_.reset(new DriveMetadataStore( |
| 116 profile->GetPath(), | 118 profile->GetPath(), |
| 117 content::BrowserThread::GetMessageLoopProxyForThread( | 119 content::BrowserThread::GetMessageLoopProxyForThread( |
| 118 content::BrowserThread::FILE))); | 120 content::BrowserThread::FILE))); |
| 119 | 121 |
| 120 metadata_store_->Initialize( | 122 metadata_store_->Initialize( |
| 121 base::Bind(&DriveFileSyncService::DidInitializeMetadataStore, | 123 base::Bind(&DriveFileSyncService::DidInitializeMetadataStore, |
| 122 weak_factory_.GetWeakPtr(), | 124 weak_factory_.GetWeakPtr(), |
| 123 base::Passed(GetToken(FROM_HERE)))); | 125 base::Passed(GetToken(FROM_HERE, TASK_TYPE_DATABASE, |
| 126 "Metadata database initialization")))); |
| 124 } | 127 } |
| 125 | 128 |
| 126 DriveFileSyncService::~DriveFileSyncService() { | 129 DriveFileSyncService::~DriveFileSyncService() { |
| 127 } | 130 } |
| 128 | 131 |
| 129 // static | 132 // static |
| 130 scoped_ptr<DriveFileSyncService> DriveFileSyncService::CreateForTesting( | 133 scoped_ptr<DriveFileSyncService> DriveFileSyncService::CreateForTesting( |
| 131 scoped_ptr<DriveFileSyncClient> sync_client, | 134 scoped_ptr<DriveFileSyncClient> sync_client, |
| 132 scoped_ptr<DriveMetadataStore> metadata_store) { | 135 scoped_ptr<DriveMetadataStore> metadata_store) { |
| 133 return make_scoped_ptr(new DriveFileSyncService( | 136 return make_scoped_ptr(new DriveFileSyncService( |
| 134 sync_client.Pass(), metadata_store.Pass())); | 137 sync_client.Pass(), metadata_store.Pass())); |
| 135 } | 138 } |
| 136 | 139 |
| 137 void DriveFileSyncService::AddObserver(Observer* observer) { | 140 void DriveFileSyncService::AddObserver(Observer* observer) { |
| 138 observers_.AddObserver(observer); | 141 observers_.AddObserver(observer); |
| 139 } | 142 } |
| 140 | 143 |
| 141 void DriveFileSyncService::RemoveObserver(Observer* observer) { | 144 void DriveFileSyncService::RemoveObserver(Observer* observer) { |
| 142 observers_.RemoveObserver(observer); | 145 observers_.RemoveObserver(observer); |
| 143 } | 146 } |
| 144 | 147 |
| 145 void DriveFileSyncService::RegisterOriginForTrackingChanges( | 148 void DriveFileSyncService::RegisterOriginForTrackingChanges( |
| 146 const GURL& origin, | 149 const GURL& origin, |
| 147 const fileapi::SyncStatusCallback& callback) { | 150 const fileapi::SyncStatusCallback& callback) { |
| 148 scoped_ptr<TaskToken> token(GetToken(FROM_HERE)); | 151 scoped_ptr<TaskToken> token(GetToken( |
| 152 FROM_HERE, TASK_TYPE_DRIVE, "Retrieving origin metadata")); |
| 149 if (!token) { | 153 if (!token) { |
| 150 pending_tasks_.push_back(base::Bind( | 154 pending_tasks_.push_back(base::Bind( |
| 151 &DriveFileSyncService::RegisterOriginForTrackingChanges, | 155 &DriveFileSyncService::RegisterOriginForTrackingChanges, |
| 152 weak_factory_.GetWeakPtr(), origin, callback)); | 156 weak_factory_.GetWeakPtr(), origin, callback)); |
| 153 return; | 157 return; |
| 154 } | 158 } |
| 155 | 159 |
| 156 if (status_ != fileapi::SYNC_STATUS_OK) { | 160 if (state_ == REMOTE_SERVICE_DISABLED) { |
| 157 NotifyTaskDone(status_, token.Pass()); | 161 token->ResetTask(FROM_HERE); |
| 158 callback.Run(status_); | 162 NotifyTaskDone(last_operation_status_, token.Pass()); |
| 163 callback.Run(last_operation_status_); |
| 159 return; | 164 return; |
| 160 } | 165 } |
| 161 | 166 |
| 162 if (metadata_store_->IsIncrementalSyncOrigin(origin) || | 167 if (metadata_store_->IsIncrementalSyncOrigin(origin) || |
| 163 metadata_store_->IsBatchSyncOrigin(origin)) { | 168 metadata_store_->IsBatchSyncOrigin(origin)) { |
| 169 token->ResetTask(FROM_HERE); |
| 164 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); | 170 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); |
| 165 callback.Run(fileapi::SYNC_STATUS_OK); | 171 callback.Run(fileapi::SYNC_STATUS_OK); |
| 166 return; | 172 return; |
| 167 } | 173 } |
| 168 | 174 |
| 169 DCHECK(!metadata_store_->sync_root_directory().empty()); | 175 DCHECK(!metadata_store_->sync_root_directory().empty()); |
| 170 sync_client_->GetDriveDirectoryForOrigin( | 176 sync_client_->GetDriveDirectoryForOrigin( |
| 171 metadata_store_->sync_root_directory(), origin, | 177 metadata_store_->sync_root_directory(), origin, |
| 172 base::Bind(&DriveFileSyncService::DidGetDirectoryForOrigin, | 178 base::Bind(&DriveFileSyncService::DidGetDirectoryForOrigin, |
| 173 weak_factory_.GetWeakPtr(), base::Passed(&token), | 179 weak_factory_.GetWeakPtr(), base::Passed(&token), |
| 174 origin, callback)); | 180 origin, callback)); |
| 175 } | 181 } |
| 176 | 182 |
| 177 void DriveFileSyncService::UnregisterOriginForTrackingChanges( | 183 void DriveFileSyncService::UnregisterOriginForTrackingChanges( |
| 178 const GURL& origin, | 184 const GURL& origin, |
| 179 const fileapi::SyncStatusCallback& callback) { | 185 const fileapi::SyncStatusCallback& callback) { |
| 180 scoped_ptr<TaskToken> token(GetToken(FROM_HERE)); | 186 scoped_ptr<TaskToken> token(GetToken(FROM_HERE, TASK_TYPE_DATABASE, "")); |
| 181 if (!token) { | 187 if (!token) { |
| 182 pending_tasks_.push_back(base::Bind( | 188 pending_tasks_.push_back(base::Bind( |
| 183 &DriveFileSyncService::UnregisterOriginForTrackingChanges, | 189 &DriveFileSyncService::UnregisterOriginForTrackingChanges, |
| 184 weak_factory_.GetWeakPtr(), origin, callback)); | 190 weak_factory_.GetWeakPtr(), origin, callback)); |
| 185 return; | 191 return; |
| 186 } | 192 } |
| 187 | 193 |
| 188 changestamp_map_.erase(origin); | 194 changestamp_map_.erase(origin); |
| 189 | 195 |
| 190 std::vector<RemoteChange> new_queue; | 196 std::vector<RemoteChange> new_queue; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 236 |
| 231 void DriveFileSyncService::ApplyLocalChange( | 237 void DriveFileSyncService::ApplyLocalChange( |
| 232 const fileapi::FileChange& change, | 238 const fileapi::FileChange& change, |
| 233 const FilePath& local_path, | 239 const FilePath& local_path, |
| 234 const fileapi::FileSystemURL& url, | 240 const fileapi::FileSystemURL& url, |
| 235 const fileapi::SyncStatusCallback& callback) { | 241 const fileapi::SyncStatusCallback& callback) { |
| 236 NOTIMPLEMENTED(); | 242 NOTIMPLEMENTED(); |
| 237 callback.Run(fileapi::SYNC_STATUS_FAILED); | 243 callback.Run(fileapi::SYNC_STATUS_FAILED); |
| 238 } | 244 } |
| 239 | 245 |
| 246 // Called by CreateForTesting. |
| 247 DriveFileSyncService::DriveFileSyncService( |
| 248 scoped_ptr<DriveFileSyncClient> sync_client, |
| 249 scoped_ptr<DriveMetadataStore> metadata_store) |
| 250 : last_operation_status_(fileapi::SYNC_STATUS_OK), |
| 251 state_(REMOTE_SERVICE_OK), |
| 252 largest_changestamp_(0), |
| 253 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 254 token_.reset(new TaskToken(weak_factory_.GetWeakPtr())); |
| 255 sync_client_ = sync_client.Pass(); |
| 256 metadata_store_ = metadata_store.Pass(); |
| 257 |
| 258 DidInitializeMetadataStore( |
| 259 GetToken(FROM_HERE, TASK_TYPE_NONE, "Drive initialization for testing"), |
| 260 fileapi::SYNC_STATUS_OK, false); |
| 261 } |
| 262 |
| 240 scoped_ptr<DriveFileSyncService::TaskToken> DriveFileSyncService::GetToken( | 263 scoped_ptr<DriveFileSyncService::TaskToken> DriveFileSyncService::GetToken( |
| 241 const tracked_objects::Location& from_here) { | 264 const tracked_objects::Location& from_here, |
| 265 TaskType task_type, |
| 266 const std::string& description) { |
| 242 if (!token_) | 267 if (!token_) |
| 243 return scoped_ptr<TaskToken>(); | 268 return scoped_ptr<TaskToken>(); |
| 244 token_->set_location(from_here); | 269 token_->UpdateTask(from_here, task_type, description); |
| 245 return token_.Pass(); | 270 return token_.Pass(); |
| 246 } | 271 } |
| 247 | 272 |
| 248 void DriveFileSyncService::NotifyTaskDone(fileapi::SyncStatusCode status, | 273 void DriveFileSyncService::NotifyTaskDone(fileapi::SyncStatusCode status, |
| 249 scoped_ptr<TaskToken> token) { | 274 scoped_ptr<TaskToken> token) { |
| 250 DCHECK(token); | 275 DCHECK(token); |
| 251 bool status_changed = status_ != status; | 276 last_operation_status_ = status; |
| 252 status_ = status; | |
| 253 token_ = token.Pass(); | 277 token_ = token.Pass(); |
| 254 token_->set_location(tracked_objects::Location()); | |
| 255 | 278 |
| 279 if (token_->task_type() != TASK_TYPE_NONE) { |
| 280 RemoteServiceState old_state = state_; |
| 281 UpdateServiceState(); |
| 282 |
| 283 // Notify remote sync service state for healthy running updates (OK to OK |
| 284 // state transition) and for any state changes. |
| 285 if ((state_ == REMOTE_SERVICE_OK && !token_->description().empty()) || |
| 286 old_state != state_) { |
| 287 FOR_EACH_OBSERVER(Observer, observers_, |
| 288 OnRemoteServiceStateUpdated(state_, |
| 289 token_->description())); |
| 290 } |
| 291 } |
| 292 |
| 293 token_->ResetTask(FROM_HERE); |
| 256 if (status == fileapi::SYNC_STATUS_OK && !pending_tasks_.empty()) { | 294 if (status == fileapi::SYNC_STATUS_OK && !pending_tasks_.empty()) { |
| 257 base::Closure closure = pending_tasks_.front(); | 295 base::Closure closure = pending_tasks_.front(); |
| 258 pending_tasks_.pop_front(); | 296 pending_tasks_.pop_front(); |
| 259 closure.Run(); | 297 closure.Run(); |
| 260 } | 298 } |
| 299 } |
| 261 | 300 |
| 262 if (status_changed) { | 301 void DriveFileSyncService::UpdateServiceState() { |
| 263 // TODO(tzik): Refine the status to track the error. | 302 switch (last_operation_status_) { |
| 264 FOR_EACH_OBSERVER(Observer, observers_, OnRemoteSyncStatusChanged(status)); | 303 // Possible regular operation errors. |
| 304 case fileapi::SYNC_STATUS_OK: |
| 305 case fileapi::SYNC_STATUS_FILE_BUSY: |
| 306 case fileapi::SYNC_STATUS_HAS_CONFLICT: |
| 307 case fileapi::SYNC_STATUS_NOT_A_CONFLICT: |
| 308 case fileapi::SYNC_STATUS_NO_CHANGE_TO_SYNC: |
| 309 case fileapi::SYNC_FILE_ERROR_NOT_FOUND: |
| 310 case fileapi::SYNC_FILE_ERROR_FAILED: |
| 311 case fileapi::SYNC_FILE_ERROR_NO_SPACE: |
| 312 // If the service type was DRIVE and the status was ok, the state |
| 313 // should be migrated to OK state. |
| 314 if (token_->task_type() == TASK_TYPE_DRIVE) |
| 315 state_ = REMOTE_SERVICE_OK; |
| 316 break; |
| 317 |
| 318 // Authentication error. |
| 319 case fileapi::SYNC_STATUS_AUTHENTICATION_FAILED: |
| 320 state_ = REMOTE_SERVICE_AUTHENTICATION_REQUIRED; |
| 321 break; |
| 322 |
| 323 // Errors which could make the service temporarily unavailable. |
| 324 case fileapi::SYNC_STATUS_RETRY: |
| 325 case fileapi::SYNC_STATUS_NETWORK_ERROR: |
| 326 state_ = REMOTE_SERVICE_TEMPORARY_UNAVAILABLE; |
| 327 break; |
| 328 |
| 329 // Errors which would require manual user intervention to resolve. |
| 330 case fileapi::SYNC_DATABASE_ERROR_CORRUPTION: |
| 331 case fileapi::SYNC_DATABASE_ERROR_IO_ERROR: |
| 332 case fileapi::SYNC_DATABASE_ERROR_FAILED: |
| 333 case fileapi::SYNC_STATUS_ABORT: |
| 334 case fileapi::SYNC_STATUS_FAILED: |
| 335 state_ = REMOTE_SERVICE_DISABLED; |
| 336 break; |
| 337 |
| 338 // Unexpected status code. They should be explicitly added to one of the |
| 339 // above three cases. |
| 340 default: |
| 341 NOTREACHED(); |
| 342 state_ = REMOTE_SERVICE_DISABLED; |
| 343 break; |
| 265 } | 344 } |
| 266 } | 345 } |
| 267 | 346 |
| 268 void DriveFileSyncService::DidInitializeMetadataStore( | 347 void DriveFileSyncService::DidInitializeMetadataStore( |
| 269 scoped_ptr<TaskToken> token, | 348 scoped_ptr<TaskToken> token, |
| 270 fileapi::SyncStatusCode status, | 349 fileapi::SyncStatusCode status, |
| 271 bool created) { | 350 bool created) { |
| 272 if (status != fileapi::SYNC_STATUS_OK) { | 351 if (status != fileapi::SYNC_STATUS_OK) { |
| 273 NotifyTaskDone(status, token.Pass()); | 352 NotifyTaskDone(status, token.Pass()); |
| 274 return; | 353 return; |
| 275 } | 354 } |
| 276 | 355 |
| 277 if (metadata_store_->sync_root_directory().empty()) { | 356 if (metadata_store_->sync_root_directory().empty()) { |
| 278 DCHECK(metadata_store_->batch_sync_origins().empty()); | 357 DCHECK(metadata_store_->batch_sync_origins().empty()); |
| 279 DCHECK(metadata_store_->incremental_sync_origins().empty()); | 358 DCHECK(metadata_store_->incremental_sync_origins().empty()); |
| 280 | 359 |
| 360 token->UpdateTask(FROM_HERE, TASK_TYPE_DRIVE, "Retrieving drive root"); |
| 281 sync_client_->GetDriveDirectoryForSyncRoot( | 361 sync_client_->GetDriveDirectoryForSyncRoot( |
| 282 base::Bind(&DriveFileSyncService::DidGetSyncRootDirectory, | 362 base::Bind(&DriveFileSyncService::DidGetSyncRootDirectory, |
| 283 weak_factory_.GetWeakPtr(), | 363 weak_factory_.GetWeakPtr(), |
| 284 base::Passed(&token))); | 364 base::Passed(&token))); |
| 285 return; | 365 return; |
| 286 } | 366 } |
| 287 NotifyTaskDone(status, token.Pass()); | 367 NotifyTaskDone(status, token.Pass()); |
| 288 | 368 |
| 289 for (std::map<GURL, std::string>::const_iterator itr = | 369 for (std::map<GURL, std::string>::const_iterator itr = |
| 290 metadata_store_->batch_sync_origins().begin(); | 370 metadata_store_->batch_sync_origins().begin(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 304 return; | 384 return; |
| 305 } | 385 } |
| 306 | 386 |
| 307 metadata_store_->SetSyncRootDirectory(resource_id); | 387 metadata_store_->SetSyncRootDirectory(resource_id); |
| 308 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); | 388 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); |
| 309 } | 389 } |
| 310 | 390 |
| 311 void DriveFileSyncService::StartBatchSyncForOrigin( | 391 void DriveFileSyncService::StartBatchSyncForOrigin( |
| 312 const GURL& origin, | 392 const GURL& origin, |
| 313 const std::string& resource_id) { | 393 const std::string& resource_id) { |
| 314 scoped_ptr<TaskToken> token(GetToken(FROM_HERE)); | 394 scoped_ptr<TaskToken> token( |
| 395 GetToken(FROM_HERE, TASK_TYPE_DRIVE, "Retrieving largest changestamp")); |
| 315 if (!token) { | 396 if (!token) { |
| 316 pending_tasks_.push_back(base::Bind( | 397 pending_tasks_.push_back(base::Bind( |
| 317 &DriveFileSyncService::StartBatchSyncForOrigin, | 398 &DriveFileSyncService::StartBatchSyncForOrigin, |
| 318 weak_factory_.GetWeakPtr(), origin, resource_id)); | 399 weak_factory_.GetWeakPtr(), origin, resource_id)); |
| 319 return; | 400 return; |
| 320 } | 401 } |
| 321 | 402 |
| 322 sync_client_->GetLargestChangeStamp( | 403 sync_client_->GetLargestChangeStamp( |
| 323 base::Bind(&DriveFileSyncService::DidGetLargestChangeStampForBatchSync, | 404 base::Bind(&DriveFileSyncService::DidGetLargestChangeStampForBatchSync, |
| 324 weak_factory_.GetWeakPtr(), | 405 weak_factory_.GetWeakPtr(), |
| (...skipping 27 matching lines...) Expand all Loading... |
| 352 const GURL& origin, | 433 const GURL& origin, |
| 353 const std::string& resource_id, | 434 const std::string& resource_id, |
| 354 google_apis::GDataErrorCode error, | 435 google_apis::GDataErrorCode error, |
| 355 int64 largest_changestamp) { | 436 int64 largest_changestamp) { |
| 356 if (error != google_apis::HTTP_SUCCESS) { | 437 if (error != google_apis::HTTP_SUCCESS) { |
| 357 // TODO(tzik): Refine this error code. | 438 // TODO(tzik): Refine this error code. |
| 358 NotifyTaskDone(GDataErrorCodeToSyncStatusCode(error), token.Pass()); | 439 NotifyTaskDone(GDataErrorCodeToSyncStatusCode(error), token.Pass()); |
| 359 return; | 440 return; |
| 360 } | 441 } |
| 361 | 442 |
| 443 DCHECK(token); |
| 444 token->UpdateTask(FROM_HERE, TASK_TYPE_DRIVE, "Retrieving remote files"); |
| 362 sync_client_->ListFiles( | 445 sync_client_->ListFiles( |
| 363 resource_id, | 446 resource_id, |
| 364 base::Bind(&DriveFileSyncService::DidGetDirectoryContentForBatchSync, | 447 base::Bind(&DriveFileSyncService::DidGetDirectoryContentForBatchSync, |
| 365 weak_factory_.GetWeakPtr(), | 448 weak_factory_.GetWeakPtr(), |
| 366 base::Passed(&token), origin, largest_changestamp)); | 449 base::Passed(&token), origin, largest_changestamp)); |
| 367 } | 450 } |
| 368 | 451 |
| 369 void DriveFileSyncService::DidGetDirectoryContentForBatchSync( | 452 void DriveFileSyncService::DidGetDirectoryContentForBatchSync( |
| 370 scoped_ptr<TaskToken> token, | 453 scoped_ptr<TaskToken> token, |
| 371 const GURL& origin, | 454 const GURL& origin, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 int64 another_changestamp = inserted.first->second; | 518 int64 another_changestamp = inserted.first->second; |
| 436 if (another_changestamp > changestamp) | 519 if (another_changestamp > changestamp) |
| 437 return; | 520 return; |
| 438 inserted.first->second = changestamp; | 521 inserted.first->second = changestamp; |
| 439 } | 522 } |
| 440 | 523 |
| 441 pending_changes_.push(change); | 524 pending_changes_.push(change); |
| 442 } | 525 } |
| 443 | 526 |
| 444 } // namespace sync_file_system | 527 } // namespace sync_file_system |
| OLD | NEW |