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

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

Issue 636363004: Make remaining parts of components/metrics use metrics namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix cros compile Created 6 years, 2 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.cc ('k') | components/metrics/daily_event_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/cloned_install_detector.h" 5 #include "components/metrics/cloned_install_detector.h"
6 6
7 #include <string>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/location.h" 10 #include "base/location.h"
9 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
10 #include "base/prefs/pref_registry_simple.h" 12 #include "base/prefs/pref_registry_simple.h"
11 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
12 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
13 #include "base/task_runner_util.h" 15 #include "base/task_runner_util.h"
14 #include "components/metrics/cloned_install_detector.h"
15 #include "components/metrics/machine_id_provider.h" 16 #include "components/metrics/machine_id_provider.h"
16 #include "components/metrics/metrics_hashes.h" 17 #include "components/metrics/metrics_hashes.h"
17 #include "components/metrics/metrics_pref_names.h" 18 #include "components/metrics/metrics_pref_names.h"
18 19
19 namespace metrics { 20 namespace metrics {
20 21
21 namespace { 22 namespace {
22 23
23 uint32 HashRawId(const std::string& value) { 24 uint32 HashRawId(const std::string& value) {
24 uint64 hash = metrics::HashMetricName(value); 25 uint64 hash = HashMetricName(value);
25 26
26 // Only use 24 bits from the 64-bit hash. 27 // Only use 24 bits from the 64-bit hash.
27 return hash & ((1 << 24) - 1); 28 return hash & ((1 << 24) - 1);
28 } 29 }
29 30
30 // State of the generated machine id in relation to the previously stored value. 31 // State of the generated machine id in relation to the previously stored value.
31 // Note: UMA histogram enum - don't re-order or remove entries 32 // Note: UMA histogram enum - don't re-order or remove entries
32 enum MachineIdState { 33 enum MachineIdState {
33 ID_GENERATION_FAILED, 34 ID_GENERATION_FAILED,
34 ID_NO_STORED_VALUE, 35 ID_NO_STORED_VALUE,
(...skipping 15 matching lines...) Expand all
50 51
51 ClonedInstallDetector::~ClonedInstallDetector() { 52 ClonedInstallDetector::~ClonedInstallDetector() {
52 } 53 }
53 54
54 void ClonedInstallDetector::CheckForClonedInstall( 55 void ClonedInstallDetector::CheckForClonedInstall(
55 PrefService* local_state, 56 PrefService* local_state,
56 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { 57 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
57 base::PostTaskAndReplyWithResult( 58 base::PostTaskAndReplyWithResult(
58 task_runner.get(), 59 task_runner.get(),
59 FROM_HERE, 60 FROM_HERE,
60 base::Bind(&metrics::MachineIdProvider::GetMachineId, raw_id_provider_), 61 base::Bind(&MachineIdProvider::GetMachineId, raw_id_provider_),
61 base::Bind(&metrics::ClonedInstallDetector::SaveMachineId, 62 base::Bind(&ClonedInstallDetector::SaveMachineId,
62 weak_ptr_factory_.GetWeakPtr(), 63 weak_ptr_factory_.GetWeakPtr(),
63 local_state)); 64 local_state));
64 } 65 }
65 66
66 void ClonedInstallDetector::SaveMachineId(PrefService* local_state, 67 void ClonedInstallDetector::SaveMachineId(PrefService* local_state,
67 std::string raw_id) { 68 std::string raw_id) {
68 if (raw_id.empty()) { 69 if (raw_id.empty()) {
69 LogMachineIdState(ID_GENERATION_FAILED); 70 LogMachineIdState(ID_GENERATION_FAILED);
70 local_state->ClearPref(prefs::kMetricsMachineId); 71 local_state->ClearPref(prefs::kMetricsMachineId);
71 return; 72 return;
(...skipping 17 matching lines...) Expand all
89 90
90 local_state->SetInteger(prefs::kMetricsMachineId, hashed_id); 91 local_state->SetInteger(prefs::kMetricsMachineId, hashed_id);
91 } 92 }
92 93
93 // static 94 // static
94 void ClonedInstallDetector::RegisterPrefs(PrefRegistrySimple* registry) { 95 void ClonedInstallDetector::RegisterPrefs(PrefRegistrySimple* registry) {
95 registry->RegisterIntegerPref(prefs::kMetricsMachineId, 0); 96 registry->RegisterIntegerPref(prefs::kMetricsMachineId, 0);
96 } 97 }
97 98
98 } // namespace metrics 99 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/clean_exit_beacon.cc ('k') | components/metrics/daily_event_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698