OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "components/metrics/clean_exit_beacon.h" | 5 #include "components/metrics/clean_exit_beacon.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "components/metrics/metrics_pref_names.h" | 9 #include "components/metrics/metrics_pref_names.h" |
10 | 10 |
11 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/win/registry.h" | 14 #include "base/win/registry.h" |
15 #endif | 15 #endif |
16 | 16 |
17 namespace metrics { | 17 namespace metrics { |
18 | 18 |
19 CleanExitBeacon::CleanExitBeacon(const base::string16& backup_registry_key, | 19 CleanExitBeacon::CleanExitBeacon(const base::string16& backup_registry_key, |
20 PrefService* local_state) | 20 PrefService* local_state) |
21 : local_state_(local_state), | 21 : local_state_(local_state), |
22 initial_value_( | 22 initial_value_(local_state->GetBoolean(prefs::kStabilityExitedCleanly)), |
23 local_state->GetBoolean(metrics::prefs::kStabilityExitedCleanly)), | |
24 backup_registry_key_(backup_registry_key) { | 23 backup_registry_key_(backup_registry_key) { |
25 DCHECK_NE(PrefService::INITIALIZATION_STATUS_WAITING, | 24 DCHECK_NE(PrefService::INITIALIZATION_STATUS_WAITING, |
26 local_state_->GetInitializationStatus()); | 25 local_state_->GetInitializationStatus()); |
27 | 26 |
28 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
29 // An enumeration of all possible permutations of the the beacon state in the | 28 // An enumeration of all possible permutations of the the beacon state in the |
30 // registry and in Local State. | 29 // registry and in Local State. |
31 enum { | 30 enum { |
32 DIRTY_DIRTY, | 31 DIRTY_DIRTY, |
33 DIRTY_CLEAN, | 32 DIRTY_CLEAN, |
34 CLEAN_DIRTY, | 33 CLEAN_DIRTY, |
35 CLEAN_CLEAN, | 34 CLEAN_CLEAN, |
36 MISSING_DIRTY, | 35 MISSING_DIRTY, |
37 MISSING_CLEAN, | 36 MISSING_CLEAN, |
38 NUM_CONSISTENCY_ENUMS | 37 NUM_CONSISTENCY_ENUMS |
39 } consistency = DIRTY_DIRTY; | 38 } consistency = DIRTY_DIRTY; |
40 | 39 |
41 base::win::RegKey regkey; | 40 base::win::RegKey regkey; |
42 DWORD value = 0u; | 41 DWORD value = 0u; |
43 if (regkey.Open(HKEY_CURRENT_USER, | 42 if (regkey.Open(HKEY_CURRENT_USER, |
44 backup_registry_key_.c_str(), | 43 backup_registry_key_.c_str(), |
45 KEY_ALL_ACCESS) == ERROR_SUCCESS && | 44 KEY_ALL_ACCESS) == ERROR_SUCCESS && |
46 regkey.ReadValueDW( | 45 regkey.ReadValueDW( |
47 base::ASCIIToUTF16(metrics::prefs::kStabilityExitedCleanly).c_str(), | 46 base::ASCIIToUTF16(prefs::kStabilityExitedCleanly).c_str(), &value) == |
48 &value) == ERROR_SUCCESS) { | 47 ERROR_SUCCESS) { |
49 if (value) | 48 if (value) |
50 consistency = initial_value_ ? CLEAN_CLEAN : CLEAN_DIRTY; | 49 consistency = initial_value_ ? CLEAN_CLEAN : CLEAN_DIRTY; |
51 else | 50 else |
52 consistency = initial_value_ ? DIRTY_CLEAN : DIRTY_DIRTY; | 51 consistency = initial_value_ ? DIRTY_CLEAN : DIRTY_DIRTY; |
53 } else { | 52 } else { |
54 consistency = initial_value_ ? MISSING_CLEAN : MISSING_DIRTY; | 53 consistency = initial_value_ ? MISSING_CLEAN : MISSING_DIRTY; |
55 } | 54 } |
56 | 55 |
57 UMA_HISTOGRAM_ENUMERATION( | 56 UMA_HISTOGRAM_ENUMERATION( |
58 "UMA.CleanExitBeaconConsistency", consistency, NUM_CONSISTENCY_ENUMS); | 57 "UMA.CleanExitBeaconConsistency", consistency, NUM_CONSISTENCY_ENUMS); |
59 #endif | 58 #endif |
60 } | 59 } |
61 | 60 |
62 CleanExitBeacon::~CleanExitBeacon() { | 61 CleanExitBeacon::~CleanExitBeacon() { |
63 } | 62 } |
64 | 63 |
65 void CleanExitBeacon::WriteBeaconValue(bool value) { | 64 void CleanExitBeacon::WriteBeaconValue(bool value) { |
66 local_state_->SetBoolean(metrics::prefs::kStabilityExitedCleanly, value); | 65 local_state_->SetBoolean(prefs::kStabilityExitedCleanly, value); |
67 | 66 |
68 #if defined(OS_WIN) | 67 #if defined(OS_WIN) |
69 base::win::RegKey regkey; | 68 base::win::RegKey regkey; |
70 if (regkey.Create(HKEY_CURRENT_USER, | 69 if (regkey.Create(HKEY_CURRENT_USER, |
71 backup_registry_key_.c_str(), | 70 backup_registry_key_.c_str(), |
72 KEY_ALL_ACCESS) == ERROR_SUCCESS) { | 71 KEY_ALL_ACCESS) == ERROR_SUCCESS) { |
73 regkey.WriteValue( | 72 regkey.WriteValue( |
74 base::ASCIIToUTF16(metrics::prefs::kStabilityExitedCleanly).c_str(), | 73 base::ASCIIToUTF16(prefs::kStabilityExitedCleanly).c_str(), |
75 value ? 1u : 0u); | 74 value ? 1u : 0u); |
76 } | 75 } |
77 #endif | 76 #endif |
78 } | 77 } |
79 | 78 |
80 } // namespace metrics | 79 } // namespace metrics |
OLD | NEW |