Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: components/sync/driver/glue/sync_backend_host_impl.cc

Issue 2559123002: [Sync] SyncEngine refactor part 2: SyncServiceBase. (Closed)
Patch Set: Address comments. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/sync/driver/glue/sync_backend_host_impl.h" 5 #include "components/sync/driver/glue/sync_backend_host_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 name_(name), 52 name_(name),
53 sync_prefs_(sync_prefs), 53 sync_prefs_(sync_prefs),
54 invalidator_(invalidator), 54 invalidator_(invalidator),
55 weak_ptr_factory_(this) { 55 weak_ptr_factory_(this) {
56 core_ = new SyncBackendHostCore(name_, sync_folder, 56 core_ = new SyncBackendHostCore(name_, sync_folder,
57 weak_ptr_factory_.GetWeakPtr()); 57 weak_ptr_factory_.GetWeakPtr());
58 } 58 }
59 59
60 SyncBackendHostImpl::~SyncBackendHostImpl() { 60 SyncBackendHostImpl::~SyncBackendHostImpl() {
61 DCHECK(!core_.get() && !host_) << "Must call Shutdown before destructor."; 61 DCHECK(!core_.get() && !host_) << "Must call Shutdown before destructor.";
62 DCHECK(!registrar_.get()); 62 DCHECK(!registrar_);
63 } 63 }
64 64
65 void SyncBackendHostImpl::Initialize( 65 void SyncBackendHostImpl::Initialize(InitParams params) {
66 SyncEngineHost* host, 66 CHECK(params.sync_task_runner);
67 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner, 67 DCHECK(params.host);
68 const WeakHandle<JsEventHandler>& event_handler, 68 DCHECK(params.registrar);
69 const GURL& sync_service_url,
70 const std::string& sync_user_agent,
71 const SyncCredentials& credentials,
72 bool delete_sync_data_folder,
73 bool enable_local_sync_backend,
74 const base::FilePath& local_sync_backend_folder,
75 std::unique_ptr<SyncManagerFactory> sync_manager_factory,
76 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler,
77 const base::Closure& report_unrecoverable_error_function,
78 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter,
79 std::unique_ptr<SyncEncryptionHandler::NigoriState> saved_nigori_state) {
80 CHECK(sync_task_runner);
81 sync_task_runner_ = sync_task_runner;
82 69
83 registrar_ = base::MakeUnique<SyncBackendRegistrar>( 70 sync_task_runner_ = params.sync_task_runner;
84 name_, base::Bind(&SyncClient::CreateModelWorkerForGroup, 71 host_ = params.host;
85 base::Unretained(sync_client_))); 72 registrar_ = params.registrar.get();
86 73
87 DCHECK(host); 74 sync_task_runner_->PostTask(
88 host_ = host; 75 FROM_HERE, base::Bind(&SyncBackendHostCore::DoInitialize, core_,
89 76 base::Passed(&params)));
90 std::vector<scoped_refptr<ModelSafeWorker>> workers;
91 registrar_->GetWorkers(&workers);
92
93 EngineComponentsFactory::Switches factory_switches = {
94 EngineComponentsFactory::ENCRYPTION_KEYSTORE,
95 EngineComponentsFactory::BACKOFF_NORMAL};
96
97 base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
98 if (cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) {
99 factory_switches.backoff_override =
100 EngineComponentsFactory::BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE;
101 }
102 if (cl->HasSwitch(switches::kSyncEnableGetUpdateAvoidance)) {
103 factory_switches.pre_commit_updates_policy =
104 EngineComponentsFactory::FORCE_ENABLE_PRE_COMMIT_UPDATE_AVOIDANCE;
105 }
106 if (cl->HasSwitch(switches::kSyncShortNudgeDelayForTest)) {
107 factory_switches.nudge_delay =
108 EngineComponentsFactory::NudgeDelay::SHORT_NUDGE_DELAY;
109 }
110
111 std::map<ModelType, int64_t> invalidation_versions;
112 sync_prefs_->GetInvalidationVersions(&invalidation_versions);
113
114 std::unique_ptr<DoInitializeOptions> init_opts(new DoInitializeOptions(
115 sync_task_runner_, registrar_.get(), workers,
116 sync_client_->GetExtensionsActivity(), event_handler, sync_service_url,
117 sync_user_agent, http_post_provider_factory_getter.Run(
118 core_->GetRequestContextCancelationSignal()),
119 credentials, invalidator_ ? invalidator_->GetInvalidatorClientId() : "",
120 std::move(sync_manager_factory), delete_sync_data_folder,
121 enable_local_sync_backend, local_sync_backend_folder,
122 sync_prefs_->GetEncryptionBootstrapToken(),
123 sync_prefs_->GetKeystoreEncryptionBootstrapToken(),
124 std::unique_ptr<EngineComponentsFactory>(
125 new EngineComponentsFactoryImpl(factory_switches)),
126 unrecoverable_error_handler, report_unrecoverable_error_function,
127 std::move(saved_nigori_state), invalidation_versions));
128 InitCore(std::move(init_opts));
129 } 77 }
130 78
131 void SyncBackendHostImpl::TriggerRefresh(const ModelTypeSet& types) { 79 void SyncBackendHostImpl::TriggerRefresh(const ModelTypeSet& types) {
132 DCHECK(thread_checker_.CalledOnValidThread()); 80 DCHECK(thread_checker_.CalledOnValidThread());
133 sync_task_runner_->PostTask( 81 sync_task_runner_->PostTask(
134 FROM_HERE, 82 FROM_HERE,
135 base::Bind(&SyncBackendHostCore::DoRefreshTypes, core_, types)); 83 base::Bind(&SyncBackendHostCore::DoRefreshTypes, core_, types));
136 } 84 }
137 85
138 void SyncBackendHostImpl::UpdateCredentials( 86 void SyncBackendHostImpl::UpdateCredentials(
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 invalidation_handler_registered_ = false; 193 invalidation_handler_registered_ = false;
246 194
247 model_type_connector_.reset(); 195 model_type_connector_.reset();
248 196
249 // Shut down and destroy SyncManager. SyncManager holds a pointer to 197 // Shut down and destroy SyncManager. SyncManager holds a pointer to
250 // |registrar_| so its destruction must be sequenced before the destruction of 198 // |registrar_| so its destruction must be sequenced before the destruction of
251 // |registrar_|. 199 // |registrar_|.
252 sync_task_runner_->PostTask( 200 sync_task_runner_->PostTask(
253 FROM_HERE, base::Bind(&SyncBackendHostCore::DoShutdown, core_, reason)); 201 FROM_HERE, base::Bind(&SyncBackendHostCore::DoShutdown, core_, reason));
254 core_ = nullptr; 202 core_ = nullptr;
255 203 registrar_ = nullptr;
256 // Destroy |registrar_|.
257 sync_task_runner_->DeleteSoon(FROM_HERE, registrar_.release());
258 } 204 }
259 205
260 void SyncBackendHostImpl::UnregisterInvalidationIds() { 206 void SyncBackendHostImpl::UnregisterInvalidationIds() {
261 if (invalidation_handler_registered_) { 207 if (invalidation_handler_registered_) {
262 CHECK(invalidator_->UpdateRegisteredInvalidationIds(this, ObjectIdSet())); 208 CHECK(invalidator_->UpdateRegisteredInvalidationIds(this, ObjectIdSet()));
263 } 209 }
264 } 210 }
265 211
266 ModelTypeSet SyncBackendHostImpl::ConfigureDataTypes( 212 ModelTypeSet SyncBackendHostImpl::ConfigureDataTypes(
267 ConfigureReason reason, 213 ConfigureReason reason,
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 SyncCycleSnapshot SyncBackendHostImpl::GetLastCycleSnapshot() const { 367 SyncCycleSnapshot SyncBackendHostImpl::GetLastCycleSnapshot() const {
422 return last_snapshot_; 368 return last_snapshot_;
423 } 369 }
424 370
425 bool SyncBackendHostImpl::HasUnsyncedItems() const { 371 bool SyncBackendHostImpl::HasUnsyncedItems() const {
426 DCHECK(initialized()); 372 DCHECK(initialized());
427 return core_->sync_manager()->HasUnsyncedItems(); 373 return core_->sync_manager()->HasUnsyncedItems();
428 } 374 }
429 375
430 bool SyncBackendHostImpl::IsNigoriEnabled() const { 376 bool SyncBackendHostImpl::IsNigoriEnabled() const {
431 return registrar_.get() && registrar_->IsNigoriEnabled(); 377 return registrar_ && registrar_->IsNigoriEnabled();
432 } 378 }
433 379
434 PassphraseType SyncBackendHostImpl::GetPassphraseType() const { 380 PassphraseType SyncBackendHostImpl::GetPassphraseType() const {
435 return cached_passphrase_type_; 381 return cached_passphrase_type_;
436 } 382 }
437 383
438 base::Time SyncBackendHostImpl::GetExplicitPassphraseTime() const { 384 base::Time SyncBackendHostImpl::GetExplicitPassphraseTime() const {
439 return cached_explicit_passphrase_time_; 385 return cached_explicit_passphrase_time_;
440 } 386 }
441 387
442 bool SyncBackendHostImpl::IsCryptographerReady( 388 bool SyncBackendHostImpl::IsCryptographerReady(
443 const BaseTransaction* trans) const { 389 const BaseTransaction* trans) const {
444 return initialized() && trans->GetCryptographer() && 390 return initialized() && trans->GetCryptographer() &&
445 trans->GetCryptographer()->is_ready(); 391 trans->GetCryptographer()->is_ready();
446 } 392 }
447 393
448 void SyncBackendHostImpl::GetModelSafeRoutingInfo( 394 void SyncBackendHostImpl::GetModelSafeRoutingInfo(
449 ModelSafeRoutingInfo* out) const { 395 ModelSafeRoutingInfo* out) const {
450 if (initialized()) { 396 if (initialized()) {
451 CHECK(registrar_.get()); 397 CHECK(registrar_);
452 registrar_->GetModelSafeRoutingInfo(out); 398 registrar_->GetModelSafeRoutingInfo(out);
453 } else { 399 } else {
454 NOTREACHED(); 400 NOTREACHED();
455 } 401 }
456 } 402 }
457 403
458 void SyncBackendHostImpl::FlushDirectory() const { 404 void SyncBackendHostImpl::FlushDirectory() const {
459 DCHECK(initialized()); 405 DCHECK(initialized());
460 sync_task_runner_->PostTask( 406 sync_task_runner_->PostTask(
461 FROM_HERE, base::Bind(&SyncBackendHostCore::SaveChanges, core_)); 407 FROM_HERE, base::Bind(&SyncBackendHostCore::SaveChanges, core_));
(...skipping 22 matching lines...) Expand all
484 } 430 }
485 431
486 void SyncBackendHostImpl::DisableDirectoryTypeDebugInfoForwarding() { 432 void SyncBackendHostImpl::DisableDirectoryTypeDebugInfoForwarding() {
487 DCHECK(initialized()); 433 DCHECK(initialized());
488 sync_task_runner_->PostTask( 434 sync_task_runner_->PostTask(
489 FROM_HERE, 435 FROM_HERE,
490 base::Bind(&SyncBackendHostCore::DisableDirectoryTypeDebugInfoForwarding, 436 base::Bind(&SyncBackendHostCore::DisableDirectoryTypeDebugInfoForwarding,
491 core_)); 437 core_));
492 } 438 }
493 439
494 void SyncBackendHostImpl::InitCore(
495 std::unique_ptr<DoInitializeOptions> options) {
496 sync_task_runner_->PostTask(
497 FROM_HERE, base::Bind(&SyncBackendHostCore::DoInitialize, core_,
498 base::Passed(&options)));
499 }
500
501 void SyncBackendHostImpl::RequestConfigureSyncer( 440 void SyncBackendHostImpl::RequestConfigureSyncer(
502 ConfigureReason reason, 441 ConfigureReason reason,
503 ModelTypeSet to_download, 442 ModelTypeSet to_download,
504 const ModelSafeRoutingInfo& routing_info, 443 const ModelSafeRoutingInfo& routing_info,
505 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task, 444 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task,
506 const base::Closure& retry_callback) { 445 const base::Closure& retry_callback) {
507 sync_task_runner_->PostTask( 446 sync_task_runner_->PostTask(
508 FROM_HERE, 447 FROM_HERE,
509 base::Bind(&SyncBackendHostCore::DoConfigureSyncer, core_, reason, 448 base::Bind(&SyncBackendHostCore::DoConfigureSyncer, core_, reason,
510 to_download, routing_info, ready_task, retry_callback)); 449 to_download, routing_info, ready_task, retry_callback));
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 const SyncManager::ClearServerDataCallback& frontend_callback) { 695 const SyncManager::ClearServerDataCallback& frontend_callback) {
757 DCHECK(thread_checker_.CalledOnValidThread()); 696 DCHECK(thread_checker_.CalledOnValidThread());
758 frontend_callback.Run(); 697 frontend_callback.Run();
759 } 698 }
760 699
761 } // namespace syncer 700 } // namespace syncer
762 701
763 #undef SDVLOG 702 #undef SDVLOG
764 703
765 #undef SLOG 704 #undef SLOG
OLDNEW
« no previous file with comments | « components/sync/driver/glue/sync_backend_host_impl.h ('k') | components/sync/driver/glue/sync_backend_host_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698