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 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. | |
SteveT
2012/12/13 16:24:08
Could you add a brief doc for this class?
Bart N.
2012/12/14 18:21:42
Done.
| |
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 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 // Adds Chrome experiment and metrics state as custom headers to |headers|. | |
60 // Some headers may not be set given the |incognito| mode or whether | |
61 // the user has |uma_enabled|. Also, we never transmit headers to non-Google | |
62 // sites, which is checked based on the destination |url|. | |
63 void AppendHeaders(const GURL& url, | |
64 bool incognito, | |
65 bool uma_enabled, | |
66 net::HttpRequestHeaders* headers); | |
67 | |
68 // Prepares the variation IDs cache with initial values if not already done. | |
69 // This method also registers the caller with the FieldTrialList to receive | |
70 // new variation IDs. | |
71 void InitVariationIDsCacheIfNeeded(); | |
72 | |
73 // Takes whatever is currently in |variation_ids_set_| and recreates | |
74 // |variation_ids_header_| with it. | |
75 void UpdateVariationIDsHeaderValue(); | |
76 | |
77 // Guards |variation_ids_cache_initialized_|, |variation_ids_set_| and | |
78 // |variation_ids_header_|. | |
79 base::Lock lock_; | |
80 | |
81 // Whether or not we've initialized the cache. | |
82 bool variation_ids_cache_initialized_; | |
83 | |
84 // Keep a cache of variation IDs that are transmitted in headers to Google. | |
85 // This consists of a list of valid IDs, and the actual transmitted header. | |
86 std::set<chrome_variations::VariationID> variation_ids_set_; | |
87 std::string variation_ids_header_; | |
88 | |
89 DISALLOW_COPY_AND_ASSIGN(ChromeMetricsHelper); | |
90 }; | |
91 | |
92 #endif // CHROME_BROWSER_CHROME_METRICS_HELPER_H_ | |
OLD | NEW |