| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 #include "components/sync/engine/configure_reason.h" | 62 #include "components/sync/engine/configure_reason.h" |
| 63 #include "components/sync/engine/cycle/model_neutral_state.h" | 63 #include "components/sync/engine/cycle/model_neutral_state.h" |
| 64 #include "components/sync/engine/cycle/type_debug_info_observer.h" | 64 #include "components/sync/engine/cycle/type_debug_info_observer.h" |
| 65 #include "components/sync/engine/net/http_bridge_network_resources.h" | 65 #include "components/sync/engine/net/http_bridge_network_resources.h" |
| 66 #include "components/sync/engine/net/network_resources.h" | 66 #include "components/sync/engine/net/network_resources.h" |
| 67 #include "components/sync/engine/sync_encryption_handler.h" | 67 #include "components/sync/engine/sync_encryption_handler.h" |
| 68 #include "components/sync/engine/sync_string_conversions.h" | 68 #include "components/sync/engine/sync_string_conversions.h" |
| 69 #include "components/sync/js/js_event_details.h" | 69 #include "components/sync/js/js_event_details.h" |
| 70 #include "components/sync/model/change_processor.h" | 70 #include "components/sync/model/change_processor.h" |
| 71 #include "components/sync/model/model_type_change_processor.h" | 71 #include "components/sync/model/model_type_change_processor.h" |
| 72 #include "components/sync/model/model_type_store.h" | |
| 73 #include "components/sync/model/sync_error.h" | 72 #include "components/sync/model/sync_error.h" |
| 74 #include "components/sync/protocol/sync.pb.h" | 73 #include "components/sync/protocol/sync.pb.h" |
| 75 #include "components/sync/syncable/directory.h" | 74 #include "components/sync/syncable/directory.h" |
| 76 #include "components/sync/syncable/sync_db_util.h" | 75 #include "components/sync/syncable/sync_db_util.h" |
| 77 #include "components/sync/syncable/syncable_read_transaction.h" | 76 #include "components/sync/syncable/syncable_read_transaction.h" |
| 78 #include "components/sync_preferences/pref_service_syncable.h" | 77 #include "components/sync_preferences/pref_service_syncable.h" |
| 79 #include "components/sync_sessions/favicon_cache.h" | 78 #include "components/sync_sessions/favicon_cache.h" |
| 80 #include "components/sync_sessions/session_data_type_controller.h" | 79 #include "components/sync_sessions/session_data_type_controller.h" |
| 81 #include "components/sync_sessions/sessions_sync_manager.h" | 80 #include "components/sync_sessions/sessions_sync_manager.h" |
| 82 #include "components/sync_sessions/sync_sessions_client.h" | 81 #include "components/sync_sessions/sync_sessions_client.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 init_params.debug_identifier), | 185 init_params.debug_identifier), |
| 187 OAuth2TokenService::Consumer("sync"), | 186 OAuth2TokenService::Consumer("sync"), |
| 188 last_auth_error_(AuthError::AuthErrorNone()), | 187 last_auth_error_(AuthError::AuthErrorNone()), |
| 189 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED), | 188 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED), |
| 190 sync_service_url_( | 189 sync_service_url_( |
| 191 syncer::GetSyncServiceURL(*base::CommandLine::ForCurrentProcess(), | 190 syncer::GetSyncServiceURL(*base::CommandLine::ForCurrentProcess(), |
| 192 init_params.channel)), | 191 init_params.channel)), |
| 193 network_time_update_callback_( | 192 network_time_update_callback_( |
| 194 std::move(init_params.network_time_update_callback)), | 193 std::move(init_params.network_time_update_callback)), |
| 195 url_request_context_(init_params.url_request_context), | 194 url_request_context_(init_params.url_request_context), |
| 196 blocking_pool_(init_params.blocking_pool), | 195 blocking_task_runner_(std::move(init_params.blocking_task_runner)), |
| 197 is_first_time_sync_configure_(false), | 196 is_first_time_sync_configure_(false), |
| 198 engine_initialized_(false), | 197 engine_initialized_(false), |
| 199 sync_disabled_by_admin_(false), | 198 sync_disabled_by_admin_(false), |
| 200 is_auth_in_progress_(false), | 199 is_auth_in_progress_(false), |
| 201 local_sync_backend_folder_(init_params.local_sync_backend_folder), | 200 local_sync_backend_folder_(init_params.local_sync_backend_folder), |
| 202 unrecoverable_error_reason_(ERROR_REASON_UNSET), | 201 unrecoverable_error_reason_(ERROR_REASON_UNSET), |
| 203 expect_sync_configuration_aborted_(false), | 202 expect_sync_configuration_aborted_(false), |
| 204 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), | 203 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), |
| 205 encrypt_everything_allowed_(true), | 204 encrypt_everything_allowed_(true), |
| 206 encrypt_everything_(false), | 205 encrypt_everything_(false), |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 sessions_sync_manager_ = base::MakeUnique<SessionsSyncManager>( | 266 sessions_sync_manager_ = base::MakeUnique<SessionsSyncManager>( |
| 268 sync_client_->GetSyncSessionsClient(), &sync_prefs_, local_device_.get(), | 267 sync_client_->GetSyncSessionsClient(), &sync_prefs_, local_device_.get(), |
| 269 std::move(router), | 268 std::move(router), |
| 270 base::Bind(&ProfileSyncService::NotifyForeignSessionUpdated, | 269 base::Bind(&ProfileSyncService::NotifyForeignSessionUpdated, |
| 271 sync_enabled_weak_factory_.GetWeakPtr()), | 270 sync_enabled_weak_factory_.GetWeakPtr()), |
| 272 base::Bind(&ProfileSyncService::TriggerRefresh, | 271 base::Bind(&ProfileSyncService::TriggerRefresh, |
| 273 sync_enabled_weak_factory_.GetWeakPtr(), | 272 sync_enabled_weak_factory_.GetWeakPtr(), |
| 274 syncer::ModelTypeSet(syncer::SESSIONS))); | 273 syncer::ModelTypeSet(syncer::SESSIONS))); |
| 275 | 274 |
| 276 if (base::FeatureList::IsEnabled(switches::kSyncUSSDeviceInfo)) { | 275 if (base::FeatureList::IsEnabled(switches::kSyncUSSDeviceInfo)) { |
| 277 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( | |
| 278 blocking_pool_->GetSequencedTaskRunnerWithShutdownBehavior( | |
| 279 blocking_pool_->GetSequenceToken(), | |
| 280 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | |
| 281 // TODO(skym): Stop creating leveldb files when signed out. | 276 // TODO(skym): Stop creating leveldb files when signed out. |
| 282 // TODO(skym): Verify using AsUTF8Unsafe is okay here. Should work as long | 277 // TODO(skym): Verify using AsUTF8Unsafe is okay here. Should work as long |
| 283 // as the Local State file is guaranteed to be UTF-8. | 278 // as the Local State file is guaranteed to be UTF-8. |
| 284 device_info_sync_bridge_ = base::MakeUnique<DeviceInfoSyncBridge>( | 279 device_info_sync_bridge_ = base::MakeUnique<DeviceInfoSyncBridge>( |
| 285 local_device_.get(), | 280 local_device_.get(), GetModelTypeStoreFactory(syncer::DEVICE_INFO), |
| 286 base::Bind(&ModelTypeStore::CreateStore, syncer::DEVICE_INFO, | |
| 287 sync_data_folder_.Append(base::FilePath(kLevelDBFolderName)) | |
| 288 .AsUTF8Unsafe(), | |
| 289 blocking_task_runner), | |
| 290 base::BindRepeating( | 281 base::BindRepeating( |
| 291 &ModelTypeChangeProcessor::Create, | 282 &ModelTypeChangeProcessor::Create, |
| 292 base::BindRepeating(&syncer::ReportUnrecoverableError, channel_))); | 283 base::BindRepeating(&syncer::ReportUnrecoverableError, channel_))); |
| 293 } else { | 284 } else { |
| 294 device_info_sync_service_ = | 285 device_info_sync_service_ = |
| 295 base::MakeUnique<DeviceInfoSyncService>(local_device_.get()); | 286 base::MakeUnique<DeviceInfoSyncService>(local_device_.get()); |
| 296 } | 287 } |
| 297 | 288 |
| 298 syncer::SyncApiComponentFactory::RegisterDataTypesMethod | 289 syncer::SyncApiComponentFactory::RegisterDataTypesMethod |
| 299 register_platform_types_callback = | 290 register_platform_types_callback = |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 signin_scoped_device_id = "local_device"; | 958 signin_scoped_device_id = "local_device"; |
| 968 } else { | 959 } else { |
| 969 SigninClient* signin_client = signin_->GetOriginal()->signin_client(); | 960 SigninClient* signin_client = signin_->GetOriginal()->signin_client(); |
| 970 DCHECK(signin_client); | 961 DCHECK(signin_client); |
| 971 std::string signin_scoped_device_id = | 962 std::string signin_scoped_device_id = |
| 972 signin_client->GetSigninScopedDeviceId(); | 963 signin_client->GetSigninScopedDeviceId(); |
| 973 } | 964 } |
| 974 | 965 |
| 975 // Initialize local device info. | 966 // Initialize local device info. |
| 976 local_device_->Initialize(cache_guid, signin_scoped_device_id, | 967 local_device_->Initialize(cache_guid, signin_scoped_device_id, |
| 977 blocking_pool_); | 968 blocking_task_runner_); |
| 978 | 969 |
| 979 if (protocol_event_observers_.might_have_observers()) { | 970 if (protocol_event_observers_.might_have_observers()) { |
| 980 engine_->RequestBufferedProtocolEventsAndEnableForwarding(); | 971 engine_->RequestBufferedProtocolEventsAndEnableForwarding(); |
| 981 } | 972 } |
| 982 | 973 |
| 983 if (type_debug_info_observers_.might_have_observers()) { | 974 if (type_debug_info_observers_.might_have_observers()) { |
| 984 engine_->EnableDirectoryTypeDebugInfoForwarding(); | 975 engine_->EnableDirectoryTypeDebugInfoForwarding(); |
| 985 } | 976 } |
| 986 | 977 |
| 987 // If we have a cached passphrase use it to decrypt/encrypt data now that the | 978 // If we have a cached passphrase use it to decrypt/encrypt data now that the |
| (...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1815 DCHECK(thread_checker_.CalledOnValidThread()); | 1806 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1816 return engine_ && engine_->IsCryptographerReady(trans); | 1807 return engine_ && engine_->IsCryptographerReady(trans); |
| 1817 } | 1808 } |
| 1818 | 1809 |
| 1819 void ProfileSyncService::SetPlatformSyncAllowedProvider( | 1810 void ProfileSyncService::SetPlatformSyncAllowedProvider( |
| 1820 const PlatformSyncAllowedProvider& platform_sync_allowed_provider) { | 1811 const PlatformSyncAllowedProvider& platform_sync_allowed_provider) { |
| 1821 DCHECK(thread_checker_.CalledOnValidThread()); | 1812 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1822 platform_sync_allowed_provider_ = platform_sync_allowed_provider; | 1813 platform_sync_allowed_provider_ = platform_sync_allowed_provider; |
| 1823 } | 1814 } |
| 1824 | 1815 |
| 1816 syncer::ModelTypeStoreFactory ProfileSyncService::GetModelTypeStoreFactory( |
| 1817 ModelType type) { |
| 1818 return base::Bind(&ModelTypeStore::CreateStore, type, |
| 1819 sync_data_folder_.Append(base::FilePath(kLevelDBFolderName)) |
| 1820 .AsUTF8Unsafe(), |
| 1821 blocking_task_runner_); |
| 1822 } |
| 1823 |
| 1825 void ProfileSyncService::ConfigureDataTypeManager() { | 1824 void ProfileSyncService::ConfigureDataTypeManager() { |
| 1826 // Don't configure datatypes if the setup UI is still on the screen - this | 1825 // Don't configure datatypes if the setup UI is still on the screen - this |
| 1827 // is to help multi-screen setting UIs (like iOS) where they don't want to | 1826 // is to help multi-screen setting UIs (like iOS) where they don't want to |
| 1828 // start syncing data until the user is done configuring encryption options, | 1827 // start syncing data until the user is done configuring encryption options, |
| 1829 // etc. ReconfigureDatatypeManager() will get called again once the UI calls | 1828 // etc. ReconfigureDatatypeManager() will get called again once the UI calls |
| 1830 // SetSetupInProgress(false). | 1829 // SetSetupInProgress(false). |
| 1831 if (!CanConfigureDataTypes()) { | 1830 if (!CanConfigureDataTypes()) { |
| 1832 // If we can't configure the data type manager yet, we should still notify | 1831 // If we can't configure the data type manager yet, we should still notify |
| 1833 // observers. This is to support multiple setup UIs being open at once. | 1832 // observers. This is to support multiple setup UIs being open at once. |
| 1834 NotifyObservers(); | 1833 NotifyObservers(); |
| (...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2635 | 2634 |
| 2636 DCHECK(startup_controller_->IsSetupInProgress()); | 2635 DCHECK(startup_controller_->IsSetupInProgress()); |
| 2637 startup_controller_->SetSetupInProgress(false); | 2636 startup_controller_->SetSetupInProgress(false); |
| 2638 | 2637 |
| 2639 if (IsEngineInitialized()) | 2638 if (IsEngineInitialized()) |
| 2640 ReconfigureDatatypeManager(); | 2639 ReconfigureDatatypeManager(); |
| 2641 NotifyObservers(); | 2640 NotifyObservers(); |
| 2642 } | 2641 } |
| 2643 | 2642 |
| 2644 } // namespace browser_sync | 2643 } // namespace browser_sync |
| OLD | NEW |