OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "components/metrics/clean_exit_beacon.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/prefs/pref_registry_simple.h" | |
9 #include "base/prefs/pref_service.h" | |
10 | |
11 #if defined(OS_WIN) | |
12 #include "base/metrics/histogram.h" | |
13 #include "base/strings/utf_string_conversions.h" | |
14 #include "base/win/registry.h" | |
15 #endif | |
16 | |
17 namespace { | |
18 | |
19 // True if the previous run of the program exited cleanly. | |
20 const char kStabilityExitedCleanly[] = | |
21 "user_experience_metrics.stability.exited_cleanly"; | |
Alexei Svitkine (slow)
2014/09/11 15:23:28
What's the reason for moving the pref? I think we
erikwright (departed)
2014/09/11 15:39:14
Exposing the name of a preference permits violatio
Alexei Svitkine (slow)
2014/09/11 15:57:28
I agree in principle, but at the same time we lose
erikwright (departed)
2014/09/11 19:00:29
Done. I didn't add a comment, as it's not really a
| |
22 | |
23 } // namespace | |
24 | |
25 #if defined(OS_WIN) | |
Alexei Svitkine (slow)
2014/09/11 15:23:28
There's too many ifdefs for my preference.
How ab
erikwright (departed)
2014/09/11 15:39:14
It seems a bit strange to declare and implement (e
Alexei Svitkine (slow)
2014/09/11 15:57:28
My original thought would have been for the method
erikwright (departed)
2014/09/11 16:03:14
I think the location used for storage in the regis
Alexei Svitkine (slow)
2014/09/11 17:07:19
Okay, then let's go with the with my suggestion of
erikwright (departed)
2014/09/11 19:00:28
Done.
| |
26 CleanExitBeacon::CleanExitBeacon(const base::string16& backup_registry_key, | |
27 PrefService* local_state) | |
28 : backup_registry_key_(backup_registry_key), | |
29 local_state_(local_state), | |
30 initial_value_(local_state->GetBoolean(kStabilityExitedCleanly)) { | |
31 DCHECK_NE(PrefService::INITIALIZATION_STATUS_WAITING, | |
32 local_state_->GetInitializationStatus()); | |
33 enum { | |
34 DIRTY_DIRTY, | |
35 DIRTY_CLEAN, | |
36 CLEAN_DIRTY, | |
37 CLEAN_CLEAN, | |
38 MISSING_DIRTY, | |
39 MISSING_CLEAN, | |
40 NUM_CONSISTENCY_ENUMS | |
41 } consistency = DIRTY_DIRTY; | |
42 | |
43 base::win::RegKey regkey; | |
44 DWORD value = 0u; | |
45 if (regkey.Open(HKEY_CURRENT_USER, | |
46 backup_registry_key_.c_str(), | |
47 KEY_ALL_ACCESS) == ERROR_SUCCESS && | |
48 regkey.ReadValueDW(base::ASCIIToUTF16(kStabilityExitedCleanly).c_str(), | |
49 &value) == ERROR_SUCCESS) { | |
50 if (value) | |
51 consistency = initial_value_ ? CLEAN_CLEAN : CLEAN_DIRTY; | |
52 else | |
53 consistency = initial_value_ ? DIRTY_CLEAN : DIRTY_DIRTY; | |
54 } else { | |
55 consistency = initial_value_ ? MISSING_CLEAN : MISSING_DIRTY; | |
56 } | |
57 | |
58 UMA_HISTOGRAM_ENUMERATION( | |
59 "UMA.CleanExitBeaconConsistency", consistency, NUM_CONSISTENCY_ENUMS); | |
60 } | |
61 #else | |
62 CleanExitBeacon::CleanExitBeacon(PrefService* local_state) | |
63 : local_state_(local_state), | |
64 initial_value_(local_state->GetBoolean(kStabilityExitedCleanly)) { | |
65 DCHECK_NE(PrefService::INITIALIZATION_STATUS_WAITING, | |
66 local_state_->GetInitializationStatus()); | |
67 } | |
68 #endif | |
69 | |
70 CleanExitBeacon::~CleanExitBeacon() { | |
71 } | |
72 | |
73 void CleanExitBeacon::RegisterPrefs(PrefRegistrySimple* registry) { | |
74 registry->RegisterBooleanPref(kStabilityExitedCleanly, true); | |
75 } | |
76 | |
77 void CleanExitBeacon::WriteBeaconValue(bool value) { | |
78 local_state_->SetBoolean(kStabilityExitedCleanly, value); | |
79 local_state_->CommitPendingWrite(); | |
80 | |
81 #if defined(OS_WIN) | |
82 base::win::RegKey regkey; | |
83 if (regkey.Open(HKEY_CURRENT_USER, | |
84 backup_registry_key_.c_str(), | |
85 KEY_ALL_ACCESS) == ERROR_SUCCESS) { | |
86 regkey.WriteValue(base::ASCIIToUTF16(kStabilityExitedCleanly).c_str(), | |
87 value ? 1u : 0u); | |
88 } | |
89 #endif | |
90 } | |
OLD | NEW |