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

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 437683002: Wire sync shutdown reason from PSS all the way down to sync manager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | sync/internal_api/public/shutdown_reason.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/sync/profile_sync_service.h" 5 #include "chrome/browser/sync/profile_sync_service.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 #include "content/public/browser/notification_service.h" 82 #include "content/public/browser/notification_service.h"
83 #include "content/public/browser/notification_source.h" 83 #include "content/public/browser/notification_source.h"
84 #include "grit/generated_resources.h" 84 #include "grit/generated_resources.h"
85 #include "net/cookies/cookie_monster.h" 85 #include "net/cookies/cookie_monster.h"
86 #include "net/url_request/url_request_context_getter.h" 86 #include "net/url_request/url_request_context_getter.h"
87 #include "sync/api/sync_error.h" 87 #include "sync/api/sync_error.h"
88 #include "sync/internal_api/public/configure_reason.h" 88 #include "sync/internal_api/public/configure_reason.h"
89 #include "sync/internal_api/public/http_bridge_network_resources.h" 89 #include "sync/internal_api/public/http_bridge_network_resources.h"
90 #include "sync/internal_api/public/network_resources.h" 90 #include "sync/internal_api/public/network_resources.h"
91 #include "sync/internal_api/public/sessions/type_debug_info_observer.h" 91 #include "sync/internal_api/public/sessions/type_debug_info_observer.h"
92 #include "sync/internal_api/public/shutdown_reason.h"
92 #include "sync/internal_api/public/sync_context_proxy.h" 93 #include "sync/internal_api/public/sync_context_proxy.h"
93 #include "sync/internal_api/public/sync_encryption_handler.h" 94 #include "sync/internal_api/public/sync_encryption_handler.h"
94 #include "sync/internal_api/public/util/experiments.h" 95 #include "sync/internal_api/public/util/experiments.h"
95 #include "sync/internal_api/public/util/sync_db_util.h" 96 #include "sync/internal_api/public/util/sync_db_util.h"
96 #include "sync/internal_api/public/util/sync_string_conversions.h" 97 #include "sync/internal_api/public/util/sync_string_conversions.h"
97 #include "sync/js/js_event_details.h" 98 #include "sync/js/js_event_details.h"
98 #include "sync/util/cryptographer.h" 99 #include "sync/util/cryptographer.h"
99 #include "ui/base/l10n/l10n_util.h" 100 #include "ui/base/l10n/l10n_util.h"
100 #include "ui/base/l10n/time_format.h" 101 #include "ui/base/l10n/time_format.h"
101 102
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 639
639 void ProfileSyncService::StartUpSlowBackendComponents( 640 void ProfileSyncService::StartUpSlowBackendComponents(
640 ProfileSyncService::BackendMode mode) { 641 ProfileSyncService::BackendMode mode) {
641 DCHECK_NE(IDLE, mode); 642 DCHECK_NE(IDLE, mode);
642 if (backend_mode_ == mode) { 643 if (backend_mode_ == mode) {
643 return; 644 return;
644 } 645 }
645 646
646 DVLOG(1) << "Start backend mode: " << mode; 647 DVLOG(1) << "Start backend mode: " << mode;
647 648
648 if (backend_) 649 if (backend_) {
649 ShutdownImpl(browser_sync::SyncBackendHost::STOP_AND_CLAIM_THREAD); 650 if (mode == SYNC)
651 ShutdownImpl(syncer::SWITCH_MODE_SYNC);
652 else
653 ShutdownImpl(syncer::STOP_SYNC);
654 }
650 655
651 backend_mode_ = mode; 656 backend_mode_ = mode;
652 657
653 if (backend_mode_ == ROLLBACK) 658 if (backend_mode_ == ROLLBACK)
654 ClearBrowsingDataSinceFirstSync(); 659 ClearBrowsingDataSinceFirstSync();
655 else if (backend_mode_ == SYNC) 660 else if (backend_mode_ == SYNC)
656 CheckSyncBackupIfNeeded(); 661 CheckSyncBackupIfNeeded();
657 662
658 base::FilePath sync_folder = backend_mode_ == SYNC ? 663 base::FilePath sync_folder = backend_mode_ == SYNC ?
659 base::FilePath(kSyncDataFolderName) : 664 base::FilePath(kSyncDataFolderName) :
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 if (HasSyncingBackend()) { 781 if (HasSyncingBackend()) {
777 RequestAccessToken(); 782 RequestAccessToken();
778 } else { 783 } else {
779 startup_controller_.TryStart(); 784 startup_controller_.TryStart();
780 } 785 }
781 } 786 }
782 787
783 void ProfileSyncService::Shutdown() { 788 void ProfileSyncService::Shutdown() {
784 UnregisterAuthNotifications(); 789 UnregisterAuthNotifications();
785 790
786 ShutdownImpl(browser_sync::SyncBackendHost::STOP); 791 ShutdownImpl(syncer::BROWSER_SHUTDOWN);
787 if (sync_error_controller_) { 792 if (sync_error_controller_) {
788 // Destroy the SyncErrorController when the service shuts down for good. 793 // Destroy the SyncErrorController when the service shuts down for good.
789 RemoveObserver(sync_error_controller_.get()); 794 RemoveObserver(sync_error_controller_.get());
790 sync_error_controller_.reset(); 795 sync_error_controller_.reset();
791 } 796 }
792 797
793 if (sync_thread_) 798 if (sync_thread_)
794 sync_thread_->Stop(); 799 sync_thread_->Stop();
795 } 800 }
796 801
797 void ProfileSyncService::ShutdownImpl( 802 void ProfileSyncService::ShutdownImpl(syncer::ShutdownReason reason) {
798 browser_sync::SyncBackendHost::ShutdownOption option) {
799 if (!backend_) 803 if (!backend_)
800 return; 804 return;
801 805
802 non_blocking_data_type_manager_.DisconnectSyncBackend(); 806 non_blocking_data_type_manager_.DisconnectSyncBackend();
803 807
804 // First, we spin down the backend to stop change processing as soon as 808 // First, we spin down the backend to stop change processing as soon as
805 // possible. 809 // possible.
806 base::Time shutdown_start_time = base::Time::Now(); 810 base::Time shutdown_start_time = base::Time::Now();
807 backend_->StopSyncingForShutdown(); 811 backend_->StopSyncingForShutdown();
808 812
(...skipping 14 matching lines...) Expand all
823 827
824 // Shutdown the migrator before the backend to ensure it doesn't pull a null 828 // Shutdown the migrator before the backend to ensure it doesn't pull a null
825 // snapshot. 829 // snapshot.
826 migrator_.reset(); 830 migrator_.reset();
827 sync_js_controller_.AttachJsBackend(WeakHandle<syncer::JsBackend>()); 831 sync_js_controller_.AttachJsBackend(WeakHandle<syncer::JsBackend>());
828 832
829 // Move aside the backend so nobody else tries to use it while we are 833 // Move aside the backend so nobody else tries to use it while we are
830 // shutting it down. 834 // shutting it down.
831 scoped_ptr<SyncBackendHost> doomed_backend(backend_.release()); 835 scoped_ptr<SyncBackendHost> doomed_backend(backend_.release());
832 if (doomed_backend) { 836 if (doomed_backend) {
833 sync_thread_ = doomed_backend->Shutdown(option); 837 sync_thread_ = doomed_backend->Shutdown(reason);
834 doomed_backend.reset(); 838 doomed_backend.reset();
835 } 839 }
836 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time; 840 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time;
837 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time); 841 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time);
838 842
839 weak_factory_.InvalidateWeakPtrs(); 843 weak_factory_.InvalidateWeakPtrs();
840 844
841 if (backend_mode_ == SYNC) 845 if (backend_mode_ == SYNC)
842 startup_controller_.Reset(GetRegisteredDataTypes()); 846 startup_controller_.Reset(GetRegisteredDataTypes());
843 847
(...skipping 14 matching lines...) Expand all
858 UpdateAuthErrorState(GoogleServiceAuthError::AuthErrorNone()); 862 UpdateAuthErrorState(GoogleServiceAuthError::AuthErrorNone());
859 863
860 NotifyObservers(); 864 NotifyObservers();
861 } 865 }
862 866
863 void ProfileSyncService::DisableForUser() { 867 void ProfileSyncService::DisableForUser() {
864 // Clear prefs (including SyncSetupHasCompleted) before shutting down so 868 // Clear prefs (including SyncSetupHasCompleted) before shutting down so
865 // PSS clients don't think we're set up while we're shutting down. 869 // PSS clients don't think we're set up while we're shutting down.
866 sync_prefs_.ClearPreferences(); 870 sync_prefs_.ClearPreferences();
867 ClearUnrecoverableError(); 871 ClearUnrecoverableError();
868 ShutdownImpl(browser_sync::SyncBackendHost::DISABLE_AND_CLAIM_THREAD); 872 ShutdownImpl(syncer::DISABLE_SYNC);
869 } 873 }
870 874
871 bool ProfileSyncService::HasSyncSetupCompleted() const { 875 bool ProfileSyncService::HasSyncSetupCompleted() const {
872 return sync_prefs_.HasSyncSetupCompleted(); 876 return sync_prefs_.HasSyncSetupCompleted();
873 } 877 }
874 878
875 void ProfileSyncService::SetSyncSetupCompleted() { 879 void ProfileSyncService::SetSyncSetupCompleted() {
876 sync_prefs_.SetSyncSetupCompleted(); 880 sync_prefs_.SetSyncSetupCompleted();
877 } 881 }
878 882
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 from_here.Write(true, true, &location); 941 from_here.Write(true, true, &location);
938 LOG(ERROR) 942 LOG(ERROR)
939 << "Unrecoverable error detected at " << location 943 << "Unrecoverable error detected at " << location
940 << " -- ProfileSyncService unusable: " << message; 944 << " -- ProfileSyncService unusable: " << message;
941 945
942 // Shut all data types down. 946 // Shut all data types down.
943 base::MessageLoop::current()->PostTask(FROM_HERE, 947 base::MessageLoop::current()->PostTask(FROM_HERE,
944 base::Bind(&ProfileSyncService::ShutdownImpl, 948 base::Bind(&ProfileSyncService::ShutdownImpl,
945 weak_factory_.GetWeakPtr(), 949 weak_factory_.GetWeakPtr(),
946 delete_sync_database ? 950 delete_sync_database ?
947 browser_sync::SyncBackendHost::DISABLE_AND_CLAIM_THREAD : 951 syncer::DISABLE_SYNC : syncer::STOP_SYNC));
948 browser_sync::SyncBackendHost::STOP_AND_CLAIM_THREAD));
949 } 952 }
950 953
951 // TODO(zea): Move this logic into the DataTypeController/DataTypeManager. 954 // TODO(zea): Move this logic into the DataTypeController/DataTypeManager.
952 void ProfileSyncService::DisableDatatype(const syncer::SyncError& error) { 955 void ProfileSyncService::DisableDatatype(const syncer::SyncError& error) {
953 // First deactivate the type so that no further server changes are 956 // First deactivate the type so that no further server changes are
954 // passed onto the change processor. 957 // passed onto the change processor.
955 DeactivateDataType(error.model_type()); 958 DeactivateDataType(error.model_type());
956 959
957 std::map<syncer::ModelType, syncer::SyncError> errors; 960 std::map<syncer::ModelType, syncer::SyncError> errors;
958 errors[error.model_type()] = error; 961 errors[error.model_type()] = error;
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 } 1444 }
1442 #endif 1445 #endif
1443 break; 1446 break;
1444 case syncer::ROLLBACK_DONE: 1447 case syncer::ROLLBACK_DONE:
1445 backup_rollback_controller_.OnRollbackDone(); 1448 backup_rollback_controller_.OnRollbackDone();
1446 break; 1449 break;
1447 case syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT: 1450 case syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT:
1448 // Sync disabled by domain admin. we should stop syncing until next 1451 // Sync disabled by domain admin. we should stop syncing until next
1449 // restart. 1452 // restart.
1450 sync_disabled_by_admin_ = true; 1453 sync_disabled_by_admin_ = true;
1451 ShutdownImpl(browser_sync::SyncBackendHost::DISABLE_AND_CLAIM_THREAD); 1454 ShutdownImpl(syncer::DISABLE_SYNC);
1452 break; 1455 break;
1453 default: 1456 default:
1454 NOTREACHED(); 1457 NOTREACHED();
1455 } 1458 }
1456 NotifyObservers(); 1459 NotifyObservers();
1457 1460
1458 backup_rollback_controller_.Start(base::TimeDelta()); 1461 backup_rollback_controller_.Start(base::TimeDelta());
1459 } 1462 }
1460 1463
1461 void ProfileSyncService::OnConfigureDone( 1464 void ProfileSyncService::OnConfigureDone(
1462 const DataTypeManager::ConfigureResult& result) { 1465 const DataTypeManager::ConfigureResult& result) {
1463 // We should have cleared our cached passphrase before we get here (in 1466 // We should have cleared our cached passphrase before we get here (in
1464 // OnBackendInitialized()). 1467 // OnBackendInitialized()).
1465 DCHECK(cached_passphrase_.empty()); 1468 DCHECK(cached_passphrase_.empty());
1466 1469
1467 configure_status_ = result.status; 1470 configure_status_ = result.status;
1468 1471
1469 if (backend_mode_ != SYNC) { 1472 if (backend_mode_ != SYNC) {
1470 if (configure_status_ == DataTypeManager::OK || 1473 if (configure_status_ == DataTypeManager::OK ||
1471 configure_status_ == DataTypeManager::PARTIAL_SUCCESS) { 1474 configure_status_ == DataTypeManager::PARTIAL_SUCCESS) {
1472 StartSyncingWithServer(); 1475 StartSyncingWithServer();
1473 } else if (!expect_sync_configuration_aborted_) { 1476 } else if (!expect_sync_configuration_aborted_) {
1474 DVLOG(1) << "Backup/rollback backend failed to configure."; 1477 DVLOG(1) << "Backup/rollback backend failed to configure.";
1475 ShutdownImpl(browser_sync::SyncBackendHost::STOP_AND_CLAIM_THREAD); 1478 ShutdownImpl(syncer::STOP_SYNC);
1476 } 1479 }
1477 1480
1478 return; 1481 return;
1479 } 1482 }
1480 1483
1481 if (!sync_configure_start_time_.is_null()) { 1484 if (!sync_configure_start_time_.is_null()) {
1482 if (result.status == DataTypeManager::OK || 1485 if (result.status == DataTypeManager::OK ||
1483 result.status == DataTypeManager::PARTIAL_SUCCESS) { 1486 result.status == DataTypeManager::PARTIAL_SUCCESS) {
1484 base::Time sync_configure_stop_time = base::Time::Now(); 1487 base::Time sync_configure_stop_time = base::Time::Now();
1485 base::TimeDelta delta = sync_configure_stop_time - 1488 base::TimeDelta delta = sync_configure_stop_time -
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after
2426 return false; 2429 return false;
2427 2430
2428 return directory_data_type_manager_->state() == DataTypeManager::CONFIGURED; 2431 return directory_data_type_manager_->state() == DataTypeManager::CONFIGURED;
2429 } 2432 }
2430 2433
2431 void ProfileSyncService::StopAndSuppress() { 2434 void ProfileSyncService::StopAndSuppress() {
2432 sync_prefs_.SetStartSuppressed(true); 2435 sync_prefs_.SetStartSuppressed(true);
2433 if (HasSyncingBackend()) { 2436 if (HasSyncingBackend()) {
2434 backend_->UnregisterInvalidationIds(); 2437 backend_->UnregisterInvalidationIds();
2435 } 2438 }
2436 ShutdownImpl(browser_sync::SyncBackendHost::STOP_AND_CLAIM_THREAD); 2439 ShutdownImpl(syncer::STOP_SYNC);
2437 } 2440 }
2438 2441
2439 bool ProfileSyncService::IsStartSuppressed() const { 2442 bool ProfileSyncService::IsStartSuppressed() const {
2440 return sync_prefs_.IsStartSuppressed(); 2443 return sync_prefs_.IsStartSuppressed();
2441 } 2444 }
2442 2445
2443 SigninManagerBase* ProfileSyncService::signin() const { 2446 SigninManagerBase* ProfileSyncService::signin() const {
2444 if (!signin_) 2447 if (!signin_)
2445 return NULL; 2448 return NULL;
2446 return signin_->GetOriginal(); 2449 return signin_->GetOriginal();
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
2609 LOG(WARNING) << "The following sync URL specified at the command-line " 2612 LOG(WARNING) << "The following sync URL specified at the command-line "
2610 << "is invalid: " << value; 2613 << "is invalid: " << value;
2611 } 2614 }
2612 } 2615 }
2613 } 2616 }
2614 return result; 2617 return result;
2615 } 2618 }
2616 2619
2617 void ProfileSyncService::StartStopBackupForTesting() { 2620 void ProfileSyncService::StartStopBackupForTesting() {
2618 if (backend_mode_ == BACKUP) 2621 if (backend_mode_ == BACKUP)
2619 ShutdownImpl(browser_sync::SyncBackendHost::STOP_AND_CLAIM_THREAD); 2622 ShutdownImpl(syncer::STOP_SYNC);
2620 else 2623 else
2621 backup_rollback_controller_.Start(base::TimeDelta()); 2624 backup_rollback_controller_.Start(base::TimeDelta());
2622 } 2625 }
2623 2626
2624 void ProfileSyncService::CheckSyncBackupIfNeeded() { 2627 void ProfileSyncService::CheckSyncBackupIfNeeded() {
2625 DCHECK_EQ(backend_mode_, SYNC); 2628 DCHECK_EQ(backend_mode_, SYNC);
2626 2629
2627 #if defined(ENABLE_PRE_SYNC_BACKUP) 2630 #if defined(ENABLE_PRE_SYNC_BACKUP)
2628 // Check backup once a day. 2631 // Check backup once a day.
2629 if (!last_backup_time_ && 2632 if (!last_backup_time_ &&
(...skipping 30 matching lines...) Expand all
2660 browser_sync::SyncedDeviceTracker* device_tracker = 2663 browser_sync::SyncedDeviceTracker* device_tracker =
2661 backend_->GetSyncedDeviceTracker(); 2664 backend_->GetSyncedDeviceTracker();
2662 if (device_tracker) 2665 if (device_tracker)
2663 device_tracker->UpdateLocalDeviceBackupTime(*last_backup_time_); 2666 device_tracker->UpdateLocalDeviceBackupTime(*last_backup_time_);
2664 } 2667 }
2665 } 2668 }
2666 2669
2667 base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const { 2670 base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const {
2668 return backend_->GetSyncedDeviceTracker()->GetLocalDeviceBackupTime(); 2671 return backend_->GetSyncedDeviceTracker()->GetLocalDeviceBackupTime();
2669 } 2672 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | sync/internal_api/public/shutdown_reason.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698