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

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

Issue 2533083002: [Sync] SyncEngine refactor part 1: interfaces. (Closed)
Patch Set: Rebase. Created 4 years 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 // profile should get this treatment or all profile as is the case now. The 535 // profile should get this treatment or all profile as is the case now. The
536 // solution for now will be to assume profiles are created in the same order 536 // solution for now will be to assume profiles are created in the same order
537 // on all machines and in the future decide if only the Default one should be 537 // on all machines and in the future decide if only the Default one should be
538 // considered roamed. 538 // considered roamed.
539 local_sync_backend_folder = 539 local_sync_backend_folder =
540 local_sync_backend_folder.Append(base_directory_.BaseName()); 540 local_sync_backend_folder.Append(base_directory_.BaseName());
541 local_sync_backend_folder = 541 local_sync_backend_folder =
542 local_sync_backend_folder.Append(kLoopbackServerBackendFilename); 542 local_sync_backend_folder.Append(kLoopbackServerBackendFilename);
543 #endif // defined(OS_WIN) 543 #endif // defined(OS_WIN)
544 544
545 SyncBackendHost::HttpPostProviderFactoryGetter 545 SyncEngine::HttpPostProviderFactoryGetter http_post_provider_factory_getter =
546 http_post_provider_factory_getter = 546 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory,
547 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory, 547 base::Unretained(network_resources_.get()),
548 base::Unretained(network_resources_.get()), 548 url_request_context_, network_time_update_callback_);
549 url_request_context_, network_time_update_callback_);
550 549
551 backend_->Initialize( 550 backend_->Initialize(
552 this, sync_thread_->task_runner(), GetJsEventHandler(), sync_service_url_, 551 this, sync_thread_->task_runner(), GetJsEventHandler(), sync_service_url_,
553 local_device_->GetSyncUserAgent(), credentials, delete_stale_data, 552 local_device_->GetSyncUserAgent(), credentials, delete_stale_data,
554 enable_local_sync_backend, local_sync_backend_folder, 553 enable_local_sync_backend, local_sync_backend_folder,
555 base::MakeUnique<syncer::SyncManagerFactory>(), 554 base::MakeUnique<syncer::SyncManagerFactory>(),
556 MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()), 555 MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()),
557 base::Bind(syncer::ReportUnrecoverableError, channel_), 556 base::Bind(syncer::ReportUnrecoverableError, channel_),
558 http_post_provider_factory_getter, std::move(saved_nigori_state_)); 557 http_post_provider_factory_getter, std::move(saved_nigori_state_));
559 } 558 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 return; 624 return;
626 } 625 }
627 626
628 startup_controller_->OnDataTypeRequestsSyncStartup(type); 627 startup_controller_->OnDataTypeRequestsSyncStartup(type);
629 } 628 }
630 629
631 void ProfileSyncService::StartUpSlowBackendComponents() { 630 void ProfileSyncService::StartUpSlowBackendComponents() {
632 invalidation::InvalidationService* invalidator = 631 invalidation::InvalidationService* invalidator =
633 sync_client_->GetInvalidationService(); 632 sync_client_->GetInvalidationService();
634 633
635 backend_.reset( 634 backend_.reset(sync_client_->GetSyncApiComponentFactory()->CreateSyncEngine(
636 sync_client_->GetSyncApiComponentFactory()->CreateSyncBackendHost( 635 debug_identifier_, invalidator, sync_prefs_.AsWeakPtr(),
637 debug_identifier_, invalidator, sync_prefs_.AsWeakPtr(), 636 directory_path_));
638 directory_path_));
639 637
640 // Initialize the backend. Every time we start up a new SyncBackendHost, 638 // Initialize the backend. Every time we start up a new SyncEngine, we'll want
641 // we'll want to start from a fresh SyncDB, so delete any old one that might 639 // to start from a fresh SyncDB, so delete any old one that might be there.
642 // be there.
643 InitializeBackend(ShouldDeleteSyncFolder()); 640 InitializeBackend(ShouldDeleteSyncFolder());
644 641
645 UpdateFirstSyncTimePref(); 642 UpdateFirstSyncTimePref();
646 643
647 ReportPreviousSessionMemoryWarningCount(); 644 ReportPreviousSessionMemoryWarningCount();
648 } 645 }
649 646
650 void ProfileSyncService::OnGetTokenSuccess( 647 void ProfileSyncService::OnGetTokenSuccess(
651 const OAuth2TokenService::Request* request, 648 const OAuth2TokenService::Request* request,
652 const std::string& access_token, 649 const std::string& access_token,
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 data_type_manager_.reset(); 795 data_type_manager_.reset();
799 } 796 }
800 797
801 // Shutdown the migrator before the backend to ensure it doesn't pull a null 798 // Shutdown the migrator before the backend to ensure it doesn't pull a null
802 // snapshot. 799 // snapshot.
803 migrator_.reset(); 800 migrator_.reset();
804 sync_js_controller_.AttachJsBackend(WeakHandle<syncer::JsBackend>()); 801 sync_js_controller_.AttachJsBackend(WeakHandle<syncer::JsBackend>());
805 802
806 backend_->Shutdown(reason); 803 backend_->Shutdown(reason);
807 backend_.reset(); 804 backend_.reset();
805
808 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time; 806 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time;
809 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time); 807 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time);
810 808
811 sync_enabled_weak_factory_.InvalidateWeakPtrs(); 809 sync_enabled_weak_factory_.InvalidateWeakPtrs();
812 810
813 startup_controller_->Reset(GetRegisteredDataTypes()); 811 startup_controller_->Reset(GetRegisteredDataTypes());
814 812
815 // If the sync DB is getting destroyed, the local DeviceInfo is no longer 813 // If the sync DB is getting destroyed, the local DeviceInfo is no longer
816 // valid and should be cleared from the cache. 814 // valid and should be cleared from the cache.
817 if (reason == syncer::ShutdownReason::DISABLE_SYNC) { 815 if (reason == syncer::ShutdownReason::DISABLE_SYNC) {
(...skipping 19 matching lines...) Expand all
837 NotifyObservers(); 835 NotifyObservers();
838 836
839 // Mark this as a clean shutdown(without crash). 837 // Mark this as a clean shutdown(without crash).
840 sync_prefs_.SetCleanShutdown(true); 838 sync_prefs_.SetCleanShutdown(true);
841 } 839 }
842 840
843 void ProfileSyncService::StopImpl(SyncStopDataFate data_fate) { 841 void ProfileSyncService::StopImpl(SyncStopDataFate data_fate) {
844 switch (data_fate) { 842 switch (data_fate) {
845 case KEEP_DATA: 843 case KEEP_DATA:
846 // TODO(maxbogue): Investigate whether this logic can/should be moved 844 // TODO(maxbogue): Investigate whether this logic can/should be moved
847 // into ShutdownImpl or SyncBackendHost itself. 845 // into ShutdownImpl or the sync engine itself.
848 if (HasSyncingBackend()) { 846 if (HasSyncingBackend()) {
849 backend_->UnregisterInvalidationIds(); 847 backend_->UnregisterInvalidationIds();
850 } 848 }
851 ShutdownImpl(syncer::STOP_SYNC); 849 ShutdownImpl(syncer::STOP_SYNC);
852 break; 850 break;
853 case CLEAR_DATA: 851 case CLEAR_DATA:
854 // Clear prefs (including SyncSetupHasCompleted) before shutting down so 852 // Clear prefs (including SyncSetupHasCompleted) before shutting down so
855 // PSS clients don't think we're set up while we're shutting down. 853 // PSS clients don't think we're set up while we're shutting down.
856 sync_prefs_.ClearPreferences(); 854 sync_prefs_.ClearPreferences();
857 ClearUnrecoverableError(); 855 ClearUnrecoverableError();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 is_first_time_sync_configure_ = !IsFirstSetupComplete(); 950 is_first_time_sync_configure_ = !IsFirstSetupComplete();
953 951
954 if (is_first_time_sync_configure_) { 952 if (is_first_time_sync_configure_) {
955 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); 953 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success);
956 } else { 954 } else {
957 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success); 955 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success);
958 } 956 }
959 957
960 base::Time on_backend_initialized_time = base::Time::Now(); 958 base::Time on_backend_initialized_time = base::Time::Now();
961 base::TimeDelta delta = 959 base::TimeDelta delta =
962 on_backend_initialized_time - startup_controller_->start_backend_time(); 960 on_backend_initialized_time - startup_controller_->start_engine_time();
963 if (is_first_time_sync_configure_) { 961 if (is_first_time_sync_configure_) {
964 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeFirstTime", delta); 962 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeFirstTime", delta);
965 } else { 963 } else {
966 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta); 964 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta);
967 } 965 }
968 } 966 }
969 967
970 void ProfileSyncService::PostBackendInitialization() { 968 void ProfileSyncService::PostBackendInitialization() {
971 if (protocol_event_observers_.might_have_observers()) { 969 if (protocol_event_observers_.might_have_observers()) {
972 backend_->RequestBufferedProtocolEventsAndEnableForwarding(); 970 backend_->RequestBufferedProtocolEventsAndEnableForwarding();
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 return "Datatypes not fully initialized"; 1494 return "Datatypes not fully initialized";
1497 case INITIALIZED: 1495 case INITIALIZED:
1498 return "Sync service initialized"; 1496 return "Sync service initialized";
1499 default: 1497 default:
1500 return "Status unknown: Internal error?"; 1498 return "Status unknown: Internal error?";
1501 } 1499 }
1502 } 1500 }
1503 1501
1504 std::string ProfileSyncService::GetBackendInitializationStateString() const { 1502 std::string ProfileSyncService::GetBackendInitializationStateString() const {
1505 DCHECK(thread_checker_.CalledOnValidThread()); 1503 DCHECK(thread_checker_.CalledOnValidThread());
1506 return startup_controller_->GetBackendInitializationStateString(); 1504 return startup_controller_->GetEngineInitializationStateString();
1507 } 1505 }
1508 1506
1509 bool ProfileSyncService::IsSetupInProgress() const { 1507 bool ProfileSyncService::IsSetupInProgress() const {
1510 DCHECK(thread_checker_.CalledOnValidThread()); 1508 DCHECK(thread_checker_.CalledOnValidThread());
1511 return startup_controller_->IsSetupInProgress(); 1509 return startup_controller_->IsSetupInProgress();
1512 } 1510 }
1513 1511
1514 bool ProfileSyncService::QueryDetailedSyncStatus( 1512 bool ProfileSyncService::QueryDetailedSyncStatus(SyncEngine::Status* result) {
1515 SyncBackendHost::Status* result) {
1516 DCHECK(thread_checker_.CalledOnValidThread()); 1513 DCHECK(thread_checker_.CalledOnValidThread());
1517 if (backend_.get() && backend_initialized_) { 1514 if (backend_.get() && backend_initialized_) {
1518 *result = backend_->GetDetailedStatus(); 1515 *result = backend_->GetDetailedStatus();
1519 return true; 1516 return true;
1520 } else { 1517 } else {
1521 SyncBackendHost::Status status; 1518 SyncEngine::Status status;
1522 status.sync_protocol_error = last_actionable_error_; 1519 status.sync_protocol_error = last_actionable_error_;
1523 *result = status; 1520 *result = status;
1524 return false; 1521 return false;
1525 } 1522 }
1526 } 1523 }
1527 1524
1528 const AuthError& ProfileSyncService::GetAuthError() const { 1525 const AuthError& ProfileSyncService::GetAuthError() const {
1529 DCHECK(thread_checker_.CalledOnValidThread()); 1526 DCHECK(thread_checker_.CalledOnValidThread());
1530 return last_auth_error_; 1527 return last_auth_error_;
1531 } 1528 }
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1922 backend_->GetModelSafeRoutingInfo(&routing_info); 1919 backend_->GetModelSafeRoutingInfo(&routing_info);
1923 for (ModelSafeRoutingInfo::const_iterator it = routing_info.begin(); 1920 for (ModelSafeRoutingInfo::const_iterator it = routing_info.begin();
1924 it != routing_info.end(); ++it) { 1921 it != routing_info.end(); ++it) {
1925 if (it->second == syncer::GROUP_PASSIVE) { 1922 if (it->second == syncer::GROUP_PASSIVE) {
1926 passive_types.Put(it->first); 1923 passive_types.Put(it->first);
1927 } else { 1924 } else {
1928 active_types.Put(it->first); 1925 active_types.Put(it->first);
1929 } 1926 }
1930 } 1927 }
1931 1928
1932 SyncBackendHost::Status detailed_status = backend_->GetDetailedStatus(); 1929 SyncEngine::Status detailed_status = backend_->GetDetailedStatus();
1933 ModelTypeSet& throttled_types(detailed_status.throttled_types); 1930 ModelTypeSet& throttled_types(detailed_status.throttled_types);
1934 ModelTypeSet& backed_off_types(detailed_status.backed_off_types); 1931 ModelTypeSet& backed_off_types(detailed_status.backed_off_types);
1935 ModelTypeSet registered = GetRegisteredDataTypes(); 1932 ModelTypeSet registered = GetRegisteredDataTypes();
1936 std::unique_ptr<base::DictionaryValue> type_status_header( 1933 std::unique_ptr<base::DictionaryValue> type_status_header(
1937 new base::DictionaryValue()); 1934 new base::DictionaryValue());
1938 1935
1939 type_status_header->SetString("name", "Model Type"); 1936 type_status_header->SetString("name", "Model Type");
1940 type_status_header->SetString("status", "header"); 1937 type_status_header->SetString("status", "header");
1941 type_status_header->SetString("value", "Group Type"); 1938 type_status_header->SetString("value", "Group Type");
1942 type_status_header->SetString("num_entries", "Total Entries"); 1939 type_status_header->SetString("num_entries", "Total Entries");
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
2644 2641
2645 DCHECK(startup_controller_->IsSetupInProgress()); 2642 DCHECK(startup_controller_->IsSetupInProgress());
2646 startup_controller_->SetSetupInProgress(false); 2643 startup_controller_->SetSetupInProgress(false);
2647 2644
2648 if (IsBackendInitialized()) 2645 if (IsBackendInitialized())
2649 ReconfigureDatatypeManager(); 2646 ReconfigureDatatypeManager();
2650 NotifyObservers(); 2647 NotifyObservers();
2651 } 2648 }
2652 2649
2653 } // namespace browser_sync 2650 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/browser_sync/profile_sync_service.h ('k') | components/browser_sync/profile_sync_service_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698