Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/sync_worker.h" | 5 #include "chrome/browser/sync_file_system/drive_backend/sync_worker.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 namespace sync_file_system { | 49 namespace sync_file_system { |
| 50 | 50 |
| 51 class RemoteChangeProcessor; | 51 class RemoteChangeProcessor; |
| 52 | 52 |
| 53 namespace drive_backend { | 53 namespace drive_backend { |
| 54 | 54 |
| 55 namespace { | 55 namespace { |
| 56 | 56 |
| 57 void EmptyStatusCallback(SyncStatusCode status) {} | 57 void EmptyStatusCallback(SyncStatusCode status) {} |
| 58 | 58 |
| 59 void RelayToTaskRunner(base::TaskRunner* task_runner, | |
|
peria
2014/04/16 05:56:12
I have to merge some RelayToTaskRunner().
| |
| 60 const tracked_objects::Location& from_here, | |
| 61 const base::Callback<void(void)>& callback) { | |
|
tzik
2014/04/16 17:21:19
s/base::Callback<void(void)>/base::Closure/
peria
2014/04/17 01:40:19
Done.
| |
| 62 task_runner->PostTask(from_here, callback); | |
| 63 } | |
| 64 | |
| 65 template <typename T> | |
| 66 void RelayToTaskRunner(base::TaskRunner* task_runner, | |
| 67 const tracked_objects::Location& from_here, | |
| 68 const base::Callback<void(T)>& callback, | |
| 69 const T& p1) { | |
|
tzik
2014/04/16 17:21:19
# I'll revisit later.
This probably needs base::i
tzik
2014/04/16 18:26:21
Whether we should do it or not, we can do it by:
s
peria
2014/04/17 01:40:19
Done.
| |
| 70 task_runner->PostTask(from_here, base::Bind(callback, p1)); | |
| 71 } | |
| 72 | |
| 73 template <typename T> | |
| 74 void RelayToTaskRunner(base::TaskRunner* task_runner, | |
| 75 const tracked_objects::Location& from_here, | |
| 76 const base::Callback<void(const T& p1)>& callback, | |
| 77 const T& p1) { | |
| 78 task_runner->PostTask(from_here, base::Bind(callback, p1)); | |
| 79 } | |
| 80 | |
| 81 template <typename T1, typename T2> | |
| 82 void RelayToTaskRunner(base::TaskRunner* task_runner, | |
| 83 const tracked_objects::Location& from_here, | |
| 84 const base::Callback<void(T1, const T2&)>& callback, | |
| 85 const T1& p1, | |
| 86 const T2& p2) { | |
| 87 task_runner->PostTask(from_here, base::Bind(callback, p1, p2)); | |
| 88 } | |
| 89 | |
| 90 template <typename T1, typename T2> | |
| 91 void RelayToTaskRunner(base::TaskRunner* task_runner, | |
| 92 const tracked_objects::Location& from_here, | |
| 93 const base::Callback<void(T1, T2)>& callback, | |
| 94 const T1& p1, | |
| 95 const T2& p2) { | |
| 96 task_runner->PostTask(from_here, base::Bind(callback, p1, p2)); | |
| 97 } | |
| 98 | |
| 59 } // namespace | 99 } // namespace |
| 60 | 100 |
| 61 scoped_ptr<SyncWorker> SyncWorker::CreateOnWorker( | 101 scoped_ptr<SyncWorker> SyncWorker::CreateOnWorker( |
| 62 const base::WeakPtr<drive_backend::SyncEngine>& sync_engine, | 102 const base::WeakPtr<drive_backend::SyncEngine>& sync_engine, |
| 63 const base::FilePath& base_dir, | 103 const base::FilePath& base_dir, |
| 64 scoped_ptr<SyncEngineContext> sync_engine_context, | 104 scoped_ptr<SyncEngineContext> sync_engine_context, |
| 65 leveldb::Env* env_override) { | 105 leveldb::Env* env_override) { |
| 66 scoped_ptr<SyncWorker> sync_worker( | 106 scoped_ptr<SyncWorker> sync_worker( |
| 67 new SyncWorker(sync_engine, | 107 new SyncWorker(sync_engine, |
| 68 base_dir, | 108 base_dir, |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 | 244 |
| 205 void SyncWorker::SetSyncEnabled(bool enabled) { | 245 void SyncWorker::SetSyncEnabled(bool enabled) { |
| 206 if (sync_enabled_ == enabled) | 246 if (sync_enabled_ == enabled) |
| 207 return; | 247 return; |
| 208 | 248 |
| 209 RemoteServiceState old_state = GetCurrentState(); | 249 RemoteServiceState old_state = GetCurrentState(); |
| 210 sync_enabled_ = enabled; | 250 sync_enabled_ = enabled; |
| 211 if (old_state == GetCurrentState()) | 251 if (old_state == GetCurrentState()) |
| 212 return; | 252 return; |
| 213 | 253 |
| 214 // TODO(peria): PostTask() | 254 RelayToTaskRunner(context_->GetUiTaskRunner(), |
| 215 sync_engine_->UpdateSyncEnabled(enabled); | 255 FROM_HERE, |
| 256 base::Bind(&SyncEngine::UpdateSyncEnabled, | |
| 257 base::Unretained(sync_engine_.get())), | |
|
tzik
2014/04/16 17:21:19
Pass WeakPtr directly instead of raw pointer, sinc
tzik
2014/04/16 17:42:20
BTW, just ui_task_runner->PostTask() seems to work
peria
2014/04/17 01:40:19
Done.
| |
| 258 enabled); | |
| 216 } | 259 } |
| 217 | 260 |
| 218 SyncStatusCode SyncWorker::SetDefaultConflictResolutionPolicy( | 261 SyncStatusCode SyncWorker::SetDefaultConflictResolutionPolicy( |
| 219 ConflictResolutionPolicy policy) { | 262 ConflictResolutionPolicy policy) { |
| 220 default_conflict_resolution_policy_ = policy; | 263 default_conflict_resolution_policy_ = policy; |
| 221 return SYNC_STATUS_OK; | 264 return SYNC_STATUS_OK; |
| 222 } | 265 } |
| 223 | 266 |
| 224 SyncStatusCode SyncWorker::SetConflictResolutionPolicy( | 267 SyncStatusCode SyncWorker::SetConflictResolutionPolicy( |
| 225 const GURL& origin, | 268 const GURL& origin, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 | 310 |
| 268 MaybeStartFetchChanges(); | 311 MaybeStartFetchChanges(); |
| 269 } | 312 } |
| 270 | 313 |
| 271 void SyncWorker::NotifyLastOperationStatus( | 314 void SyncWorker::NotifyLastOperationStatus( |
| 272 SyncStatusCode status, | 315 SyncStatusCode status, |
| 273 bool used_network) { | 316 bool used_network) { |
| 274 UpdateServiceStateFromSyncStatusCode(status, used_network); | 317 UpdateServiceStateFromSyncStatusCode(status, used_network); |
| 275 | 318 |
| 276 if (GetMetadataDatabase()) { | 319 if (GetMetadataDatabase()) { |
| 277 // TODO(peria): Post task | 320 RelayToTaskRunner(context_->GetUiTaskRunner(), |
| 278 sync_engine_->NotifyLastOperationStatus(); | 321 FROM_HERE, |
| 322 base::Bind(&SyncEngine::NotifyLastOperationStatus, | |
| 323 base::Unretained(sync_engine_.get()))); | |
| 279 } | 324 } |
| 280 } | 325 } |
| 281 | 326 |
| 282 void SyncWorker::OnNotificationReceived() { | 327 void SyncWorker::OnNotificationReceived() { |
| 283 if (service_state_ == REMOTE_SERVICE_TEMPORARY_UNAVAILABLE) | 328 if (service_state_ == REMOTE_SERVICE_TEMPORARY_UNAVAILABLE) |
| 284 UpdateServiceState(REMOTE_SERVICE_OK, "Got push notification for Drive."); | 329 UpdateServiceState(REMOTE_SERVICE_OK, "Got push notification for Drive."); |
| 285 | 330 |
| 286 should_check_remote_change_ = true; | 331 should_check_remote_change_ = true; |
| 287 MaybeScheduleNextTask(); | 332 MaybeScheduleNextTask(); |
| 288 } | 333 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 "Authentication required."); | 448 "Authentication required."); |
| 404 } | 449 } |
| 405 return; | 450 return; |
| 406 } | 451 } |
| 407 | 452 |
| 408 scoped_ptr<MetadataDatabase> metadata_database = | 453 scoped_ptr<MetadataDatabase> metadata_database = |
| 409 initializer->PassMetadataDatabase(); | 454 initializer->PassMetadataDatabase(); |
| 410 if (metadata_database) | 455 if (metadata_database) |
| 411 context_->SetMetadataDatabase(metadata_database.Pass()); | 456 context_->SetMetadataDatabase(metadata_database.Pass()); |
| 412 | 457 |
| 413 // TODO(peria): Post task | 458 RelayToTaskRunner(context_->GetUiTaskRunner(), |
| 414 sync_engine_->UpdateRegisteredApps(); | 459 FROM_HERE, |
| 460 base::Bind(&SyncEngine::UpdateRegisteredApps, | |
| 461 base::Unretained(sync_engine_.get()))); | |
| 415 } | 462 } |
| 416 | 463 |
| 417 void SyncWorker::DidProcessRemoteChange(RemoteToLocalSyncer* syncer, | 464 void SyncWorker::DidProcessRemoteChange(RemoteToLocalSyncer* syncer, |
| 418 const SyncFileCallback& callback, | 465 const SyncFileCallback& callback, |
| 419 SyncStatusCode status) { | 466 SyncStatusCode status) { |
| 420 if (syncer->is_sync_root_deletion()) { | 467 if (syncer->is_sync_root_deletion()) { |
| 421 MetadataDatabase::ClearDatabase(context_->PassMetadataDatabase()); | 468 MetadataDatabase::ClearDatabase(context_->PassMetadataDatabase()); |
| 422 PostInitializeTask(); | 469 PostInitializeTask(); |
| 423 callback.Run(status, syncer->url()); | 470 RelayToTaskRunner(context_->GetUiTaskRunner(), |
| 471 FROM_HERE, | |
| 472 callback, | |
| 473 status, | |
| 474 syncer->url()); | |
| 424 return; | 475 return; |
| 425 } | 476 } |
| 426 | 477 |
| 427 if (status == SYNC_STATUS_OK) { | 478 if (status == SYNC_STATUS_OK) { |
| 428 // TODO(peria): Post task | 479 RelayToTaskRunner(context_->GetUiTaskRunner(), |
| 429 sync_engine_->DidProcessRemoteChange(syncer); | 480 FROM_HERE, |
| 481 base::Bind(&SyncEngine::DidProcessRemoteChange, | |
| 482 base::Unretained(sync_engine_.get())), | |
| 483 syncer); | |
| 430 | 484 |
| 431 if (syncer->sync_action() == SYNC_ACTION_DELETED && | 485 if (syncer->sync_action() == SYNC_ACTION_DELETED && |
| 432 syncer->url().is_valid() && | 486 syncer->url().is_valid() && |
| 433 fileapi::VirtualPath::IsRootPath(syncer->url().path())) { | 487 fileapi::VirtualPath::IsRootPath(syncer->url().path())) { |
| 434 RegisterOrigin(syncer->url().origin(), base::Bind(&EmptyStatusCallback)); | 488 RegisterOrigin(syncer->url().origin(), base::Bind(&EmptyStatusCallback)); |
| 435 } | 489 } |
| 436 should_check_conflict_ = true; | 490 should_check_conflict_ = true; |
| 437 } | 491 } |
| 438 callback.Run(status, syncer->url()); | 492 |
| 493 RelayToTaskRunner(context_->GetUiTaskRunner(), | |
| 494 FROM_HERE, | |
| 495 callback, | |
| 496 status, | |
| 497 syncer->url()); | |
| 439 } | 498 } |
| 440 | 499 |
| 441 void SyncWorker::DidApplyLocalChange(LocalToRemoteSyncer* syncer, | 500 void SyncWorker::DidApplyLocalChange(LocalToRemoteSyncer* syncer, |
| 442 const SyncStatusCallback& callback, | 501 const SyncStatusCallback& callback, |
| 443 SyncStatusCode status) { | 502 SyncStatusCode status) { |
| 444 // TODO(peria): Post task | 503 // TODO(peria): PostTask (Simple replace fails DriveBackendSync* tests) |
| 445 sync_engine_->DidApplyLocalChange(syncer, status); | 504 sync_engine_->DidApplyLocalChange(syncer, status); |
|
peria
2014/04/16 05:56:12
This method needs more than replacing with RelayTo
| |
| 446 | 505 |
| 447 if (status == SYNC_STATUS_UNKNOWN_ORIGIN && syncer->url().is_valid()) { | 506 if (status == SYNC_STATUS_UNKNOWN_ORIGIN && syncer->url().is_valid()) { |
| 448 RegisterOrigin(syncer->url().origin(), | 507 RegisterOrigin(syncer->url().origin(), |
| 449 base::Bind(&EmptyStatusCallback)); | 508 base::Bind(&EmptyStatusCallback)); |
| 450 } | 509 } |
| 451 | 510 |
| 452 if (syncer->needs_remote_change_listing() && | 511 if (syncer->needs_remote_change_listing() && |
| 453 !listing_remote_changes_) { | 512 !listing_remote_changes_) { |
| 454 task_manager_->ScheduleSyncTask( | 513 task_manager_->ScheduleSyncTask( |
| 455 FROM_HERE, | 514 FROM_HERE, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 576 const std::string& description) { | 635 const std::string& description) { |
| 577 RemoteServiceState old_state = GetCurrentState(); | 636 RemoteServiceState old_state = GetCurrentState(); |
| 578 service_state_ = state; | 637 service_state_ = state; |
| 579 | 638 |
| 580 if (old_state == GetCurrentState()) | 639 if (old_state == GetCurrentState()) |
| 581 return; | 640 return; |
| 582 | 641 |
| 583 util::Log(logging::LOG_VERBOSE, FROM_HERE, | 642 util::Log(logging::LOG_VERBOSE, FROM_HERE, |
| 584 "Service state changed: %d->%d: %s", | 643 "Service state changed: %d->%d: %s", |
| 585 old_state, GetCurrentState(), description.c_str()); | 644 old_state, GetCurrentState(), description.c_str()); |
| 586 // TODO(peria): Post task | 645 |
| 587 sync_engine_->UpdateServiceState(description); | 646 RelayToTaskRunner(context_->GetUiTaskRunner(), |
| 647 FROM_HERE, | |
| 648 base::Bind(&SyncEngine::UpdateServiceState, | |
| 649 base::Unretained(sync_engine_.get())), | |
| 650 description); | |
| 588 } | 651 } |
| 589 | 652 |
| 590 } // namespace drive_backend | 653 } // namespace drive_backend |
| 591 } // namespace sync_file_system | 654 } // namespace sync_file_system |
| OLD | NEW |