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