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

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: Rebase. 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
Alexei Svitkine (slow) 2014/09/11 19:20:26 Nit: Add a newline after this.
erikwright (departed) 2014/09/11 19:42:20 Done.
16 namespace metrics {
17
18 CleanExitBeacon::CleanExitBeacon(const base::string16& backup_registry_key,
19 PrefService* local_state)
20 : local_state_(local_state),
21 initial_value_(
22 local_state->GetBoolean(metrics::prefs::kStabilityExitedCleanly)),
23 backup_registry_key_(backup_registry_key) {
24 DCHECK_NE(PrefService::INITIALIZATION_STATUS_WAITING,
25 local_state_->GetInitializationStatus());
26 #if defined(OS_WIN)
Alexei Svitkine (slow) 2014/09/11 19:20:26 Nit: Add a newline before this.
erikwright (departed) 2014/09/11 19:42:20 Done.
27 enum {
Alexei Svitkine (slow) 2014/09/11 19:20:26 Add a comment explaining the order e.g. what does
erikwright (departed) 2014/09/11 19:42:19 Done.
28 DIRTY_DIRTY,
29 DIRTY_CLEAN,
30 CLEAN_DIRTY,
31 CLEAN_CLEAN,
32 MISSING_DIRTY,
33 MISSING_CLEAN,
34 NUM_CONSISTENCY_ENUMS
35 } consistency = DIRTY_DIRTY;
36
37 base::win::RegKey regkey;
38 DWORD value = 0u;
39 if (regkey.Open(HKEY_CURRENT_USER,
40 backup_registry_key_.c_str(),
41 KEY_ALL_ACCESS) == ERROR_SUCCESS &&
42 regkey.ReadValueDW(
43 base::ASCIIToUTF16(metrics::prefs::kStabilityExitedCleanly).c_str(),
44 &value) == ERROR_SUCCESS) {
45 if (value)
46 consistency = initial_value_ ? CLEAN_CLEAN : CLEAN_DIRTY;
47 else
48 consistency = initial_value_ ? DIRTY_CLEAN : DIRTY_DIRTY;
49 } else {
50 consistency = initial_value_ ? MISSING_CLEAN : MISSING_DIRTY;
51 }
52
53 UMA_HISTOGRAM_ENUMERATION(
54 "UMA.CleanExitBeaconConsistency", consistency, NUM_CONSISTENCY_ENUMS);
55 #endif
56 }
57
58 CleanExitBeacon::~CleanExitBeacon() {
59 }
60
61 void CleanExitBeacon::WriteBeaconValue(bool value) {
62 local_state_->SetBoolean(metrics::prefs::kStabilityExitedCleanly, value);
63 local_state_->CommitPendingWrite();
Alexei Svitkine (slow) 2014/09/11 19:20:26 I don't think the previous code did this. Do we n
erikwright (departed) 2014/09/11 19:42:19 No, this is not needed for now.
64
65 #if defined(OS_WIN)
66 base::win::RegKey regkey;
67 if (regkey.Create(HKEY_CURRENT_USER,
68 backup_registry_key_.c_str(),
69 KEY_ALL_ACCESS) == ERROR_SUCCESS) {
70 regkey.WriteValue(
71 base::ASCIIToUTF16(metrics::prefs::kStabilityExitedCleanly).c_str(),
72 value ? 1u : 0u);
73 }
74 #endif
75 }
76
77 } // 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