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

Unified Diff: trunk/src/chrome/browser/metrics/metrics_service.h

Issue 268223002: Revert 268232 "Refactor MetricsStateManager class out of Metrics..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: trunk/src/chrome/browser/metrics/metrics_service.h
===================================================================
--- trunk/src/chrome/browser/metrics/metrics_service.h (revision 268245)
+++ trunk/src/chrome/browser/metrics/metrics_service.h (working copy)
@@ -69,7 +69,7 @@
}
namespace metrics {
-class MetricsStateManager;
+class ClonedInstallDetector;
}
namespace net {
@@ -127,24 +127,26 @@
SHUTDOWN_COMPLETE = 700,
};
+ enum ReportingState {
+ REPORTING_ENABLED,
+ REPORTING_DISABLED,
+ };
+
MetricsService();
virtual ~MetricsService();
// Initializes metrics recording state. Updates various bookkeeping values in
// prefs and sets up the scheduler. This is a separate function rather than
// being done by the constructor so that field trials could be created before
- // this is run.
- void InitializeMetricsRecordingState();
+ // this is run. Takes |reporting_state| parameter which specifies whether UMA
+ // is enabled.
+ void InitializeMetricsRecordingState(ReportingState reporting_state);
// Starts the metrics system, turning on recording and uploading of metrics.
// Should be called when starting up with metrics enabled, or when metrics
// are turned on.
void Start();
- // If metrics reporting is enabled, starts the metrics service. Returns
- // whether the metrics service was started.
- bool StartIfMetricsReportingEnabled();
-
// Starts the metrics system in a special test-only mode. Metrics won't ever
// be uploaded or persisted in this mode, but metrics will be recorded in
// memory.
@@ -167,13 +169,24 @@
// Returns the preferred entropy provider used to seed persistent activities
// based on whether or not metrics reporting will be permitted on this client.
+ // The caller must determine if metrics reporting will be enabled for this
+ // client and pass that state in as |reporting_will_be_enabled|.
//
- // If metrics reporting is enabled, this method returns an entropy provider
- // that has a high source of entropy, partially based on the client ID.
- // Otherwise, it returns an entropy provider that is based on a low entropy
- // source.
- scoped_ptr<const base::FieldTrial::EntropyProvider> CreateEntropyProvider();
+ // If |reporting_will_be_enabled| is true, this method returns an entropy
+ // provider that has a high source of entropy, partially based on the client
+ // ID. Otherwise, an entropy provider that is based on a low entropy source
+ // is returned.
+ //
+ // Note that this reporting state can not be checked by reporting_active()
+ // because this method may need to be called before the MetricsService needs
+ // to be started.
+ scoped_ptr<const base::FieldTrial::EntropyProvider> CreateEntropyProvider(
+ ReportingState reporting_state);
+ // Force the client ID to be generated. This is useful in case it's needed
+ // before recording.
+ void ForceClientIdCreation();
+
// At startup, prefs needs to be called with a list of all the pref names and
// types we'll be using.
static void RegisterPrefs(PrefRegistrySimple* registry);
@@ -299,6 +312,15 @@
NEED_TO_SHUTDOWN = ~CLEANLY_SHUTDOWN
};
+ // Designates which entropy source was returned from this MetricsService.
+ // This is used for testing to validate that we return the correct source
+ // depending on the state of the service.
+ enum EntropySourceReturned {
+ LAST_ENTROPY_NONE,
+ LAST_ENTROPY_LOW,
+ LAST_ENTROPY_HIGH,
+ };
+
struct ChildProcessStats;
typedef std::vector<SyntheticTrialGroup> SyntheticTrialGroups;
@@ -346,6 +368,22 @@
base::TimeDelta* incremental_uptime,
base::TimeDelta* uptime);
+ // Reset the client id and low entropy source if the kMetricsResetMetricIDs
+ // pref is true.
+ void ResetMetricsIDsIfNecessary();
+
+ // Returns the low entropy source for this client. This is a random value
+ // that is non-identifying amongst browser clients. This method will
+ // generate the entropy source value if it has not been called before.
+ int GetLowEntropySource();
+
+ // Returns the first entropy source that was returned by this service since
+ // start up, or NONE if neither was returned yet. This is exposed for testing
+ // only.
+ EntropySourceReturned entropy_source_returned() const {
+ return entropy_source_returned_;
+ }
+
// Turns recording on or off.
// DisableRecording() also forces a persistent save of logging state (if
// anything has been recorded, or transmitted).
@@ -359,8 +397,11 @@
void HandleIdleSinceLastTransmission(bool in_idle);
// Set up client ID, session ID, etc.
- void InitializeMetricsState();
+ void InitializeMetricsState(ReportingState reporting_state);
+ // Generates a new client ID to use to identify self to metrics server.
+ static std::string GenerateClientID();
+
// Schedule the next save of LocalState information. This is called
// automatically by the task that performs each save to schedule the next one.
void ScheduleNextStateSave();
@@ -471,10 +512,6 @@
void GetCurrentSyntheticFieldTrials(
std::vector<chrome_variations::ActiveGroupId>* synthetic_trials);
- // Used to manage various metrics reporting state prefs, such as client id,
- // low entropy source and whether metrics reporting is enabled.
- scoped_ptr<metrics::MetricsStateManager> state_manager_;
-
base::ActionCallback action_callback_;
content::NotificationRegistrar registrar_;
@@ -526,6 +563,12 @@
// The HTTP pipelining test server.
std::string http_pipelining_test_server_;
+ // The identifier that's sent to the server with the log reports.
+ std::string client_id_;
+
+ // The non-identifying low entropy source value.
+ int low_entropy_source_;
+
// Whether the MetricsService object has received any notifications since
// the last time a transmission was sent.
bool idle_since_last_transmission_;
@@ -566,6 +609,9 @@
scoped_refptr<chromeos::ExternalMetrics> external_metrics_;
#endif
+ // The last entropy source returned by this service, used for testing.
+ EntropySourceReturned entropy_source_returned_;
+
// Stores the time of the first call to |GetUptimes()|.
base::TimeTicks first_updated_time_;
@@ -582,10 +628,19 @@
// Field trial groups that map to Chrome configuration states.
SyntheticTrialGroups synthetic_trial_groups_;
+ scoped_ptr<metrics::ClonedInstallDetector> cloned_install_detector_;
+
+ FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ClientIdCorrectlyFormatted);
FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess);
+ FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, LowEntropySource0NotReset);
FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest,
PermutedEntropyCacheClearedWhenLowEntropyReset);
FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial);
+ FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, ResetMetricsIDs);
+ FRIEND_TEST_ALL_PREFIXES(MetricsServiceBrowserTest,
+ CheckLowEntropySourceUsed);
+ FRIEND_TEST_ALL_PREFIXES(MetricsServiceReportingTest,
+ CheckHighEntropySourceUsed);
DISALLOW_COPY_AND_ASSIGN(MetricsService);
};
@@ -607,9 +662,6 @@
FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CrashReportingEnabled);
// Returns true if prefs::kMetricsReportingEnabled is set.
- // TODO(asvitkine): Consolidate the method in MetricsStateManager.
- // TODO(asvitkine): This function does not report the correct value on
- // Android and ChromeOS, see http://crbug.com/362192.
static bool IsMetricsReportingEnabled();
// Returns true if crash reporting is enabled. This is set at the platform

Powered by Google App Engine
This is Rietveld 408576698