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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 class URLFetcher;
23 class URLRequest;
24 }
25
26 class GURL;
27 class Profile;
28 class ProfileIOData;
29
30 template <typename T> struct DefaultSingletonTraits;
31
32 // This class is a thread-safe singleton.
33 class ChromeMetricsHelper : base::FieldTrialList::Observer {
34 public:
35 static ChromeMetricsHelper* GetInstance();
36
37 // Adds Chrome experiment and metrics state as custom headers to |request|.
38 // This is a best-effort attempt, and does not interrupt the request if the
39 // headers cannot be appended.
40 void AppendHeadersToRequest(net::URLRequest* request,
41 content::ResourceContext* resource_context);
42 // Same as above but works with a |fetcher| and |profile|. Both methods
43 // internally delegate to AppendHeaders(...).
44 void AppendHeadersToFetcher(net::URLFetcher* fetcher, const Profile* profile);
45
46 // base::FieldTrialList::Observer implementation.
Peter Kasting 2012/12/11 21:08:48 Nit: If this isn't called directly through a Chrom
Bart N. 2012/12/11 23:18:56 Sure.
47 // This will add the variation ID associated with |trial_name| and
48 // |group_name| to the variation ID cache.
49 virtual void OnFieldTrialGroupFinalized(
50 const std::string& trial_name,
51 const std::string& group_name) OVERRIDE;
52
53 private:
54 ChromeMetricsHelper();
55 virtual ~ChromeMetricsHelper();
56 friend struct DefaultSingletonTraits<ChromeMetricsHelper>;
Peter Kasting 2012/12/11 21:08:48 Nit: Put friend declaration above constructor/dest
Bart N. 2012/12/11 23:18:56 Done.
57
58 void AppendHeaders(const GURL& url,
Peter Kasting 2012/12/11 21:08:48 Nit: Comment?
Bart N. 2012/12/14 18:21:42 Done.
59 bool incognito,
60 bool uma_enabled,
61 net::HttpRequestHeaders* headers);
62
63 // Prepares the variation IDs cache with initial values if not already done.
64 // This method also registers the caller with the FieldTrialList to receive
65 // new variation IDs.
66 void InitVariationIDsCacheIfNeeded();
67
68 // Takes whatever is currently in |variation_ids_set_| and recreates
69 // |variation_ids_header_| with it.
70 void UpdateVariationIDsHeaderValue();
71
72 // Guards |variation_ids_cache_initialized_|, |variation_ids_set_| and
73 // |variation_ids_header_|.
74 base::Lock lock_;
75
76 // Whether or not we've initialized the Cache.
Peter Kasting 2012/12/11 21:08:48 Nit: Cache -> cache
Bart N. 2012/12/11 23:18:56 Done.
77 bool variation_ids_cache_initialized_;
78
79 // Keep a cache of variation IDs that are transmitted in headers to Google.
80 // This consists of a list of valid IDs, and the actual transmitted header.
81 // Note that since this cache is both initialized and accessed from the IO
82 // thread, we do not need to synchronize its uses.
Peter Kasting 2012/12/11 21:08:48 I'm confused as to what this comment means. It so
Bart N. 2012/12/11 23:18:56 Ah, most of the code in this file is simply moved
83 std::set<chrome_variations::VariationID> variation_ids_set_;
84 std::string variation_ids_header_;
85
86 DISALLOW_COPY_AND_ASSIGN(ChromeMetricsHelper);
87 };
88
89 #endif // CHROME_BROWSER_CHROME_METRICS_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698