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 "chrome/browser/metrics/cloned_install_detector.h" | 5 #include "chrome/browser/metrics/cloned_install_detector.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" |
8 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
9 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
10 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/task_runner_util.h" |
11 #include "chrome/browser/metrics/cloned_install_detector.h" | 14 #include "chrome/browser/metrics/cloned_install_detector.h" |
12 #include "chrome/browser/metrics/machine_id_provider.h" | 15 #include "chrome/browser/metrics/machine_id_provider.h" |
13 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
14 #include "components/metrics/metrics_hashes.h" | 17 #include "components/metrics/metrics_hashes.h" |
15 #include "content/public/browser/browser_thread.h" | |
16 | 18 |
17 namespace metrics { | 19 namespace metrics { |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 uint32 HashRawId(const std::string& value) { | 23 uint32 HashRawId(const std::string& value) { |
22 uint64 hash = metrics::HashMetricName(value); | 24 uint64 hash = metrics::HashMetricName(value); |
23 | 25 |
24 // Only use 24 bits from the 64-bit hash. | 26 // Only use 24 bits from the 64-bit hash. |
25 return hash & ((1 << 24) - 1); | 27 return hash & ((1 << 24) - 1); |
(...skipping 15 matching lines...) Expand all Loading... |
41 } | 43 } |
42 | 44 |
43 } // namespace | 45 } // namespace |
44 | 46 |
45 ClonedInstallDetector::ClonedInstallDetector(MachineIdProvider* raw_id_provider) | 47 ClonedInstallDetector::ClonedInstallDetector(MachineIdProvider* raw_id_provider) |
46 : raw_id_provider_(raw_id_provider), | 48 : raw_id_provider_(raw_id_provider), |
47 weak_ptr_factory_(this) {} | 49 weak_ptr_factory_(this) {} |
48 | 50 |
49 ClonedInstallDetector::~ClonedInstallDetector() {} | 51 ClonedInstallDetector::~ClonedInstallDetector() {} |
50 | 52 |
51 void ClonedInstallDetector::CheckForClonedInstall(PrefService* local_state) { | 53 void ClonedInstallDetector::CheckForClonedInstall( |
52 content::BrowserThread::PostTaskAndReplyWithResult( | 54 PrefService* local_state, |
53 content::BrowserThread::FILE, | 55 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
| 56 base::PostTaskAndReplyWithResult( |
| 57 task_runner.get(), |
54 FROM_HERE, | 58 FROM_HERE, |
55 base::Bind(&metrics::MachineIdProvider::GetMachineId, | 59 base::Bind(&metrics::MachineIdProvider::GetMachineId, raw_id_provider_), |
56 raw_id_provider_), | |
57 base::Bind(&metrics::ClonedInstallDetector::SaveMachineId, | 60 base::Bind(&metrics::ClonedInstallDetector::SaveMachineId, |
58 weak_ptr_factory_.GetWeakPtr(), | 61 weak_ptr_factory_.GetWeakPtr(), |
59 local_state)); | 62 local_state)); |
60 } | 63 } |
61 | 64 |
62 void ClonedInstallDetector::SaveMachineId( | 65 void ClonedInstallDetector::SaveMachineId( |
63 PrefService* local_state, | 66 PrefService* local_state, |
64 std::string raw_id) { | 67 std::string raw_id) { |
65 if (raw_id.empty()) { | 68 if (raw_id.empty()) { |
66 LogMachineIdState(ID_GENERATION_FAILED); | 69 LogMachineIdState(ID_GENERATION_FAILED); |
(...skipping 19 matching lines...) Expand all Loading... |
86 | 89 |
87 local_state->SetInteger(prefs::kMetricsMachineId, hashed_id); | 90 local_state->SetInteger(prefs::kMetricsMachineId, hashed_id); |
88 } | 91 } |
89 | 92 |
90 // static | 93 // static |
91 void ClonedInstallDetector::RegisterPrefs(PrefRegistrySimple* registry) { | 94 void ClonedInstallDetector::RegisterPrefs(PrefRegistrySimple* registry) { |
92 registry->RegisterIntegerPref(prefs::kMetricsMachineId, 0); | 95 registry->RegisterIntegerPref(prefs::kMetricsMachineId, 0); |
93 } | 96 } |
94 | 97 |
95 } // namespace metrics | 98 } // namespace metrics |
OLD | NEW |