Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / components / metrics / cloned_install_detector.h
blob065cb490c507307d33cfaf320429a43ccf6e112f
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.
5 #ifndef COMPONENTS_METRICS_CLONED_INSTALL_DETECTOR_H_
6 #define COMPONENTS_METRICS_CLONED_INSTALL_DETECTOR_H_
8 #include "base/gtest_prod_util.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
12 class PrefRegistrySimple;
13 class PrefService;
15 namespace base {
16 class SingleThreadTaskRunner;
19 namespace metrics {
21 class MachineIdProvider;
23 // A class for detecting if an install is cloned. It does this by detecting
24 // when the hardware running Chrome changes.
25 class ClonedInstallDetector {
26 public:
27 explicit ClonedInstallDetector(MachineIdProvider* raw_id_provider);
28 virtual ~ClonedInstallDetector();
30 // Posts a task to |task_runner| to generate a machine ID and store it to a
31 // local state pref. If the newly generated ID is different than the
32 // previously stored one, then the install is considered cloned. The ID is a
33 // 24-bit value based off of machine characteristics. This value should never
34 // be sent over the network.
35 // TODO(jwd): Implement change detection.
36 void CheckForClonedInstall(
37 PrefService* local_state,
38 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
40 static void RegisterPrefs(PrefRegistrySimple* registry);
42 private:
43 FRIEND_TEST_ALL_PREFIXES(ClonedInstallDetectorTest, SaveId);
44 FRIEND_TEST_ALL_PREFIXES(ClonedInstallDetectorTest, DetectClone);
46 // Converts raw_id into a 24-bit hash and stores the hash in |local_state|.
47 // |raw_id| is not a const ref because it's passed from a cross-thread post
48 // task.
49 void SaveMachineId(PrefService* local_state, std::string raw_id);
51 scoped_refptr<MachineIdProvider> raw_id_provider_;
52 base::WeakPtrFactory<ClonedInstallDetector> weak_ptr_factory_;
54 DISALLOW_COPY_AND_ASSIGN(ClonedInstallDetector);
57 } // namespace metrics
59 #endif // COMPONENTS_METRICS_CLONED_INSTALL_DETECTOR_H_