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_core.h" | 5 #include "components/sync/driver/glue/sync_backend_host_core.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "components/data_use_measurement/core/data_use_user_data.h" | 13 #include "components/data_use_measurement/core/data_use_user_data.h" |
14 #include "components/invalidation/public/invalidation_util.h" | 14 #include "components/invalidation/public/invalidation_util.h" |
15 #include "components/invalidation/public/object_id_invalidation_map.h" | 15 #include "components/invalidation/public/object_id_invalidation_map.h" |
16 #include "components/sync/core/http_post_provider_factory.h" | 16 #include "components/sync/core/http_post_provider_factory.h" |
17 #include "components/sync/core/internal_components_factory.h" | 17 #include "components/sync/core/internal_components_factory.h" |
18 #include "components/sync/core/sync_manager.h" | 18 #include "components/sync/core/sync_manager.h" |
19 #include "components/sync/core/sync_manager_factory.h" | 19 #include "components/sync/core/sync_manager_factory.h" |
| 20 #include "components/sync/driver/glue/sync_backend_registrar.h" |
| 21 #include "components/sync/driver/invalidation_adapter.h" |
| 22 #include "components/sync/driver/local_device_info_provider_impl.h" |
20 #include "components/sync/engine/events/protocol_event.h" | 23 #include "components/sync/engine/events/protocol_event.h" |
21 #include "components/sync/sessions/commit_counters.h" | 24 #include "components/sync/sessions/commit_counters.h" |
22 #include "components/sync/sessions/status_counters.h" | 25 #include "components/sync/sessions/status_counters.h" |
23 #include "components/sync/sessions/sync_session_snapshot.h" | 26 #include "components/sync/sessions/sync_session_snapshot.h" |
24 #include "components/sync/sessions/update_counters.h" | 27 #include "components/sync/sessions/update_counters.h" |
25 #include "components/sync_driver/glue/sync_backend_registrar.h" | |
26 #include "components/sync_driver/invalidation_adapter.h" | |
27 #include "components/sync_driver/local_device_info_provider_impl.h" | |
28 #include "url/gurl.h" | 28 #include "url/gurl.h" |
29 | 29 |
30 // Helper macros to log with the syncer thread name; useful when there | 30 // Helper macros to log with the syncer thread name; useful when there |
31 // are multiple syncers involved. | 31 // are multiple syncers involved. |
32 | 32 |
33 #define SLOG(severity) LOG(severity) << name_ << ": " | 33 #define SLOG(severity) LOG(severity) << name_ << ": " |
34 | 34 |
35 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " | 35 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " |
36 | 36 |
37 static const int kSaveChangesIntervalSeconds = 10; | 37 static const int kSaveChangesIntervalSeconds = 10; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 SyncBackendHostCore::~SyncBackendHostCore() { | 128 SyncBackendHostCore::~SyncBackendHostCore() { |
129 DCHECK(!sync_manager_.get()); | 129 DCHECK(!sync_manager_.get()); |
130 } | 130 } |
131 | 131 |
132 void SyncBackendHostCore::OnSyncCycleCompleted( | 132 void SyncBackendHostCore::OnSyncCycleCompleted( |
133 const syncer::sessions::SyncSessionSnapshot& snapshot) { | 133 const syncer::sessions::SyncSessionSnapshot& snapshot) { |
134 if (!sync_loop_) | 134 if (!sync_loop_) |
135 return; | 135 return; |
136 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 136 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
137 | 137 |
138 host_.Call( | 138 host_.Call(FROM_HERE, |
139 FROM_HERE, | 139 &SyncBackendHostImpl::HandleSyncCycleCompletedOnFrontendLoop, |
140 &SyncBackendHostImpl::HandleSyncCycleCompletedOnFrontendLoop, | 140 snapshot); |
141 snapshot); | |
142 } | 141 } |
143 | 142 |
144 void SyncBackendHostCore::DoRefreshTypes(syncer::ModelTypeSet types) { | 143 void SyncBackendHostCore::DoRefreshTypes(syncer::ModelTypeSet types) { |
145 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 144 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
146 sync_manager_->RefreshTypes(types); | 145 sync_manager_->RefreshTypes(types); |
147 } | 146 } |
148 | 147 |
149 void SyncBackendHostCore::OnInitializationComplete( | 148 void SyncBackendHostCore::OnInitializationComplete( |
150 const syncer::WeakHandle<syncer::JsBackend>& js_backend, | 149 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
151 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 150 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
(...skipping 28 matching lines...) Expand all Loading... |
180 | 179 |
181 // Before proceeding any further, we need to download the control types and | 180 // Before proceeding any further, we need to download the control types and |
182 // purge any partial data (ie. data downloaded for a type that was on its way | 181 // purge any partial data (ie. data downloaded for a type that was on its way |
183 // to being initially synced, but didn't quite make it.). The following | 182 // to being initially synced, but didn't quite make it.). The following |
184 // configure cycle will take care of this. It depends on the registrar state | 183 // configure cycle will take care of this. It depends on the registrar state |
185 // which we initialize below to ensure that we don't perform any downloads if | 184 // which we initialize below to ensure that we don't perform any downloads if |
186 // all control types have already completed their initial sync. | 185 // all control types have already completed their initial sync. |
187 registrar_->SetInitialTypes(restored_types); | 186 registrar_->SetInitialTypes(restored_types); |
188 | 187 |
189 syncer::ConfigureReason reason = | 188 syncer::ConfigureReason reason = |
190 restored_types.Empty() ? | 189 restored_types.Empty() ? syncer::CONFIGURE_REASON_NEW_CLIENT |
191 syncer::CONFIGURE_REASON_NEW_CLIENT : | 190 : syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE; |
192 syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE; | |
193 | 191 |
194 syncer::ModelTypeSet new_control_types = registrar_->ConfigureDataTypes( | 192 syncer::ModelTypeSet new_control_types = registrar_->ConfigureDataTypes( |
195 syncer::ControlTypes(), syncer::ModelTypeSet()); | 193 syncer::ControlTypes(), syncer::ModelTypeSet()); |
196 syncer::ModelSafeRoutingInfo routing_info; | 194 syncer::ModelSafeRoutingInfo routing_info; |
197 registrar_->GetModelSafeRoutingInfo(&routing_info); | 195 registrar_->GetModelSafeRoutingInfo(&routing_info); |
198 SDVLOG(1) << "Control Types " | 196 SDVLOG(1) << "Control Types " |
199 << syncer::ModelTypeSetToString(new_control_types) | 197 << syncer::ModelTypeSetToString(new_control_types) |
200 << " added; calling ConfigureSyncer"; | 198 << " added; calling ConfigureSyncer"; |
201 | 199 |
202 syncer::ModelTypeSet types_to_purge = | 200 syncer::ModelTypeSet types_to_purge = syncer::Difference( |
203 syncer::Difference(syncer::ModelTypeSet::All(), | 201 syncer::ModelTypeSet::All(), GetRoutingInfoTypes(routing_info)); |
204 GetRoutingInfoTypes(routing_info)); | |
205 | 202 |
206 sync_manager_->ConfigureSyncer( | 203 sync_manager_->ConfigureSyncer( |
207 reason, | 204 reason, new_control_types, types_to_purge, syncer::ModelTypeSet(), |
208 new_control_types, | 205 syncer::ModelTypeSet(), routing_info, |
209 types_to_purge, | |
210 syncer::ModelTypeSet(), | |
211 syncer::ModelTypeSet(), | |
212 routing_info, | |
213 base::Bind(&SyncBackendHostCore::DoInitialProcessControlTypes, | 206 base::Bind(&SyncBackendHostCore::DoInitialProcessControlTypes, |
214 weak_ptr_factory_.GetWeakPtr()), | 207 weak_ptr_factory_.GetWeakPtr()), |
215 base::Closure()); | 208 base::Closure()); |
216 } | 209 } |
217 | 210 |
218 void SyncBackendHostCore::OnConnectionStatusChange( | 211 void SyncBackendHostCore::OnConnectionStatusChange( |
219 syncer::ConnectionStatus status) { | 212 syncer::ConnectionStatus status) { |
220 if (!sync_loop_) | 213 if (!sync_loop_) |
221 return; | 214 return; |
222 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 215 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
223 host_.Call( | 216 host_.Call(FROM_HERE, |
224 FROM_HERE, | 217 &SyncBackendHostImpl::HandleConnectionStatusChangeOnFrontendLoop, |
225 &SyncBackendHostImpl::HandleConnectionStatusChangeOnFrontendLoop, status); | 218 status); |
226 } | 219 } |
227 | 220 |
228 void SyncBackendHostCore::OnPassphraseRequired( | 221 void SyncBackendHostCore::OnPassphraseRequired( |
229 syncer::PassphraseRequiredReason reason, | 222 syncer::PassphraseRequiredReason reason, |
230 const sync_pb::EncryptedData& pending_keys) { | 223 const sync_pb::EncryptedData& pending_keys) { |
231 if (!sync_loop_) | 224 if (!sync_loop_) |
232 return; | 225 return; |
233 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 226 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
234 host_.Call( | 227 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyPassphraseRequired, reason, |
235 FROM_HERE, | 228 pending_keys); |
236 &SyncBackendHostImpl::NotifyPassphraseRequired, reason, pending_keys); | |
237 } | 229 } |
238 | 230 |
239 void SyncBackendHostCore::OnPassphraseAccepted() { | 231 void SyncBackendHostCore::OnPassphraseAccepted() { |
240 if (!sync_loop_) | 232 if (!sync_loop_) |
241 return; | 233 return; |
242 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 234 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
243 host_.Call( | 235 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyPassphraseAccepted); |
244 FROM_HERE, | |
245 &SyncBackendHostImpl::NotifyPassphraseAccepted); | |
246 } | 236 } |
247 | 237 |
248 void SyncBackendHostCore::OnBootstrapTokenUpdated( | 238 void SyncBackendHostCore::OnBootstrapTokenUpdated( |
249 const std::string& bootstrap_token, | 239 const std::string& bootstrap_token, |
250 syncer::BootstrapTokenType type) { | 240 syncer::BootstrapTokenType type) { |
251 if (!sync_loop_) | 241 if (!sync_loop_) |
252 return; | 242 return; |
253 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 243 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
254 host_.Call(FROM_HERE, | 244 host_.Call(FROM_HERE, &SyncBackendHostImpl::PersistEncryptionBootstrapToken, |
255 &SyncBackendHostImpl::PersistEncryptionBootstrapToken, | 245 bootstrap_token, type); |
256 bootstrap_token, | |
257 type); | |
258 } | 246 } |
259 | 247 |
260 void SyncBackendHostCore::OnEncryptedTypesChanged( | 248 void SyncBackendHostCore::OnEncryptedTypesChanged( |
261 syncer::ModelTypeSet encrypted_types, | 249 syncer::ModelTypeSet encrypted_types, |
262 bool encrypt_everything) { | 250 bool encrypt_everything) { |
263 if (!sync_loop_) | 251 if (!sync_loop_) |
264 return; | 252 return; |
265 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 253 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
266 // NOTE: We're in a transaction. | 254 // NOTE: We're in a transaction. |
267 host_.Call( | 255 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyEncryptedTypesChanged, |
268 FROM_HERE, | 256 encrypted_types, encrypt_everything); |
269 &SyncBackendHostImpl::NotifyEncryptedTypesChanged, | |
270 encrypted_types, encrypt_everything); | |
271 } | 257 } |
272 | 258 |
273 void SyncBackendHostCore::OnEncryptionComplete() { | 259 void SyncBackendHostCore::OnEncryptionComplete() { |
274 if (!sync_loop_) | 260 if (!sync_loop_) |
275 return; | 261 return; |
276 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 262 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
277 // NOTE: We're in a transaction. | 263 // NOTE: We're in a transaction. |
278 host_.Call( | 264 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyEncryptionComplete); |
279 FROM_HERE, | |
280 &SyncBackendHostImpl::NotifyEncryptionComplete); | |
281 } | 265 } |
282 | 266 |
283 void SyncBackendHostCore::OnCryptographerStateChanged( | 267 void SyncBackendHostCore::OnCryptographerStateChanged( |
284 syncer::Cryptographer* cryptographer) { | 268 syncer::Cryptographer* cryptographer) { |
285 // Do nothing. | 269 // Do nothing. |
286 } | 270 } |
287 | 271 |
288 void SyncBackendHostCore::OnPassphraseTypeChanged( | 272 void SyncBackendHostCore::OnPassphraseTypeChanged(syncer::PassphraseType type, |
289 syncer::PassphraseType type, base::Time passphrase_time) { | 273 base::Time passphrase_time) { |
290 host_.Call( | 274 host_.Call(FROM_HERE, |
291 FROM_HERE, | 275 &SyncBackendHostImpl::HandlePassphraseTypeChangedOnFrontendLoop, |
292 &SyncBackendHostImpl::HandlePassphraseTypeChangedOnFrontendLoop, | 276 type, passphrase_time); |
293 type, passphrase_time); | |
294 } | 277 } |
295 | 278 |
296 void SyncBackendHostCore::OnLocalSetPassphraseEncryption( | 279 void SyncBackendHostCore::OnLocalSetPassphraseEncryption( |
297 const syncer::SyncEncryptionHandler::NigoriState& nigori_state) { | 280 const syncer::SyncEncryptionHandler::NigoriState& nigori_state) { |
298 host_.Call( | 281 host_.Call( |
299 FROM_HERE, | 282 FROM_HERE, |
300 &SyncBackendHostImpl::HandleLocalSetPassphraseEncryptionOnFrontendLoop, | 283 &SyncBackendHostImpl::HandleLocalSetPassphraseEncryptionOnFrontendLoop, |
301 nigori_state); | 284 nigori_state); |
302 } | 285 } |
303 | 286 |
(...skipping 22 matching lines...) Expand all Loading... |
326 FROM_HERE, | 309 FROM_HERE, |
327 &SyncBackendHostImpl::HandleDirectoryStatusCountersUpdatedOnFrontendLoop, | 310 &SyncBackendHostImpl::HandleDirectoryStatusCountersUpdatedOnFrontendLoop, |
328 type, counters); | 311 type, counters); |
329 } | 312 } |
330 | 313 |
331 void SyncBackendHostCore::OnActionableError( | 314 void SyncBackendHostCore::OnActionableError( |
332 const syncer::SyncProtocolError& sync_error) { | 315 const syncer::SyncProtocolError& sync_error) { |
333 if (!sync_loop_) | 316 if (!sync_loop_) |
334 return; | 317 return; |
335 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 318 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
336 host_.Call( | 319 host_.Call(FROM_HERE, |
337 FROM_HERE, | 320 &SyncBackendHostImpl::HandleActionableErrorEventOnFrontendLoop, |
338 &SyncBackendHostImpl::HandleActionableErrorEventOnFrontendLoop, | 321 sync_error); |
339 sync_error); | |
340 } | 322 } |
341 | 323 |
342 void SyncBackendHostCore::OnMigrationRequested(syncer::ModelTypeSet types) { | 324 void SyncBackendHostCore::OnMigrationRequested(syncer::ModelTypeSet types) { |
343 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 325 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
344 host_.Call( | 326 host_.Call(FROM_HERE, |
345 FROM_HERE, | 327 &SyncBackendHostImpl::HandleMigrationRequestedOnFrontendLoop, |
346 &SyncBackendHostImpl::HandleMigrationRequestedOnFrontendLoop, | 328 types); |
347 types); | |
348 } | 329 } |
349 | 330 |
350 void SyncBackendHostCore::OnProtocolEvent( | 331 void SyncBackendHostCore::OnProtocolEvent(const syncer::ProtocolEvent& event) { |
351 const syncer::ProtocolEvent& event) { | |
352 // TODO(rlarocque): Find a way to pass event_clone as a scoped_ptr. | 332 // TODO(rlarocque): Find a way to pass event_clone as a scoped_ptr. |
353 if (forward_protocol_events_) { | 333 if (forward_protocol_events_) { |
354 std::unique_ptr<syncer::ProtocolEvent> event_clone(event.Clone()); | 334 std::unique_ptr<syncer::ProtocolEvent> event_clone(event.Clone()); |
355 host_.Call( | 335 host_.Call(FROM_HERE, |
356 FROM_HERE, | 336 &SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop, |
357 &SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop, | 337 event_clone.release()); |
358 event_clone.release()); | |
359 } | 338 } |
360 } | 339 } |
361 | 340 |
362 void SyncBackendHostCore::DoOnInvalidatorStateChange( | 341 void SyncBackendHostCore::DoOnInvalidatorStateChange( |
363 syncer::InvalidatorState state) { | 342 syncer::InvalidatorState state) { |
364 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 343 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
365 sync_manager_->SetInvalidatorEnabled(state == syncer::INVALIDATIONS_ENABLED); | 344 sync_manager_->SetInvalidatorEnabled(state == syncer::INVALIDATIONS_ENABLED); |
366 } | 345 } |
367 | 346 |
368 void SyncBackendHostCore::DoOnIncomingInvalidation( | 347 void SyncBackendHostCore::DoOnIncomingInvalidation( |
(...skipping 22 matching lines...) Expand all Loading... |
391 } | 370 } |
392 std::unique_ptr<syncer::InvalidationInterface> inv_adapter( | 371 std::unique_ptr<syncer::InvalidationInterface> inv_adapter( |
393 new InvalidationAdapter(invalidation)); | 372 new InvalidationAdapter(invalidation)); |
394 sync_manager_->OnIncomingInvalidation(type, std::move(inv_adapter)); | 373 sync_manager_->OnIncomingInvalidation(type, std::move(inv_adapter)); |
395 if (!invalidation.is_unknown_version()) | 374 if (!invalidation.is_unknown_version()) |
396 last_invalidation_versions_[type] = invalidation.version(); | 375 last_invalidation_versions_[type] = invalidation.version(); |
397 } | 376 } |
398 } | 377 } |
399 } | 378 } |
400 | 379 |
401 host_.Call( | 380 host_.Call(FROM_HERE, &SyncBackendHostImpl::UpdateInvalidationVersions, |
402 FROM_HERE, | 381 last_invalidation_versions_); |
403 &SyncBackendHostImpl::UpdateInvalidationVersions, | |
404 last_invalidation_versions_); | |
405 } | 382 } |
406 | 383 |
407 void SyncBackendHostCore::DoInitialize( | 384 void SyncBackendHostCore::DoInitialize( |
408 std::unique_ptr<DoInitializeOptions> options) { | 385 std::unique_ptr<DoInitializeOptions> options) { |
409 DCHECK(!sync_loop_); | 386 DCHECK(!sync_loop_); |
410 sync_loop_ = options->sync_loop; | 387 sync_loop_ = options->sync_loop; |
411 DCHECK(sync_loop_); | 388 DCHECK(sync_loop_); |
412 | 389 |
413 // Finish initializing the HttpBridgeFactory. We do this here because | 390 // Finish initializing the HttpBridgeFactory. We do this here because |
414 // building the user agent may block on some platforms. | 391 // building the user agent may block on some platforms. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 const syncer::ModelSafeRoutingInfo& routing_info, | 454 const syncer::ModelSafeRoutingInfo& routing_info, |
478 base::Time last_poll_time) { | 455 base::Time last_poll_time) { |
479 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 456 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
480 sync_manager_->StartSyncingNormally(routing_info, last_poll_time); | 457 sync_manager_->StartSyncingNormally(routing_info, last_poll_time); |
481 } | 458 } |
482 | 459 |
483 void SyncBackendHostCore::DoSetEncryptionPassphrase( | 460 void SyncBackendHostCore::DoSetEncryptionPassphrase( |
484 const std::string& passphrase, | 461 const std::string& passphrase, |
485 bool is_explicit) { | 462 bool is_explicit) { |
486 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 463 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
487 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase( | 464 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase(passphrase, |
488 passphrase, is_explicit); | 465 is_explicit); |
489 } | 466 } |
490 | 467 |
491 void SyncBackendHostCore::DoInitialProcessControlTypes() { | 468 void SyncBackendHostCore::DoInitialProcessControlTypes() { |
492 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 469 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
493 | 470 |
494 DVLOG(1) << "Initilalizing Control Types"; | 471 DVLOG(1) << "Initilalizing Control Types"; |
495 | 472 |
496 // Initialize encryption. | 473 // Initialize encryption. |
497 sync_manager_->GetEncryptionHandler()->Init(); | 474 sync_manager_->GetEncryptionHandler()->Init(); |
498 | 475 |
499 // Note: experiments are currently handled via SBH::AddExperimentalTypes, | 476 // Note: experiments are currently handled via SBH::AddExperimentalTypes, |
500 // which is called at the end of every sync cycle. | 477 // which is called at the end of every sync cycle. |
501 // TODO(zea): eventually add an experiment handler and initialize it here. | 478 // TODO(zea): eventually add an experiment handler and initialize it here. |
502 | 479 |
503 if (!sync_manager_->GetUserShare()) { // NULL in some tests. | 480 if (!sync_manager_->GetUserShare()) { // NULL in some tests. |
504 DVLOG(1) << "Skipping initialization of DeviceInfo"; | 481 DVLOG(1) << "Skipping initialization of DeviceInfo"; |
505 host_.Call( | 482 host_.Call(FROM_HERE, |
506 FROM_HERE, | 483 &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop); |
507 &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop); | |
508 return; | 484 return; |
509 } | 485 } |
510 | 486 |
511 if (!sync_manager_->InitialSyncEndedTypes().HasAll(syncer::ControlTypes())) { | 487 if (!sync_manager_->InitialSyncEndedTypes().HasAll(syncer::ControlTypes())) { |
512 LOG(ERROR) << "Failed to download control types"; | 488 LOG(ERROR) << "Failed to download control types"; |
513 host_.Call( | 489 host_.Call(FROM_HERE, |
514 FROM_HERE, | 490 &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop); |
515 &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop); | |
516 return; | 491 return; |
517 } | 492 } |
518 | 493 |
519 host_.Call(FROM_HERE, | 494 host_.Call(FROM_HERE, |
520 &SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop, | 495 &SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop, |
521 js_backend_, debug_info_listener_, | 496 js_backend_, debug_info_listener_, |
522 base::Passed(sync_manager_->GetModelTypeConnectorProxy()), | 497 base::Passed(sync_manager_->GetModelTypeConnectorProxy()), |
523 sync_manager_->cache_guid()); | 498 sync_manager_->cache_guid()); |
524 | 499 |
525 js_backend_.Reset(); | 500 js_backend_.Reset(); |
526 debug_info_listener_.Reset(); | 501 debug_info_listener_.Reset(); |
527 } | 502 } |
528 | 503 |
529 void SyncBackendHostCore::DoSetDecryptionPassphrase( | 504 void SyncBackendHostCore::DoSetDecryptionPassphrase( |
530 const std::string& passphrase) { | 505 const std::string& passphrase) { |
531 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 506 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
532 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase( | 507 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase(passphrase); |
533 passphrase); | |
534 } | 508 } |
535 | 509 |
536 void SyncBackendHostCore::DoEnableEncryptEverything() { | 510 void SyncBackendHostCore::DoEnableEncryptEverything() { |
537 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 511 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
538 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything(); | 512 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything(); |
539 } | 513 } |
540 | 514 |
541 void SyncBackendHostCore::ShutdownOnUIThread() { | 515 void SyncBackendHostCore::ShutdownOnUIThread() { |
542 // This will cut short any blocking network tasks, cut short any in-progress | 516 // This will cut short any blocking network tasks, cut short any in-progress |
543 // sync cycles, and prevent the creation of new blocking network tasks and new | 517 // sync cycles, and prevent the creation of new blocking network tasks and new |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 sync_manager_->RemoveObserver(this); | 555 sync_manager_->RemoveObserver(this); |
582 sync_manager_->ShutdownOnSyncThread(reason); | 556 sync_manager_->ShutdownOnSyncThread(reason); |
583 sync_manager_.reset(); | 557 sync_manager_.reset(); |
584 } | 558 } |
585 } | 559 } |
586 | 560 |
587 void SyncBackendHostCore::DoConfigureSyncer( | 561 void SyncBackendHostCore::DoConfigureSyncer( |
588 syncer::ConfigureReason reason, | 562 syncer::ConfigureReason reason, |
589 const DoConfigureSyncerTypes& config_types, | 563 const DoConfigureSyncerTypes& config_types, |
590 const syncer::ModelSafeRoutingInfo routing_info, | 564 const syncer::ModelSafeRoutingInfo routing_info, |
591 const base::Callback<void(syncer::ModelTypeSet, | 565 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& |
592 syncer::ModelTypeSet)>& ready_task, | 566 ready_task, |
593 const base::Closure& retry_callback) { | 567 const base::Closure& retry_callback) { |
594 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 568 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
595 DCHECK(!ready_task.is_null()); | 569 DCHECK(!ready_task.is_null()); |
596 DCHECK(!retry_callback.is_null()); | 570 DCHECK(!retry_callback.is_null()); |
597 base::Closure chained_ready_task( | 571 base::Closure chained_ready_task(base::Bind( |
598 base::Bind(&SyncBackendHostCore::DoFinishConfigureDataTypes, | 572 &SyncBackendHostCore::DoFinishConfigureDataTypes, |
599 weak_ptr_factory_.GetWeakPtr(), | 573 weak_ptr_factory_.GetWeakPtr(), config_types.to_download, ready_task)); |
600 config_types.to_download, | |
601 ready_task)); | |
602 base::Closure chained_retry_task( | 574 base::Closure chained_retry_task( |
603 base::Bind(&SyncBackendHostCore::DoRetryConfiguration, | 575 base::Bind(&SyncBackendHostCore::DoRetryConfiguration, |
604 weak_ptr_factory_.GetWeakPtr(), | 576 weak_ptr_factory_.GetWeakPtr(), retry_callback)); |
605 retry_callback)); | 577 sync_manager_->ConfigureSyncer(reason, config_types.to_download, |
606 sync_manager_->ConfigureSyncer(reason, | 578 config_types.to_purge, config_types.to_journal, |
607 config_types.to_download, | 579 config_types.to_unapply, routing_info, |
608 config_types.to_purge, | 580 chained_ready_task, chained_retry_task); |
609 config_types.to_journal, | |
610 config_types.to_unapply, | |
611 routing_info, | |
612 chained_ready_task, | |
613 chained_retry_task); | |
614 } | 581 } |
615 | 582 |
616 void SyncBackendHostCore::DoFinishConfigureDataTypes( | 583 void SyncBackendHostCore::DoFinishConfigureDataTypes( |
617 syncer::ModelTypeSet types_to_config, | 584 syncer::ModelTypeSet types_to_config, |
618 const base::Callback<void(syncer::ModelTypeSet, | 585 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& |
619 syncer::ModelTypeSet)>& ready_task) { | 586 ready_task) { |
620 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 587 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
621 | 588 |
622 // Update the enabled types for the bridge and sync manager. | 589 // Update the enabled types for the bridge and sync manager. |
623 syncer::ModelSafeRoutingInfo routing_info; | 590 syncer::ModelSafeRoutingInfo routing_info; |
624 registrar_->GetModelSafeRoutingInfo(&routing_info); | 591 registrar_->GetModelSafeRoutingInfo(&routing_info); |
625 syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); | 592 syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); |
626 enabled_types.RemoveAll(syncer::ProxyTypes()); | 593 enabled_types.RemoveAll(syncer::ProxyTypes()); |
627 | 594 |
628 const syncer::ModelTypeSet failed_configuration_types = | 595 const syncer::ModelTypeSet failed_configuration_types = |
629 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes()); | 596 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes()); |
630 const syncer::ModelTypeSet succeeded_configuration_types = | 597 const syncer::ModelTypeSet succeeded_configuration_types = |
631 Difference(types_to_config, failed_configuration_types); | 598 Difference(types_to_config, failed_configuration_types); |
632 host_.Call(FROM_HERE, | 599 host_.Call(FROM_HERE, |
633 &SyncBackendHostImpl::FinishConfigureDataTypesOnFrontendLoop, | 600 &SyncBackendHostImpl::FinishConfigureDataTypesOnFrontendLoop, |
634 enabled_types, | 601 enabled_types, succeeded_configuration_types, |
635 succeeded_configuration_types, | 602 failed_configuration_types, ready_task); |
636 failed_configuration_types, | |
637 ready_task); | |
638 } | 603 } |
639 | 604 |
640 void SyncBackendHostCore::DoRetryConfiguration( | 605 void SyncBackendHostCore::DoRetryConfiguration( |
641 const base::Closure& retry_callback) { | 606 const base::Closure& retry_callback) { |
642 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 607 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
643 host_.Call(FROM_HERE, | 608 host_.Call(FROM_HERE, &SyncBackendHostImpl::RetryConfigurationOnFrontendLoop, |
644 &SyncBackendHostImpl::RetryConfigurationOnFrontendLoop, | |
645 retry_callback); | 609 retry_callback); |
646 } | 610 } |
647 | 611 |
648 void SyncBackendHostCore::SendBufferedProtocolEventsAndEnableForwarding() { | 612 void SyncBackendHostCore::SendBufferedProtocolEventsAndEnableForwarding() { |
649 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 613 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
650 forward_protocol_events_ = true; | 614 forward_protocol_events_ = true; |
651 | 615 |
652 if (sync_manager_) { | 616 if (sync_manager_) { |
653 // Grab our own copy of the buffered events. | 617 // Grab our own copy of the buffered events. |
654 // The buffer is not modified by this operation. | 618 // The buffer is not modified by this operation. |
655 std::vector<syncer::ProtocolEvent*> buffered_events; | 619 std::vector<syncer::ProtocolEvent*> buffered_events; |
656 sync_manager_->GetBufferedProtocolEvents().release(&buffered_events); | 620 sync_manager_->GetBufferedProtocolEvents().release(&buffered_events); |
657 | 621 |
658 // Send them all over the fence to the host. | 622 // Send them all over the fence to the host. |
659 for (std::vector<syncer::ProtocolEvent*>::iterator it = | 623 for (std::vector<syncer::ProtocolEvent*>::iterator it = |
660 buffered_events.begin(); it != buffered_events.end(); ++it) { | 624 buffered_events.begin(); |
| 625 it != buffered_events.end(); ++it) { |
661 // TODO(rlarocque): Make it explicit that host_ takes ownership. | 626 // TODO(rlarocque): Make it explicit that host_ takes ownership. |
662 host_.Call( | 627 host_.Call(FROM_HERE, |
663 FROM_HERE, | 628 &SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop, *it); |
664 &SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop, | |
665 *it); | |
666 } | 629 } |
667 } | 630 } |
668 } | 631 } |
669 | 632 |
670 void SyncBackendHostCore::DisableProtocolEventForwarding() { | 633 void SyncBackendHostCore::DisableProtocolEventForwarding() { |
671 forward_protocol_events_ = false; | 634 forward_protocol_events_ = false; |
672 } | 635 } |
673 | 636 |
674 void SyncBackendHostCore::EnableDirectoryTypeDebugInfoForwarding() { | 637 void SyncBackendHostCore::EnableDirectoryTypeDebugInfoForwarding() { |
675 DCHECK(sync_manager_); | 638 DCHECK(sync_manager_); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 types_vector.push_back(it.Get()); | 680 types_vector.push_back(it.Get()); |
718 if (!enabled_types.Has(it.Get())) { | 681 if (!enabled_types.Has(it.Get())) { |
719 node_lists.push_back(new base::ListValue()); | 682 node_lists.push_back(new base::ListValue()); |
720 } else { | 683 } else { |
721 node_lists.push_back( | 684 node_lists.push_back( |
722 sync_manager_->GetAllNodesForType(it.Get()).release()); | 685 sync_manager_->GetAllNodesForType(it.Get()).release()); |
723 } | 686 } |
724 } | 687 } |
725 | 688 |
726 task_runner->PostTask( | 689 task_runner->PostTask( |
727 FROM_HERE, | 690 FROM_HERE, base::Bind(callback, types_vector, base::Passed(&node_lists))); |
728 base::Bind(callback, types_vector, base::Passed(&node_lists))); | |
729 } | 691 } |
730 | 692 |
731 void SyncBackendHostCore::StartSavingChanges() { | 693 void SyncBackendHostCore::StartSavingChanges() { |
732 // We may already be shut down. | 694 // We may already be shut down. |
733 if (!sync_loop_) | 695 if (!sync_loop_) |
734 return; | 696 return; |
735 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 697 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
736 DCHECK(!save_changes_timer_.get()); | 698 DCHECK(!save_changes_timer_.get()); |
737 save_changes_timer_.reset(new base::RepeatingTimer()); | 699 save_changes_timer_.reset(new base::RepeatingTimer()); |
738 save_changes_timer_->Start(FROM_HERE, | 700 save_changes_timer_->Start( |
739 base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds), | 701 FROM_HERE, base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds), |
740 this, &SyncBackendHostCore::SaveChanges); | 702 this, &SyncBackendHostCore::SaveChanges); |
741 } | 703 } |
742 | 704 |
743 void SyncBackendHostCore::SaveChanges() { | 705 void SyncBackendHostCore::SaveChanges() { |
744 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 706 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
745 sync_manager_->SaveChanges(); | 707 sync_manager_->SaveChanges(); |
746 } | 708 } |
747 | 709 |
748 void SyncBackendHostCore::DoClearServerData( | 710 void SyncBackendHostCore::DoClearServerData( |
749 const syncer::SyncManager::ClearServerDataCallback& frontend_callback) { | 711 const syncer::SyncManager::ClearServerDataCallback& frontend_callback) { |
(...skipping 10 matching lines...) Expand all Loading... |
760 sync_manager_->OnCookieJarChanged(account_mismatch, empty_jar); | 722 sync_manager_->OnCookieJarChanged(account_mismatch, empty_jar); |
761 } | 723 } |
762 | 724 |
763 void SyncBackendHostCore::ClearServerDataDone( | 725 void SyncBackendHostCore::ClearServerDataDone( |
764 const base::Closure& frontend_callback) { | 726 const base::Closure& frontend_callback) { |
765 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); | 727 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
766 host_.Call(FROM_HERE, &SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop, | 728 host_.Call(FROM_HERE, &SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop, |
767 frontend_callback); | 729 frontend_callback); |
768 } | 730 } |
769 | 731 |
770 | |
771 } // namespace browser_sync | 732 } // namespace browser_sync |
OLD | NEW |