| 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 <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 } | 358 } |
| 359 | 359 |
| 360 #if defined(ENABLE_PRE_SYNC_BACKUP) | 360 #if defined(ENABLE_PRE_SYNC_BACKUP) |
| 361 if (!running_rollback && signin_->GetAccountIdToUse().empty()) { | 361 if (!running_rollback && signin_->GetAccountIdToUse().empty()) { |
| 362 CleanUpBackup(); | 362 CleanUpBackup(); |
| 363 } | 363 } |
| 364 #else | 364 #else |
| 365 DCHECK(!running_rollback); | 365 DCHECK(!running_rollback); |
| 366 #endif | 366 #endif |
| 367 | 367 |
| 368 memory_pressure_listener_.reset(new base::MemoryPressureListener(base::Bind( |
| 369 &ProfileSyncService::OnMemoryPressure, weak_factory_.GetWeakPtr()))); |
| 368 startup_controller_->Reset(GetRegisteredDataTypes()); | 370 startup_controller_->Reset(GetRegisteredDataTypes()); |
| 369 startup_controller_->TryStart(); | 371 startup_controller_->TryStart(); |
| 370 } | 372 } |
| 371 | 373 |
| 372 void ProfileSyncService::TrySyncDatatypePrefRecovery() { | 374 void ProfileSyncService::TrySyncDatatypePrefRecovery() { |
| 373 DCHECK(!backend_initialized()); | 375 DCHECK(!backend_initialized()); |
| 374 if (!HasSyncSetupCompleted()) | 376 if (!HasSyncSetupCompleted()) |
| 375 return; | 377 return; |
| 376 | 378 |
| 377 // There was a bug where OnUserChoseDatatypes was not properly called on | 379 // There was a bug where OnUserChoseDatatypes was not properly called on |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 invalidator, | 697 invalidator, |
| 696 sync_prefs_.AsWeakPtr(), | 698 sync_prefs_.AsWeakPtr(), |
| 697 sync_folder)); | 699 sync_folder)); |
| 698 | 700 |
| 699 // Initialize the backend. Every time we start up a new SyncBackendHost, | 701 // Initialize the backend. Every time we start up a new SyncBackendHost, |
| 700 // we'll want to start from a fresh SyncDB, so delete any old one that might | 702 // we'll want to start from a fresh SyncDB, so delete any old one that might |
| 701 // be there. | 703 // be there. |
| 702 InitializeBackend(ShouldDeleteSyncFolder()); | 704 InitializeBackend(ShouldDeleteSyncFolder()); |
| 703 | 705 |
| 704 UpdateFirstSyncTimePref(); | 706 UpdateFirstSyncTimePref(); |
| 707 |
| 708 CheckPreviousShutdownMemoryWarning(); |
| 705 } | 709 } |
| 706 | 710 |
| 707 void ProfileSyncService::OnGetTokenSuccess( | 711 void ProfileSyncService::OnGetTokenSuccess( |
| 708 const OAuth2TokenService::Request* request, | 712 const OAuth2TokenService::Request* request, |
| 709 const std::string& access_token, | 713 const std::string& access_token, |
| 710 const base::Time& expiration_time) { | 714 const base::Time& expiration_time) { |
| 711 DCHECK_EQ(access_token_request_, request); | 715 DCHECK_EQ(access_token_request_, request); |
| 712 access_token_request_.reset(); | 716 access_token_request_.reset(); |
| 713 access_token_ = access_token; | 717 access_token_ = access_token; |
| 714 token_receive_time_ = base::Time::Now(); | 718 token_receive_time_ = base::Time::Now(); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 encryption_pending_ = false; | 909 encryption_pending_ = false; |
| 906 encrypt_everything_ = false; | 910 encrypt_everything_ = false; |
| 907 encrypted_types_ = syncer::SyncEncryptionHandler::SensitiveTypes(); | 911 encrypted_types_ = syncer::SyncEncryptionHandler::SensitiveTypes(); |
| 908 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED; | 912 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED; |
| 909 request_access_token_retry_timer_.Stop(); | 913 request_access_token_retry_timer_.Stop(); |
| 910 // Revert to "no auth error". | 914 // Revert to "no auth error". |
| 911 if (last_auth_error_.state() != GoogleServiceAuthError::NONE) | 915 if (last_auth_error_.state() != GoogleServiceAuthError::NONE) |
| 912 UpdateAuthErrorState(GoogleServiceAuthError::AuthErrorNone()); | 916 UpdateAuthErrorState(GoogleServiceAuthError::AuthErrorNone()); |
| 913 | 917 |
| 914 NotifyObservers(); | 918 NotifyObservers(); |
| 919 |
| 920 sync_prefs_.SetCurrentShutdown(false); |
| 915 } | 921 } |
| 916 | 922 |
| 917 void ProfileSyncService::DisableForUser() { | 923 void ProfileSyncService::DisableForUser() { |
| 918 // Clear prefs (including SyncSetupHasCompleted) before shutting down so | 924 // Clear prefs (including SyncSetupHasCompleted) before shutting down so |
| 919 // PSS clients don't think we're set up while we're shutting down. | 925 // PSS clients don't think we're set up while we're shutting down. |
| 920 sync_prefs_.ClearPreferences(); | 926 sync_prefs_.ClearPreferences(); |
| 921 ClearUnrecoverableError(); | 927 ClearUnrecoverableError(); |
| 922 ShutdownImpl(syncer::DISABLE_SYNC); | 928 ShutdownImpl(syncer::DISABLE_SYNC); |
| 923 } | 929 } |
| 924 | 930 |
| (...skipping 1788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2713 std::string birthday; | 2719 std::string birthday; |
| 2714 syncer::UserShare* user_share = GetUserShare(); | 2720 syncer::UserShare* user_share = GetUserShare(); |
| 2715 if (user_share && user_share->directory.get()) { | 2721 if (user_share && user_share->directory.get()) { |
| 2716 birthday = user_share->directory->store_birthday(); | 2722 birthday = user_share->directory->store_birthday(); |
| 2717 } | 2723 } |
| 2718 if (!access_token_.empty() && !cache_guid.empty() && !birthday.empty()) { | 2724 if (!access_token_.empty() && !cache_guid.empty() && !birthday.empty()) { |
| 2719 sync_stopped_reporter_->ReportSyncStopped( | 2725 sync_stopped_reporter_->ReportSyncStopped( |
| 2720 access_token_, cache_guid, birthday); | 2726 access_token_, cache_guid, birthday); |
| 2721 } | 2727 } |
| 2722 } | 2728 } |
| 2729 |
| 2730 void ProfileSyncService::OnMemoryPressure( |
| 2731 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| 2732 if (memory_pressure_level == |
| 2733 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
| 2734 sync_prefs_.SetMemoryPressure(sync_prefs_.GetMemoryPressure() + 1); |
| 2735 } |
| 2736 } |
| 2737 |
| 2738 void ProfileSyncService::CheckPreviousShutdownMemoryWarning() { |
| 2739 int warning_received = sync_prefs_.GetMemoryPressure(); |
| 2740 |
| 2741 if (-1 != warning_received) { |
| 2742 // -1 means it is new client |
| 2743 if (sync_prefs_.IsPreviousCrashed()) { |
| 2744 UMA_HISTOGRAM_COUNTS("Sync.MemoryPressureWarningBeforeCrash", |
| 2745 warning_received); |
| 2746 } else { |
| 2747 UMA_HISTOGRAM_COUNTS("Sync.MemoryPressureWarningwithoutCrash", |
| 2748 warning_received); |
| 2749 } |
| 2750 } |
| 2751 sync_prefs_.SetMemoryPressure(0); |
| 2752 sync_prefs_.SetCurrentShutdown(true); |
| 2753 } |
| OLD | NEW |