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" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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(PrefService* local_state) { |
52 content::BrowserThread::PostTaskAndReplyWithResult( | 52 DVLOG(2) << "\n\nabout to post some tasks.\n\n"; |
53 bool res = content::BrowserThread::PostTaskAndReplyWithResult( | |
53 content::BrowserThread::FILE, | 54 content::BrowserThread::FILE, |
54 FROM_HERE, | 55 FROM_HERE, |
55 base::Bind(&metrics::MachineIdProvider::GetMachineId, | 56 base::Bind(&metrics::MachineIdProvider::GetMachineId, |
56 raw_id_provider_), | 57 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)); |
61 DVLOG(2) << "\n\ntask posted? " << res << "\n\n"; | |
60 } | 62 } |
61 | 63 |
62 void ClonedInstallDetector::SaveMachineId( | 64 void ClonedInstallDetector::SaveMachineId( |
63 PrefService* local_state, | 65 PrefService* local_state, |
64 std::string raw_id) { | 66 std::string raw_id) { |
67 DVLOG(2) << "\n\nsaving id: " << raw_id << "\n\n"; | |
65 if (raw_id.empty()) { | 68 if (raw_id.empty()) { |
66 LogMachineIdState(ID_GENERATION_FAILED); | 69 LogMachineIdState(ID_GENERATION_FAILED); |
67 local_state->ClearPref(prefs::kMetricsMachineId); | 70 local_state->ClearPref(prefs::kMetricsMachineId); |
68 return; | 71 return; |
69 } | 72 } |
70 | 73 |
71 int hashed_id = HashRawId(raw_id); | 74 int hashed_id = HashRawId(raw_id); |
72 | 75 |
73 MachineIdState id_state = ID_NO_STORED_VALUE; | 76 MachineIdState id_state = ID_NO_STORED_VALUE; |
74 if (local_state->HasPrefPath(prefs::kMetricsMachineId)) { | 77 if (local_state->HasPrefPath(prefs::kMetricsMachineId)) { |
75 id_state = local_state->GetInteger(prefs::kMetricsMachineId) == hashed_id ? | 78 if (local_state->GetInteger(prefs::kMetricsMachineId) != hashed_id) { |
76 ID_UNCHANGED : ID_CHANGED; | 79 id_state = ID_CHANGED; |
80 local_state->SetBoolean(prefs::kMetricsCloneDetected, true); | |
Alexei Svitkine (slow)
2014/03/26 21:34:50
Is there a way we can make the querying and settin
| |
81 } else { | |
82 id_state = ID_UNCHANGED; | |
83 } | |
77 } | 84 } |
78 | 85 |
79 LogMachineIdState(id_state); | 86 LogMachineIdState(id_state); |
80 | 87 |
81 local_state->SetInteger(prefs::kMetricsMachineId, hashed_id); | 88 local_state->SetInteger(prefs::kMetricsMachineId, hashed_id); |
82 } | 89 } |
83 | 90 |
84 // static | 91 // static |
85 void ClonedInstallDetector::RegisterPrefs(PrefRegistrySimple* registry) { | 92 void ClonedInstallDetector::RegisterPrefs(PrefRegistrySimple* registry) { |
86 registry->RegisterIntegerPref(prefs::kMetricsMachineId, 0); | 93 registry->RegisterIntegerPref(prefs::kMetricsMachineId, 0); |
94 registry->RegisterBooleanPref(prefs::kMetricsCloneDetected, false); | |
87 } | 95 } |
88 | 96 |
89 } // namespace metrics | 97 } // namespace metrics |
OLD | NEW |