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

Side by Side Diff: chrome/browser/metrics/variations/variations_http_header_provider.h

Issue 11821019: Move the Chrome Variations HTTP header helper file into c/b/metrics/variations, and fix up lock beh… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove TODO Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROME_METRICS_HELPER_H_ 5 #ifndef CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_HTTP_HEADER_PROVIDER_H_
6 #define CHROME_BROWSER_CHROME_METRICS_HELPER_H_ 6 #define CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_HTTP_HEADER_PROVIDER_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/metrics/field_trial.h" 12 #include "base/metrics/field_trial.h"
13 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #include "chrome/common/metrics/variations/variation_ids.h" 14 #include "chrome/common/metrics/variations/variation_ids.h"
15 15
16 namespace content { 16 namespace content {
17 class ResourceContext; 17 class ResourceContext;
18 } 18 }
19 19
20 namespace net { 20 namespace net {
21 class HttpRequestHeaders; 21 class HttpRequestHeaders;
22 } 22 }
23 23
24 class GURL; 24 class GURL;
25 class Profile; 25 class Profile;
26 class ProfileIOData; 26 class ProfileIOData;
27 27
28 template <typename T> struct DefaultSingletonTraits; 28 template <typename T> struct DefaultSingletonTraits;
29 29
30 namespace chrome_variations {
31
30 // A helper class for maintaining Chrome experiments and metrics state 32 // A helper class for maintaining Chrome experiments and metrics state
31 // transmitted in custom HTTP request headers. 33 // transmitted in custom HTTP request headers.
32 // This class is a thread-safe singleton. 34 // This class is a thread-safe singleton.
33 class ChromeMetricsHelper : base::FieldTrialList::Observer { 35 class VariationsHttpHeaderProvider : base::FieldTrialList::Observer {
34 public: 36 public:
35 static ChromeMetricsHelper* GetInstance(); 37 static VariationsHttpHeaderProvider* GetInstance();
36 38
37 // Adds Chrome experiment and metrics state as custom headers to |headers|. 39 // Adds Chrome experiment and metrics state as custom headers to |headers|.
38 // Some headers may not be set given the |incognito| mode or whether 40 // 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 41 // the user has |uma_enabled|. Also, we never transmit headers to non-Google
40 // sites, which is checked based on the destination |url|. 42 // sites, which is checked based on the destination |url|.
41 void AppendHeaders(const GURL& url, 43 void AppendHeaders(const GURL& url,
42 bool incognito, 44 bool incognito,
43 bool uma_enabled, 45 bool uma_enabled,
44 net::HttpRequestHeaders* headers); 46 net::HttpRequestHeaders* headers);
45 47
46 private: 48 private:
47 friend struct DefaultSingletonTraits<ChromeMetricsHelper>; 49 friend struct DefaultSingletonTraits<VariationsHttpHeaderProvider>;
48 50
49 ChromeMetricsHelper(); 51 VariationsHttpHeaderProvider();
50 virtual ~ChromeMetricsHelper(); 52 virtual ~VariationsHttpHeaderProvider();
51 53
52 // base::FieldTrialList::Observer implementation. 54 // base::FieldTrialList::Observer implementation.
53 // This will add the variation ID associated with |trial_name| and 55 // This will add the variation ID associated with |trial_name| and
54 // |group_name| to the variation ID cache. 56 // |group_name| to the variation ID cache.
55 virtual void OnFieldTrialGroupFinalized( 57 virtual void OnFieldTrialGroupFinalized(
56 const std::string& trial_name, 58 const std::string& trial_name,
57 const std::string& group_name) OVERRIDE; 59 const std::string& group_name) OVERRIDE;
58 60
59 // Prepares the variation IDs cache with initial values if not already done. 61 // Prepares the variation IDs cache with initial values if not already done.
60 // This method also registers the caller with the FieldTrialList to receive 62 // This method also registers the caller with the FieldTrialList to receive
61 // new variation IDs. 63 // new variation IDs.
62 void InitVariationIDsCacheIfNeeded(); 64 void InitVariationIDsCacheIfNeeded();
63 65
64 // Takes whatever is currently in |variation_ids_set_| and recreates 66 // Takes whatever is currently in |variation_ids_set_| and recreates
65 // |variation_ids_header_| with it. 67 // |variation_ids_header_| with it. Assumes the the |lock_| is currently
68 // held.
66 void UpdateVariationIDsHeaderValue(); 69 void UpdateVariationIDsHeaderValue();
67 70
68 // Guards |variation_ids_cache_initialized_|, |variation_ids_set_| and 71 // Guards |variation_ids_cache_initialized_|, |variation_ids_set_| and
69 // |variation_ids_header_|. 72 // |variation_ids_header_|.
70 base::Lock lock_; 73 base::Lock lock_;
71 74
72 // Whether or not we've initialized the cache. 75 // Whether or not we've initialized the cache.
73 bool variation_ids_cache_initialized_; 76 bool variation_ids_cache_initialized_;
74 77
75 // Keep a cache of variation IDs that are transmitted in headers to Google. 78 // 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. 79 // This consists of a list of valid IDs, and the actual transmitted header.
77 std::set<chrome_variations::VariationID> variation_ids_set_; 80 std::set<chrome_variations::VariationID> variation_ids_set_;
78 std::string variation_ids_header_; 81 std::string variation_ids_header_;
79 82
80 DISALLOW_COPY_AND_ASSIGN(ChromeMetricsHelper); 83 DISALLOW_COPY_AND_ASSIGN(VariationsHttpHeaderProvider);
81 }; 84 };
82 85
83 #endif // CHROME_BROWSER_CHROME_METRICS_HELPER_H_ 86 } // namespace chrome_variations
87
88 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_HTTP_HEADER_PROVIDER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chrome_metrics_helper.cc ('k') | chrome/browser/metrics/variations/variations_http_header_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698