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

Unified Diff: chrome/browser/metrics/metrics_state_manager.h

Issue 256143006: Refactor MetricsStateManager class out of MetricsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 8 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: chrome/browser/metrics/metrics_state_manager.h
===================================================================
--- chrome/browser/metrics/metrics_state_manager.h (revision 0)
+++ chrome/browser/metrics/metrics_state_manager.h (working copy)
@@ -0,0 +1,111 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_METRICS_METRICS_STATE_MANAGER_H_
+#define CHROME_BROWSER_METRICS_METRICS_STATE_MANAGER_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/gtest_prod_util.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/metrics/field_trial.h"
+
+class PrefService;
+class PrefRegistrySimple;
+
+namespace metrics {
+
+class ClonedInstallDetector;
+
+// Responsible for managing MetricsService state prefs, specifically the UMA
+// client id and low entropy source.
+class MetricsStateManager {
+ public:
+ explicit MetricsStateManager(PrefService* local_state);
+ virtual ~MetricsStateManager();
+
+ // Returns true if the user opted in to sending metric reports.
+ 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
+
+ // Returns the client ID for this client, or the empty string if the user is
+ // not opted in to metrics reporting.
+ const std::string& client_id() const { return client_id_; }
+
+ // Force the client ID to be generated. This is useful in case it's needed
+ // before recording.
+ void ForceClientIdCreation();
+
+ // 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.
+ // 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.
+ // should not be called more than once.
+ void CheckForClonedInstall();
+
+ // Returns the preferred entropy provider used to seed persistent activities
+ // 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.
+ //
+ // 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, an entropy provider that is based on a low entropy source is
+ // returned.
+ scoped_ptr<const base::FieldTrial::EntropyProvider> CreateEntropyProvider();
+
+ // Registers local state prefs used by this class.
+ static void RegisterPrefs(PrefRegistrySimple* registry);
+
+ private:
+ FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, EntropySourceUsed_Low);
+ FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, EntropySourceUsed_High);
+ FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, LowEntropySource0NotReset);
+ FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest,
+ PermutedEntropyCacheClearedWhenLowEntropyReset);
+ FRIEND_TEST_ALL_PREFIXES(MetricsStateManagerTest, ResetMetricsIDs);
+
+ // 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.
+ // This is used for testing to validate that we return the correct source
+ // depending on the state of the service.
+ 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
+ LAST_ENTROPY_NONE,
+ LAST_ENTROPY_LOW,
+ LAST_ENTROPY_HIGH,
+ };
+
+ // 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_;
+ }
+
+ // Reset the client id and low entropy source if the kMetricsResetMetricIDs
+ // pref is true.
+ void ResetMetricsIDsIfNecessary();
+
+ PrefService* local_state_;
+
+ // 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
+ bool metrics_reporting_enabled_;
+
+ // 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_;
+
+ // The last entropy source returned by this service, used for testing.
+ EntropySourceReturned entropy_source_returned_;
+
+ scoped_ptr<ClonedInstallDetector> cloned_install_detector_;
+
+ DISALLOW_COPY_AND_ASSIGN(MetricsStateManager);
+};
+
+} // namespace metrics
+
+#endif // CHROME_BROWSER_METRICS_METRICS_STATE_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698