Chromium Code Reviews| 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(); | |
| 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(); | |
|
jwd
2014/05/01 15:51:14
Is this needed public? Since it's always called on
Alexei Svitkine (slow)
2014/05/01 18:01:45
It's public because it's also called from MetricsS
| |
| 39 | |
| 40 // Check if this install was cloned or imaged from another machine. If a | |
| 41 // clone is detected, reset the client id and low entropy source. This | |
| 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. | |
| 47 // The caller must determine if metrics reporting will be enabled for this | |
| 48 // client and pass that state in as |reporting_will_be_enabled|. | |
|
jwd
2014/05/01 15:51:14
Update comment re: |reporting_will_be_enabled|
Alexei Svitkine (slow)
2014/05/01 18:01:45
Done.
| |
| 49 // | |
| 50 // If |reporting_will_be_enabled| is true, this method returns an entropy | |
| 51 // provider that has a high source of entropy, partially based on the client | |
| 52 // ID. Otherwise, an entropy provider that is based on a low entropy source | |
| 53 // is returned. | |
| 54 // | |
| 55 // Note that this reporting state can not be checked by reporting_active() | |
| 56 // because this method may need to be called before the MetricsService needs | |
| 57 // to be started. | |
| 58 scoped_ptr<const base::FieldTrial::EntropyProvider> CreateEntropyProvider(); | |
| 59 | |
| 60 // Registers local state prefs used by this class. | |
| 61 static void RegisterPrefs(PrefRegistrySimple* registry); | |
| 62 | |
| 63 private: | |
| 64 FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, EntropySourceUsed_Low); | |
| 65 FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, EntropySourceUsed_High); | |
| 66 FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, LowEntropySource0NotReset); | |
| 67 FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, | |
| 68 PermutedEntropyCacheClearedWhenLowEntropyReset); | |
| 69 FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, ResetMetricsIDs); | |
| 70 | |
| 71 // Designates which entropy source was returned from this MetricsService. | |
| 72 // This is used for testing to validate that we return the correct source | |
| 73 // depending on the state of the service. | |
| 74 enum EntropySourceReturned { | |
| 75 LAST_ENTROPY_NONE, | |
| 76 LAST_ENTROPY_LOW, | |
| 77 LAST_ENTROPY_HIGH, | |
| 78 }; | |
| 79 | |
| 80 // Returns the low entropy source for this client. This is a random value | |
| 81 // that is non-identifying amongst browser clients. This method will | |
| 82 // generate the entropy source value if it has not been called before. | |
| 83 int GetLowEntropySource(); | |
| 84 | |
| 85 // Returns the first entropy source that was returned by this service since | |
| 86 // start up, or NONE if neither was returned yet. This is exposed for testing | |
| 87 // only. | |
| 88 EntropySourceReturned entropy_source_returned() const { | |
| 89 return entropy_source_returned_; | |
| 90 } | |
| 91 | |
| 92 // Reset the client id and low entropy source if the kMetricsResetMetricIDs | |
| 93 // pref is true. | |
| 94 void ResetMetricsIDsIfNecessary(); | |
| 95 | |
| 96 PrefService* local_state_; | |
| 97 | |
| 98 // TODO(asvitkine): Update this when the user toggles this state. | |
| 99 bool metrics_reporting_enabled_; | |
| 100 | |
| 101 // The identifier that's sent to the server with the log reports. | |
| 102 std::string client_id_; | |
| 103 | |
| 104 // The non-identifying low entropy source value. | |
| 105 int low_entropy_source_; | |
| 106 | |
| 107 // The last entropy source returned by this service, used for testing. | |
| 108 EntropySourceReturned entropy_source_returned_; | |
| 109 | |
| 110 // Set to true when |ResetMetricsIDsIfNecessary| is called for the first time. | |
| 111 // This prevents multiple resets within the same Chrome session. | |
| 112 bool metrics_ids_reset_check_performed_; | |
| 113 | |
| 114 scoped_ptr<ClonedInstallDetector> cloned_install_detector_; | |
| 115 | |
| 116 DISALLOW_COPY_AND_ASSIGN(MetricsStateManager); | |
| 117 }; | |
| 118 | |
| 119 } // namespace metrics | |
| 120 | |
| 121 #endif // CHROME_BROWSER_METRICS_METRICS_STATE_MANAGER_H_ | |
| OLD | NEW |