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