[go: nahoru, domu]

blob: c38e05254ea8c926260ba9f240f24726e16299ba [file] [log] [blame]
jwd@chromium.org99c892d2014-03-24 18:11:211// 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
blundell@chromium.org66d176a2014-05-22 13:49:395#ifndef COMPONENTS_METRICS_CLONED_INSTALL_DETECTOR_H_
6#define COMPONENTS_METRICS_CLONED_INSTALL_DETECTOR_H_
jwd@chromium.org99c892d2014-03-24 18:11:217
8#include "base/gtest_prod_util.h"
avi26062922015-12-26 00:14:189#include "base/macros.h"
jwd@chromium.org99c892d2014-03-24 18:11:2110#include "base/memory/weak_ptr.h"
11
12class PrefRegistrySimple;
13class PrefService;
14
15namespace metrics {
16
jwd@chromium.org99c892d2014-03-24 18:11:2117// A class for detecting if an install is cloned. It does this by detecting
18// when the hardware running Chrome changes.
19class ClonedInstallDetector {
20 public:
Gabriel Charette45f796f2017-07-12 07:00:5421 ClonedInstallDetector();
jwd@chromium.org99c892d2014-03-24 18:11:2122 virtual ~ClonedInstallDetector();
23
blundell@chromium.org61b0d482014-05-20 14:49:1024 // Posts a task to |task_runner| to generate a machine ID and store it to a
25 // local state pref. If the newly generated ID is different than the
26 // previously stored one, then the install is considered cloned. The ID is a
27 // 24-bit value based off of machine characteristics. This value should never
28 // be sent over the network.
Gabriel Charette45f796f2017-07-12 07:00:5429 void CheckForClonedInstall(PrefService* local_state);
jwd@chromium.org99c892d2014-03-24 18:11:2130
31 static void RegisterPrefs(PrefRegistrySimple* registry);
32
Joshua Berenhaus5235d4fe2020-01-23 19:03:4533 // Returns true for the whole session if we detected a cloned install during
34 // the construction of a client id.
35 bool ShouldResetClientIds(PrefService* local_state);
36
37 // Returns true for the whole session if we detect a cloned install this
38 // session.
39 bool ClonedInstallDetectedInCurrentSession() const;
40
jwd@chromium.org99c892d2014-03-24 18:11:2141 private:
42 FRIEND_TEST_ALL_PREFIXES(ClonedInstallDetectorTest, SaveId);
jwd@chromium.org37d4709a2014-03-29 03:07:4043 FRIEND_TEST_ALL_PREFIXES(ClonedInstallDetectorTest, DetectClone);
Joshua Berenhaus5235d4fe2020-01-23 19:03:4544 FRIEND_TEST_ALL_PREFIXES(ClonedInstallDetectorTest, ShouldResetClientIds);
45 FRIEND_TEST_ALL_PREFIXES(ClonedInstallDetectorTest,
46 ClonedInstallDetectedInCurrentSession);
47 FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, CheckProviderResetIds);
jwd@chromium.org99c892d2014-03-24 18:11:2148
49 // Converts raw_id into a 24-bit hash and stores the hash in |local_state|.
50 // |raw_id| is not a const ref because it's passed from a cross-thread post
51 // task.
ki.stfu939799a42015-09-28 04:41:2052 void SaveMachineId(PrefService* local_state, const std::string& raw_id);
jwd@chromium.org99c892d2014-03-24 18:11:2153
Joshua Berenhaus5235d4fe2020-01-23 19:03:4554 // Indicates that we detected a cloned install during the current session.
55 bool detected_this_session_ = false;
56
57 // Indicates that we detected a cloned install during the construction of a
58 // client id and should reset client ids as a result.
59 bool should_reset_client_ids_ = false;
60
Jeremy Roman5c341f6d2019-07-15 15:56:1061 base::WeakPtrFactory<ClonedInstallDetector> weak_ptr_factory_{this};
jwd@chromium.org99c892d2014-03-24 18:11:2162
63 DISALLOW_COPY_AND_ASSIGN(ClonedInstallDetector);
64};
65
66} // namespace metrics
67
blundell@chromium.org66d176a2014-05-22 13:49:3968#endif // COMPONENTS_METRICS_CLONED_INSTALL_DETECTOR_H_