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 ReportPreviousSessionMemoryWarningCount(); | |
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 // Mark this shutdown cleanly(without crash). | |
stanisc
2015/05/15 23:11:04
How about this: mark this as a clean shutdown.
Gang Wu
2015/05/15 23:21:41
Done.
| |
921 sync_prefs_.SetCleanShutdown(true); | |
915 } | 922 } |
916 | 923 |
917 void ProfileSyncService::DisableForUser() { | 924 void ProfileSyncService::DisableForUser() { |
918 // Clear prefs (including SyncSetupHasCompleted) before shutting down so | 925 // Clear prefs (including SyncSetupHasCompleted) before shutting down so |
919 // PSS clients don't think we're set up while we're shutting down. | 926 // PSS clients don't think we're set up while we're shutting down. |
920 sync_prefs_.ClearPreferences(); | 927 sync_prefs_.ClearPreferences(); |
921 ClearUnrecoverableError(); | 928 ClearUnrecoverableError(); |
922 ShutdownImpl(syncer::DISABLE_SYNC); | 929 ShutdownImpl(syncer::DISABLE_SYNC); |
923 } | 930 } |
924 | 931 |
(...skipping 1788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2713 std::string birthday; | 2720 std::string birthday; |
2714 syncer::UserShare* user_share = GetUserShare(); | 2721 syncer::UserShare* user_share = GetUserShare(); |
2715 if (user_share && user_share->directory.get()) { | 2722 if (user_share && user_share->directory.get()) { |
2716 birthday = user_share->directory->store_birthday(); | 2723 birthday = user_share->directory->store_birthday(); |
2717 } | 2724 } |
2718 if (!access_token_.empty() && !cache_guid.empty() && !birthday.empty()) { | 2725 if (!access_token_.empty() && !cache_guid.empty() && !birthday.empty()) { |
2719 sync_stopped_reporter_->ReportSyncStopped( | 2726 sync_stopped_reporter_->ReportSyncStopped( |
2720 access_token_, cache_guid, birthday); | 2727 access_token_, cache_guid, birthday); |
2721 } | 2728 } |
2722 } | 2729 } |
2730 | |
2731 void ProfileSyncService::OnMemoryPressure( | |
2732 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | |
2733 if (memory_pressure_level == | |
2734 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { | |
2735 sync_prefs_.SetMemoryPressureWarningCount( | |
2736 sync_prefs_.GetMemoryPressureWarningCount() + 1); | |
2737 } | |
2738 } | |
2739 | |
2740 void ProfileSyncService::ReportPreviousSessionMemoryWarningCount() { | |
2741 int warning_received = sync_prefs_.GetMemoryPressureWarningCount(); | |
2742 | |
2743 if (-1 != warning_received) { | |
2744 // -1 means it is new client. | |
2745 if (!sync_prefs_.DidSyncShutdownCleanly()) { | |
2746 UMA_HISTOGRAM_COUNTS("Sync.MemoryPressureWarningBeforeUncleanShutdown", | |
2747 warning_received); | |
2748 } else { | |
2749 UMA_HISTOGRAM_COUNTS("Sync.MemoryPressureWarningBeforeCleanShutdown", | |
2750 warning_received); | |
2751 } | |
2752 } | |
2753 sync_prefs_.SetMemoryPressureWarningCount(0); | |
2754 // Will to true during a clean shutdown, so crash or something elase will | |
stanisc
2015/05/15 23:11:04
There are still a couple of typos here. Please rev
Gang Wu
2015/05/15 23:21:41
Done.
| |
2755 // remain this as false. | |
2756 sync_prefs_.SetCleanShutdown(false); | |
2757 } | |
OLD | NEW |