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

Side by Side Diff: components/sync/driver/sync_service_base.cc

Issue 2663783002: [Sync] Split encryption state and logic out of PSS and SBHI. (Closed)
Patch Set: Tweak comment. Created 3 years, 10 months 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/sync_service_base.h" 5 #include "components/sync/driver/sync_service_base.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 const version_info::Channel& channel, 57 const version_info::Channel& channel,
58 const base::FilePath& base_directory, 58 const base::FilePath& base_directory,
59 const std::string& debug_identifier) 59 const std::string& debug_identifier)
60 : sync_client_(std::move(sync_client)), 60 : sync_client_(std::move(sync_client)),
61 signin_(std::move(signin)), 61 signin_(std::move(signin)),
62 channel_(channel), 62 channel_(channel),
63 base_directory_(base_directory), 63 base_directory_(base_directory),
64 sync_data_folder_( 64 sync_data_folder_(
65 base_directory_.Append(base::FilePath(kSyncDataFolderName))), 65 base_directory_.Append(base::FilePath(kSyncDataFolderName))),
66 debug_identifier_(debug_identifier), 66 debug_identifier_(debug_identifier),
67 sync_prefs_(sync_client_->GetPrefService()) {} 67 sync_prefs_(sync_client_->GetPrefService()) {
68 ResetCryptoState();
69 }
68 70
69 SyncServiceBase::~SyncServiceBase() = default; 71 SyncServiceBase::~SyncServiceBase() = default;
70 72
73 void SyncServiceBase::AddObserver(SyncServiceObserver* observer) {
74 DCHECK(thread_checker_.CalledOnValidThread());
75 observers_.AddObserver(observer);
76 }
77
78 void SyncServiceBase::RemoveObserver(SyncServiceObserver* observer) {
79 DCHECK(thread_checker_.CalledOnValidThread());
80 observers_.RemoveObserver(observer);
81 }
82
83 bool SyncServiceBase::HasObserver(const SyncServiceObserver* observer) const {
84 DCHECK(thread_checker_.CalledOnValidThread());
85 return observers_.HasObserver(observer);
86 }
87
88 void SyncServiceBase::NotifyObservers() {
89 for (auto& observer : observers_) {
90 observer.OnStateChanged();
91 }
92 }
93
71 void SyncServiceBase::InitializeEngine() { 94 void SyncServiceBase::InitializeEngine() {
72 DCHECK(engine_); 95 DCHECK(engine_);
73 96
74 if (!sync_thread_) { 97 if (!sync_thread_) {
75 sync_thread_ = base::MakeUnique<base::Thread>("Chrome_SyncThread"); 98 sync_thread_ = base::MakeUnique<base::Thread>("Chrome_SyncThread");
76 base::Thread::Options options; 99 base::Thread::Options options;
77 options.timer_slack = base::TIMER_SLACK_MAXIMUM; 100 options.timer_slack = base::TIMER_SLACK_MAXIMUM;
78 CHECK(sync_thread_->StartWithOptions(options)); 101 CHECK(sync_thread_->StartWithOptions(options));
79 } 102 }
80 103
81 SyncEngine::InitParams params; 104 SyncEngine::InitParams params;
82 params.sync_task_runner = sync_thread_->task_runner(); 105 params.sync_task_runner = sync_thread_->task_runner();
83 params.host = this; 106 params.host = this;
84 params.registrar = base::MakeUnique<SyncBackendRegistrar>( 107 params.registrar = base::MakeUnique<SyncBackendRegistrar>(
85 debug_identifier_, base::Bind(&SyncClient::CreateModelWorkerForGroup, 108 debug_identifier_, base::Bind(&SyncClient::CreateModelWorkerForGroup,
86 base::Unretained(sync_client_.get()))); 109 base::Unretained(sync_client_.get())));
110 params.encryption_observer_proxy = crypto_->GetEncryptionObserverProxy();
87 params.extensions_activity = sync_client_->GetExtensionsActivity(); 111 params.extensions_activity = sync_client_->GetExtensionsActivity();
88 params.event_handler = GetJsEventHandler(); 112 params.event_handler = GetJsEventHandler();
89 params.service_url = sync_service_url(); 113 params.service_url = sync_service_url();
90 params.sync_user_agent = GetLocalDeviceInfoProvider()->GetSyncUserAgent(); 114 params.sync_user_agent = GetLocalDeviceInfoProvider()->GetSyncUserAgent();
91 params.http_factory_getter = MakeHttpPostProviderFactoryGetter(); 115 params.http_factory_getter = MakeHttpPostProviderFactoryGetter();
92 params.credentials = GetCredentials(); 116 params.credentials = GetCredentials();
93 invalidation::InvalidationService* invalidator = 117 invalidation::InvalidationService* invalidator =
94 sync_client_->GetInvalidationService(); 118 sync_client_->GetInvalidationService();
95 params.invalidator_client_id = 119 params.invalidator_client_id =
96 invalidator ? invalidator->GetInvalidatorClientId() : "", 120 invalidator ? invalidator->GetInvalidatorClientId() : "",
97 params.sync_manager_factory = base::MakeUnique<SyncManagerFactory>(); 121 params.sync_manager_factory = base::MakeUnique<SyncManagerFactory>();
98 // The first time we start up the engine we want to ensure we have a clean 122 // The first time we start up the engine we want to ensure we have a clean
99 // directory, so delete any old one that might be there. 123 // directory, so delete any old one that might be there.
100 params.delete_sync_data_folder = !IsFirstSetupComplete(); 124 params.delete_sync_data_folder = !IsFirstSetupComplete();
101 params.enable_local_sync_backend = 125 params.enable_local_sync_backend =
102 GetLocalSyncConfig(&params.local_sync_backend_folder); 126 GetLocalSyncConfig(&params.local_sync_backend_folder);
103 params.restored_key_for_bootstrapping = 127 params.restored_key_for_bootstrapping =
104 sync_prefs_.GetEncryptionBootstrapToken(); 128 sync_prefs_.GetEncryptionBootstrapToken();
105 params.restored_keystore_key_for_bootstrapping = 129 params.restored_keystore_key_for_bootstrapping =
106 sync_prefs_.GetKeystoreEncryptionBootstrapToken(); 130 sync_prefs_.GetKeystoreEncryptionBootstrapToken();
107 params.engine_components_factory = 131 params.engine_components_factory =
108 base::MakeUnique<EngineComponentsFactoryImpl>( 132 base::MakeUnique<EngineComponentsFactoryImpl>(
109 EngineSwitchesFromCommandLine()); 133 EngineSwitchesFromCommandLine());
110 params.unrecoverable_error_handler = GetUnrecoverableErrorHandler(); 134 params.unrecoverable_error_handler = GetUnrecoverableErrorHandler();
111 params.report_unrecoverable_error_function = 135 params.report_unrecoverable_error_function =
112 base::Bind(ReportUnrecoverableError, channel_); 136 base::Bind(ReportUnrecoverableError, channel_);
113 params.saved_nigori_state = MoveSavedNigoriState(); 137 params.saved_nigori_state = crypto_->TakeSavedNigoriState();
114 sync_prefs_.GetInvalidationVersions(&params.invalidation_versions); 138 sync_prefs_.GetInvalidationVersions(&params.invalidation_versions);
115 139
116 engine_->Initialize(std::move(params)); 140 engine_->Initialize(std::move(params));
117 } 141 }
118 142
119 bool SyncServiceBase::GetLocalSyncConfig( 143 bool SyncServiceBase::GetLocalSyncConfig(
120 base::FilePath* local_sync_backend_folder) const { 144 base::FilePath* local_sync_backend_folder) const {
121 bool enable_local_sync_backend = false; 145 bool enable_local_sync_backend = false;
122 *local_sync_backend_folder = sync_prefs_.GetLocalSyncBackendDir(); 146 *local_sync_backend_folder = sync_prefs_.GetLocalSyncBackendDir();
123 #if defined(OS_WIN) 147 #if defined(OS_WIN)
(...skipping 14 matching lines...) Expand all
138 // considered roamed. 162 // considered roamed.
139 // See http://crbug.com/674928. 163 // See http://crbug.com/674928.
140 *local_sync_backend_folder = 164 *local_sync_backend_folder =
141 local_sync_backend_folder->Append(base_directory_.BaseName()); 165 local_sync_backend_folder->Append(base_directory_.BaseName());
142 *local_sync_backend_folder = 166 *local_sync_backend_folder =
143 local_sync_backend_folder->Append(kLoopbackServerBackendFilename); 167 local_sync_backend_folder->Append(kLoopbackServerBackendFilename);
144 #endif // defined(OS_WIN) 168 #endif // defined(OS_WIN)
145 return enable_local_sync_backend; 169 return enable_local_sync_backend;
146 } 170 }
147 171
172 void SyncServiceBase::ResetCryptoState() {
173 crypto_ = base::MakeUnique<SyncServiceCrypto>(
174 base::BindRepeating(&SyncServiceBase::NotifyObservers,
175 base::Unretained(this)),
176 base::BindRepeating(&SyncService::GetPreferredDataTypes,
177 base::Unretained(this)),
178 &sync_prefs_);
179 }
180
148 } // namespace syncer 181 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/driver/sync_service_base.h ('k') | components/sync/driver/sync_service_crypto.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698