Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(761)

Side by Side Diff: components/metrics/metrics_state_manager.h

Issue 372473004: Retrieve client_id from GoogleUpdateSettings when its missing from Local State. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #ifndef COMPONENTS_METRICS_METRICS_STATE_MANAGER_H_ 5 #ifndef COMPONENTS_METRICS_METRICS_STATE_MANAGER_H_
6 #define COMPONENTS_METRICS_METRICS_STATE_MANAGER_H_ 6 #define COMPONENTS_METRICS_METRICS_STATE_MANAGER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/metrics/field_trial.h" 14 #include "base/metrics/field_trial.h"
15 15
16 class PrefService; 16 class PrefService;
17 class PrefRegistrySimple; 17 class PrefRegistrySimple;
18 18
19 namespace metrics { 19 namespace metrics {
20 20
21 class ClonedInstallDetector; 21 class ClonedInstallDetector;
22 22
23 // Responsible for managing MetricsService state prefs, specifically the UMA 23 // Responsible for managing MetricsService state prefs, specifically the UMA
24 // client id and low entropy source. Code outside the metrics directory should 24 // client id and low entropy source. Code outside the metrics directory should
25 // not be instantiating or using this class directly. 25 // not be instantiating or using this class directly.
26 class MetricsStateManager { 26 class MetricsStateManager {
27 public: 27 public:
28 // A callback that can be invoked to save client info.
29 typedef base::Callback<bool(const std::string& client_id,
grt (UTC plus 2) 2014/07/08 14:48:01 why not void? the return value is ignored in the i
gab 2014/07/09 19:16:59 Done.
30 int64 installation_date)> SaveClientInfoCallback;
31 // A callback that can be invoked to retrieve client info saved through the
grt (UTC plus 2) 2014/07/08 14:48:01 newline above how about Load/Store rather than Ret
gab 2014/07/09 19:16:59 I like it, done in precursor rename CL.
32 // SaveClientInfoCallback.
33 typedef base::Callback<bool(std::string* client_id, int64* installation_date)>
grt (UTC plus 2) 2014/07/08 14:48:01 consider making this a void function too, and stip
gab 2014/07/09 19:16:59 Actually changed the API altogether here, introduc
34 RetrieveClientInfoCallback;
35
28 virtual ~MetricsStateManager(); 36 virtual ~MetricsStateManager();
29 37
30 // Returns true if the user opted in to sending metric reports. 38 // Returns true if the user opted in to sending metric reports.
31 bool IsMetricsReportingEnabled(); 39 bool IsMetricsReportingEnabled();
32 40
33 // Returns the client ID for this client, or the empty string if the user is 41 // Returns the client ID for this client, or the empty string if the user is
34 // not opted in to metrics reporting. 42 // not opted in to metrics reporting.
35 const std::string& client_id() const { return client_id_; } 43 const std::string& client_id() const { return client_id_; }
36 44
37 // Forces the client ID to be generated. This is useful in case it's needed 45 // Forces the client ID to be generated. This is useful in case it's needed
(...skipping 12 matching lines...) Expand all
50 // If metrics reporting is enabled, this method returns an entropy provider 58 // If metrics reporting is enabled, this method returns an entropy provider
51 // that has a high source of entropy, partially based on the client ID. 59 // that has a high source of entropy, partially based on the client ID.
52 // Otherwise, it returns an entropy provider that is based on a low entropy 60 // Otherwise, it returns an entropy provider that is based on a low entropy
53 // source. 61 // source.
54 scoped_ptr<const base::FieldTrial::EntropyProvider> CreateEntropyProvider(); 62 scoped_ptr<const base::FieldTrial::EntropyProvider> CreateEntropyProvider();
55 63
56 // Creates the MetricsStateManager, enforcing that only a single instance 64 // Creates the MetricsStateManager, enforcing that only a single instance
57 // of the class exists at a time. Returns NULL if an instance exists already. 65 // of the class exists at a time. Returns NULL if an instance exists already.
58 static scoped_ptr<MetricsStateManager> Create( 66 static scoped_ptr<MetricsStateManager> Create(
59 PrefService* local_state, 67 PrefService* local_state,
60 const base::Callback<bool(void)>& is_reporting_enabled_callback); 68 const base::Callback<bool(void)>& is_reporting_enabled_callback,
69 const SaveClientInfoCallback& save_client_info,
70 const RetrieveClientInfoCallback& retrieve_client_info);
61 71
62 // Registers local state prefs used by this class. 72 // Registers local state prefs used by this class.
63 static void RegisterPrefs(PrefRegistrySimple* registry); 73 static void RegisterPrefs(PrefRegistrySimple* registry);
64 74
65 private: 75 private:
66 FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, EntropySourceUsed_Low); 76 FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, EntropySourceUsed_Low);
67 FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, EntropySourceUsed_High); 77 FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, EntropySourceUsed_High);
68 FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, LowEntropySource0NotReset); 78 FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, LowEntropySource0NotReset);
69 FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, 79 FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest,
70 PermutedEntropyCacheClearedWhenLowEntropyReset); 80 PermutedEntropyCacheClearedWhenLowEntropyReset);
71 FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, ResetMetricsIDs); 81 FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, ResetMetricsIDs);
72 82
73 // Designates which entropy source was returned from this class. 83 // Designates which entropy source was returned from this class.
74 // This is used for testing to validate that we return the correct source 84 // This is used for testing to validate that we return the correct source
75 // depending on the state of the service. 85 // depending on the state of the service.
76 enum EntropySourceType { 86 enum EntropySourceType {
77 ENTROPY_SOURCE_NONE, 87 ENTROPY_SOURCE_NONE,
78 ENTROPY_SOURCE_LOW, 88 ENTROPY_SOURCE_LOW,
79 ENTROPY_SOURCE_HIGH, 89 ENTROPY_SOURCE_HIGH,
80 }; 90 };
81 91
82 // Creates the MetricsStateManager with the given |local_state|. Calls 92 // Creates the MetricsStateManager with the given |local_state|. Calls
83 // |is_reporting_enabled_callback| to query whether metrics reporting is 93 // |is_reporting_enabled_callback| to query whether metrics reporting is
84 // enabled. Clients should instead use Create(), which enforces a single 94 // enabled. Clients should instead use Create(), which enforces that a single
85 // instance of this class is alive at any given time. 95 // instance of this class be alive at any given time.
96 // |save_client_info| should back up client info to solid state such that it
grt (UTC plus 2) 2014/07/08 14:48:01 solid state -> persistent storage (not everyone ro
gab 2014/07/09 19:16:59 Done.
97 // is later retrievable by |retrieve_client_info|.
86 MetricsStateManager( 98 MetricsStateManager(
87 PrefService* local_state, 99 PrefService* local_state,
88 const base::Callback<bool(void)>& is_reporting_enabled_callback); 100 const base::Callback<bool(void)>& is_reporting_enabled_callback,
101 const SaveClientInfoCallback& save_client_info,
102 const RetrieveClientInfoCallback& retrieve_client_info);
89 103
90 // Returns the low entropy source for this client. This is a random value 104 // Returns the low entropy source for this client. This is a random value
91 // that is non-identifying amongst browser clients. This method will 105 // that is non-identifying amongst browser clients. This method will
92 // generate the entropy source value if it has not been called before. 106 // generate the entropy source value if it has not been called before.
93 int GetLowEntropySource(); 107 int GetLowEntropySource();
94 108
95 // Returns the first entropy source that was returned by this service since 109 // Returns the first entropy source that was returned by this service since
96 // start up, or NONE if neither was returned yet. This is exposed for testing 110 // start up, or NONE if neither was returned yet. This is exposed for testing
97 // only. 111 // only.
98 EntropySourceType entropy_source_returned() const { 112 EntropySourceType entropy_source_returned() const {
99 return entropy_source_returned_; 113 return entropy_source_returned_;
100 } 114 }
101 115
102 // Reset the client id and low entropy source if the kMetricsResetMetricIDs 116 // Reset the client id and low entropy source if the kMetricsResetMetricIDs
103 // pref is true. 117 // pref is true.
104 void ResetMetricsIDsIfNecessary(); 118 void ResetMetricsIDsIfNecessary();
105 119
106 // Whether an instance of this class exists. Used to enforce that there aren't 120 // Whether an instance of this class exists. Used to enforce that there aren't
107 // multiple instances of this class at a given time. 121 // multiple instances of this class at a given time.
108 static bool instance_exists_; 122 static bool instance_exists_;
109 123
110 // Weak pointer to the local state prefs store. 124 // Weak pointer to the local state prefs store.
111 PrefService* const local_state_; 125 PrefService* const local_state_;
112 126
113 const base::Callback<bool(void)> is_reporting_enabled_callback_; 127 const base::Callback<bool(void)> is_reporting_enabled_callback_;
114 128
129 const SaveClientInfoCallback save_client_info_;
grt (UTC plus 2) 2014/07/08 14:48:01 add doc comments
gab 2014/07/09 19:16:59 I find that in the case of typedef'ed callbacks, a
grt (UTC plus 2) 2014/07/10 14:03:32 sorry i left out the justification for the request
130 const RetrieveClientInfoCallback retrieve_client_info_;
131
115 // The identifier that's sent to the server with the log reports. 132 // The identifier that's sent to the server with the log reports.
116 std::string client_id_; 133 std::string client_id_;
117 134
118 // The non-identifying low entropy source value. 135 // The non-identifying low entropy source value.
119 int low_entropy_source_; 136 int low_entropy_source_;
120 137
121 // The last entropy source returned by this service, used for testing. 138 // The last entropy source returned by this service, used for testing.
122 EntropySourceType entropy_source_returned_; 139 EntropySourceType entropy_source_returned_;
123 140
124 scoped_ptr<ClonedInstallDetector> cloned_install_detector_; 141 scoped_ptr<ClonedInstallDetector> cloned_install_detector_;
125 142
126 DISALLOW_COPY_AND_ASSIGN(MetricsStateManager); 143 DISALLOW_COPY_AND_ASSIGN(MetricsStateManager);
127 }; 144 };
128 145
129 } // namespace metrics 146 } // namespace metrics
130 147
131 #endif // COMPONENTS_METRICS_METRICS_STATE_MANAGER_H_ 148 #endif // COMPONENTS_METRICS_METRICS_STATE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698