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

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

Issue 2388163002: [Sync] Move //components/sync to the syncer namespace, take 2. (Closed)
Patch Set: Rebase. Created 4 years, 2 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 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/command_line.h" 9 #include "base/command_line.h"
10 #include "base/feature_list.h" 10 #include "base/feature_list.h"
(...skipping 20 matching lines...) Expand all
31 #include "components/sync/engine/events/protocol_event.h" 31 #include "components/sync/engine/events/protocol_event.h"
32 #include "components/sync/engine/sync_string_conversions.h" 32 #include "components/sync/engine/sync_string_conversions.h"
33 33
34 // Helper macros to log with the syncer thread name; useful when there 34 // Helper macros to log with the syncer thread name; useful when there
35 // are multiple syncers involved. 35 // are multiple syncers involved.
36 36
37 #define SLOG(severity) LOG(severity) << name_ << ": " 37 #define SLOG(severity) LOG(severity) << name_ << ": "
38 38
39 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " 39 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": "
40 40
41 using syncer::InternalComponentsFactory; 41 namespace syncer {
42
43 namespace browser_sync {
44 42
45 SyncBackendHostImpl::SyncBackendHostImpl( 43 SyncBackendHostImpl::SyncBackendHostImpl(
46 const std::string& name, 44 const std::string& name,
47 sync_driver::SyncClient* sync_client, 45 SyncClient* sync_client,
48 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, 46 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
49 invalidation::InvalidationService* invalidator, 47 invalidation::InvalidationService* invalidator,
50 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, 48 const base::WeakPtr<SyncPrefs>& sync_prefs,
51 const base::FilePath& sync_folder) 49 const base::FilePath& sync_folder)
52 : frontend_task_runner_(base::ThreadTaskRunnerHandle::Get()), 50 : frontend_task_runner_(base::ThreadTaskRunnerHandle::Get()),
53 sync_client_(sync_client), 51 sync_client_(sync_client),
54 ui_thread_(ui_thread), 52 ui_thread_(ui_thread),
55 name_(name), 53 name_(name),
56 initialized_(false), 54 initialized_(false),
57 sync_prefs_(sync_prefs), 55 sync_prefs_(sync_prefs),
58 frontend_(NULL), 56 frontend_(NULL),
59 cached_passphrase_type_(syncer::PassphraseType::IMPLICIT_PASSPHRASE), 57 cached_passphrase_type_(PassphraseType::IMPLICIT_PASSPHRASE),
60 invalidator_(invalidator), 58 invalidator_(invalidator),
61 invalidation_handler_registered_(false), 59 invalidation_handler_registered_(false),
62 weak_ptr_factory_(this) { 60 weak_ptr_factory_(this) {
63 core_ = new SyncBackendHostCore(name_, sync_folder, 61 core_ = new SyncBackendHostCore(name_, sync_folder,
64 sync_prefs_->IsFirstSetupComplete(), 62 sync_prefs_->IsFirstSetupComplete(),
65 weak_ptr_factory_.GetWeakPtr()); 63 weak_ptr_factory_.GetWeakPtr());
66 } 64 }
67 65
68 SyncBackendHostImpl::~SyncBackendHostImpl() { 66 SyncBackendHostImpl::~SyncBackendHostImpl() {
69 DCHECK(!core_.get() && !frontend_) << "Must call Shutdown before destructor."; 67 DCHECK(!core_.get() && !frontend_) << "Must call Shutdown before destructor.";
70 DCHECK(!registrar_.get()); 68 DCHECK(!registrar_.get());
71 } 69 }
72 70
73 void SyncBackendHostImpl::Initialize( 71 void SyncBackendHostImpl::Initialize(
74 sync_driver::SyncFrontend* frontend, 72 SyncFrontend* frontend,
75 std::unique_ptr<base::Thread> sync_thread, 73 std::unique_ptr<base::Thread> sync_thread,
76 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, 74 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread,
77 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread, 75 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread,
78 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, 76 const WeakHandle<JsEventHandler>& event_handler,
79 const GURL& sync_service_url, 77 const GURL& sync_service_url,
80 const std::string& sync_user_agent, 78 const std::string& sync_user_agent,
81 const syncer::SyncCredentials& credentials, 79 const SyncCredentials& credentials,
82 bool delete_sync_data_folder, 80 bool delete_sync_data_folder,
83 std::unique_ptr<syncer::SyncManagerFactory> sync_manager_factory, 81 std::unique_ptr<SyncManagerFactory> sync_manager_factory,
84 const syncer::WeakHandle<syncer::UnrecoverableErrorHandler>& 82 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler,
85 unrecoverable_error_handler,
86 const base::Closure& report_unrecoverable_error_function, 83 const base::Closure& report_unrecoverable_error_function,
87 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter, 84 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter,
88 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> 85 std::unique_ptr<SyncEncryptionHandler::NigoriState> saved_nigori_state) {
89 saved_nigori_state) { 86 registrar_.reset(new SyncBackendRegistrar(name_, sync_client_,
90 registrar_.reset(new browser_sync::SyncBackendRegistrar( 87 std::move(sync_thread), ui_thread_,
91 name_, sync_client_, std::move(sync_thread), ui_thread_, db_thread, 88 db_thread, file_thread));
92 file_thread));
93 CHECK(registrar_->sync_thread()); 89 CHECK(registrar_->sync_thread());
94 90
95 frontend_ = frontend; 91 frontend_ = frontend;
96 DCHECK(frontend); 92 DCHECK(frontend);
97 93
98 std::vector<scoped_refptr<syncer::ModelSafeWorker>> workers; 94 std::vector<scoped_refptr<ModelSafeWorker>> workers;
99 registrar_->GetWorkers(&workers); 95 registrar_->GetWorkers(&workers);
100 96
101 InternalComponentsFactory::Switches factory_switches = { 97 InternalComponentsFactory::Switches factory_switches = {
102 InternalComponentsFactory::ENCRYPTION_KEYSTORE, 98 InternalComponentsFactory::ENCRYPTION_KEYSTORE,
103 InternalComponentsFactory::BACKOFF_NORMAL}; 99 InternalComponentsFactory::BACKOFF_NORMAL};
104 100
105 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); 101 base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
106 if (cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) { 102 if (cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) {
107 factory_switches.backoff_override = 103 factory_switches.backoff_override =
108 InternalComponentsFactory::BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE; 104 InternalComponentsFactory::BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE;
109 } 105 }
110 if (cl->HasSwitch(switches::kSyncEnableGetUpdateAvoidance)) { 106 if (cl->HasSwitch(switches::kSyncEnableGetUpdateAvoidance)) {
111 factory_switches.pre_commit_updates_policy = 107 factory_switches.pre_commit_updates_policy =
112 InternalComponentsFactory::FORCE_ENABLE_PRE_COMMIT_UPDATE_AVOIDANCE; 108 InternalComponentsFactory::FORCE_ENABLE_PRE_COMMIT_UPDATE_AVOIDANCE;
113 } 109 }
114 110
115 std::map<syncer::ModelType, int64_t> invalidation_versions; 111 std::map<ModelType, int64_t> invalidation_versions;
116 sync_prefs_->GetInvalidationVersions(&invalidation_versions); 112 sync_prefs_->GetInvalidationVersions(&invalidation_versions);
117 113
118 std::unique_ptr<DoInitializeOptions> init_opts(new DoInitializeOptions( 114 std::unique_ptr<DoInitializeOptions> init_opts(new DoInitializeOptions(
119 registrar_->sync_thread()->message_loop(), registrar_.get(), workers, 115 registrar_->sync_thread()->message_loop(), registrar_.get(), workers,
120 sync_client_->GetExtensionsActivity(), event_handler, sync_service_url, 116 sync_client_->GetExtensionsActivity(), event_handler, sync_service_url,
121 sync_user_agent, http_post_provider_factory_getter.Run( 117 sync_user_agent, http_post_provider_factory_getter.Run(
122 core_->GetRequestContextCancelationSignal()), 118 core_->GetRequestContextCancelationSignal()),
123 credentials, invalidator_ ? invalidator_->GetInvalidatorClientId() : "", 119 credentials, invalidator_ ? invalidator_->GetInvalidatorClientId() : "",
124 std::move(sync_manager_factory), delete_sync_data_folder, 120 std::move(sync_manager_factory), delete_sync_data_folder,
125 sync_prefs_->GetEncryptionBootstrapToken(), 121 sync_prefs_->GetEncryptionBootstrapToken(),
126 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), 122 sync_prefs_->GetKeystoreEncryptionBootstrapToken(),
127 std::unique_ptr<InternalComponentsFactory>( 123 std::unique_ptr<InternalComponentsFactory>(
128 new syncer::InternalComponentsFactoryImpl(factory_switches)), 124 new InternalComponentsFactoryImpl(factory_switches)),
129 unrecoverable_error_handler, report_unrecoverable_error_function, 125 unrecoverable_error_handler, report_unrecoverable_error_function,
130 std::move(saved_nigori_state), invalidation_versions)); 126 std::move(saved_nigori_state), invalidation_versions));
131 InitCore(std::move(init_opts)); 127 InitCore(std::move(init_opts));
132 } 128 }
133 129
134 void SyncBackendHostImpl::TriggerRefresh(const syncer::ModelTypeSet& types) { 130 void SyncBackendHostImpl::TriggerRefresh(const ModelTypeSet& types) {
135 DCHECK(ui_thread_->BelongsToCurrentThread()); 131 DCHECK(ui_thread_->BelongsToCurrentThread());
136 registrar_->sync_thread()->task_runner()->PostTask( 132 registrar_->sync_thread()->task_runner()->PostTask(
137 FROM_HERE, 133 FROM_HERE,
138 base::Bind(&SyncBackendHostCore::DoRefreshTypes, core_, types)); 134 base::Bind(&SyncBackendHostCore::DoRefreshTypes, core_, types));
139 } 135 }
140 136
141 void SyncBackendHostImpl::UpdateCredentials( 137 void SyncBackendHostImpl::UpdateCredentials(
142 const syncer::SyncCredentials& credentials) { 138 const SyncCredentials& credentials) {
143 DCHECK(registrar_->sync_thread()->IsRunning()); 139 DCHECK(registrar_->sync_thread()->IsRunning());
144 registrar_->sync_thread()->task_runner()->PostTask( 140 registrar_->sync_thread()->task_runner()->PostTask(
145 FROM_HERE, base::Bind(&SyncBackendHostCore::DoUpdateCredentials, 141 FROM_HERE, base::Bind(&SyncBackendHostCore::DoUpdateCredentials,
146 core_, credentials)); 142 core_, credentials));
147 } 143 }
148 144
149 void SyncBackendHostImpl::StartSyncingWithServer() { 145 void SyncBackendHostImpl::StartSyncingWithServer() {
150 SDVLOG(1) << "SyncBackendHostImpl::StartSyncingWithServer called."; 146 SDVLOG(1) << "SyncBackendHostImpl::StartSyncingWithServer called.";
151 147
152 syncer::ModelSafeRoutingInfo routing_info; 148 ModelSafeRoutingInfo routing_info;
153 registrar_->GetModelSafeRoutingInfo(&routing_info); 149 registrar_->GetModelSafeRoutingInfo(&routing_info);
154 150
155 registrar_->sync_thread()->task_runner()->PostTask( 151 registrar_->sync_thread()->task_runner()->PostTask(
156 FROM_HERE, base::Bind(&SyncBackendHostCore::DoStartSyncing, core_, 152 FROM_HERE, base::Bind(&SyncBackendHostCore::DoStartSyncing, core_,
157 routing_info, sync_prefs_->GetLastPollTime())); 153 routing_info, sync_prefs_->GetLastPollTime()));
158 } 154 }
159 155
160 void SyncBackendHostImpl::SetEncryptionPassphrase(const std::string& passphrase, 156 void SyncBackendHostImpl::SetEncryptionPassphrase(const std::string& passphrase,
161 bool is_explicit) { 157 bool is_explicit) {
162 DCHECK(registrar_->sync_thread()->IsRunning()); 158 DCHECK(registrar_->sync_thread()->IsRunning());
163 if (!IsNigoriEnabled()) { 159 if (!IsNigoriEnabled()) {
164 NOTREACHED() << "SetEncryptionPassphrase must never be called when nigori" 160 NOTREACHED() << "SetEncryptionPassphrase must never be called when nigori"
165 " is disabled."; 161 " is disabled.";
166 return; 162 return;
167 } 163 }
168 164
169 // We should never be called with an empty passphrase. 165 // We should never be called with an empty passphrase.
170 DCHECK(!passphrase.empty()); 166 DCHECK(!passphrase.empty());
171 167
172 // This should only be called by the frontend. 168 // This should only be called by the frontend.
173 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); 169 DCHECK(frontend_task_runner_->BelongsToCurrentThread());
174 170
175 // SetEncryptionPassphrase should never be called if we are currently 171 // SetEncryptionPassphrase should never be called if we are currently
176 // encrypted with an explicit passphrase. 172 // encrypted with an explicit passphrase.
177 DCHECK( 173 DCHECK(cached_passphrase_type_ == PassphraseType::KEYSTORE_PASSPHRASE ||
178 cached_passphrase_type_ == syncer::PassphraseType::KEYSTORE_PASSPHRASE || 174 cached_passphrase_type_ == PassphraseType::IMPLICIT_PASSPHRASE);
179 cached_passphrase_type_ == syncer::PassphraseType::IMPLICIT_PASSPHRASE);
180 175
181 // Post an encryption task on the syncer thread. 176 // Post an encryption task on the syncer thread.
182 registrar_->sync_thread()->task_runner()->PostTask( 177 registrar_->sync_thread()->task_runner()->PostTask(
183 FROM_HERE, base::Bind(&SyncBackendHostCore::DoSetEncryptionPassphrase, 178 FROM_HERE, base::Bind(&SyncBackendHostCore::DoSetEncryptionPassphrase,
184 core_, passphrase, is_explicit)); 179 core_, passphrase, is_explicit));
185 } 180 }
186 181
187 bool SyncBackendHostImpl::SetDecryptionPassphrase( 182 bool SyncBackendHostImpl::SetDecryptionPassphrase(
188 const std::string& passphrase) { 183 const std::string& passphrase) {
189 if (!IsNigoriEnabled()) { 184 if (!IsNigoriEnabled()) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 frontend_ = NULL; 227 frontend_ = NULL;
233 228
234 DCHECK(registrar_->sync_thread()->IsRunning()); 229 DCHECK(registrar_->sync_thread()->IsRunning());
235 230
236 registrar_->RequestWorkerStopOnUIThread(); 231 registrar_->RequestWorkerStopOnUIThread();
237 232
238 core_->ShutdownOnUIThread(); 233 core_->ShutdownOnUIThread();
239 } 234 }
240 235
241 std::unique_ptr<base::Thread> SyncBackendHostImpl::Shutdown( 236 std::unique_ptr<base::Thread> SyncBackendHostImpl::Shutdown(
242 syncer::ShutdownReason reason) { 237 ShutdownReason reason) {
243 // StopSyncingForShutdown() (which nulls out |frontend_|) should be 238 // StopSyncingForShutdown() (which nulls out |frontend_|) should be
244 // called first. 239 // called first.
245 DCHECK(!frontend_); 240 DCHECK(!frontend_);
246 DCHECK(registrar_->sync_thread()->IsRunning()); 241 DCHECK(registrar_->sync_thread()->IsRunning());
247 242
248 bool sync_thread_claimed = (reason != syncer::BROWSER_SHUTDOWN); 243 bool sync_thread_claimed = (reason != BROWSER_SHUTDOWN);
249 244
250 if (invalidation_handler_registered_) { 245 if (invalidation_handler_registered_) {
251 if (reason == syncer::DISABLE_SYNC) { 246 if (reason == DISABLE_SYNC) {
252 UnregisterInvalidationIds(); 247 UnregisterInvalidationIds();
253 } 248 }
254 invalidator_->UnregisterInvalidationHandler(this); 249 invalidator_->UnregisterInvalidationHandler(this);
255 invalidator_ = NULL; 250 invalidator_ = NULL;
256 } 251 }
257 invalidation_handler_registered_ = false; 252 invalidation_handler_registered_ = false;
258 253
259 model_type_connector_.reset(); 254 model_type_connector_.reset();
260 255
261 // Shut down and destroy sync manager. 256 // Shut down and destroy sync manager.
262 registrar_->sync_thread()->task_runner()->PostTask( 257 registrar_->sync_thread()->task_runner()->PostTask(
263 FROM_HERE, 258 FROM_HERE,
264 base::Bind(&SyncBackendHostCore::DoShutdown, core_, reason)); 259 base::Bind(&SyncBackendHostCore::DoShutdown, core_, reason));
265 core_ = NULL; 260 core_ = NULL;
266 261
267 // Worker cleanup. 262 // Worker cleanup.
268 SyncBackendRegistrar* detached_registrar = registrar_.release(); 263 SyncBackendRegistrar* detached_registrar = registrar_.release();
269 detached_registrar->sync_thread()->task_runner()->PostTask( 264 detached_registrar->sync_thread()->task_runner()->PostTask(
270 FROM_HERE, base::Bind(&SyncBackendRegistrar::Shutdown, 265 FROM_HERE, base::Bind(&SyncBackendRegistrar::Shutdown,
271 base::Unretained(detached_registrar))); 266 base::Unretained(detached_registrar)));
272 267
273 if (sync_thread_claimed) 268 if (sync_thread_claimed)
274 return detached_registrar->ReleaseSyncThread(); 269 return detached_registrar->ReleaseSyncThread();
275 else 270 else
276 return std::unique_ptr<base::Thread>(); 271 return std::unique_ptr<base::Thread>();
277 } 272 }
278 273
279 void SyncBackendHostImpl::UnregisterInvalidationIds() { 274 void SyncBackendHostImpl::UnregisterInvalidationIds() {
280 if (invalidation_handler_registered_) { 275 if (invalidation_handler_registered_) {
281 CHECK(invalidator_->UpdateRegisteredInvalidationIds(this, 276 CHECK(invalidator_->UpdateRegisteredInvalidationIds(this, ObjectIdSet()));
282 syncer::ObjectIdSet()));
283 } 277 }
284 } 278 }
285 279
286 syncer::ModelTypeSet SyncBackendHostImpl::ConfigureDataTypes( 280 ModelTypeSet SyncBackendHostImpl::ConfigureDataTypes(
287 syncer::ConfigureReason reason, 281 ConfigureReason reason,
288 const DataTypeConfigStateMap& config_state_map, 282 const DataTypeConfigStateMap& config_state_map,
289 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& 283 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task,
290 ready_task,
291 const base::Callback<void()>& retry_callback) { 284 const base::Callback<void()>& retry_callback) {
292 // Only one configure is allowed at a time. This is guaranteed by our 285 // Only one configure is allowed at a time. This is guaranteed by our
293 // callers. The SyncBackendHostImpl requests one configure as the backend is 286 // callers. The SyncBackendHostImpl requests one configure as the backend is
294 // initializing and waits for it to complete. After initialization, all 287 // initializing and waits for it to complete. After initialization, all
295 // configurations will pass through the DataTypeManager, which is careful to 288 // configurations will pass through the DataTypeManager, which is careful to
296 // never send a new configure request until the current request succeeds. 289 // never send a new configure request until the current request succeeds.
297 290
298 // The SyncBackendRegistrar's routing info will be updated by adding the 291 // The SyncBackendRegistrar's routing info will be updated by adding the
299 // types_to_add to the list then removing types_to_remove. Any types which 292 // types_to_add to the list then removing types_to_remove. Any types which
300 // are not in either of those sets will remain untouched. 293 // are not in either of those sets will remain untouched.
301 // 294 //
302 // Types which were not in the list previously are not fully downloaded, so we 295 // Types which were not in the list previously are not fully downloaded, so we
303 // must ask the syncer to download them. Any newly supported datatypes will 296 // must ask the syncer to download them. Any newly supported datatypes will
304 // not have been in that routing info list, so they will be among the types 297 // not have been in that routing info list, so they will be among the types
305 // downloaded if they are enabled. 298 // downloaded if they are enabled.
306 // 299 //
307 // The SyncBackendRegistrar's state was initially derived from the types 300 // The SyncBackendRegistrar's state was initially derived from the types
308 // detected to have been downloaded in the database. Afterwards it is 301 // detected to have been downloaded in the database. Afterwards it is
309 // modified only by this function. We expect it to remain in sync with the 302 // modified only by this function. We expect it to remain in sync with the
310 // backend because configuration requests are never aborted; they are retried 303 // backend because configuration requests are never aborted; they are retried
311 // until they succeed or the backend is shut down. 304 // until they succeed or the backend is shut down.
312 305
313 syncer::ModelTypeSet disabled_types = 306 ModelTypeSet disabled_types = GetDataTypesInState(DISABLED, config_state_map);
314 GetDataTypesInState(DISABLED, config_state_map); 307 ModelTypeSet fatal_types = GetDataTypesInState(FATAL, config_state_map);
315 syncer::ModelTypeSet fatal_types = 308 ModelTypeSet crypto_types = GetDataTypesInState(CRYPTO, config_state_map);
316 GetDataTypesInState(FATAL, config_state_map); 309 ModelTypeSet unready_types = GetDataTypesInState(UNREADY, config_state_map);
317 syncer::ModelTypeSet crypto_types =
318 GetDataTypesInState(CRYPTO, config_state_map);
319 syncer::ModelTypeSet unready_types =
320 GetDataTypesInState(UNREADY, config_state_map);
321 310
322 disabled_types.PutAll(fatal_types); 311 disabled_types.PutAll(fatal_types);
323 disabled_types.PutAll(crypto_types); 312 disabled_types.PutAll(crypto_types);
324 disabled_types.PutAll(unready_types); 313 disabled_types.PutAll(unready_types);
325 314
326 syncer::ModelTypeSet active_types = 315 ModelTypeSet active_types =
327 GetDataTypesInState(CONFIGURE_ACTIVE, config_state_map); 316 GetDataTypesInState(CONFIGURE_ACTIVE, config_state_map);
328 syncer::ModelTypeSet clean_first_types = 317 ModelTypeSet clean_first_types =
329 GetDataTypesInState(CONFIGURE_CLEAN, config_state_map); 318 GetDataTypesInState(CONFIGURE_CLEAN, config_state_map);
330 syncer::ModelTypeSet types_to_download = registrar_->ConfigureDataTypes( 319 ModelTypeSet types_to_download = registrar_->ConfigureDataTypes(
331 syncer::Union(active_types, clean_first_types), disabled_types); 320 Union(active_types, clean_first_types), disabled_types);
332 types_to_download.PutAll(clean_first_types); 321 types_to_download.PutAll(clean_first_types);
333 types_to_download.RemoveAll(syncer::ProxyTypes()); 322 types_to_download.RemoveAll(ProxyTypes());
334 if (!types_to_download.Empty()) 323 if (!types_to_download.Empty())
335 types_to_download.Put(syncer::NIGORI); 324 types_to_download.Put(NIGORI);
336 325
337 // TODO(sync): crbug.com/137550. 326 // TODO(sync): crbug.com/137550.
338 // It's dangerous to configure types that have progress markers. Types with 327 // It's dangerous to configure types that have progress markers. Types with
339 // progress markers can trigger a MIGRATION_DONE response. We are not 328 // progress markers can trigger a MIGRATION_DONE response. We are not
340 // prepared to handle a migration during a configure, so we must ensure that 329 // prepared to handle a migration during a configure, so we must ensure that
341 // all our types_to_download actually contain no data before we sync them. 330 // all our types_to_download actually contain no data before we sync them.
342 // 331 //
343 // One common way to end up in this situation used to be types which 332 // One common way to end up in this situation used to be types which
344 // downloaded some or all of their data but have not applied it yet. We avoid 333 // downloaded some or all of their data but have not applied it yet. We avoid
345 // problems with those types by purging the data of any such partially synced 334 // problems with those types by purging the data of any such partially synced
346 // types soon after we load the directory. 335 // types soon after we load the directory.
347 // 336 //
348 // Another possible scenario is that we have newly supported or newly enabled 337 // Another possible scenario is that we have newly supported or newly enabled
349 // data types being downloaded here but the nigori type, which is always 338 // data types being downloaded here but the nigori type, which is always
350 // included in any GetUpdates request, requires migration. The server has 339 // included in any GetUpdates request, requires migration. The server has
351 // code to detect this scenario based on the configure reason, the fact that 340 // code to detect this scenario based on the configure reason, the fact that
352 // the nigori type is the only requested type which requires migration, and 341 // the nigori type is the only requested type which requires migration, and
353 // that the requested types list includes at least one non-nigori type. It 342 // that the requested types list includes at least one non-nigori type. It
354 // will not send a MIGRATION_DONE response in that case. We still need to be 343 // will not send a MIGRATION_DONE response in that case. We still need to be
355 // careful to not send progress markers for non-nigori types, though. If a 344 // careful to not send progress markers for non-nigori types, though. If a
356 // non-nigori type in the request requires migration, a MIGRATION_DONE 345 // non-nigori type in the request requires migration, a MIGRATION_DONE
357 // response will be sent. 346 // response will be sent.
358 347
359 syncer::ModelSafeRoutingInfo routing_info; 348 ModelSafeRoutingInfo routing_info;
360 registrar_->GetModelSafeRoutingInfo(&routing_info); 349 registrar_->GetModelSafeRoutingInfo(&routing_info);
361 350
362 syncer::ModelTypeSet current_types = registrar_->GetLastConfiguredTypes(); 351 ModelTypeSet current_types = registrar_->GetLastConfiguredTypes();
363 syncer::ModelTypeSet types_to_purge = 352 ModelTypeSet types_to_purge = Difference(ModelTypeSet::All(), current_types);
364 syncer::Difference(syncer::ModelTypeSet::All(), current_types); 353 ModelTypeSet inactive_types =
365 syncer::ModelTypeSet inactive_types =
366 GetDataTypesInState(CONFIGURE_INACTIVE, config_state_map); 354 GetDataTypesInState(CONFIGURE_INACTIVE, config_state_map);
367 types_to_purge.RemoveAll(inactive_types); 355 types_to_purge.RemoveAll(inactive_types);
368 types_to_purge.RemoveAll(unready_types); 356 types_to_purge.RemoveAll(unready_types);
369 357
370 // If a type has already been disabled and unapplied or journaled, it will 358 // If a type has already been disabled and unapplied or journaled, it will
371 // not be part of the |types_to_purge| set, and therefore does not need 359 // not be part of the |types_to_purge| set, and therefore does not need
372 // to be acted on again. 360 // to be acted on again.
373 fatal_types.RetainAll(types_to_purge); 361 fatal_types.RetainAll(types_to_purge);
374 syncer::ModelTypeSet unapply_types = 362 ModelTypeSet unapply_types = Union(crypto_types, clean_first_types);
375 syncer::Union(crypto_types, clean_first_types);
376 unapply_types.RetainAll(types_to_purge); 363 unapply_types.RetainAll(types_to_purge);
377 364
378 DCHECK(syncer::Intersection(current_types, fatal_types).Empty()); 365 DCHECK(Intersection(current_types, fatal_types).Empty());
379 DCHECK(syncer::Intersection(current_types, crypto_types).Empty()); 366 DCHECK(Intersection(current_types, crypto_types).Empty());
380 DCHECK(current_types.HasAll(types_to_download)); 367 DCHECK(current_types.HasAll(types_to_download));
381 368
382 SDVLOG(1) << "Types " << syncer::ModelTypeSetToString(types_to_download) 369 SDVLOG(1) << "Types " << ModelTypeSetToString(types_to_download)
383 << " added; calling DoConfigureSyncer"; 370 << " added; calling DoConfigureSyncer";
384 // Divide up the types into their corresponding actions (each is mutually 371 // Divide up the types into their corresponding actions (each is mutually
385 // exclusive): 372 // exclusive):
386 // - Types which have just been added to the routing info (types_to_download): 373 // - Types which have just been added to the routing info (types_to_download):
387 // are downloaded. 374 // are downloaded.
388 // - Types which have encountered a fatal error (fatal_types) are deleted 375 // - Types which have encountered a fatal error (fatal_types) are deleted
389 // from the directory and journaled in the delete journal. 376 // from the directory and journaled in the delete journal.
390 // - Types which have encountered a cryptographer error (crypto_types) are 377 // - Types which have encountered a cryptographer error (crypto_types) are
391 // unapplied (local state is purged but sync state is not). 378 // unapplied (local state is purged but sync state is not).
392 // - All other types not in the routing info (types just disabled) are deleted 379 // - All other types not in the routing info (types just disabled) are deleted
393 // from the directory. 380 // from the directory.
394 // - Everything else (enabled types and already disabled types) is not 381 // - Everything else (enabled types and already disabled types) is not
395 // touched. 382 // touched.
396 RequestConfigureSyncer(reason, types_to_download, types_to_purge, fatal_types, 383 RequestConfigureSyncer(reason, types_to_download, types_to_purge, fatal_types,
397 unapply_types, inactive_types, routing_info, 384 unapply_types, inactive_types, routing_info,
398 ready_task, retry_callback); 385 ready_task, retry_callback);
399 386
400 DCHECK(syncer::Intersection(active_types, types_to_purge).Empty()); 387 DCHECK(Intersection(active_types, types_to_purge).Empty());
401 DCHECK(syncer::Intersection(active_types, fatal_types).Empty()); 388 DCHECK(Intersection(active_types, fatal_types).Empty());
402 DCHECK(syncer::Intersection(active_types, unapply_types).Empty()); 389 DCHECK(Intersection(active_types, unapply_types).Empty());
403 DCHECK(syncer::Intersection(active_types, inactive_types).Empty()); 390 DCHECK(Intersection(active_types, inactive_types).Empty());
404 return syncer::Difference(active_types, types_to_download); 391 return Difference(active_types, types_to_download);
405 } 392 }
406 393
407 void SyncBackendHostImpl::EnableEncryptEverything() { 394 void SyncBackendHostImpl::EnableEncryptEverything() {
408 registrar_->sync_thread()->task_runner()->PostTask( 395 registrar_->sync_thread()->task_runner()->PostTask(
409 FROM_HERE, 396 FROM_HERE,
410 base::Bind(&SyncBackendHostCore::DoEnableEncryptEverything, core_)); 397 base::Bind(&SyncBackendHostCore::DoEnableEncryptEverything, core_));
411 } 398 }
412 399
413 void SyncBackendHostImpl::ActivateDirectoryDataType( 400 void SyncBackendHostImpl::ActivateDirectoryDataType(
414 syncer::ModelType type, 401 ModelType type,
415 syncer::ModelSafeGroup group, 402 ModelSafeGroup group,
416 sync_driver::ChangeProcessor* change_processor) { 403 ChangeProcessor* change_processor) {
417 registrar_->ActivateDataType(type, group, change_processor, GetUserShare()); 404 registrar_->ActivateDataType(type, group, change_processor, GetUserShare());
418 } 405 }
419 406
420 void SyncBackendHostImpl::DeactivateDirectoryDataType(syncer::ModelType type) { 407 void SyncBackendHostImpl::DeactivateDirectoryDataType(ModelType type) {
421 registrar_->DeactivateDataType(type); 408 registrar_->DeactivateDataType(type);
422 } 409 }
423 410
424 void SyncBackendHostImpl::ActivateNonBlockingDataType( 411 void SyncBackendHostImpl::ActivateNonBlockingDataType(
425 syncer::ModelType type, 412 ModelType type,
426 std::unique_ptr<syncer_v2::ActivationContext> activation_context) { 413 std::unique_ptr<ActivationContext> activation_context) {
427 registrar_->RegisterNonBlockingType(type); 414 registrar_->RegisterNonBlockingType(type);
428 if (activation_context->data_type_state.initial_sync_done()) 415 if (activation_context->data_type_state.initial_sync_done())
429 registrar_->AddRestoredNonBlockingType(type); 416 registrar_->AddRestoredNonBlockingType(type);
430 model_type_connector_->ConnectType(type, std::move(activation_context)); 417 model_type_connector_->ConnectType(type, std::move(activation_context));
431 } 418 }
432 419
433 void SyncBackendHostImpl::DeactivateNonBlockingDataType( 420 void SyncBackendHostImpl::DeactivateNonBlockingDataType(ModelType type) {
434 syncer::ModelType type) {
435 model_type_connector_->DisconnectType(type); 421 model_type_connector_->DisconnectType(type);
436 } 422 }
437 423
438 syncer::UserShare* SyncBackendHostImpl::GetUserShare() const { 424 UserShare* SyncBackendHostImpl::GetUserShare() const {
439 return core_->sync_manager()->GetUserShare(); 425 return core_->sync_manager()->GetUserShare();
440 } 426 }
441 427
442 SyncBackendHostImpl::Status SyncBackendHostImpl::GetDetailedStatus() { 428 SyncBackendHostImpl::Status SyncBackendHostImpl::GetDetailedStatus() {
443 DCHECK(initialized()); 429 DCHECK(initialized());
444 return core_->sync_manager()->GetDetailedStatus(); 430 return core_->sync_manager()->GetDetailedStatus();
445 } 431 }
446 432
447 syncer::SyncCycleSnapshot SyncBackendHostImpl::GetLastCycleSnapshot() const { 433 SyncCycleSnapshot SyncBackendHostImpl::GetLastCycleSnapshot() const {
448 return last_snapshot_; 434 return last_snapshot_;
449 } 435 }
450 436
451 bool SyncBackendHostImpl::HasUnsyncedItems() const { 437 bool SyncBackendHostImpl::HasUnsyncedItems() const {
452 DCHECK(initialized()); 438 DCHECK(initialized());
453 return core_->sync_manager()->HasUnsyncedItems(); 439 return core_->sync_manager()->HasUnsyncedItems();
454 } 440 }
455 441
456 bool SyncBackendHostImpl::IsNigoriEnabled() const { 442 bool SyncBackendHostImpl::IsNigoriEnabled() const {
457 return registrar_.get() && registrar_->IsNigoriEnabled(); 443 return registrar_.get() && registrar_->IsNigoriEnabled();
458 } 444 }
459 445
460 syncer::PassphraseType SyncBackendHostImpl::GetPassphraseType() const { 446 PassphraseType SyncBackendHostImpl::GetPassphraseType() const {
461 return cached_passphrase_type_; 447 return cached_passphrase_type_;
462 } 448 }
463 449
464 base::Time SyncBackendHostImpl::GetExplicitPassphraseTime() const { 450 base::Time SyncBackendHostImpl::GetExplicitPassphraseTime() const {
465 return cached_explicit_passphrase_time_; 451 return cached_explicit_passphrase_time_;
466 } 452 }
467 453
468 bool SyncBackendHostImpl::IsCryptographerReady( 454 bool SyncBackendHostImpl::IsCryptographerReady(
469 const syncer::BaseTransaction* trans) const { 455 const BaseTransaction* trans) const {
470 return initialized() && trans->GetCryptographer() && 456 return initialized() && trans->GetCryptographer() &&
471 trans->GetCryptographer()->is_ready(); 457 trans->GetCryptographer()->is_ready();
472 } 458 }
473 459
474 void SyncBackendHostImpl::GetModelSafeRoutingInfo( 460 void SyncBackendHostImpl::GetModelSafeRoutingInfo(
475 syncer::ModelSafeRoutingInfo* out) const { 461 ModelSafeRoutingInfo* out) const {
476 if (initialized()) { 462 if (initialized()) {
477 CHECK(registrar_.get()); 463 CHECK(registrar_.get());
478 registrar_->GetModelSafeRoutingInfo(out); 464 registrar_->GetModelSafeRoutingInfo(out);
479 } else { 465 } else {
480 NOTREACHED(); 466 NOTREACHED();
481 } 467 }
482 } 468 }
483 469
484 void SyncBackendHostImpl::FlushDirectory() const { 470 void SyncBackendHostImpl::FlushDirectory() const {
485 DCHECK(initialized()); 471 DCHECK(initialized());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 } 504 }
519 505
520 void SyncBackendHostImpl::InitCore( 506 void SyncBackendHostImpl::InitCore(
521 std::unique_ptr<DoInitializeOptions> options) { 507 std::unique_ptr<DoInitializeOptions> options) {
522 registrar_->sync_thread()->task_runner()->PostTask( 508 registrar_->sync_thread()->task_runner()->PostTask(
523 FROM_HERE, base::Bind(&SyncBackendHostCore::DoInitialize, core_, 509 FROM_HERE, base::Bind(&SyncBackendHostCore::DoInitialize, core_,
524 base::Passed(&options))); 510 base::Passed(&options)));
525 } 511 }
526 512
527 void SyncBackendHostImpl::RequestConfigureSyncer( 513 void SyncBackendHostImpl::RequestConfigureSyncer(
528 syncer::ConfigureReason reason, 514 ConfigureReason reason,
529 syncer::ModelTypeSet to_download, 515 ModelTypeSet to_download,
530 syncer::ModelTypeSet to_purge, 516 ModelTypeSet to_purge,
531 syncer::ModelTypeSet to_journal, 517 ModelTypeSet to_journal,
532 syncer::ModelTypeSet to_unapply, 518 ModelTypeSet to_unapply,
533 syncer::ModelTypeSet to_ignore, 519 ModelTypeSet to_ignore,
534 const syncer::ModelSafeRoutingInfo& routing_info, 520 const ModelSafeRoutingInfo& routing_info,
535 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& 521 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task,
536 ready_task,
537 const base::Closure& retry_callback) { 522 const base::Closure& retry_callback) {
538 DoConfigureSyncerTypes config_types; 523 DoConfigureSyncerTypes config_types;
539 config_types.to_download = to_download; 524 config_types.to_download = to_download;
540 config_types.to_purge = to_purge; 525 config_types.to_purge = to_purge;
541 config_types.to_journal = to_journal; 526 config_types.to_journal = to_journal;
542 config_types.to_unapply = to_unapply; 527 config_types.to_unapply = to_unapply;
543 registrar_->sync_thread()->task_runner()->PostTask( 528 registrar_->sync_thread()->task_runner()->PostTask(
544 FROM_HERE, 529 FROM_HERE,
545 base::Bind(&SyncBackendHostCore::DoConfigureSyncer, core_, reason, 530 base::Bind(&SyncBackendHostCore::DoConfigureSyncer, core_, reason,
546 config_types, routing_info, ready_task, retry_callback)); 531 config_types, routing_info, ready_task, retry_callback));
547 } 532 }
548 533
549 void SyncBackendHostImpl::FinishConfigureDataTypesOnFrontendLoop( 534 void SyncBackendHostImpl::FinishConfigureDataTypesOnFrontendLoop(
550 const syncer::ModelTypeSet enabled_types, 535 const ModelTypeSet enabled_types,
551 const syncer::ModelTypeSet succeeded_configuration_types, 536 const ModelTypeSet succeeded_configuration_types,
552 const syncer::ModelTypeSet failed_configuration_types, 537 const ModelTypeSet failed_configuration_types,
553 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& 538 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task) {
554 ready_task) {
555 if (!frontend_) 539 if (!frontend_)
556 return; 540 return;
557 541
558 if (invalidator_) { 542 if (invalidator_) {
559 CHECK(invalidator_->UpdateRegisteredInvalidationIds( 543 CHECK(invalidator_->UpdateRegisteredInvalidationIds(
560 this, ModelTypeSetToObjectIdSet(enabled_types))); 544 this, ModelTypeSetToObjectIdSet(enabled_types)));
561 } 545 }
562 546
563 if (!ready_task.is_null()) 547 if (!ready_task.is_null())
564 ready_task.Run(succeeded_configuration_types, failed_configuration_types); 548 ready_task.Run(succeeded_configuration_types, failed_configuration_types);
565 } 549 }
566 550
567 void SyncBackendHostImpl::AddExperimentalTypes() { 551 void SyncBackendHostImpl::AddExperimentalTypes() {
568 CHECK(initialized()); 552 CHECK(initialized());
569 syncer::Experiments experiments; 553 Experiments experiments;
570 if (core_->sync_manager()->ReceivedExperiment(&experiments)) 554 if (core_->sync_manager()->ReceivedExperiment(&experiments))
571 frontend_->OnExperimentsChanged(experiments); 555 frontend_->OnExperimentsChanged(experiments);
572 } 556 }
573 557
574 void SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop( 558 void SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop(
575 const syncer::WeakHandle<syncer::JsBackend> js_backend, 559 const WeakHandle<JsBackend> js_backend,
576 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener> 560 const WeakHandle<DataTypeDebugInfoListener> debug_info_listener,
577 debug_info_listener, 561 std::unique_ptr<ModelTypeConnector> model_type_connector,
578 std::unique_ptr<syncer_v2::ModelTypeConnector> model_type_connector,
579 const std::string& cache_guid) { 562 const std::string& cache_guid) {
580 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); 563 DCHECK(frontend_task_runner_->BelongsToCurrentThread());
581 564
582 model_type_connector_ = std::move(model_type_connector); 565 model_type_connector_ = std::move(model_type_connector);
583 566
584 if (!frontend_) 567 if (!frontend_)
585 return; 568 return;
586 569
587 initialized_ = true; 570 initialized_ = true;
588 571
(...skipping 12 matching lines...) Expand all
601 AddExperimentalTypes(); 584 AddExperimentalTypes();
602 frontend_->OnBackendInitialized(js_backend, debug_info_listener, cache_guid, 585 frontend_->OnBackendInitialized(js_backend, debug_info_listener, cache_guid,
603 true); 586 true);
604 } 587 }
605 588
606 void SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop() { 589 void SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop() {
607 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); 590 DCHECK(frontend_task_runner_->BelongsToCurrentThread());
608 if (!frontend_) 591 if (!frontend_)
609 return; 592 return;
610 593
611 frontend_->OnBackendInitialized( 594 frontend_->OnBackendInitialized(WeakHandle<JsBackend>(),
612 syncer::WeakHandle<syncer::JsBackend>(), 595 WeakHandle<DataTypeDebugInfoListener>(), "",
613 syncer::WeakHandle<syncer::DataTypeDebugInfoListener>(), "", false); 596 false);
614 } 597 }
615 598
616 void SyncBackendHostImpl::HandleSyncCycleCompletedOnFrontendLoop( 599 void SyncBackendHostImpl::HandleSyncCycleCompletedOnFrontendLoop(
617 const syncer::SyncCycleSnapshot& snapshot) { 600 const SyncCycleSnapshot& snapshot) {
618 if (!frontend_) 601 if (!frontend_)
619 return; 602 return;
620 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); 603 DCHECK(frontend_task_runner_->BelongsToCurrentThread());
621 604
622 last_snapshot_ = snapshot; 605 last_snapshot_ = snapshot;
623 606
624 SDVLOG(1) << "Got snapshot " << snapshot.ToString(); 607 SDVLOG(1) << "Got snapshot " << snapshot.ToString();
625 608
626 if (!snapshot.poll_finish_time().is_null()) 609 if (!snapshot.poll_finish_time().is_null())
627 sync_prefs_->SetLastPollTime(snapshot.poll_finish_time()); 610 sync_prefs_->SetLastPollTime(snapshot.poll_finish_time());
628 611
629 // Process any changes to the datatypes we're syncing. 612 // Process any changes to the datatypes we're syncing.
630 // TODO(sync): add support for removing types. 613 // TODO(sync): add support for removing types.
631 if (initialized()) 614 if (initialized())
632 AddExperimentalTypes(); 615 AddExperimentalTypes();
633 616
634 if (initialized()) 617 if (initialized())
635 frontend_->OnSyncCycleCompleted(); 618 frontend_->OnSyncCycleCompleted();
636 } 619 }
637 620
638 void SyncBackendHostImpl::RetryConfigurationOnFrontendLoop( 621 void SyncBackendHostImpl::RetryConfigurationOnFrontendLoop(
639 const base::Closure& retry_callback) { 622 const base::Closure& retry_callback) {
640 SDVLOG(1) << "Failed to complete configuration, informing of retry."; 623 SDVLOG(1) << "Failed to complete configuration, informing of retry.";
641 retry_callback.Run(); 624 retry_callback.Run();
642 } 625 }
643 626
644 void SyncBackendHostImpl::PersistEncryptionBootstrapToken( 627 void SyncBackendHostImpl::PersistEncryptionBootstrapToken(
645 const std::string& token, 628 const std::string& token,
646 syncer::BootstrapTokenType token_type) { 629 BootstrapTokenType token_type) {
647 CHECK(sync_prefs_.get()); 630 CHECK(sync_prefs_.get());
648 if (token_type == syncer::PASSPHRASE_BOOTSTRAP_TOKEN) 631 if (token_type == PASSPHRASE_BOOTSTRAP_TOKEN)
649 sync_prefs_->SetEncryptionBootstrapToken(token); 632 sync_prefs_->SetEncryptionBootstrapToken(token);
650 else 633 else
651 sync_prefs_->SetKeystoreEncryptionBootstrapToken(token); 634 sync_prefs_->SetKeystoreEncryptionBootstrapToken(token);
652 } 635 }
653 636
654 void SyncBackendHostImpl::HandleActionableErrorEventOnFrontendLoop( 637 void SyncBackendHostImpl::HandleActionableErrorEventOnFrontendLoop(
655 const syncer::SyncProtocolError& sync_error) { 638 const SyncProtocolError& sync_error) {
656 if (!frontend_) 639 if (!frontend_)
657 return; 640 return;
658 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); 641 DCHECK(frontend_task_runner_->BelongsToCurrentThread());
659 frontend_->OnActionableError(sync_error); 642 frontend_->OnActionableError(sync_error);
660 } 643 }
661 644
662 void SyncBackendHostImpl::HandleMigrationRequestedOnFrontendLoop( 645 void SyncBackendHostImpl::HandleMigrationRequestedOnFrontendLoop(
663 syncer::ModelTypeSet types) { 646 ModelTypeSet types) {
664 if (!frontend_) 647 if (!frontend_)
665 return; 648 return;
666 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); 649 DCHECK(frontend_task_runner_->BelongsToCurrentThread());
667 frontend_->OnMigrationNeededForTypes(types); 650 frontend_->OnMigrationNeededForTypes(types);
668 } 651 }
669 652
670 void SyncBackendHostImpl::OnInvalidatorStateChange( 653 void SyncBackendHostImpl::OnInvalidatorStateChange(InvalidatorState state) {
671 syncer::InvalidatorState state) {
672 registrar_->sync_thread()->task_runner()->PostTask( 654 registrar_->sync_thread()->task_runner()->PostTask(
673 FROM_HERE, base::Bind(&SyncBackendHostCore::DoOnInvalidatorStateChange, 655 FROM_HERE, base::Bind(&SyncBackendHostCore::DoOnInvalidatorStateChange,
674 core_, state)); 656 core_, state));
675 } 657 }
676 658
677 void SyncBackendHostImpl::OnIncomingInvalidation( 659 void SyncBackendHostImpl::OnIncomingInvalidation(
678 const syncer::ObjectIdInvalidationMap& invalidation_map) { 660 const ObjectIdInvalidationMap& invalidation_map) {
679 registrar_->sync_thread()->task_runner()->PostTask( 661 registrar_->sync_thread()->task_runner()->PostTask(
680 FROM_HERE, base::Bind(&SyncBackendHostCore::DoOnIncomingInvalidation, 662 FROM_HERE, base::Bind(&SyncBackendHostCore::DoOnIncomingInvalidation,
681 core_, invalidation_map)); 663 core_, invalidation_map));
682 } 664 }
683 665
684 std::string SyncBackendHostImpl::GetOwnerName() const { 666 std::string SyncBackendHostImpl::GetOwnerName() const {
685 return "SyncBackendHostImpl"; 667 return "SyncBackendHostImpl";
686 } 668 }
687 669
688 bool SyncBackendHostImpl::CheckPassphraseAgainstCachedPendingKeys( 670 bool SyncBackendHostImpl::CheckPassphraseAgainstCachedPendingKeys(
689 const std::string& passphrase) const { 671 const std::string& passphrase) const {
690 DCHECK(cached_pending_keys_.has_blob()); 672 DCHECK(cached_pending_keys_.has_blob());
691 DCHECK(!passphrase.empty()); 673 DCHECK(!passphrase.empty());
692 syncer::Nigori nigori; 674 Nigori nigori;
693 nigori.InitByDerivation("localhost", "dummy", passphrase); 675 nigori.InitByDerivation("localhost", "dummy", passphrase);
694 std::string plaintext; 676 std::string plaintext;
695 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); 677 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext);
696 DVLOG_IF(1, result) << "Passphrase failed to decrypt pending keys."; 678 DVLOG_IF(1, result) << "Passphrase failed to decrypt pending keys.";
697 return result; 679 return result;
698 } 680 }
699 681
700 void SyncBackendHostImpl::NotifyPassphraseRequired( 682 void SyncBackendHostImpl::NotifyPassphraseRequired(
701 syncer::PassphraseRequiredReason reason, 683 PassphraseRequiredReason reason,
702 sync_pb::EncryptedData pending_keys) { 684 sync_pb::EncryptedData pending_keys) {
703 if (!frontend_) 685 if (!frontend_)
704 return; 686 return;
705 687
706 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); 688 DCHECK(frontend_task_runner_->BelongsToCurrentThread());
707 689
708 // Update our cache of the cryptographer's pending keys. 690 // Update our cache of the cryptographer's pending keys.
709 cached_pending_keys_ = pending_keys; 691 cached_pending_keys_ = pending_keys;
710 692
711 frontend_->OnPassphraseRequired(reason, pending_keys); 693 frontend_->OnPassphraseRequired(reason, pending_keys);
712 } 694 }
713 695
714 void SyncBackendHostImpl::NotifyPassphraseAccepted() { 696 void SyncBackendHostImpl::NotifyPassphraseAccepted() {
715 if (!frontend_) 697 if (!frontend_)
716 return; 698 return;
717 699
718 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); 700 DCHECK(frontend_task_runner_->BelongsToCurrentThread());
719 701
720 // Clear our cache of the cryptographer's pending keys. 702 // Clear our cache of the cryptographer's pending keys.
721 cached_pending_keys_.clear_blob(); 703 cached_pending_keys_.clear_blob();
722 frontend_->OnPassphraseAccepted(); 704 frontend_->OnPassphraseAccepted();
723 } 705 }
724 706
725 void SyncBackendHostImpl::NotifyEncryptedTypesChanged( 707 void SyncBackendHostImpl::NotifyEncryptedTypesChanged(
726 syncer::ModelTypeSet encrypted_types, 708 ModelTypeSet encrypted_types,
727 bool encrypt_everything) { 709 bool encrypt_everything) {
728 if (!frontend_) 710 if (!frontend_)
729 return; 711 return;
730 712
731 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); 713 DCHECK(frontend_task_runner_->BelongsToCurrentThread());
732 frontend_->OnEncryptedTypesChanged(encrypted_types, encrypt_everything); 714 frontend_->OnEncryptedTypesChanged(encrypted_types, encrypt_everything);
733 } 715 }
734 716
735 void SyncBackendHostImpl::NotifyEncryptionComplete() { 717 void SyncBackendHostImpl::NotifyEncryptionComplete() {
736 if (!frontend_) 718 if (!frontend_)
737 return; 719 return;
738 720
739 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); 721 DCHECK(frontend_task_runner_->BelongsToCurrentThread());
740 frontend_->OnEncryptionComplete(); 722 frontend_->OnEncryptionComplete();
741 } 723 }
742 724
743 void SyncBackendHostImpl::HandlePassphraseTypeChangedOnFrontendLoop( 725 void SyncBackendHostImpl::HandlePassphraseTypeChangedOnFrontendLoop(
744 syncer::PassphraseType type, 726 PassphraseType type,
745 base::Time explicit_passphrase_time) { 727 base::Time explicit_passphrase_time) {
746 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); 728 DCHECK(frontend_task_runner_->BelongsToCurrentThread());
747 DVLOG(1) << "Passphrase type changed to " 729 DVLOG(1) << "Passphrase type changed to " << PassphraseTypeToString(type);
748 << syncer::PassphraseTypeToString(type);
749 cached_passphrase_type_ = type; 730 cached_passphrase_type_ = type;
750 cached_explicit_passphrase_time_ = explicit_passphrase_time; 731 cached_explicit_passphrase_time_ = explicit_passphrase_time;
751 } 732 }
752 733
753 void SyncBackendHostImpl::HandleLocalSetPassphraseEncryptionOnFrontendLoop( 734 void SyncBackendHostImpl::HandleLocalSetPassphraseEncryptionOnFrontendLoop(
754 const syncer::SyncEncryptionHandler::NigoriState& nigori_state) { 735 const SyncEncryptionHandler::NigoriState& nigori_state) {
755 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); 736 DCHECK(frontend_task_runner_->BelongsToCurrentThread());
756 frontend_->OnLocalSetPassphraseEncryption(nigori_state); 737 frontend_->OnLocalSetPassphraseEncryption(nigori_state);
757 } 738 }
758 739
759 void SyncBackendHostImpl::HandleConnectionStatusChangeOnFrontendLoop( 740 void SyncBackendHostImpl::HandleConnectionStatusChangeOnFrontendLoop(
760 syncer::ConnectionStatus status) { 741 ConnectionStatus status) {
761 if (!frontend_) 742 if (!frontend_)
762 return; 743 return;
763 744
764 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); 745 DCHECK(frontend_task_runner_->BelongsToCurrentThread());
765 746
766 DVLOG(1) << "Connection status changed: " 747 DVLOG(1) << "Connection status changed: " << ConnectionStatusToString(status);
767 << syncer::ConnectionStatusToString(status);
768 frontend_->OnConnectionStatusChange(status); 748 frontend_->OnConnectionStatusChange(status);
769 } 749 }
770 750
771 void SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop( 751 void SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop(
772 std::unique_ptr<syncer::ProtocolEvent> event) { 752 std::unique_ptr<ProtocolEvent> event) {
773 if (!frontend_) 753 if (!frontend_)
774 return; 754 return;
775 frontend_->OnProtocolEvent(*event); 755 frontend_->OnProtocolEvent(*event);
776 } 756 }
777 757
778 void SyncBackendHostImpl::HandleDirectoryCommitCountersUpdatedOnFrontendLoop( 758 void SyncBackendHostImpl::HandleDirectoryCommitCountersUpdatedOnFrontendLoop(
779 syncer::ModelType type, 759 ModelType type,
780 const syncer::CommitCounters& counters) { 760 const CommitCounters& counters) {
781 if (!frontend_) 761 if (!frontend_)
782 return; 762 return;
783 frontend_->OnDirectoryTypeCommitCounterUpdated(type, counters); 763 frontend_->OnDirectoryTypeCommitCounterUpdated(type, counters);
784 } 764 }
785 765
786 void SyncBackendHostImpl::HandleDirectoryUpdateCountersUpdatedOnFrontendLoop( 766 void SyncBackendHostImpl::HandleDirectoryUpdateCountersUpdatedOnFrontendLoop(
787 syncer::ModelType type, 767 ModelType type,
788 const syncer::UpdateCounters& counters) { 768 const UpdateCounters& counters) {
789 if (!frontend_) 769 if (!frontend_)
790 return; 770 return;
791 frontend_->OnDirectoryTypeUpdateCounterUpdated(type, counters); 771 frontend_->OnDirectoryTypeUpdateCounterUpdated(type, counters);
792 } 772 }
793 773
794 void SyncBackendHostImpl::HandleDirectoryStatusCountersUpdatedOnFrontendLoop( 774 void SyncBackendHostImpl::HandleDirectoryStatusCountersUpdatedOnFrontendLoop(
795 syncer::ModelType type, 775 ModelType type,
796 const syncer::StatusCounters& counters) { 776 const StatusCounters& counters) {
797 if (!frontend_) 777 if (!frontend_)
798 return; 778 return;
799 frontend_->OnDirectoryTypeStatusCounterUpdated(type, counters); 779 frontend_->OnDirectoryTypeStatusCounterUpdated(type, counters);
800 } 780 }
801 781
802 void SyncBackendHostImpl::UpdateInvalidationVersions( 782 void SyncBackendHostImpl::UpdateInvalidationVersions(
803 const std::map<syncer::ModelType, int64_t>& invalidation_versions) { 783 const std::map<ModelType, int64_t>& invalidation_versions) {
804 sync_prefs_->UpdateInvalidationVersions(invalidation_versions); 784 sync_prefs_->UpdateInvalidationVersions(invalidation_versions);
805 } 785 }
806 786
807 base::MessageLoop* SyncBackendHostImpl::GetSyncLoopForTesting() { 787 base::MessageLoop* SyncBackendHostImpl::GetSyncLoopForTesting() {
808 return registrar_->sync_thread()->message_loop(); 788 return registrar_->sync_thread()->message_loop();
809 } 789 }
810 790
811 void SyncBackendHostImpl::RefreshTypesForTest(syncer::ModelTypeSet types) { 791 void SyncBackendHostImpl::RefreshTypesForTest(ModelTypeSet types) {
812 DCHECK(ui_thread_->BelongsToCurrentThread()); 792 DCHECK(ui_thread_->BelongsToCurrentThread());
813 793
814 registrar_->sync_thread()->task_runner()->PostTask( 794 registrar_->sync_thread()->task_runner()->PostTask(
815 FROM_HERE, 795 FROM_HERE,
816 base::Bind(&SyncBackendHostCore::DoRefreshTypes, core_, types)); 796 base::Bind(&SyncBackendHostCore::DoRefreshTypes, core_, types));
817 } 797 }
818 798
819 void SyncBackendHostImpl::ClearServerData( 799 void SyncBackendHostImpl::ClearServerData(
820 const syncer::SyncManager::ClearServerDataCallback& callback) { 800 const SyncManager::ClearServerDataCallback& callback) {
821 DCHECK(ui_thread_->BelongsToCurrentThread()); 801 DCHECK(ui_thread_->BelongsToCurrentThread());
822 registrar_->sync_thread()->task_runner()->PostTask( 802 registrar_->sync_thread()->task_runner()->PostTask(
823 FROM_HERE, base::Bind(&SyncBackendHostCore::DoClearServerData, 803 FROM_HERE, base::Bind(&SyncBackendHostCore::DoClearServerData,
824 core_, callback)); 804 core_, callback));
825 } 805 }
826 806
827 void SyncBackendHostImpl::OnCookieJarChanged(bool account_mismatch, 807 void SyncBackendHostImpl::OnCookieJarChanged(bool account_mismatch,
828 bool empty_jar) { 808 bool empty_jar) {
829 DCHECK(ui_thread_->BelongsToCurrentThread()); 809 DCHECK(ui_thread_->BelongsToCurrentThread());
830 registrar_->sync_thread()->task_runner()->PostTask( 810 registrar_->sync_thread()->task_runner()->PostTask(
831 FROM_HERE, base::Bind(&SyncBackendHostCore::DoOnCookieJarChanged, 811 FROM_HERE, base::Bind(&SyncBackendHostCore::DoOnCookieJarChanged,
832 core_, account_mismatch, empty_jar)); 812 core_, account_mismatch, empty_jar));
833 } 813 }
834 814
835 void SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop( 815 void SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop(
836 const syncer::SyncManager::ClearServerDataCallback& frontend_callback) { 816 const SyncManager::ClearServerDataCallback& frontend_callback) {
837 DCHECK(ui_thread_->BelongsToCurrentThread()); 817 DCHECK(ui_thread_->BelongsToCurrentThread());
838 frontend_callback.Run(); 818 frontend_callback.Run();
839 } 819 }
840 820
841 } // namespace browser_sync 821 } // namespace syncer
842 822
843 #undef SDVLOG 823 #undef SDVLOG
844 824
845 #undef SLOG 825 #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