| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_VARIATIONS_NET_VARIATIONS_HTTP_HEADER_PROVIDER_H_ | 5 #ifndef COMPONENTS_VARIATIONS_NET_VARIATIONS_HTTP_HEADER_PROVIDER_H_ |
| 6 #define COMPONENTS_VARIATIONS_NET_VARIATIONS_HTTP_HEADER_PROVIDER_H_ | 6 #define COMPONENTS_VARIATIONS_NET_VARIATIONS_HTTP_HEADER_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 12 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 13 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
| 14 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 16 #include "components/metrics/metrics_service.h" |
| 15 #include "components/variations/variations_associated_data.h" | 17 #include "components/variations/variations_associated_data.h" |
| 16 | 18 |
| 17 namespace content { | 19 namespace content { |
| 18 class ResourceContext; | 20 class ResourceContext; |
| 19 } | 21 } |
| 20 | 22 |
| 21 namespace net { | 23 namespace net { |
| 22 class HttpRequestHeaders; | 24 class HttpRequestHeaders; |
| 23 } | 25 } |
| 24 | 26 |
| 25 class GURL; | 27 class GURL; |
| 26 | 28 |
| 27 template <typename T> struct DefaultSingletonTraits; | 29 template <typename T> struct DefaultSingletonTraits; |
| 28 | 30 |
| 29 namespace variations { | 31 namespace variations { |
| 30 | 32 |
| 31 // A helper class for maintaining client experiments and metrics state | 33 // A helper class for maintaining client experiments and metrics state |
| 32 // transmitted in custom HTTP request headers. | 34 // transmitted in custom HTTP request headers. |
| 33 // This class is a thread-safe singleton. | 35 // This class is a thread-safe singleton. |
| 34 class VariationsHttpHeaderProvider : base::FieldTrialList::Observer { | 36 class VariationsHttpHeaderProvider : public base::FieldTrialList::Observer, |
| 37 public metrics::SyntheticTrialObserver { |
| 35 public: | 38 public: |
| 36 static VariationsHttpHeaderProvider* GetInstance(); | 39 static VariationsHttpHeaderProvider* GetInstance(); |
| 37 | 40 |
| 38 // Adds Chrome experiment and metrics state as custom headers to |headers|. | 41 // Adds Chrome experiment and metrics state as custom headers to |headers|. |
| 39 // Some headers may not be set given the |incognito| mode or whether | 42 // Some headers may not be set given the |incognito| mode or whether |
| 40 // the user has |uma_enabled|. Also, we never transmit headers to non-Google | 43 // the user has |uma_enabled|. Also, we never transmit headers to non-Google |
| 41 // sites, which is checked based on the destination |url|. | 44 // sites, which is checked based on the destination |url|. |
| 42 void AppendHeaders(const GURL& url, | 45 void AppendHeaders(const GURL& url, |
| 43 bool incognito, | 46 bool incognito, |
| 44 bool uma_enabled, | 47 bool uma_enabled, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 59 FRIEND_TEST_ALL_PREFIXES(VariationsHttpHeaderProviderTest, | 62 FRIEND_TEST_ALL_PREFIXES(VariationsHttpHeaderProviderTest, |
| 60 SetDefaultVariationIds_Valid); | 63 SetDefaultVariationIds_Valid); |
| 61 FRIEND_TEST_ALL_PREFIXES(VariationsHttpHeaderProviderTest, | 64 FRIEND_TEST_ALL_PREFIXES(VariationsHttpHeaderProviderTest, |
| 62 SetDefaultVariationIds_Invalid); | 65 SetDefaultVariationIds_Invalid); |
| 63 FRIEND_TEST_ALL_PREFIXES(VariationsHttpHeaderProviderTest, | 66 FRIEND_TEST_ALL_PREFIXES(VariationsHttpHeaderProviderTest, |
| 64 OnFieldTrialGroupFinalized); | 67 OnFieldTrialGroupFinalized); |
| 65 | 68 |
| 66 VariationsHttpHeaderProvider(); | 69 VariationsHttpHeaderProvider(); |
| 67 ~VariationsHttpHeaderProvider() override; | 70 ~VariationsHttpHeaderProvider() override; |
| 68 | 71 |
| 69 // base::FieldTrialList::Observer implementation. | 72 // base::FieldTrialList::Observer: |
| 70 // This will add the variation ID associated with |trial_name| and | 73 // This will add the variation ID associated with |trial_name| and |
| 71 // |group_name| to the variation ID cache. | 74 // |group_name| to the variation ID cache. |
| 72 void OnFieldTrialGroupFinalized(const std::string& trial_name, | 75 void OnFieldTrialGroupFinalized(const std::string& trial_name, |
| 73 const std::string& group_name) override; | 76 const std::string& group_name) override; |
| 74 | 77 |
| 78 // metrics::SyntheticTrialObserver: |
| 79 void OnSyntheticTrialsChanged( |
| 80 const std::vector<metrics::SyntheticTrialGroup>& groups) override; |
| 81 |
| 75 // Prepares the variation IDs cache with initial values if not already done. | 82 // Prepares the variation IDs cache with initial values if not already done. |
| 76 // This method also registers the caller with the FieldTrialList to receive | 83 // This method also registers the caller with the FieldTrialList to receive |
| 77 // new variation IDs. | 84 // new variation IDs. |
| 78 void InitVariationIDsCacheIfNeeded(); | 85 void InitVariationIDsCacheIfNeeded(); |
| 79 | 86 |
| 80 // Takes whatever is currently in |variation_ids_set_| and recreates | 87 // Takes whatever is currently in |variation_ids_set_| and recreates |
| 81 // |variation_ids_header_| with it. Assumes the the |lock_| is currently | 88 // |variation_ids_header_| with it. Assumes the the |lock_| is currently |
| 82 // held. | 89 // held. |
| 83 void UpdateVariationIDsHeaderValue(); | 90 void UpdateVariationIDsHeaderValue(); |
| 84 | 91 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 95 | 102 |
| 96 // Keep a cache of variation IDs that are transmitted in headers to Google. | 103 // Keep a cache of variation IDs that are transmitted in headers to Google. |
| 97 // This consists of a list of valid IDs, and the actual transmitted header. | 104 // This consists of a list of valid IDs, and the actual transmitted header. |
| 98 std::set<VariationID> variation_ids_set_; | 105 std::set<VariationID> variation_ids_set_; |
| 99 std::set<VariationID> variation_trigger_ids_set_; | 106 std::set<VariationID> variation_trigger_ids_set_; |
| 100 | 107 |
| 101 // Provides the google experiment ids forced from command line. | 108 // Provides the google experiment ids forced from command line. |
| 102 std::set<VariationID> default_variation_ids_set_; | 109 std::set<VariationID> default_variation_ids_set_; |
| 103 std::set<VariationID> default_trigger_id_set_; | 110 std::set<VariationID> default_trigger_id_set_; |
| 104 | 111 |
| 112 // Variations ids from synthetic field trials. |
| 113 std::set<VariationID> synthetic_variation_ids_set_; |
| 114 |
| 105 std::string variation_ids_header_; | 115 std::string variation_ids_header_; |
| 106 | 116 |
| 107 DISALLOW_COPY_AND_ASSIGN(VariationsHttpHeaderProvider); | 117 DISALLOW_COPY_AND_ASSIGN(VariationsHttpHeaderProvider); |
| 108 }; | 118 }; |
| 109 | 119 |
| 110 } // namespace variations | 120 } // namespace variations |
| 111 | 121 |
| 112 #endif // COMPONENTS_VARIATIONS_NET_VARIATIONS_HTTP_HEADER_PROVIDER_H_ | 122 #endif // COMPONENTS_VARIATIONS_NET_VARIATIONS_HTTP_HEADER_PROVIDER_H_ |
| OLD | NEW |