[email protected] | 99c892d | 2014-03-24 18:11:21 | [diff] [blame^] | 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 | #ifndef CHROME_BROWSER_METRICS_CLONED_INSTALL_DETECTOR_H_ |
| 6 | #define CHROME_BROWSER_METRICS_CLONED_INSTALL_DETECTOR_H_ |
| 7 | |
| 8 | #include "base/gtest_prod_util.h" |
| 9 | #include "base/memory/ref_counted.h" |
| 10 | #include "base/memory/weak_ptr.h" |
| 11 | |
| 12 | class PrefRegistrySimple; |
| 13 | class PrefService; |
| 14 | |
| 15 | namespace metrics { |
| 16 | |
| 17 | class MachineIdProvider; |
| 18 | |
| 19 | // A class for detecting if an install is cloned. It does this by detecting |
| 20 | // when the hardware running Chrome changes. |
| 21 | class ClonedInstallDetector { |
| 22 | public: |
| 23 | explicit ClonedInstallDetector(MachineIdProvider* raw_id_provider); |
| 24 | virtual ~ClonedInstallDetector(); |
| 25 | |
| 26 | // Posts a task to generate a machine ID and store it to a local state pref. |
| 27 | // If the newly generated ID is different than the previously stored one, then |
| 28 | // the install is considered cloned. The ID is a 24-bit value based off of |
| 29 | // machine characteristics. This value should never be sent over the network. |
| 30 | // TODO(jwd): Implement change detection. |
| 31 | void CheckForClonedInstall(PrefService* local_state); |
| 32 | |
| 33 | static void RegisterPrefs(PrefRegistrySimple* registry); |
| 34 | |
| 35 | private: |
| 36 | FRIEND_TEST_ALL_PREFIXES(ClonedInstallDetectorTest, SaveId); |
| 37 | |
| 38 | // Converts raw_id into a 24-bit hash and stores the hash in |local_state|. |
| 39 | // |raw_id| is not a const ref because it's passed from a cross-thread post |
| 40 | // task. |
| 41 | void SaveMachineId(PrefService* local_state, std::string raw_id); |
| 42 | |
| 43 | scoped_refptr<MachineIdProvider> raw_id_provider_; |
| 44 | base::WeakPtrFactory<ClonedInstallDetector> weak_ptr_factory_; |
| 45 | |
| 46 | DISALLOW_COPY_AND_ASSIGN(ClonedInstallDetector); |
| 47 | }; |
| 48 | |
| 49 | } // namespace metrics |
| 50 | |
| 51 | #endif // CHROME_BROWSER_METRICS_CLONED_INSTALL_DETECTOR_H_ |