| 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 "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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 | 503 |
| 504 void ProfileSyncService::StartUp(StartUpDeferredOption deferred_option) { | 504 void ProfileSyncService::StartUp(StartUpDeferredOption deferred_option) { |
| 505 // Don't start up multiple times. | 505 // Don't start up multiple times. |
| 506 if (backend_) { | 506 if (backend_) { |
| 507 DVLOG(1) << "Skipping bringing up backend host."; | 507 DVLOG(1) << "Skipping bringing up backend host."; |
| 508 return; | 508 return; |
| 509 } | 509 } |
| 510 | 510 |
| 511 DCHECK(IsSyncEnabledAndLoggedIn()); | 511 DCHECK(IsSyncEnabledAndLoggedIn()); |
| 512 | 512 |
| 513 last_synced_time_ = sync_prefs_.GetLastSyncedTime(); | 513 if (start_up_time_.is_null()) { |
| 514 | 514 start_up_time_ = base::Time::Now(); |
| 515 DCHECK(start_up_time_.is_null()); | 515 last_synced_time_ = sync_prefs_.GetLastSyncedTime(); |
| 516 start_up_time_ = base::Time::Now(); | |
| 517 | 516 |
| 518 #if defined(OS_CHROMEOS) | 517 #if defined(OS_CHROMEOS) |
| 519 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken(); | 518 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken(); |
| 520 if (bootstrap_token.empty()) { | 519 if (bootstrap_token.empty()) { |
| 521 sync_prefs_.SetEncryptionBootstrapToken( | 520 sync_prefs_.SetEncryptionBootstrapToken( |
| 522 sync_prefs_.GetSpareBootstrapToken()); | 521 sync_prefs_.GetSpareBootstrapToken()); |
| 523 } | 522 } |
| 524 #endif | 523 #endif |
| 525 | 524 |
| 526 if (!sync_global_error_) { | 525 if (!sync_global_error_) { |
| 527 #if !defined(OS_ANDROID) | 526 #if !defined(OS_ANDROID) |
| 528 sync_global_error_.reset(new SyncGlobalError(this, signin())); | 527 sync_global_error_.reset(new SyncGlobalError(this, signin())); |
| 529 #endif | 528 #endif |
| 530 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( | 529 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( |
| 531 sync_global_error_.get()); | 530 sync_global_error_.get()); |
| 532 AddObserver(sync_global_error_.get()); | 531 AddObserver(sync_global_error_.get()); |
| 532 } |
| 533 } else { |
| 534 // We don't care to prevent multiple calls to StartUp in deferred mode |
| 535 // because it's fast and has no side effects. |
| 536 DCHECK_EQ(STARTUP_BACKEND_DEFERRED, deferred_option); |
| 533 } | 537 } |
| 534 | 538 |
| 535 if (deferred_option == STARTUP_BACKEND_DEFERRED && | 539 if (deferred_option == STARTUP_BACKEND_DEFERRED && |
| 536 CommandLine::ForCurrentProcess()-> | 540 CommandLine::ForCurrentProcess()-> |
| 537 HasSwitch(switches::kSyncEnableDeferredStartup)) { | 541 HasSwitch(switches::kSyncEnableDeferredStartup)) { |
| 538 return; | 542 return; |
| 539 } | 543 } |
| 540 | 544 |
| 541 StartUpSlowBackendComponents(); | 545 StartUpSlowBackendComponents(); |
| 542 } | 546 } |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 doomed_backend->Shutdown(sync_disabled); | 717 doomed_backend->Shutdown(sync_disabled); |
| 714 | 718 |
| 715 doomed_backend.reset(); | 719 doomed_backend.reset(); |
| 716 } | 720 } |
| 717 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time; | 721 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time; |
| 718 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time); | 722 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time); |
| 719 | 723 |
| 720 weak_factory_.InvalidateWeakPtrs(); | 724 weak_factory_.InvalidateWeakPtrs(); |
| 721 | 725 |
| 722 // Clear various flags. | 726 // Clear various flags. |
| 727 start_up_time_ = base::Time(); |
| 723 expect_sync_configuration_aborted_ = false; | 728 expect_sync_configuration_aborted_ = false; |
| 724 is_auth_in_progress_ = false; | 729 is_auth_in_progress_ = false; |
| 725 backend_initialized_ = false; | 730 backend_initialized_ = false; |
| 726 // NULL if we're called from Shutdown(). | 731 // NULL if we're called from Shutdown(). |
| 727 if (invalidator_registrar_) | 732 if (invalidator_registrar_) |
| 728 UpdateInvalidatorRegistrarState(); | 733 UpdateInvalidatorRegistrarState(); |
| 729 cached_passphrase_.clear(); | 734 cached_passphrase_.clear(); |
| 730 encryption_pending_ = false; | 735 encryption_pending_ = false; |
| 731 encrypt_everything_ = false; | 736 encrypt_everything_ = false; |
| 732 encrypted_types_ = syncer::SyncEncryptionHandler::SensitiveTypes(); | 737 encrypted_types_ = syncer::SyncEncryptionHandler::SensitiveTypes(); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 } | 889 } |
| 885 | 890 |
| 886 DCHECK(!start_up_time_.is_null()); | 891 DCHECK(!start_up_time_.is_null()); |
| 887 base::Time on_backend_initialized_time = base::Time::Now(); | 892 base::Time on_backend_initialized_time = base::Time::Now(); |
| 888 base::TimeDelta delta = on_backend_initialized_time - start_up_time_; | 893 base::TimeDelta delta = on_backend_initialized_time - start_up_time_; |
| 889 if (is_first_time_sync_configure_) { | 894 if (is_first_time_sync_configure_) { |
| 890 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeFirstTime", delta); | 895 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeFirstTime", delta); |
| 891 } else { | 896 } else { |
| 892 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta); | 897 UMA_HISTOGRAM_LONG_TIMES("Sync.BackendInitializeRestoreTime", delta); |
| 893 } | 898 } |
| 894 start_up_time_ = base::Time(); | |
| 895 | 899 |
| 896 if (!success) { | 900 if (!success) { |
| 897 // Something went unexpectedly wrong. Play it safe: stop syncing at once | 901 // Something went unexpectedly wrong. Play it safe: stop syncing at once |
| 898 // and surface error UI to alert the user sync has stopped. | 902 // and surface error UI to alert the user sync has stopped. |
| 899 // Keep the directory around for now so that on restart we will retry | 903 // Keep the directory around for now so that on restart we will retry |
| 900 // again and potentially succeed in presence of transient file IO failures | 904 // again and potentially succeed in presence of transient file IO failures |
| 901 // or permissions issues, etc. | 905 // or permissions issues, etc. |
| 902 // | 906 // |
| 903 // TODO(rlarocque): Consider making this UnrecoverableError less special. | 907 // TODO(rlarocque): Consider making this UnrecoverableError less special. |
| 904 // Unlike every other UnrecoverableError, it does not delete our sync data. | 908 // Unlike every other UnrecoverableError, it does not delete our sync data. |
| (...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2104 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine
d-behaviour-after-directly-calling-the-destru. | 2108 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine
d-behaviour-after-directly-calling-the-destru. |
| 2105 ProfileSyncService* old_this = this; | 2109 ProfileSyncService* old_this = this; |
| 2106 this->~ProfileSyncService(); | 2110 this->~ProfileSyncService(); |
| 2107 new(old_this) ProfileSyncService( | 2111 new(old_this) ProfileSyncService( |
| 2108 new ProfileSyncComponentsFactoryImpl(profile, | 2112 new ProfileSyncComponentsFactoryImpl(profile, |
| 2109 CommandLine::ForCurrentProcess()), | 2113 CommandLine::ForCurrentProcess()), |
| 2110 profile, | 2114 profile, |
| 2111 signin, | 2115 signin, |
| 2112 behavior); | 2116 behavior); |
| 2113 } | 2117 } |
| OLD | NEW |