Commit 6ccf4231 authored by Justin Cohen's avatar Justin Cohen Committed by Chromium LUCI CQ

ios: Compare user defaults to pref for save shutdown beacon.

There is some speculation that local state is not persisting properly
in some cases.  Add a histogram to also set the value in NSUserDefaults
and to compare those two values.

Bug: 1161529

Change-Id: I67f4caf8060f037151dcc6653825ec17b556dee6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2611966Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarMohammad Refaat <mrefaat@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Auto-Submit: Justin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841071}
parent d3f1d3b7
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
...@@ -111,6 +112,17 @@ void BindNetworkChangeManagerReceiver( ...@@ -111,6 +112,17 @@ void BindNetworkChangeManagerReceiver(
network_change_manager->AddReceiver(std::move(receiver)); network_change_manager->AddReceiver(std::move(receiver));
} }
// Used to enable the workaround for a local state not persisting sometimes.
NSString* const kLastSessionExitedCleanly = @"LastSessionExitedCleanly";
// Set both local_state and user defaults kLastSessionExitedCleanly to |clean|.
void SetLastSessionExitedCleanly(PrefService* local_state, bool clean) {
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool:clean forKey:kLastSessionExitedCleanly];
[defaults synchronize];
local_state->SetBoolean(prefs::kLastSessionExitedCleanly, clean);
}
} // namespace } // namespace
ApplicationContextImpl::ApplicationContextImpl( ApplicationContextImpl::ApplicationContextImpl(
...@@ -233,7 +245,7 @@ void ApplicationContextImpl::OnAppEnterForeground() { ...@@ -233,7 +245,7 @@ void ApplicationContextImpl::OnAppEnterForeground() {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
PrefService* local_state = GetLocalState(); PrefService* local_state = GetLocalState();
local_state->SetBoolean(prefs::kLastSessionExitedCleanly, false); SetLastSessionExitedCleanly(local_state, false);
// Tell the metrics services that the application resumes. // Tell the metrics services that the application resumes.
metrics::MetricsService* metrics_service = GetMetricsService(); metrics::MetricsService* metrics_service = GetMetricsService();
...@@ -267,7 +279,7 @@ void ApplicationContextImpl::OnAppEnterBackground() { ...@@ -267,7 +279,7 @@ void ApplicationContextImpl::OnAppEnterBackground() {
} }
PrefService* local_state = GetLocalState(); PrefService* local_state = GetLocalState();
local_state->SetBoolean(prefs::kLastSessionExitedCleanly, true); SetLastSessionExitedCleanly(local_state, true);
// Tell the metrics services they were cleanly shutdown. // Tell the metrics services they were cleanly shutdown.
metrics::MetricsService* metrics_service = GetMetricsService(); metrics::MetricsService* metrics_service = GetMetricsService();
...@@ -520,6 +532,37 @@ void ApplicationContextImpl::CreateLocalState() { ...@@ -520,6 +532,37 @@ void ApplicationContextImpl::CreateLocalState() {
was_last_shutdown_clean_ = was_last_shutdown_clean_ =
local_state_->GetBoolean(prefs::kLastSessionExitedCleanly); local_state_->GetBoolean(prefs::kLastSessionExitedCleanly);
} }
// The logic below mirrors clean_exit_beacon. For historical reasons ios/
// does not use this beacon directly. This code should be merged with clean
// exit beacon (as long as the user default workaround can also go into the
// clean exit beacon).
// An enumeration of all possible permutations of the the beacon state in the
// registry and in Local State.
enum {
DIRTY_DIRTY,
DIRTY_CLEAN,
CLEAN_DIRTY,
CLEAN_CLEAN,
MISSING_DIRTY,
MISSING_CLEAN,
NUM_CONSISTENCY_ENUMS
} consistency = DIRTY_DIRTY;
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:kLastSessionExitedCleanly] != nil) {
bool user_defaults_was_last_shutdown_clean_ =
[defaults boolForKey:kLastSessionExitedCleanly];
if (user_defaults_was_last_shutdown_clean_) {
consistency = was_last_shutdown_clean_ ? CLEAN_CLEAN : CLEAN_DIRTY;
} else {
consistency = was_last_shutdown_clean_ ? DIRTY_CLEAN : DIRTY_DIRTY;
}
} else {
consistency = was_last_shutdown_clean_ ? MISSING_CLEAN : MISSING_DIRTY;
}
base::UmaHistogramEnumeration("UMA.CleanExitBeaconConsistency", consistency,
NUM_CONSISTENCY_ENUMS);
} }
void ApplicationContextImpl::CreateGCMDriver() { void ApplicationContextImpl::CreateGCMDriver() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment