Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(660)

Side by Side Diff: components/browser_sync/profile_sync_service.cc

Issue 2732333003: [Sync] ModelTypeStore factory shouldn't require valid PSS to function correctly (Closed)
Patch Set: Rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 1000 * 3600 * 4, // 4 hours. 141 1000 * 3600 * 4, // 4 hours.
142 142
143 // Time to keep an entry from being discarded even when it 143 // Time to keep an entry from being discarded even when it
144 // has no significant state, -1 to never discard. 144 // has no significant state, -1 to never discard.
145 -1, 145 -1,
146 146
147 // Don't use initial delay unless the last request was an error. 147 // Don't use initial delay unless the last request was an error.
148 false, 148 false,
149 }; 149 };
150 150
151 const base::FilePath::CharType kLevelDBFolderName[] =
152 FILE_PATH_LITERAL("LevelDB");
153
154 } // namespace 151 } // namespace
155 152
156 ProfileSyncService::InitParams::InitParams() = default; 153 ProfileSyncService::InitParams::InitParams() = default;
157 ProfileSyncService::InitParams::InitParams(InitParams&& other) = default; 154 ProfileSyncService::InitParams::InitParams(InitParams&& other) = default;
158 ProfileSyncService::InitParams::~InitParams() = default; 155 ProfileSyncService::InitParams::~InitParams() = default;
159 156
160 ProfileSyncService::ProfileSyncService(InitParams init_params) 157 ProfileSyncService::ProfileSyncService(InitParams init_params)
161 : SyncServiceBase(std::move(init_params.sync_client), 158 : SyncServiceBase(std::move(init_params.sync_client),
162 std::move(init_params.signin_wrapper), 159 std::move(init_params.signin_wrapper),
163 init_params.channel, 160 init_params.channel,
164 init_params.base_directory, 161 init_params.base_directory,
165 init_params.debug_identifier), 162 init_params.debug_identifier),
166 OAuth2TokenService::Consumer("sync"), 163 OAuth2TokenService::Consumer("sync"),
167 last_auth_error_(AuthError::AuthErrorNone()), 164 last_auth_error_(AuthError::AuthErrorNone()),
168 sync_service_url_( 165 sync_service_url_(
169 syncer::GetSyncServiceURL(*base::CommandLine::ForCurrentProcess(), 166 syncer::GetSyncServiceURL(*base::CommandLine::ForCurrentProcess(),
170 init_params.channel)), 167 init_params.channel)),
171 network_time_update_callback_( 168 network_time_update_callback_(
172 std::move(init_params.network_time_update_callback)), 169 std::move(init_params.network_time_update_callback)),
173 url_request_context_(init_params.url_request_context), 170 url_request_context_(init_params.url_request_context),
174 blocking_task_runner_(std::move(init_params.blocking_task_runner)),
175 is_first_time_sync_configure_(false), 171 is_first_time_sync_configure_(false),
176 engine_initialized_(false), 172 engine_initialized_(false),
177 sync_disabled_by_admin_(false), 173 sync_disabled_by_admin_(false),
178 is_auth_in_progress_(false), 174 is_auth_in_progress_(false),
179 unrecoverable_error_reason_(ERROR_REASON_UNSET), 175 unrecoverable_error_reason_(ERROR_REASON_UNSET),
180 expect_sync_configuration_aborted_(false), 176 expect_sync_configuration_aborted_(false),
181 configure_status_(DataTypeManager::UNKNOWN), 177 configure_status_(DataTypeManager::UNKNOWN),
182 oauth2_token_service_(init_params.oauth2_token_service), 178 oauth2_token_service_(init_params.oauth2_token_service),
183 request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy), 179 request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy),
184 connection_status_(syncer::CONNECTION_NOT_ATTEMPTED), 180 connection_status_(syncer::CONNECTION_NOT_ATTEMPTED),
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 base::Bind(&ProfileSyncService::NotifyForeignSessionUpdated, 238 base::Bind(&ProfileSyncService::NotifyForeignSessionUpdated,
243 sync_enabled_weak_factory_.GetWeakPtr()), 239 sync_enabled_weak_factory_.GetWeakPtr()),
244 base::Bind(&ProfileSyncService::TriggerRefresh, 240 base::Bind(&ProfileSyncService::TriggerRefresh,
245 sync_enabled_weak_factory_.GetWeakPtr(), 241 sync_enabled_weak_factory_.GetWeakPtr(),
246 syncer::ModelTypeSet(syncer::SESSIONS))); 242 syncer::ModelTypeSet(syncer::SESSIONS)));
247 243
248 if (base::FeatureList::IsEnabled(switches::kSyncUSSDeviceInfo)) { 244 if (base::FeatureList::IsEnabled(switches::kSyncUSSDeviceInfo)) {
249 // TODO(skym): Stop creating leveldb files when signed out. 245 // TODO(skym): Stop creating leveldb files when signed out.
250 // TODO(skym): Verify using AsUTF8Unsafe is okay here. Should work as long 246 // TODO(skym): Verify using AsUTF8Unsafe is okay here. Should work as long
251 // as the Local State file is guaranteed to be UTF-8. 247 // as the Local State file is guaranteed to be UTF-8.
248 const syncer::ModelTypeStoreFactory& store_factory =
249 GetModelTypeStoreFactory(syncer::DEVICE_INFO, base_directory_,
250 sync_client_->GetBlockingPool());
252 device_info_sync_bridge_ = base::MakeUnique<DeviceInfoSyncBridge>( 251 device_info_sync_bridge_ = base::MakeUnique<DeviceInfoSyncBridge>(
253 local_device_.get(), GetModelTypeStoreFactory(syncer::DEVICE_INFO), 252 local_device_.get(), store_factory,
254 base::BindRepeating( 253 base::BindRepeating(
255 &ModelTypeChangeProcessor::Create, 254 &ModelTypeChangeProcessor::Create,
256 base::BindRepeating(&syncer::ReportUnrecoverableError, channel_))); 255 base::BindRepeating(&syncer::ReportUnrecoverableError, channel_)));
257 } else { 256 } else {
258 device_info_sync_service_ = 257 device_info_sync_service_ =
259 base::MakeUnique<DeviceInfoSyncService>(local_device_.get()); 258 base::MakeUnique<DeviceInfoSyncService>(local_device_.get());
260 } 259 }
261 260
262 syncer::SyncApiComponentFactory::RegisterDataTypesMethod 261 syncer::SyncApiComponentFactory::RegisterDataTypesMethod
263 register_platform_types_callback = 262 register_platform_types_callback =
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 550
552 startup_controller_->OnDataTypeRequestsSyncStartup(type); 551 startup_controller_->OnDataTypeRequestsSyncStartup(type);
553 } 552 }
554 553
555 void ProfileSyncService::StartUpSlowEngineComponents() { 554 void ProfileSyncService::StartUpSlowEngineComponents() {
556 invalidation::InvalidationService* invalidator = 555 invalidation::InvalidationService* invalidator =
557 sync_client_->GetInvalidationService(); 556 sync_client_->GetInvalidationService();
558 557
559 engine_.reset(sync_client_->GetSyncApiComponentFactory()->CreateSyncEngine( 558 engine_.reset(sync_client_->GetSyncApiComponentFactory()->CreateSyncEngine(
560 debug_identifier_, invalidator, sync_prefs_.AsWeakPtr(), 559 debug_identifier_, invalidator, sync_prefs_.AsWeakPtr(),
561 sync_data_folder_)); 560 FormatSyncDataPath(base_directory_)));
562 561
563 // Clear any old errors the first time sync starts. 562 // Clear any old errors the first time sync starts.
564 if (!IsFirstSetupComplete()) 563 if (!IsFirstSetupComplete())
565 ClearStaleErrors(); 564 ClearStaleErrors();
566 565
567 InitializeEngine(); 566 InitializeEngine();
568 567
569 UpdateFirstSyncTimePref(); 568 UpdateFirstSyncTimePref();
570 569
571 ReportPreviousSessionMemoryWarningCount(); 570 ReportPreviousSessionMemoryWarningCount();
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 } 686 }
688 687
689 void ProfileSyncService::ShutdownImpl(syncer::ShutdownReason reason) { 688 void ProfileSyncService::ShutdownImpl(syncer::ShutdownReason reason) {
690 if (!engine_) { 689 if (!engine_) {
691 if (reason == syncer::ShutdownReason::DISABLE_SYNC && sync_thread_) { 690 if (reason == syncer::ShutdownReason::DISABLE_SYNC && sync_thread_) {
692 // If the engine is already shut down when a DISABLE_SYNC happens, 691 // If the engine is already shut down when a DISABLE_SYNC happens,
693 // the data directory needs to be cleaned up here. 692 // the data directory needs to be cleaned up here.
694 sync_thread_->task_runner()->PostTask( 693 sync_thread_->task_runner()->PostTask(
695 FROM_HERE, 694 FROM_HERE,
696 base::Bind(&syncer::syncable::Directory::DeleteDirectoryFiles, 695 base::Bind(&syncer::syncable::Directory::DeleteDirectoryFiles,
697 sync_data_folder_)); 696 FormatSyncDataPath(base_directory_)));
698 } 697 }
699 return; 698 return;
700 } 699 }
701 700
702 if (reason == syncer::ShutdownReason::STOP_SYNC || 701 if (reason == syncer::ShutdownReason::STOP_SYNC ||
703 reason == syncer::ShutdownReason::DISABLE_SYNC) { 702 reason == syncer::ShutdownReason::DISABLE_SYNC) {
704 RemoveClientFromServer(); 703 RemoveClientFromServer();
705 } 704 }
706 705
707 // First, we spin down the engine to stop change processing as soon as 706 // First, we spin down the engine to stop change processing as soon as
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 signin_scoped_device_id = "local_device"; 922 signin_scoped_device_id = "local_device";
924 } else { 923 } else {
925 SigninClient* signin_client = signin_->GetOriginal()->signin_client(); 924 SigninClient* signin_client = signin_->GetOriginal()->signin_client();
926 DCHECK(signin_client); 925 DCHECK(signin_client);
927 std::string signin_scoped_device_id = 926 std::string signin_scoped_device_id =
928 signin_client->GetSigninScopedDeviceId(); 927 signin_client->GetSigninScopedDeviceId();
929 } 928 }
930 929
931 // Initialize local device info. 930 // Initialize local device info.
932 local_device_->Initialize(cache_guid, signin_scoped_device_id, 931 local_device_->Initialize(cache_guid, signin_scoped_device_id,
933 blocking_task_runner_); 932 sync_client_->GetBlockingPool());
934 933
935 if (protocol_event_observers_.might_have_observers()) { 934 if (protocol_event_observers_.might_have_observers()) {
936 engine_->RequestBufferedProtocolEventsAndEnableForwarding(); 935 engine_->RequestBufferedProtocolEventsAndEnableForwarding();
937 } 936 }
938 937
939 if (type_debug_info_observers_.might_have_observers()) { 938 if (type_debug_info_observers_.might_have_observers()) {
940 engine_->EnableDirectoryTypeDebugInfoForwarding(); 939 engine_->EnableDirectoryTypeDebugInfoForwarding();
941 } 940 }
942 941
943 // The very first time the backend initializes is effectively the first time 942 // The very first time the backend initializes is effectively the first time
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
1663 DCHECK(thread_checker_.CalledOnValidThread()); 1662 DCHECK(thread_checker_.CalledOnValidThread());
1664 return engine_ && engine_->IsCryptographerReady(trans); 1663 return engine_ && engine_->IsCryptographerReady(trans);
1665 } 1664 }
1666 1665
1667 void ProfileSyncService::SetPlatformSyncAllowedProvider( 1666 void ProfileSyncService::SetPlatformSyncAllowedProvider(
1668 const PlatformSyncAllowedProvider& platform_sync_allowed_provider) { 1667 const PlatformSyncAllowedProvider& platform_sync_allowed_provider) {
1669 DCHECK(thread_checker_.CalledOnValidThread()); 1668 DCHECK(thread_checker_.CalledOnValidThread());
1670 platform_sync_allowed_provider_ = platform_sync_allowed_provider; 1669 platform_sync_allowed_provider_ = platform_sync_allowed_provider;
1671 } 1670 }
1672 1671
1672 // static
1673 syncer::ModelTypeStoreFactory ProfileSyncService::GetModelTypeStoreFactory( 1673 syncer::ModelTypeStoreFactory ProfileSyncService::GetModelTypeStoreFactory(
1674 ModelType type) { 1674 ModelType type,
1675 return base::Bind(&ModelTypeStore::CreateStore, type, 1675 const base::FilePath& base_path,
1676 sync_data_folder_.Append(base::FilePath(kLevelDBFolderName)) 1676 base::SequencedWorkerPool* blocking_pool) {
1677 .AsUTF8Unsafe(), 1677 // TODO(skym): Verify using AsUTF8Unsafe is okay here. Should work as long
1678 blocking_task_runner_); 1678 // as the Local State file is guaranteed to be UTF-8.
1679 std::string path = FormatSharedModelTypeStorePath(base_path).AsUTF8Unsafe();
1680 base::SequencedWorkerPool::SequenceToken sequence_token =
1681 blocking_pool->GetNamedSequenceToken(path);
skym 2017/03/08 19:28:15 Cool!
1682 scoped_refptr<base::SequencedTaskRunner> task_runner =
1683 blocking_pool->GetSequencedTaskRunnerWithShutdownBehavior(
1684 blocking_pool->GetNamedSequenceToken(path),
1685 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
1686 return base::Bind(&ModelTypeStore::CreateStore, type, path, task_runner);
1679 } 1687 }
1680 1688
1681 void ProfileSyncService::ConfigureDataTypeManager() { 1689 void ProfileSyncService::ConfigureDataTypeManager() {
1682 // Don't configure datatypes if the setup UI is still on the screen - this 1690 // Don't configure datatypes if the setup UI is still on the screen - this
1683 // is to help multi-screen setting UIs (like iOS) where they don't want to 1691 // is to help multi-screen setting UIs (like iOS) where they don't want to
1684 // start syncing data until the user is done configuring encryption options, 1692 // start syncing data until the user is done configuring encryption options,
1685 // etc. ReconfigureDatatypeManager() will get called again once the UI calls 1693 // etc. ReconfigureDatatypeManager() will get called again once the UI calls
1686 // SetSetupInProgress(false). 1694 // SetSetupInProgress(false).
1687 if (!CanConfigureDataTypes()) { 1695 if (!CanConfigureDataTypes()) {
1688 // If we can't configure the data type manager yet, we should still notify 1696 // If we can't configure the data type manager yet, we should still notify
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
2323 void ProfileSyncService::FlushDirectory() const { 2331 void ProfileSyncService::FlushDirectory() const {
2324 DCHECK(thread_checker_.CalledOnValidThread()); 2332 DCHECK(thread_checker_.CalledOnValidThread());
2325 // engine_initialized_ implies engine_ isn't null and the manager exists. 2333 // engine_initialized_ implies engine_ isn't null and the manager exists.
2326 // If sync is not initialized yet, we fail silently. 2334 // If sync is not initialized yet, we fail silently.
2327 if (engine_initialized_) 2335 if (engine_initialized_)
2328 engine_->FlushDirectory(); 2336 engine_->FlushDirectory();
2329 } 2337 }
2330 2338
2331 base::FilePath ProfileSyncService::GetDirectoryPathForTest() const { 2339 base::FilePath ProfileSyncService::GetDirectoryPathForTest() const {
2332 DCHECK(thread_checker_.CalledOnValidThread()); 2340 DCHECK(thread_checker_.CalledOnValidThread());
2333 return sync_data_folder_; 2341 return FormatSyncDataPath(base_directory_);
2334 } 2342 }
2335 2343
2336 base::MessageLoop* ProfileSyncService::GetSyncLoopForTest() const { 2344 base::MessageLoop* ProfileSyncService::GetSyncLoopForTest() const {
2337 DCHECK(thread_checker_.CalledOnValidThread()); 2345 DCHECK(thread_checker_.CalledOnValidThread());
2338 if (sync_thread_) { 2346 if (sync_thread_) {
2339 return sync_thread_->message_loop(); 2347 return sync_thread_->message_loop();
2340 } else { 2348 } else {
2341 return nullptr; 2349 return nullptr;
2342 } 2350 }
2343 } 2351 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
2421 2429
2422 DCHECK(startup_controller_->IsSetupInProgress()); 2430 DCHECK(startup_controller_->IsSetupInProgress());
2423 startup_controller_->SetSetupInProgress(false); 2431 startup_controller_->SetSetupInProgress(false);
2424 2432
2425 if (IsEngineInitialized()) 2433 if (IsEngineInitialized())
2426 ReconfigureDatatypeManager(); 2434 ReconfigureDatatypeManager();
2427 NotifyObservers(); 2435 NotifyObservers();
2428 } 2436 }
2429 2437
2430 } // namespace browser_sync 2438 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698