Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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_CHROME_METRICS_HELPER_H_ | |
| 6 #define CHROME_BROWSER_CHROME_METRICS_HELPER_H_ | |
| 7 | |
| 8 #include <set> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/metrics/field_trial.h" | |
| 13 #include "base/synchronization/lock.h" | |
| 14 #include "chrome/common/metrics/variations/variation_ids.h" | |
| 15 | |
| 16 namespace content { | |
| 17 class ResourceContext; | |
| 18 } | |
| 19 | |
| 20 namespace net { | |
| 21 class HttpRequestHeaders; | |
| 22 } | |
| 23 | |
| 24 class GURL; | |
| 25 class Profile; | |
| 26 class ProfileIOData; | |
| 27 | |
| 28 template <typename T> struct DefaultSingletonTraits; | |
|
Peter Kasting
2012/12/17 19:51:57
Tiny nit: I have no idea if we document this somew
| |
| 29 | |
| 30 // A helper class for maintaining Chrome experiments and metrics state | |
| 31 // transmitted in custom HTTP request headers. | |
| 32 // 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
| |
| 33 class ChromeMetricsHelper : base::FieldTrialList::Observer { | |
| 34 public: | |
| 35 static ChromeMetricsHelper* GetInstance(); | |
| 36 | |
| 37 // Adds Chrome experiment and metrics state as custom headers to |headers|. | |
| 38 // Some headers may not be set given the |incognito| mode or whether | |
| 39 // the user has |uma_enabled|. Also, we never transmit headers to non-Google | |
| 40 // sites, which is checked based on the destination |url|. | |
| 41 void AppendHeaders(const GURL& url, | |
| 42 bool incognito, | |
| 43 bool uma_enabled, | |
| 44 net::HttpRequestHeaders* headers); | |
| 45 | |
| 46 private: | |
| 47 friend struct DefaultSingletonTraits<ChromeMetricsHelper>; | |
| 48 | |
| 49 ChromeMetricsHelper(); | |
| 50 virtual ~ChromeMetricsHelper(); | |
| 51 | |
| 52 // base::FieldTrialList::Observer implementation. | |
| 53 // This will add the variation ID associated with |trial_name| and | |
| 54 // |group_name| to the variation ID cache. | |
| 55 virtual void OnFieldTrialGroupFinalized( | |
| 56 const std::string& trial_name, | |
| 57 const std::string& group_name) OVERRIDE; | |
| 58 | |
| 59 // Prepares the variation IDs cache with initial values if not already done. | |
| 60 // This method also registers the caller with the FieldTrialList to receive | |
| 61 // new variation IDs. | |
| 62 void InitVariationIDsCacheIfNeeded(); | |
| 63 | |
| 64 // Takes whatever is currently in |variation_ids_set_| and recreates | |
| 65 // |variation_ids_header_| with it. | |
| 66 void UpdateVariationIDsHeaderValue(); | |
| 67 | |
| 68 // Guards |variation_ids_cache_initialized_|, |variation_ids_set_| and | |
| 69 // |variation_ids_header_|. | |
| 70 base::Lock lock_; | |
| 71 | |
| 72 // Whether or not we've initialized the cache. | |
| 73 bool variation_ids_cache_initialized_; | |
| 74 | |
| 75 // Keep a cache of variation IDs that are transmitted in headers to Google. | |
| 76 // This consists of a list of valid IDs, and the actual transmitted header. | |
| 77 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
| |
| 78 std::string variation_ids_header_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(ChromeMetricsHelper); | |
| 81 }; | |
| 82 | |
| 83 #endif // CHROME_BROWSER_CHROME_METRICS_HELPER_H_ | |
| OLD | NEW |