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

Unified Diff: chrome/browser/chrome_metrics_helper.h

Issue 11522009: X-Chrome-Variations logic refactoring (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Merged with head. Created 8 years 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/chrome_metrics_helper.h
diff --git a/chrome/browser/chrome_metrics_helper.h b/chrome/browser/chrome_metrics_helper.h
new file mode 100644
index 0000000000000000000000000000000000000000..268b55cccb5c440ce382bf34e8900c930d7979b3
--- /dev/null
+++ b/chrome/browser/chrome_metrics_helper.h
@@ -0,0 +1,83 @@
+// Copyright (c) 2012 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_CHROME_METRICS_HELPER_H_
+#define CHROME_BROWSER_CHROME_METRICS_HELPER_H_
+
+#include <set>
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/metrics/field_trial.h"
+#include "base/synchronization/lock.h"
+#include "chrome/common/metrics/variations/variation_ids.h"
+
+namespace content {
+class ResourceContext;
+}
+
+namespace net {
+class HttpRequestHeaders;
+}
+
+class GURL;
+class Profile;
+class ProfileIOData;
+
+template <typename T> struct DefaultSingletonTraits;
Peter Kasting 2012/12/17 19:51:57 Tiny nit: I have no idea if we document this somew
+
+// A helper class for maintaining Chrome experiments and metrics state
+// transmitted in custom HTTP request headers.
+// This class is a thread-safe singleton.
Peter Kasting 2012/12/17 19:51:57 So, this critical question never got answered by S
SteveT 2012/12/17 20:30:46 So it's not just the call to GetActiveFieldTrialGr
Bart N. 2012/12/17 20:43:36 No, I was referring to the fact that all public me
SteveT 2012/12/17 20:49:56 GetActiveFieldTrialGroups (you were referring to t
Bart N. 2012/12/17 21:09:14 Yes, GetActiveFieldTrialGroups. So my understandin
SteveT 2012/12/17 21:17:59 Yes, that seems fair. Is it OK for us to keep the
+class ChromeMetricsHelper : base::FieldTrialList::Observer {
+ public:
+ static ChromeMetricsHelper* GetInstance();
+
+ // Adds Chrome experiment and metrics state as custom headers to |headers|.
+ // Some headers may not be set given the |incognito| mode or whether
+ // the user has |uma_enabled|. Also, we never transmit headers to non-Google
+ // sites, which is checked based on the destination |url|.
+ void AppendHeaders(const GURL& url,
+ bool incognito,
+ bool uma_enabled,
+ net::HttpRequestHeaders* headers);
+
+ private:
+ friend struct DefaultSingletonTraits<ChromeMetricsHelper>;
+
+ ChromeMetricsHelper();
+ virtual ~ChromeMetricsHelper();
+
+ // base::FieldTrialList::Observer implementation.
+ // This will add the variation ID associated with |trial_name| and
+ // |group_name| to the variation ID cache.
+ virtual void OnFieldTrialGroupFinalized(
+ const std::string& trial_name,
+ const std::string& group_name) OVERRIDE;
+
+ // Prepares the variation IDs cache with initial values if not already done.
+ // This method also registers the caller with the FieldTrialList to receive
+ // new variation IDs.
+ void InitVariationIDsCacheIfNeeded();
+
+ // Takes whatever is currently in |variation_ids_set_| and recreates
+ // |variation_ids_header_| with it.
+ void UpdateVariationIDsHeaderValue();
+
+ // Guards |variation_ids_cache_initialized_|, |variation_ids_set_| and
+ // |variation_ids_header_|.
+ base::Lock lock_;
+
+ // Whether or not we've initialized the cache.
+ bool variation_ids_cache_initialized_;
+
+ // Keep a cache of variation IDs that are transmitted in headers to Google.
+ // This consists of a list of valid IDs, and the actual transmitted header.
+ std::set<chrome_variations::VariationID> variation_ids_set_;
Peter Kasting 2012/12/17 19:51:57 Nit: Consider a typedef (e.g. "Variations") for th
+ std::string variation_ids_header_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChromeMetricsHelper);
+};
+
+#endif // CHROME_BROWSER_CHROME_METRICS_HELPER_H_

Powered by Google App Engine
This is Rietveld 408576698