| 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 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 base::Time on_engine_initialized_time = base::Time::Now(); | 957 base::Time on_engine_initialized_time = base::Time::Now(); |
| 958 base::TimeDelta delta = | 958 base::TimeDelta delta = |
| 959 on_engine_initialized_time - startup_controller_->start_engine_time(); | 959 on_engine_initialized_time - startup_controller_->start_engine_time(); |
| 960 if (is_first_time_sync_configure_) { | 960 if (is_first_time_sync_configure_) { |
| 961 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeFirstTime", delta); | 961 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeFirstTime", delta); |
| 962 } else { | 962 } else { |
| 963 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta); | 963 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta); |
| 964 } | 964 } |
| 965 } | 965 } |
| 966 | 966 |
| 967 void ProfileSyncService::PostEngineInitialization() { | |
| 968 if (protocol_event_observers_.might_have_observers()) { | |
| 969 engine_->RequestBufferedProtocolEventsAndEnableForwarding(); | |
| 970 } | |
| 971 | |
| 972 if (type_debug_info_observers_.might_have_observers()) { | |
| 973 engine_->EnableDirectoryTypeDebugInfoForwarding(); | |
| 974 } | |
| 975 | |
| 976 // If we have a cached passphrase use it to decrypt/encrypt data now that the | |
| 977 // engine is initialized. We want to call this before notifying observers in | |
| 978 // case this operation affects the "passphrase required" status. | |
| 979 ConsumeCachedPassphraseIfPossible(); | |
| 980 | |
| 981 // The very first time the engine initializes is effectively the first time | |
| 982 // we can say we successfully "synced". LastSyncedTime will only be null in | |
| 983 // this case, because the pref wasn't restored on StartUp. | |
| 984 if (sync_prefs_.GetLastSyncedTime().is_null()) { | |
| 985 UpdateLastSyncedTime(); | |
| 986 } | |
| 987 | |
| 988 // Auto-start means IsFirstSetupComplete gets set automatically. | |
| 989 if (start_behavior_ == AUTO_START && !IsFirstSetupComplete()) { | |
| 990 // This will trigger a configure if it completes setup. | |
| 991 SetFirstSetupComplete(); | |
| 992 } else if (CanConfigureDataTypes()) { | |
| 993 ConfigureDataTypeManager(); | |
| 994 } | |
| 995 | |
| 996 // Check for a cookie jar mismatch. | |
| 997 std::vector<gaia::ListedAccount> accounts; | |
| 998 std::vector<gaia::ListedAccount> signed_out_accounts; | |
| 999 GoogleServiceAuthError error(GoogleServiceAuthError::NONE); | |
| 1000 if (gaia_cookie_manager_service_ && | |
| 1001 gaia_cookie_manager_service_->ListAccounts( | |
| 1002 &accounts, &signed_out_accounts, "ChromiumProfileSyncService")) { | |
| 1003 OnGaiaAccountsInCookieUpdated(accounts, signed_out_accounts, error); | |
| 1004 } | |
| 1005 | |
| 1006 NotifyObservers(); | |
| 1007 } | |
| 1008 | |
| 1009 void ProfileSyncService::OnEngineInitialized( | 967 void ProfileSyncService::OnEngineInitialized( |
| 968 ModelTypeSet initial_types, |
| 1010 const syncer::WeakHandle<syncer::JsBackend>& js_backend, | 969 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
| 1011 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 970 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
| 1012 debug_info_listener, | 971 debug_info_listener, |
| 1013 const std::string& cache_guid, | 972 const std::string& cache_guid, |
| 1014 bool success) { | 973 bool success) { |
| 1015 DCHECK(thread_checker_.CalledOnValidThread()); | 974 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1016 UpdateEngineInitUMA(success); | 975 UpdateEngineInitUMA(success); |
| 1017 | 976 |
| 1018 if (!success) { | 977 if (!success) { |
| 1019 // Something went unexpectedly wrong. Play it safe: stop syncing at once | 978 // Something went unexpectedly wrong. Play it safe: stop syncing at once |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1040 | 999 |
| 1041 SigninClient* signin_client = signin_->GetOriginal()->signin_client(); | 1000 SigninClient* signin_client = signin_->GetOriginal()->signin_client(); |
| 1042 DCHECK(signin_client); | 1001 DCHECK(signin_client); |
| 1043 std::string signin_scoped_device_id = | 1002 std::string signin_scoped_device_id = |
| 1044 signin_client->GetSigninScopedDeviceId(); | 1003 signin_client->GetSigninScopedDeviceId(); |
| 1045 | 1004 |
| 1046 // Initialize local device info. | 1005 // Initialize local device info. |
| 1047 local_device_->Initialize(cache_guid, signin_scoped_device_id, | 1006 local_device_->Initialize(cache_guid, signin_scoped_device_id, |
| 1048 blocking_pool_); | 1007 blocking_pool_); |
| 1049 | 1008 |
| 1050 PostEngineInitialization(); | 1009 if (protocol_event_observers_.might_have_observers()) { |
| 1010 engine_->RequestBufferedProtocolEventsAndEnableForwarding(); |
| 1011 } |
| 1012 |
| 1013 if (type_debug_info_observers_.might_have_observers()) { |
| 1014 engine_->EnableDirectoryTypeDebugInfoForwarding(); |
| 1015 } |
| 1016 |
| 1017 // If we have a cached passphrase use it to decrypt/encrypt data now that the |
| 1018 // backend is initialized. We want to call this before notifying observers in |
| 1019 // case this operation affects the "passphrase required" status. |
| 1020 ConsumeCachedPassphraseIfPossible(); |
| 1021 |
| 1022 // The very first time the backend initializes is effectively the first time |
| 1023 // we can say we successfully "synced". LastSyncedTime will only be null in |
| 1024 // this case, because the pref wasn't restored on StartUp. |
| 1025 if (sync_prefs_.GetLastSyncedTime().is_null()) { |
| 1026 UpdateLastSyncedTime(); |
| 1027 } |
| 1028 |
| 1029 data_type_manager_.reset( |
| 1030 sync_client_->GetSyncApiComponentFactory()->CreateDataTypeManager( |
| 1031 initial_types, debug_info_listener_, &data_type_controllers_, this, |
| 1032 engine_.get(), this)); |
| 1033 |
| 1034 // Auto-start means IsFirstSetupComplete gets set automatically. |
| 1035 if (start_behavior_ == AUTO_START && !IsFirstSetupComplete()) { |
| 1036 // This will trigger a configure if it completes setup. |
| 1037 SetFirstSetupComplete(); |
| 1038 } else if (CanConfigureDataTypes()) { |
| 1039 ConfigureDataTypeManager(); |
| 1040 } |
| 1041 |
| 1042 // Check for a cookie jar mismatch. |
| 1043 std::vector<gaia::ListedAccount> accounts; |
| 1044 std::vector<gaia::ListedAccount> signed_out_accounts; |
| 1045 GoogleServiceAuthError error(GoogleServiceAuthError::NONE); |
| 1046 if (gaia_cookie_manager_service_ && |
| 1047 gaia_cookie_manager_service_->ListAccounts( |
| 1048 &accounts, &signed_out_accounts, "ChromiumProfileSyncService")) { |
| 1049 OnGaiaAccountsInCookieUpdated(accounts, signed_out_accounts, error); |
| 1050 } |
| 1051 |
| 1052 NotifyObservers(); |
| 1051 } | 1053 } |
| 1052 | 1054 |
| 1053 void ProfileSyncService::OnSyncCycleCompleted() { | 1055 void ProfileSyncService::OnSyncCycleCompleted() { |
| 1054 DCHECK(thread_checker_.CalledOnValidThread()); | 1056 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1055 UpdateLastSyncedTime(); | 1057 UpdateLastSyncedTime(); |
| 1056 const syncer::SyncCycleSnapshot snapshot = GetLastCycleSnapshot(); | 1058 const syncer::SyncCycleSnapshot snapshot = GetLastCycleSnapshot(); |
| 1057 if (IsDataTypeControllerRunning(syncer::SESSIONS) && | 1059 if (IsDataTypeControllerRunning(syncer::SESSIONS) && |
| 1058 snapshot.model_neutral_state().get_updates_request_types.Has( | 1060 snapshot.model_neutral_state().get_updates_request_types.Has( |
| 1059 syncer::SESSIONS) && | 1061 syncer::SESSIONS) && |
| 1060 !syncer::HasSyncerError(snapshot.model_neutral_state())) { | 1062 !syncer::HasSyncerError(snapshot.model_neutral_state())) { |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1824 // etc. ReconfigureDatatypeManager() will get called again once the UI calls | 1826 // etc. ReconfigureDatatypeManager() will get called again once the UI calls |
| 1825 // SetSetupInProgress(false). | 1827 // SetSetupInProgress(false). |
| 1826 if (!CanConfigureDataTypes()) { | 1828 if (!CanConfigureDataTypes()) { |
| 1827 // If we can't configure the data type manager yet, we should still notify | 1829 // If we can't configure the data type manager yet, we should still notify |
| 1828 // observers. This is to support multiple setup UIs being open at once. | 1830 // observers. This is to support multiple setup UIs being open at once. |
| 1829 NotifyObservers(); | 1831 NotifyObservers(); |
| 1830 return; | 1832 return; |
| 1831 } | 1833 } |
| 1832 | 1834 |
| 1833 bool restart = false; | 1835 bool restart = false; |
| 1834 if (!data_type_manager_) { | 1836 if (!migrator_) { |
| 1835 restart = true; | 1837 restart = true; |
| 1836 data_type_manager_.reset( | |
| 1837 sync_client_->GetSyncApiComponentFactory()->CreateDataTypeManager( | |
| 1838 debug_info_listener_, &data_type_controllers_, this, engine_.get(), | |
| 1839 this)); | |
| 1840 | 1838 |
| 1841 // We create the migrator at the same time. | 1839 // We create the migrator at the same time. |
| 1842 migrator_ = base::MakeUnique<BackendMigrator>( | 1840 migrator_ = base::MakeUnique<BackendMigrator>( |
| 1843 debug_identifier_, GetUserShare(), this, data_type_manager_.get(), | 1841 debug_identifier_, GetUserShare(), this, data_type_manager_.get(), |
| 1844 base::Bind(&ProfileSyncService::StartSyncingWithServer, | 1842 base::Bind(&ProfileSyncService::StartSyncingWithServer, |
| 1845 base::Unretained(this))); | 1843 base::Unretained(this))); |
| 1846 } | 1844 } |
| 1847 | 1845 |
| 1848 syncer::ModelTypeSet types; | 1846 syncer::ModelTypeSet types; |
| 1849 syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN; | 1847 syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN; |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2640 | 2638 |
| 2641 DCHECK(startup_controller_->IsSetupInProgress()); | 2639 DCHECK(startup_controller_->IsSetupInProgress()); |
| 2642 startup_controller_->SetSetupInProgress(false); | 2640 startup_controller_->SetSetupInProgress(false); |
| 2643 | 2641 |
| 2644 if (IsEngineInitialized()) | 2642 if (IsEngineInitialized()) |
| 2645 ReconfigureDatatypeManager(); | 2643 ReconfigureDatatypeManager(); |
| 2646 NotifyObservers(); | 2644 NotifyObservers(); |
| 2647 } | 2645 } |
| 2648 | 2646 |
| 2649 } // namespace browser_sync | 2647 } // namespace browser_sync |
| OLD | NEW |