Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: components/metrics/clean_exit_beacon.cc

Issue 558683002: Extract the handling of the clean exit beacon from MetricsService. The extracted implementation sup… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/metrics/clean_exit_beacon.h ('k') | components/metrics/metrics_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_service.h"
9 #include "components/metrics/metrics_pref_names.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 metrics {
18
19 CleanExitBeacon::CleanExitBeacon(const base::string16& backup_registry_key,
20 PrefService* local_state)
21 : local_state_(local_state),
22 initial_value_(
23 local_state->GetBoolean(metrics::prefs::kStabilityExitedCleanly)),
24 backup_registry_key_(backup_registry_key) {
25 DCHECK_NE(PrefService::INITIALIZATION_STATUS_WAITING,
26 local_state_->GetInitializationStatus());
27
28 #if defined(OS_WIN)
29 // An enumeration of all possible permutations of the the beacon state in the
30 // registry and in Local State.
31 enum {
32 DIRTY_DIRTY,
33 DIRTY_CLEAN,
34 CLEAN_DIRTY,
35 CLEAN_CLEAN,
36 MISSING_DIRTY,
37 MISSING_CLEAN,
38 NUM_CONSISTENCY_ENUMS
39 } consistency = DIRTY_DIRTY;
40
41 base::win::RegKey regkey;
42 DWORD value = 0u;
43 if (regkey.Open(HKEY_CURRENT_USER,
44 backup_registry_key_.c_str(),
45 KEY_ALL_ACCESS) == ERROR_SUCCESS &&
46 regkey.ReadValueDW(
47 base::ASCIIToUTF16(metrics::prefs::kStabilityExitedCleanly).c_str(),
48 &value) == ERROR_SUCCESS) {
49 if (value)
50 consistency = initial_value_ ? CLEAN_CLEAN : CLEAN_DIRTY;
51 else
52 consistency = initial_value_ ? DIRTY_CLEAN : DIRTY_DIRTY;
53 } else {
54 consistency = initial_value_ ? MISSING_CLEAN : MISSING_DIRTY;
55 }
56
57 UMA_HISTOGRAM_ENUMERATION(
58 "UMA.CleanExitBeaconConsistency", consistency, NUM_CONSISTENCY_ENUMS);
59 #endif
60 }
61
62 CleanExitBeacon::~CleanExitBeacon() {
63 }
64
65 void CleanExitBeacon::WriteBeaconValue(bool value) {
66 local_state_->SetBoolean(metrics::prefs::kStabilityExitedCleanly, value);
67
68 #if defined(OS_WIN)
69 base::win::RegKey regkey;
70 if (regkey.Create(HKEY_CURRENT_USER,
71 backup_registry_key_.c_str(),
72 KEY_ALL_ACCESS) == ERROR_SUCCESS) {
73 regkey.WriteValue(
74 base::ASCIIToUTF16(metrics::prefs::kStabilityExitedCleanly).c_str(),
75 value ? 1u : 0u);
76 }
77 #endif
78 }
79
80 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/clean_exit_beacon.h ('k') | components/metrics/metrics_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698