Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser_sync/profile_sync_service.h" | 5 #include "components/browser_sync/profile_sync_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <cstddef> | 9 #include <cstddef> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 using syncer::JsBackend; | 101 using syncer::JsBackend; |
| 102 using syncer::JsController; | 102 using syncer::JsController; |
| 103 using syncer::JsEventDetails; | 103 using syncer::JsEventDetails; |
| 104 using syncer::JsEventHandler; | 104 using syncer::JsEventHandler; |
| 105 using syncer::ModelSafeRoutingInfo; | 105 using syncer::ModelSafeRoutingInfo; |
| 106 using syncer::ModelType; | 106 using syncer::ModelType; |
| 107 using syncer::ModelTypeChangeProcessor; | 107 using syncer::ModelTypeChangeProcessor; |
| 108 using syncer::ModelTypeSet; | 108 using syncer::ModelTypeSet; |
| 109 using syncer::ModelTypeStore; | 109 using syncer::ModelTypeStore; |
| 110 using syncer::ProtocolEventObserver; | 110 using syncer::ProtocolEventObserver; |
| 111 using syncer::SyncBackendHost; | 111 using syncer::SyncEngine; |
| 112 using syncer::SyncCredentials; | 112 using syncer::SyncCredentials; |
| 113 using syncer::SyncProtocolError; | 113 using syncer::SyncProtocolError; |
| 114 using syncer::WeakHandle; | 114 using syncer::WeakHandle; |
| 115 | 115 |
| 116 namespace browser_sync { | 116 namespace browser_sync { |
| 117 | 117 |
| 118 typedef GoogleServiceAuthError AuthError; | 118 typedef GoogleServiceAuthError AuthError; |
| 119 | 119 |
| 120 const char kSyncUnrecoverableErrorHistogram[] = "Sync.UnrecoverableErrors"; | 120 const char kSyncUnrecoverableErrorHistogram[] = "Sync.UnrecoverableErrors"; |
| 121 | 121 |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 // profile should get this treatment or all profile as is the case now. The | 529 // profile should get this treatment or all profile as is the case now. The |
| 530 // solution for now will be to assume profiles are created in the same order | 530 // solution for now will be to assume profiles are created in the same order |
| 531 // on all machines and in the future decide if only the Default one should be | 531 // on all machines and in the future decide if only the Default one should be |
| 532 // considered roamed. | 532 // considered roamed. |
| 533 local_sync_backend_folder = | 533 local_sync_backend_folder = |
| 534 local_sync_backend_folder.Append(base_directory_.BaseName()); | 534 local_sync_backend_folder.Append(base_directory_.BaseName()); |
| 535 local_sync_backend_folder = | 535 local_sync_backend_folder = |
| 536 local_sync_backend_folder.Append(kLoopbackServerBackendFilename); | 536 local_sync_backend_folder.Append(kLoopbackServerBackendFilename); |
| 537 #endif // defined(OS_WIN) | 537 #endif // defined(OS_WIN) |
| 538 | 538 |
| 539 SyncBackendHost::HttpPostProviderFactoryGetter | 539 SyncEngine::HttpPostProviderFactoryGetter http_post_provider_factory_getter = |
| 540 http_post_provider_factory_getter = | 540 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory, |
| 541 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory, | 541 base::Unretained(network_resources_.get()), |
| 542 base::Unretained(network_resources_.get()), | 542 url_request_context_, network_time_update_callback_); |
| 543 url_request_context_, network_time_update_callback_); | |
| 544 | 543 |
| 545 backend_->Initialize( | 544 backend_->Initialize( |
| 546 this, sync_thread_->task_runner(), GetJsEventHandler(), sync_service_url_, | 545 this, sync_thread_->task_runner(), GetJsEventHandler(), sync_service_url_, |
| 547 local_device_->GetSyncUserAgent(), credentials, delete_stale_data, | 546 local_device_->GetSyncUserAgent(), credentials, delete_stale_data, |
| 548 enable_local_sync_backend, local_sync_backend_folder, | 547 enable_local_sync_backend, local_sync_backend_folder, |
| 549 base::MakeUnique<syncer::SyncManagerFactory>(), | 548 base::MakeUnique<syncer::SyncManagerFactory>(), |
| 550 MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()), | 549 MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()), |
| 551 base::Bind(syncer::ReportUnrecoverableError, channel_), | 550 base::Bind(syncer::ReportUnrecoverableError, channel_), |
| 552 http_post_provider_factory_getter, std::move(saved_nigori_state_)); | 551 http_post_provider_factory_getter, std::move(saved_nigori_state_)); |
| 553 } | 552 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 614 return; | 613 return; |
| 615 } | 614 } |
| 616 | 615 |
| 617 startup_controller_->OnDataTypeRequestsSyncStartup(type); | 616 startup_controller_->OnDataTypeRequestsSyncStartup(type); |
| 618 } | 617 } |
| 619 | 618 |
| 620 void ProfileSyncService::StartUpSlowBackendComponents() { | 619 void ProfileSyncService::StartUpSlowBackendComponents() { |
| 621 invalidation::InvalidationService* invalidator = | 620 invalidation::InvalidationService* invalidator = |
| 622 sync_client_->GetInvalidationService(); | 621 sync_client_->GetInvalidationService(); |
| 623 | 622 |
| 624 backend_.reset( | 623 backend_.reset(sync_client_->GetSyncApiComponentFactory()->CreateSyncEngine( |
| 625 sync_client_->GetSyncApiComponentFactory()->CreateSyncBackendHost( | 624 debug_identifier_, invalidator, sync_prefs_.AsWeakPtr(), |
| 626 debug_identifier_, invalidator, sync_prefs_.AsWeakPtr(), | 625 directory_path_)); |
| 627 directory_path_)); | |
| 628 | 626 |
| 629 // Initialize the backend. Every time we start up a new SyncBackendHost, | 627 // Initialize the backend. Every time we start up a new SyncEngine, we'll want |
| 630 // we'll want to start from a fresh SyncDB, so delete any old one that might | 628 // to start from a fresh SyncDB, so delete any old one that might be there. |
| 631 // be there. | |
| 632 InitializeBackend(ShouldDeleteSyncFolder()); | 629 InitializeBackend(ShouldDeleteSyncFolder()); |
| 633 | 630 |
| 634 UpdateFirstSyncTimePref(); | 631 UpdateFirstSyncTimePref(); |
| 635 | 632 |
| 636 ReportPreviousSessionMemoryWarningCount(); | 633 ReportPreviousSessionMemoryWarningCount(); |
| 637 } | 634 } |
| 638 | 635 |
| 639 void ProfileSyncService::OnGetTokenSuccess( | 636 void ProfileSyncService::OnGetTokenSuccess( |
| 640 const OAuth2TokenService::Request* request, | 637 const OAuth2TokenService::Request* request, |
| 641 const std::string& access_token, | 638 const std::string& access_token, |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 781 data_type_manager_.reset(); | 778 data_type_manager_.reset(); |
| 782 } | 779 } |
| 783 | 780 |
| 784 // Shutdown the migrator before the backend to ensure it doesn't pull a null | 781 // Shutdown the migrator before the backend to ensure it doesn't pull a null |
| 785 // snapshot. | 782 // snapshot. |
| 786 migrator_.reset(); | 783 migrator_.reset(); |
| 787 sync_js_controller_.AttachJsBackend(WeakHandle<syncer::JsBackend>()); | 784 sync_js_controller_.AttachJsBackend(WeakHandle<syncer::JsBackend>()); |
| 788 | 785 |
| 789 // Move aside the backend so nobody else tries to use it while we are | 786 // Move aside the backend so nobody else tries to use it while we are |
| 790 // shutting it down. | 787 // shutting it down. |
| 791 std::unique_ptr<SyncBackendHost> doomed_backend(backend_.release()); | 788 std::unique_ptr<SyncEngine> doomed_backend(backend_.release()); |
| 792 if (doomed_backend) { | 789 if (doomed_backend) { |
| 793 doomed_backend->Shutdown(reason); | 790 doomed_backend->Shutdown(reason); |
| 794 doomed_backend.reset(); | 791 doomed_backend.reset(); |
| 795 } | 792 } |
| 796 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time; | 793 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time; |
| 797 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time); | 794 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time); |
| 798 | 795 |
| 799 sync_enabled_weak_factory_.InvalidateWeakPtrs(); | 796 sync_enabled_weak_factory_.InvalidateWeakPtrs(); |
| 800 | 797 |
| 801 startup_controller_->Reset(GetRegisteredDataTypes()); | 798 startup_controller_->Reset(GetRegisteredDataTypes()); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 825 NotifyObservers(); | 822 NotifyObservers(); |
| 826 | 823 |
| 827 // Mark this as a clean shutdown(without crash). | 824 // Mark this as a clean shutdown(without crash). |
| 828 sync_prefs_.SetCleanShutdown(true); | 825 sync_prefs_.SetCleanShutdown(true); |
| 829 } | 826 } |
| 830 | 827 |
| 831 void ProfileSyncService::StopImpl(SyncStopDataFate data_fate) { | 828 void ProfileSyncService::StopImpl(SyncStopDataFate data_fate) { |
| 832 switch (data_fate) { | 829 switch (data_fate) { |
| 833 case KEEP_DATA: | 830 case KEEP_DATA: |
| 834 // TODO(maxbogue): Investigate whether this logic can/should be moved | 831 // TODO(maxbogue): Investigate whether this logic can/should be moved |
| 835 // into ShutdownImpl or SyncBackendHost itself. | 832 // into ShutdownImpl or SyncEngine itself. |
|
skym
2016/12/02 20:54:54
This is so ambiguous and confusing with this name.
maxbogue
2016/12/02 23:59:27
Clarified it to "sync engine" (aka the last of the
| |
| 836 if (HasSyncingBackend()) { | 833 if (HasSyncingBackend()) { |
| 837 backend_->UnregisterInvalidationIds(); | 834 backend_->UnregisterInvalidationIds(); |
| 838 } | 835 } |
| 839 ShutdownImpl(syncer::STOP_SYNC); | 836 ShutdownImpl(syncer::STOP_SYNC); |
| 840 break; | 837 break; |
| 841 case CLEAR_DATA: | 838 case CLEAR_DATA: |
| 842 // Clear prefs (including SyncSetupHasCompleted) before shutting down so | 839 // Clear prefs (including SyncSetupHasCompleted) before shutting down so |
| 843 // PSS clients don't think we're set up while we're shutting down. | 840 // PSS clients don't think we're set up while we're shutting down. |
| 844 sync_prefs_.ClearPreferences(); | 841 sync_prefs_.ClearPreferences(); |
| 845 ClearUnrecoverableError(); | 842 ClearUnrecoverableError(); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 936 is_first_time_sync_configure_ = !IsFirstSetupComplete(); | 933 is_first_time_sync_configure_ = !IsFirstSetupComplete(); |
| 937 | 934 |
| 938 if (is_first_time_sync_configure_) { | 935 if (is_first_time_sync_configure_) { |
| 939 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); | 936 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); |
| 940 } else { | 937 } else { |
| 941 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success); | 938 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success); |
| 942 } | 939 } |
| 943 | 940 |
| 944 base::Time on_backend_initialized_time = base::Time::Now(); | 941 base::Time on_backend_initialized_time = base::Time::Now(); |
| 945 base::TimeDelta delta = | 942 base::TimeDelta delta = |
| 946 on_backend_initialized_time - startup_controller_->start_backend_time(); | 943 on_backend_initialized_time - startup_controller_->start_engine_time(); |
| 947 if (is_first_time_sync_configure_) { | 944 if (is_first_time_sync_configure_) { |
| 948 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeFirstTime", delta); | 945 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeFirstTime", delta); |
| 949 } else { | 946 } else { |
| 950 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta); | 947 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta); |
| 951 } | 948 } |
| 952 } | 949 } |
| 953 | 950 |
| 954 void ProfileSyncService::PostBackendInitialization() { | 951 void ProfileSyncService::PostBackendInitialization() { |
| 955 if (protocol_event_observers_.might_have_observers()) { | 952 if (protocol_event_observers_.might_have_observers()) { |
| 956 backend_->RequestBufferedProtocolEventsAndEnableForwarding(); | 953 backend_->RequestBufferedProtocolEventsAndEnableForwarding(); |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1468 case DATATYPES_NOT_INITIALIZED: | 1465 case DATATYPES_NOT_INITIALIZED: |
| 1469 return "Datatypes not fully initialized"; | 1466 return "Datatypes not fully initialized"; |
| 1470 case INITIALIZED: | 1467 case INITIALIZED: |
| 1471 return "Sync service initialized"; | 1468 return "Sync service initialized"; |
| 1472 default: | 1469 default: |
| 1473 return "Status unknown: Internal error?"; | 1470 return "Status unknown: Internal error?"; |
| 1474 } | 1471 } |
| 1475 } | 1472 } |
| 1476 | 1473 |
| 1477 std::string ProfileSyncService::GetBackendInitializationStateString() const { | 1474 std::string ProfileSyncService::GetBackendInitializationStateString() const { |
| 1478 return startup_controller_->GetBackendInitializationStateString(); | 1475 return startup_controller_->GetEngineInitializationStateString(); |
| 1479 } | 1476 } |
| 1480 | 1477 |
| 1481 bool ProfileSyncService::IsSetupInProgress() const { | 1478 bool ProfileSyncService::IsSetupInProgress() const { |
| 1482 return startup_controller_->IsSetupInProgress(); | 1479 return startup_controller_->IsSetupInProgress(); |
| 1483 } | 1480 } |
| 1484 | 1481 |
| 1485 bool ProfileSyncService::QueryDetailedSyncStatus( | 1482 bool ProfileSyncService::QueryDetailedSyncStatus(SyncEngine::Status* result) { |
| 1486 SyncBackendHost::Status* result) { | |
| 1487 if (backend_.get() && backend_initialized_) { | 1483 if (backend_.get() && backend_initialized_) { |
| 1488 *result = backend_->GetDetailedStatus(); | 1484 *result = backend_->GetDetailedStatus(); |
| 1489 return true; | 1485 return true; |
| 1490 } else { | 1486 } else { |
| 1491 SyncBackendHost::Status status; | 1487 SyncEngine::Status status; |
| 1492 status.sync_protocol_error = last_actionable_error_; | 1488 status.sync_protocol_error = last_actionable_error_; |
| 1493 *result = status; | 1489 *result = status; |
| 1494 return false; | 1490 return false; |
| 1495 } | 1491 } |
| 1496 } | 1492 } |
| 1497 | 1493 |
| 1498 const AuthError& ProfileSyncService::GetAuthError() const { | 1494 const AuthError& ProfileSyncService::GetAuthError() const { |
| 1499 return last_auth_error_; | 1495 return last_auth_error_; |
| 1500 } | 1496 } |
| 1501 | 1497 |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1859 backend_->GetModelSafeRoutingInfo(&routing_info); | 1855 backend_->GetModelSafeRoutingInfo(&routing_info); |
| 1860 for (ModelSafeRoutingInfo::const_iterator it = routing_info.begin(); | 1856 for (ModelSafeRoutingInfo::const_iterator it = routing_info.begin(); |
| 1861 it != routing_info.end(); ++it) { | 1857 it != routing_info.end(); ++it) { |
| 1862 if (it->second == syncer::GROUP_PASSIVE) { | 1858 if (it->second == syncer::GROUP_PASSIVE) { |
| 1863 passive_types.Put(it->first); | 1859 passive_types.Put(it->first); |
| 1864 } else { | 1860 } else { |
| 1865 active_types.Put(it->first); | 1861 active_types.Put(it->first); |
| 1866 } | 1862 } |
| 1867 } | 1863 } |
| 1868 | 1864 |
| 1869 SyncBackendHost::Status detailed_status = backend_->GetDetailedStatus(); | 1865 SyncEngine::Status detailed_status = backend_->GetDetailedStatus(); |
| 1870 ModelTypeSet& throttled_types(detailed_status.throttled_types); | 1866 ModelTypeSet& throttled_types(detailed_status.throttled_types); |
| 1871 ModelTypeSet& backed_off_types(detailed_status.backed_off_types); | 1867 ModelTypeSet& backed_off_types(detailed_status.backed_off_types); |
| 1872 ModelTypeSet registered = GetRegisteredDataTypes(); | 1868 ModelTypeSet registered = GetRegisteredDataTypes(); |
| 1873 std::unique_ptr<base::DictionaryValue> type_status_header( | 1869 std::unique_ptr<base::DictionaryValue> type_status_header( |
| 1874 new base::DictionaryValue()); | 1870 new base::DictionaryValue()); |
| 1875 | 1871 |
| 1876 type_status_header->SetString("name", "Model Type"); | 1872 type_status_header->SetString("name", "Model Type"); |
| 1877 type_status_header->SetString("status", "header"); | 1873 type_status_header->SetString("status", "header"); |
| 1878 type_status_header->SetString("value", "Group Type"); | 1874 type_status_header->SetString("value", "Group Type"); |
| 1879 type_status_header->SetString("num_entries", "Total Entries"); | 1875 type_status_header->SetString("num_entries", "Total Entries"); |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2534 | 2530 |
| 2535 DCHECK(startup_controller_->IsSetupInProgress()); | 2531 DCHECK(startup_controller_->IsSetupInProgress()); |
| 2536 startup_controller_->SetSetupInProgress(false); | 2532 startup_controller_->SetSetupInProgress(false); |
| 2537 | 2533 |
| 2538 if (IsBackendInitialized()) | 2534 if (IsBackendInitialized()) |
| 2539 ReconfigureDatatypeManager(); | 2535 ReconfigureDatatypeManager(); |
| 2540 NotifyObservers(); | 2536 NotifyObservers(); |
| 2541 } | 2537 } |
| 2542 | 2538 |
| 2543 } // namespace browser_sync | 2539 } // namespace browser_sync |
| OLD | NEW |