1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/metrics/clean_exit_beacon.h"
7 #include "base/logging.h"
8 #include "base/prefs/pref_service.h"
9 #include "components/metrics/metrics_pref_names.h"
12 #include "base/metrics/histogram.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "base/win/registry.h"
19 CleanExitBeacon::CleanExitBeacon(const base::string16
& backup_registry_key
,
20 PrefService
* local_state
)
21 : local_state_(local_state
),
22 initial_value_(local_state
->GetBoolean(prefs::kStabilityExitedCleanly
)),
23 backup_registry_key_(backup_registry_key
) {
24 DCHECK_NE(PrefService::INITIALIZATION_STATUS_WAITING
,
25 local_state_
->GetInitializationStatus());
28 // An enumeration of all possible permutations of the the beacon state in the
29 // registry and in Local State.
38 } consistency
= DIRTY_DIRTY
;
40 base::win::RegKey regkey
;
42 if (regkey
.Open(HKEY_CURRENT_USER
,
43 backup_registry_key_
.c_str(),
44 KEY_ALL_ACCESS
) == ERROR_SUCCESS
&&
46 base::ASCIIToUTF16(prefs::kStabilityExitedCleanly
).c_str(), &value
) ==
49 consistency
= initial_value_
? CLEAN_CLEAN
: CLEAN_DIRTY
;
51 consistency
= initial_value_
? DIRTY_CLEAN
: DIRTY_DIRTY
;
53 consistency
= initial_value_
? MISSING_CLEAN
: MISSING_DIRTY
;
56 UMA_HISTOGRAM_ENUMERATION(
57 "UMA.CleanExitBeaconConsistency", consistency
, NUM_CONSISTENCY_ENUMS
);
61 CleanExitBeacon::~CleanExitBeacon() {
64 void CleanExitBeacon::WriteBeaconValue(bool value
) {
65 local_state_
->SetBoolean(prefs::kStabilityExitedCleanly
, value
);
68 base::win::RegKey regkey
;
69 if (regkey
.Create(HKEY_CURRENT_USER
,
70 backup_registry_key_
.c_str(),
71 KEY_ALL_ACCESS
) == ERROR_SUCCESS
) {
73 base::ASCIIToUTF16(prefs::kStabilityExitedCleanly
).c_str(),
79 } // namespace metrics