OLD | NEW |
---|---|
(Empty) | |
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_METRICS_STATE_MANAGER_H_ | |
6 #define CHROME_BROWSER_METRICS_METRICS_STATE_MANAGER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/gtest_prod_util.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/metrics/field_trial.h" | |
14 | |
15 class PrefService; | |
16 class PrefRegistrySimple; | |
17 | |
18 namespace metrics { | |
19 | |
20 class ClonedInstallDetector; | |
21 | |
22 // Responsible for managing MetricsService state prefs, specifically the UMA | |
23 // client id and low entropy source. | |
24 class MetricsStateManager { | |
25 public: | |
26 explicit MetricsStateManager(PrefService* local_state); | |
27 virtual ~MetricsStateManager(); | |
28 | |
29 // Returns true if the user opted in to sending metric reports. | |
30 bool IsMetricsReportingEnabled(); | |
Ilya Sherman
2014/05/02 05:12:38
I'm not comfortable with exposing this as a public
Alexei Svitkine (slow)
2014/05/02 15:21:46
It's not a static method, so someone needs to have
Ilya Sherman
2014/05/02 19:35:06
It's pretty easy to construct an instance of this
Alexei Svitkine (slow)
2014/05/02 20:21:31
In the previous patchset, I added this comment to
Ilya Sherman
2014/05/02 20:30:06
I saw the comment -- thanks for adding it! -- but
Steven Holte
2014/05/02 20:39:01
Hm, it looks like there is a fairly common xyz::in
Alexei Svitkine (slow)
2014/05/02 20:45:51
I'm okay with doing this as well, but perhaps this
Ilya Sherman
2014/05/02 20:49:48
Yeah, once we move to a component, I bet we can en
Alexei Svitkine (slow)
2014/05/02 21:49:52
Per offline discussion, went with a Create() facto
| |
31 | |
32 // Returns the client ID for this client, or the empty string if the user is | |
33 // not opted in to metrics reporting. | |
34 const std::string& client_id() const { return client_id_; } | |
35 | |
36 // Force the client ID to be generated. This is useful in case it's needed | |
37 // before recording. | |
38 void ForceClientIdCreation(); | |
39 | |
40 // Check if this install was cloned or imaged from another machine. If a | |
Ilya Sherman
2014/05/02 05:12:38
nit: "Check" -> "Checks"
Alexei Svitkine (slow)
2014/05/02 15:21:46
Done.
| |
41 // clone is detected, reset the client id and low entropy source. This | |
Ilya Sherman
2014/05/02 05:12:38
nit: "reset" -> "resets"
Alexei Svitkine (slow)
2014/05/02 15:21:46
Done.
| |
42 // should not be called more than once. | |
43 void CheckForClonedInstall(); | |
44 | |
45 // Returns the preferred entropy provider used to seed persistent activities | |
46 // based on whether or not metrics reporting will be permitted on this client. | |
Ilya Sherman
2014/05/02 05:12:38
nit: "will be permitted" -> "is permitted"?
Alexei Svitkine (slow)
2014/05/02 15:21:46
Done.
| |
47 // | |
48 // If metrics reporting is enabled, this method returns an entropy provider | |
49 // that has a high source of entropy, partially based on the client ID. | |
50 // Otherwise, an entropy provider that is based on a low entropy source is | |
51 // returned. | |
52 scoped_ptr<const base::FieldTrial::EntropyProvider> CreateEntropyProvider(); | |
53 | |
54 // Registers local state prefs used by this class. | |
55 static void RegisterPrefs(PrefRegistrySimple* registry); | |
56 | |
57 private: | |
58 FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, EntropySourceUsed_Low); | |
59 FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, EntropySourceUsed_High); | |
60 FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, LowEntropySource0NotReset); | |
61 FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, | |
62 PermutedEntropyCacheClearedWhenLowEntropyReset); | |
63 FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, ResetMetricsIDs); | |
64 | |
65 // Designates which entropy source was returned from this MetricsService. | |
Ilya Sherman
2014/05/02 05:12:38
nit: Please update the comment.
Alexei Svitkine (slow)
2014/05/02 15:21:46
Done.
| |
66 // This is used for testing to validate that we return the correct source | |
67 // depending on the state of the service. | |
68 enum EntropySourceReturned { | |
Ilya Sherman
2014/05/02 05:12:38
nit: Perhaps name this "LastEntropySource", to mat
Alexei Svitkine (slow)
2014/05/02 15:21:46
I actually went with EntropySourceType and renamed
| |
69 LAST_ENTROPY_NONE, | |
70 LAST_ENTROPY_LOW, | |
71 LAST_ENTROPY_HIGH, | |
72 }; | |
73 | |
74 // Returns the low entropy source for this client. This is a random value | |
75 // that is non-identifying amongst browser clients. This method will | |
76 // generate the entropy source value if it has not been called before. | |
77 int GetLowEntropySource(); | |
78 | |
79 // Returns the first entropy source that was returned by this service since | |
80 // start up, or NONE if neither was returned yet. This is exposed for testing | |
81 // only. | |
82 EntropySourceReturned entropy_source_returned() const { | |
83 return entropy_source_returned_; | |
84 } | |
85 | |
86 // Reset the client id and low entropy source if the kMetricsResetMetricIDs | |
87 // pref is true. | |
88 void ResetMetricsIDsIfNecessary(); | |
89 | |
90 PrefService* local_state_; | |
91 | |
92 // TODO(asvitkine): Update this when the user toggles this state. | |
Ilya Sherman
2014/05/02 05:12:38
Are you intending to address this TODO as part of
Alexei Svitkine (slow)
2014/05/02 15:21:46
It was safe because it was only checked during sta
| |
93 bool metrics_reporting_enabled_; | |
94 | |
95 // The identifier that's sent to the server with the log reports. | |
96 std::string client_id_; | |
97 | |
98 // The non-identifying low entropy source value. | |
99 int low_entropy_source_; | |
100 | |
101 // The last entropy source returned by this service, used for testing. | |
102 EntropySourceReturned entropy_source_returned_; | |
103 | |
104 scoped_ptr<ClonedInstallDetector> cloned_install_detector_; | |
105 | |
106 DISALLOW_COPY_AND_ASSIGN(MetricsStateManager); | |
107 }; | |
108 | |
109 } // namespace metrics | |
110 | |
111 #endif // CHROME_BROWSER_METRICS_METRICS_STATE_MANAGER_H_ | |
OLD | NEW |