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

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

Issue 2481313002: [Sync] Move sync thread ownership to ProfileSyncService. (Closed)
Patch Set: Address comments. Created 4 years, 1 month 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 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 bool ProfileSyncService::ShouldDeleteSyncFolder() { 489 bool ProfileSyncService::ShouldDeleteSyncFolder() {
490 return !IsFirstSetupComplete(); 490 return !IsFirstSetupComplete();
491 } 491 }
492 492
493 void ProfileSyncService::InitializeBackend(bool delete_stale_data) { 493 void ProfileSyncService::InitializeBackend(bool delete_stale_data) {
494 if (!backend_) { 494 if (!backend_) {
495 NOTREACHED(); 495 NOTREACHED();
496 return; 496 return;
497 } 497 }
498 498
499 if (!sync_thread_) {
500 sync_thread_ = base::MakeUnique<base::Thread>("Chrome_SyncThread");
501 base::Thread::Options options;
502 options.timer_slack = base::TIMER_SLACK_MAXIMUM;
503 CHECK(sync_thread_->StartWithOptions(options));
504 }
505
499 SyncCredentials credentials = GetCredentials(); 506 SyncCredentials credentials = GetCredentials();
500 507
501 if (delete_stale_data) 508 if (delete_stale_data)
502 ClearStaleErrors(); 509 ClearStaleErrors();
503 510
504 bool enable_local_sync_backend = false; 511 bool enable_local_sync_backend = false;
505 base::FilePath local_sync_backend_folder; 512 base::FilePath local_sync_backend_folder;
506 #if defined(OS_WIN) 513 #if defined(OS_WIN)
507 enable_local_sync_backend = base::CommandLine::ForCurrentProcess()->HasSwitch( 514 enable_local_sync_backend = base::CommandLine::ForCurrentProcess()->HasSwitch(
508 switches::kEnableLocalSyncBackend); 515 switches::kEnableLocalSyncBackend);
(...skipping 22 matching lines...) Expand all
531 local_sync_backend_folder.Append(kLoopbackServerBackendFilename); 538 local_sync_backend_folder.Append(kLoopbackServerBackendFilename);
532 #endif // defined(OS_WIN) 539 #endif // defined(OS_WIN)
533 540
534 SyncBackendHost::HttpPostProviderFactoryGetter 541 SyncBackendHost::HttpPostProviderFactoryGetter
535 http_post_provider_factory_getter = 542 http_post_provider_factory_getter =
536 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory, 543 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory,
537 base::Unretained(network_resources_.get()), 544 base::Unretained(network_resources_.get()),
538 url_request_context_, network_time_update_callback_); 545 url_request_context_, network_time_update_callback_);
539 546
540 backend_->Initialize( 547 backend_->Initialize(
541 this, std::move(sync_thread_), db_thread_, file_thread_, 548 this, sync_thread_.get(), db_thread_, file_thread_, GetJsEventHandler(),
542 GetJsEventHandler(), sync_service_url_, local_device_->GetSyncUserAgent(), 549 sync_service_url_, local_device_->GetSyncUserAgent(), credentials,
543 credentials, delete_stale_data, enable_local_sync_backend, 550 delete_stale_data, enable_local_sync_backend, local_sync_backend_folder,
544 local_sync_backend_folder, std::unique_ptr<syncer::SyncManagerFactory>( 551 base::MakeUnique<syncer::SyncManagerFactory>(),
545 new syncer::SyncManagerFactory()),
546 MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()), 552 MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()),
547 base::Bind(syncer::ReportUnrecoverableError, channel_), 553 base::Bind(syncer::ReportUnrecoverableError, channel_),
548 http_post_provider_factory_getter, std::move(saved_nigori_state_)); 554 http_post_provider_factory_getter, std::move(saved_nigori_state_));
549 } 555 }
550 556
551 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { 557 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const {
552 if (encryption_pending()) 558 if (encryption_pending())
553 return true; 559 return true;
554 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes(); 560 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes();
555 const syncer::ModelTypeSet encrypted_types = GetEncryptedDataTypes(); 561 const syncer::ModelTypeSet encrypted_types = GetEncryptedDataTypes();
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 785
780 // Shutdown the migrator before the backend to ensure it doesn't pull a null 786 // Shutdown the migrator before the backend to ensure it doesn't pull a null
781 // snapshot. 787 // snapshot.
782 migrator_.reset(); 788 migrator_.reset();
783 sync_js_controller_.AttachJsBackend(WeakHandle<syncer::JsBackend>()); 789 sync_js_controller_.AttachJsBackend(WeakHandle<syncer::JsBackend>());
784 790
785 // Move aside the backend so nobody else tries to use it while we are 791 // Move aside the backend so nobody else tries to use it while we are
786 // shutting it down. 792 // shutting it down.
787 std::unique_ptr<SyncBackendHost> doomed_backend(backend_.release()); 793 std::unique_ptr<SyncBackendHost> doomed_backend(backend_.release());
788 if (doomed_backend) { 794 if (doomed_backend) {
789 sync_thread_ = doomed_backend->Shutdown(reason); 795 doomed_backend->Shutdown(reason);
790 doomed_backend.reset(); 796 doomed_backend.reset();
791 } 797 }
792 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time; 798 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time;
793 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time); 799 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time);
794 800
795 sync_enabled_weak_factory_.InvalidateWeakPtrs(); 801 sync_enabled_weak_factory_.InvalidateWeakPtrs();
796 802
797 startup_controller_->Reset(GetRegisteredDataTypes()); 803 startup_controller_->Reset(GetRegisteredDataTypes());
798 804
799 // If the sync DB is getting destroyed, the local DeviceInfo is no longer 805 // If the sync DB is getting destroyed, the local DeviceInfo is no longer
(...skipping 1641 matching lines...) Expand 10 before | Expand all | Expand 10 after
2441 backend_->FlushDirectory(); 2447 backend_->FlushDirectory();
2442 } 2448 }
2443 2449
2444 base::FilePath ProfileSyncService::GetDirectoryPathForTest() const { 2450 base::FilePath ProfileSyncService::GetDirectoryPathForTest() const {
2445 return directory_path_; 2451 return directory_path_;
2446 } 2452 }
2447 2453
2448 base::MessageLoop* ProfileSyncService::GetSyncLoopForTest() const { 2454 base::MessageLoop* ProfileSyncService::GetSyncLoopForTest() const {
2449 if (sync_thread_) { 2455 if (sync_thread_) {
2450 return sync_thread_->message_loop(); 2456 return sync_thread_->message_loop();
2451 } else if (backend_) {
2452 return backend_->GetSyncLoopForTesting();
2453 } else { 2457 } else {
2454 return nullptr; 2458 return nullptr;
2455 } 2459 }
2456 } 2460 }
2457 2461
2458 void ProfileSyncService::RefreshTypesForTest(syncer::ModelTypeSet types) { 2462 void ProfileSyncService::RefreshTypesForTest(syncer::ModelTypeSet types) {
2459 if (backend_initialized_) 2463 if (backend_initialized_)
2460 backend_->RefreshTypesForTest(types); 2464 backend_->RefreshTypesForTest(types);
2461 } 2465 }
2462 2466
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2525 2529
2526 DCHECK(startup_controller_->IsSetupInProgress()); 2530 DCHECK(startup_controller_->IsSetupInProgress());
2527 startup_controller_->SetSetupInProgress(false); 2531 startup_controller_->SetSetupInProgress(false);
2528 2532
2529 if (IsBackendInitialized()) 2533 if (IsBackendInitialized())
2530 ReconfigureDatatypeManager(); 2534 ReconfigureDatatypeManager();
2531 NotifyObservers(); 2535 NotifyObservers();
2532 } 2536 }
2533 2537
2534 } // namespace browser_sync 2538 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/browser_sync/profile_sync_service.h ('k') | components/browser_sync/profile_sync_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698