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 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/feature_list.h" | 12 #include "base/feature_list.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
16 #include "components/invalidation/public/invalidation_service.h" | 16 #include "components/invalidation/public/invalidation_service.h" |
17 #include "components/invalidation/public/object_id_invalidation_map.h" | 17 #include "components/invalidation/public/object_id_invalidation_map.h" |
18 #include "components/signin/core/browser/signin_client.h" | 18 #include "components/signin/core/browser/signin_client.h" |
19 #include "components/sync/base/experiments.h" | 19 #include "components/sync/base/experiments.h" |
20 #include "components/sync/base/sync_string_conversions.h" | 20 #include "components/sync/base/sync_string_conversions.h" |
21 #include "components/sync/core/activation_context.h" | 21 #include "components/sync/core/activation_context.h" |
22 #include "components/sync/core/base_transaction.h" | 22 #include "components/sync/core/base_transaction.h" |
23 #include "components/sync/core/http_bridge.h" | 23 #include "components/sync/core/http_bridge.h" |
24 #include "components/sync/core/internal_components_factory.h" | 24 #include "components/sync/core/internal_components_factory.h" |
25 #include "components/sync/core/internal_components_factory_impl.h" | 25 #include "components/sync/core/internal_components_factory_impl.h" |
26 #include "components/sync/core/sync_manager.h" | 26 #include "components/sync/core/sync_manager.h" |
27 #include "components/sync/core/sync_manager_factory.h" | 27 #include "components/sync/core/sync_manager_factory.h" |
| 28 #include "components/sync/driver/glue/sync_backend_host_core.h" |
| 29 #include "components/sync/driver/glue/sync_backend_registrar.h" |
| 30 #include "components/sync/driver/invalidation_helper.h" |
| 31 #include "components/sync/driver/sync_client.h" |
| 32 #include "components/sync/driver/sync_driver_switches.h" |
| 33 #include "components/sync/driver/sync_frontend.h" |
| 34 #include "components/sync/driver/sync_prefs.h" |
28 #include "components/sync/engine/events/protocol_event.h" | 35 #include "components/sync/engine/events/protocol_event.h" |
29 #include "components/sync_driver/glue/sync_backend_host_core.h" | |
30 #include "components/sync_driver/glue/sync_backend_registrar.h" | |
31 #include "components/sync_driver/invalidation_helper.h" | |
32 #include "components/sync_driver/sync_client.h" | |
33 #include "components/sync_driver/sync_driver_switches.h" | |
34 #include "components/sync_driver/sync_frontend.h" | |
35 #include "components/sync_driver/sync_prefs.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 using syncer::InternalComponentsFactory; |
45 | 45 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> | 91 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> |
92 saved_nigori_state) { | 92 saved_nigori_state) { |
93 registrar_.reset(new browser_sync::SyncBackendRegistrar( | 93 registrar_.reset(new browser_sync::SyncBackendRegistrar( |
94 name_, sync_client_, std::move(sync_thread), ui_thread_, db_thread, | 94 name_, sync_client_, std::move(sync_thread), ui_thread_, db_thread, |
95 file_thread)); | 95 file_thread)); |
96 CHECK(registrar_->sync_thread()); | 96 CHECK(registrar_->sync_thread()); |
97 | 97 |
98 frontend_ = frontend; | 98 frontend_ = frontend; |
99 DCHECK(frontend); | 99 DCHECK(frontend); |
100 | 100 |
101 std::vector<scoped_refptr<syncer::ModelSafeWorker> > workers; | 101 std::vector<scoped_refptr<syncer::ModelSafeWorker>> workers; |
102 registrar_->GetWorkers(&workers); | 102 registrar_->GetWorkers(&workers); |
103 | 103 |
104 InternalComponentsFactory::Switches factory_switches = { | 104 InternalComponentsFactory::Switches factory_switches = { |
105 InternalComponentsFactory::ENCRYPTION_KEYSTORE, | 105 InternalComponentsFactory::ENCRYPTION_KEYSTORE, |
106 InternalComponentsFactory::BACKOFF_NORMAL | 106 InternalComponentsFactory::BACKOFF_NORMAL}; |
107 }; | |
108 | 107 |
109 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); | 108 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
110 if (cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) { | 109 if (cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) { |
111 factory_switches.backoff_override = | 110 factory_switches.backoff_override = |
112 InternalComponentsFactory::BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE; | 111 InternalComponentsFactory::BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE; |
113 } | 112 } |
114 if (cl->HasSwitch(switches::kSyncEnableGetUpdateAvoidance)) { | 113 if (cl->HasSwitch(switches::kSyncEnableGetUpdateAvoidance)) { |
115 factory_switches.pre_commit_updates_policy = | 114 factory_switches.pre_commit_updates_policy = |
116 InternalComponentsFactory::FORCE_ENABLE_PRE_COMMIT_UPDATE_AVOIDANCE; | 115 InternalComponentsFactory::FORCE_ENABLE_PRE_COMMIT_UPDATE_AVOIDANCE; |
117 } | 116 } |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 | 323 |
325 disabled_types.PutAll(fatal_types); | 324 disabled_types.PutAll(fatal_types); |
326 disabled_types.PutAll(crypto_types); | 325 disabled_types.PutAll(crypto_types); |
327 disabled_types.PutAll(unready_types); | 326 disabled_types.PutAll(unready_types); |
328 | 327 |
329 syncer::ModelTypeSet active_types = | 328 syncer::ModelTypeSet active_types = |
330 GetDataTypesInState(CONFIGURE_ACTIVE, config_state_map); | 329 GetDataTypesInState(CONFIGURE_ACTIVE, config_state_map); |
331 syncer::ModelTypeSet clean_first_types = | 330 syncer::ModelTypeSet clean_first_types = |
332 GetDataTypesInState(CONFIGURE_CLEAN, config_state_map); | 331 GetDataTypesInState(CONFIGURE_CLEAN, config_state_map); |
333 syncer::ModelTypeSet types_to_download = registrar_->ConfigureDataTypes( | 332 syncer::ModelTypeSet types_to_download = registrar_->ConfigureDataTypes( |
334 syncer::Union(active_types, clean_first_types), | 333 syncer::Union(active_types, clean_first_types), disabled_types); |
335 disabled_types); | |
336 types_to_download.PutAll(clean_first_types); | 334 types_to_download.PutAll(clean_first_types); |
337 types_to_download.RemoveAll(syncer::ProxyTypes()); | 335 types_to_download.RemoveAll(syncer::ProxyTypes()); |
338 if (!types_to_download.Empty()) | 336 if (!types_to_download.Empty()) |
339 types_to_download.Put(syncer::NIGORI); | 337 types_to_download.Put(syncer::NIGORI); |
340 | 338 |
341 // TODO(sync): crbug.com/137550. | 339 // TODO(sync): crbug.com/137550. |
342 // It's dangerous to configure types that have progress markers. Types with | 340 // It's dangerous to configure types that have progress markers. Types with |
343 // progress markers can trigger a MIGRATION_DONE response. We are not | 341 // progress markers can trigger a MIGRATION_DONE response. We are not |
344 // prepared to handle a migration during a configure, so we must ensure that | 342 // prepared to handle a migration during a configure, so we must ensure that |
345 // all our types_to_download actually contain no data before we sync them. | 343 // all our types_to_download actually contain no data before we sync them. |
(...skipping 30 matching lines...) Expand all Loading... |
376 // to be acted on again. | 374 // to be acted on again. |
377 fatal_types.RetainAll(types_to_purge); | 375 fatal_types.RetainAll(types_to_purge); |
378 syncer::ModelTypeSet unapply_types = | 376 syncer::ModelTypeSet unapply_types = |
379 syncer::Union(crypto_types, clean_first_types); | 377 syncer::Union(crypto_types, clean_first_types); |
380 unapply_types.RetainAll(types_to_purge); | 378 unapply_types.RetainAll(types_to_purge); |
381 | 379 |
382 DCHECK(syncer::Intersection(current_types, fatal_types).Empty()); | 380 DCHECK(syncer::Intersection(current_types, fatal_types).Empty()); |
383 DCHECK(syncer::Intersection(current_types, crypto_types).Empty()); | 381 DCHECK(syncer::Intersection(current_types, crypto_types).Empty()); |
384 DCHECK(current_types.HasAll(types_to_download)); | 382 DCHECK(current_types.HasAll(types_to_download)); |
385 | 383 |
386 SDVLOG(1) << "Types " | 384 SDVLOG(1) << "Types " << syncer::ModelTypeSetToString(types_to_download) |
387 << syncer::ModelTypeSetToString(types_to_download) | |
388 << " added; calling DoConfigureSyncer"; | 385 << " added; calling DoConfigureSyncer"; |
389 // Divide up the types into their corresponding actions (each is mutually | 386 // Divide up the types into their corresponding actions (each is mutually |
390 // exclusive): | 387 // exclusive): |
391 // - Types which have just been added to the routing info (types_to_download): | 388 // - Types which have just been added to the routing info (types_to_download): |
392 // are downloaded. | 389 // are downloaded. |
393 // - Types which have encountered a fatal error (fatal_types) are deleted | 390 // - Types which have encountered a fatal error (fatal_types) are deleted |
394 // from the directory and journaled in the delete journal. | 391 // from the directory and journaled in the delete journal. |
395 // - Types which have encountered a cryptographer error (crypto_types) are | 392 // - Types which have encountered a cryptographer error (crypto_types) are |
396 // unapplied (local state is purged but sync state is not). | 393 // unapplied (local state is purged but sync state is not). |
397 // - All other types not in the routing info (types just disabled) are deleted | 394 // - All other types not in the routing info (types just disabled) are deleted |
398 // from the directory. | 395 // from the directory. |
399 // - Everything else (enabled types and already disabled types) is not | 396 // - Everything else (enabled types and already disabled types) is not |
400 // touched. | 397 // touched. |
401 RequestConfigureSyncer(reason, | 398 RequestConfigureSyncer(reason, types_to_download, types_to_purge, fatal_types, |
402 types_to_download, | 399 unapply_types, inactive_types, routing_info, |
403 types_to_purge, | 400 ready_task, retry_callback); |
404 fatal_types, | |
405 unapply_types, | |
406 inactive_types, | |
407 routing_info, | |
408 ready_task, | |
409 retry_callback); | |
410 | 401 |
411 DCHECK(syncer::Intersection(active_types, types_to_purge).Empty()); | 402 DCHECK(syncer::Intersection(active_types, types_to_purge).Empty()); |
412 DCHECK(syncer::Intersection(active_types, fatal_types).Empty()); | 403 DCHECK(syncer::Intersection(active_types, fatal_types).Empty()); |
413 DCHECK(syncer::Intersection(active_types, unapply_types).Empty()); | 404 DCHECK(syncer::Intersection(active_types, unapply_types).Empty()); |
414 DCHECK(syncer::Intersection(active_types, inactive_types).Empty()); | 405 DCHECK(syncer::Intersection(active_types, inactive_types).Empty()); |
415 return syncer::Difference(active_types, types_to_download); | 406 return syncer::Difference(active_types, types_to_download); |
416 } | 407 } |
417 | 408 |
418 void SyncBackendHostImpl::EnableEncryptEverything() { | 409 void SyncBackendHostImpl::EnableEncryptEverything() { |
419 registrar_->sync_thread()->task_runner()->PostTask( | 410 registrar_->sync_thread()->task_runner()->PostTask( |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 return cached_passphrase_type_; | 464 return cached_passphrase_type_; |
474 } | 465 } |
475 | 466 |
476 base::Time SyncBackendHostImpl::GetExplicitPassphraseTime() const { | 467 base::Time SyncBackendHostImpl::GetExplicitPassphraseTime() const { |
477 return cached_explicit_passphrase_time_; | 468 return cached_explicit_passphrase_time_; |
478 } | 469 } |
479 | 470 |
480 bool SyncBackendHostImpl::IsCryptographerReady( | 471 bool SyncBackendHostImpl::IsCryptographerReady( |
481 const syncer::BaseTransaction* trans) const { | 472 const syncer::BaseTransaction* trans) const { |
482 return initialized() && trans->GetCryptographer() && | 473 return initialized() && trans->GetCryptographer() && |
483 trans->GetCryptographer()->is_ready(); | 474 trans->GetCryptographer()->is_ready(); |
484 } | 475 } |
485 | 476 |
486 void SyncBackendHostImpl::GetModelSafeRoutingInfo( | 477 void SyncBackendHostImpl::GetModelSafeRoutingInfo( |
487 syncer::ModelSafeRoutingInfo* out) const { | 478 syncer::ModelSafeRoutingInfo* out) const { |
488 if (initialized()) { | 479 if (initialized()) { |
489 CHECK(registrar_.get()); | 480 CHECK(registrar_.get()); |
490 registrar_->GetModelSafeRoutingInfo(out); | 481 registrar_->GetModelSafeRoutingInfo(out); |
491 } else { | 482 } else { |
492 NOTREACHED(); | 483 NOTREACHED(); |
493 } | 484 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 } | 538 } |
548 | 539 |
549 void SyncBackendHostImpl::RequestConfigureSyncer( | 540 void SyncBackendHostImpl::RequestConfigureSyncer( |
550 syncer::ConfigureReason reason, | 541 syncer::ConfigureReason reason, |
551 syncer::ModelTypeSet to_download, | 542 syncer::ModelTypeSet to_download, |
552 syncer::ModelTypeSet to_purge, | 543 syncer::ModelTypeSet to_purge, |
553 syncer::ModelTypeSet to_journal, | 544 syncer::ModelTypeSet to_journal, |
554 syncer::ModelTypeSet to_unapply, | 545 syncer::ModelTypeSet to_unapply, |
555 syncer::ModelTypeSet to_ignore, | 546 syncer::ModelTypeSet to_ignore, |
556 const syncer::ModelSafeRoutingInfo& routing_info, | 547 const syncer::ModelSafeRoutingInfo& routing_info, |
557 const base::Callback<void(syncer::ModelTypeSet, | 548 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& |
558 syncer::ModelTypeSet)>& ready_task, | 549 ready_task, |
559 const base::Closure& retry_callback) { | 550 const base::Closure& retry_callback) { |
560 DoConfigureSyncerTypes config_types; | 551 DoConfigureSyncerTypes config_types; |
561 config_types.to_download = to_download; | 552 config_types.to_download = to_download; |
562 config_types.to_purge = to_purge; | 553 config_types.to_purge = to_purge; |
563 config_types.to_journal = to_journal; | 554 config_types.to_journal = to_journal; |
564 config_types.to_unapply = to_unapply; | 555 config_types.to_unapply = to_unapply; |
565 registrar_->sync_thread()->task_runner()->PostTask( | 556 registrar_->sync_thread()->task_runner()->PostTask( |
566 FROM_HERE, | 557 FROM_HERE, |
567 base::Bind(&SyncBackendHostCore::DoConfigureSyncer, core_.get(), reason, | 558 base::Bind(&SyncBackendHostCore::DoConfigureSyncer, core_.get(), reason, |
568 config_types, routing_info, ready_task, retry_callback)); | 559 config_types, routing_info, ready_task, retry_callback)); |
569 } | 560 } |
570 | 561 |
571 void SyncBackendHostImpl::FinishConfigureDataTypesOnFrontendLoop( | 562 void SyncBackendHostImpl::FinishConfigureDataTypesOnFrontendLoop( |
572 const syncer::ModelTypeSet enabled_types, | 563 const syncer::ModelTypeSet enabled_types, |
573 const syncer::ModelTypeSet succeeded_configuration_types, | 564 const syncer::ModelTypeSet succeeded_configuration_types, |
574 const syncer::ModelTypeSet failed_configuration_types, | 565 const syncer::ModelTypeSet failed_configuration_types, |
575 const base::Callback<void(syncer::ModelTypeSet, | 566 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& |
576 syncer::ModelTypeSet)>& ready_task) { | 567 ready_task) { |
577 if (!frontend_) | 568 if (!frontend_) |
578 return; | 569 return; |
579 | 570 |
580 if (invalidator_) { | 571 if (invalidator_) { |
581 CHECK(invalidator_->UpdateRegisteredInvalidationIds( | 572 CHECK(invalidator_->UpdateRegisteredInvalidationIds( |
582 this, ModelTypeSetToObjectIdSet(enabled_types))); | 573 this, ModelTypeSetToObjectIdSet(enabled_types))); |
583 } | 574 } |
584 | 575 |
585 if (!ready_task.is_null()) | 576 if (!ready_task.is_null()) |
586 ready_task.Run(succeeded_configuration_types, failed_configuration_types); | 577 ready_task.Run(succeeded_configuration_types, failed_configuration_types); |
(...skipping 27 matching lines...) Expand all Loading... |
614 | 605 |
615 // Fake a state change to initialize the SyncManager's cached invalidator | 606 // Fake a state change to initialize the SyncManager's cached invalidator |
616 // state. | 607 // state. |
617 OnInvalidatorStateChange(invalidator_->GetInvalidatorState()); | 608 OnInvalidatorStateChange(invalidator_->GetInvalidatorState()); |
618 } | 609 } |
619 | 610 |
620 // Now that we've downloaded the control types, we can see if there are any | 611 // Now that we've downloaded the control types, we can see if there are any |
621 // experimental types to enable. This should be done before we inform | 612 // experimental types to enable. This should be done before we inform |
622 // the frontend to ensure they're visible in the customize screen. | 613 // the frontend to ensure they're visible in the customize screen. |
623 AddExperimentalTypes(); | 614 AddExperimentalTypes(); |
624 frontend_->OnBackendInitialized(js_backend, | 615 frontend_->OnBackendInitialized(js_backend, debug_info_listener, cache_guid, |
625 debug_info_listener, | |
626 cache_guid, | |
627 true); | 616 true); |
628 } | 617 } |
629 | 618 |
630 void SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop() { | 619 void SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop() { |
631 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); | 620 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); |
632 if (!frontend_) | 621 if (!frontend_) |
633 return; | 622 return; |
634 | 623 |
635 frontend_->OnBackendInitialized( | 624 frontend_->OnBackendInitialized( |
636 syncer::WeakHandle<syncer::JsBackend>(), | 625 syncer::WeakHandle<syncer::JsBackend>(), |
637 syncer::WeakHandle<syncer::DataTypeDebugInfoListener>(), | 626 syncer::WeakHandle<syncer::DataTypeDebugInfoListener>(), "", false); |
638 "", | |
639 false); | |
640 } | 627 } |
641 | 628 |
642 void SyncBackendHostImpl::HandleSyncCycleCompletedOnFrontendLoop( | 629 void SyncBackendHostImpl::HandleSyncCycleCompletedOnFrontendLoop( |
643 const syncer::sessions::SyncSessionSnapshot& snapshot) { | 630 const syncer::sessions::SyncSessionSnapshot& snapshot) { |
644 if (!frontend_) | 631 if (!frontend_) |
645 return; | 632 return; |
646 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); | 633 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); |
647 | 634 |
648 last_snapshot_ = snapshot; | 635 last_snapshot_ = snapshot; |
649 | 636 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 frontend_->OnPassphraseAccepted(); | 735 frontend_->OnPassphraseAccepted(); |
749 } | 736 } |
750 | 737 |
751 void SyncBackendHostImpl::NotifyEncryptedTypesChanged( | 738 void SyncBackendHostImpl::NotifyEncryptedTypesChanged( |
752 syncer::ModelTypeSet encrypted_types, | 739 syncer::ModelTypeSet encrypted_types, |
753 bool encrypt_everything) { | 740 bool encrypt_everything) { |
754 if (!frontend_) | 741 if (!frontend_) |
755 return; | 742 return; |
756 | 743 |
757 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); | 744 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); |
758 frontend_->OnEncryptedTypesChanged( | 745 frontend_->OnEncryptedTypesChanged(encrypted_types, encrypt_everything); |
759 encrypted_types, encrypt_everything); | |
760 } | 746 } |
761 | 747 |
762 void SyncBackendHostImpl::NotifyEncryptionComplete() { | 748 void SyncBackendHostImpl::NotifyEncryptionComplete() { |
763 if (!frontend_) | 749 if (!frontend_) |
764 return; | 750 return; |
765 | 751 |
766 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); | 752 DCHECK(frontend_task_runner_->BelongsToCurrentThread()); |
767 frontend_->OnEncryptionComplete(); | 753 frontend_->OnEncryptionComplete(); |
768 } | 754 } |
769 | 755 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 const syncer::SyncManager::ClearServerDataCallback& frontend_callback) { | 850 const syncer::SyncManager::ClearServerDataCallback& frontend_callback) { |
865 DCHECK(ui_thread_->BelongsToCurrentThread()); | 851 DCHECK(ui_thread_->BelongsToCurrentThread()); |
866 frontend_callback.Run(); | 852 frontend_callback.Run(); |
867 } | 853 } |
868 | 854 |
869 } // namespace browser_sync | 855 } // namespace browser_sync |
870 | 856 |
871 #undef SDVLOG | 857 #undef SDVLOG |
872 | 858 |
873 #undef SLOG | 859 #undef SLOG |
OLD | NEW |