OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PARAMS_H_ |
| 6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PARAMS_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "url/gurl.h" |
| 12 |
| 13 namespace data_reduction_proxy { |
| 14 |
| 15 // Provides initialization parameters. Proxy origins, the probe url, and the |
| 16 // authentication key are taken from flags if available and from preprocessor |
| 17 // constants otherwise. Only the key may be changed after construction. |
| 18 class DataReductionProxyParams { |
| 19 public: |
| 20 typedef std::vector<GURL> DataReductionProxyList; |
| 21 |
| 22 // Returns true if this client is part of the data reduction proxy field |
| 23 // trial. |
| 24 static bool IsIncludedInFieldTrial(); |
| 25 |
| 26 // Returns true if this client is part of field trial to use an alternative |
| 27 // configuration for the data reduction proxy. |
| 28 static bool IsIncludedInAlternativeFieldTrial(); |
| 29 |
| 30 // Returns true if this client is part of the field trial that should display |
| 31 // a promotion for the data reduction proxy. |
| 32 static bool IsIncludedInPromoFieldTrial(); |
| 33 |
| 34 // Returns true if this client is part of a field trial that uses preconnect |
| 35 // hinting. |
| 36 static bool IsIncludedInPreconnectHintingFieldTrial(); |
| 37 |
| 38 // Returns true if the authentication key was set on the command line. |
| 39 static bool IsKeySetOnCommandLine(); |
| 40 |
| 41 // Constructs configuration parameters. If |allowed|, then the standard |
| 42 // data reduction proxy configuration is allowed to be used. If |
| 43 // |fallback_allowed| a fallback proxy can be used if the primary proxy is |
| 44 // bypassed or disabled. If |fallback_allowed| then an alternative proxy |
| 45 // configuration is allowed to be used. This alternative configuration would |
| 46 // replace the primary and fallback proxy configurations if enabled. Finally |
| 47 // if |promo_allowed|, the client may show a promotion for the data |
| 48 // reduction proxy. |
| 49 // |
| 50 // A standard configuration has a primary proxy, and a fallback proxy for |
| 51 // http traffic. The alternative configuration has a different primary and |
| 52 // fallback proxy for http traffic, and an SSL proxy. |
| 53 DataReductionProxyParams(bool allowed, |
| 54 bool fallback_allowed, |
| 55 bool alt_allowed, |
| 56 bool promo_allowed); |
| 57 |
| 58 virtual ~DataReductionProxyParams(); |
| 59 |
| 60 // Returns the data reduction proxy primary origin. |
| 61 const GURL& origin() const { |
| 62 return origin_; |
| 63 } |
| 64 |
| 65 // Returns the data reduction proxy fallback origin. |
| 66 const GURL& fallback_origin() const { |
| 67 return fallback_origin_; |
| 68 } |
| 69 |
| 70 // Returns the data reduction proxy ssl origin that is used with the |
| 71 // alternative proxy configuration. |
| 72 const GURL& ssl_origin() const { |
| 73 return ssl_origin_; |
| 74 } |
| 75 |
| 76 // Returns the alternative data reduction proxy primary origin. |
| 77 const GURL& alt_origin() const { |
| 78 return alt_origin_; |
| 79 } |
| 80 |
| 81 // Returns the alternative data reduction proxy fallback origin. |
| 82 const GURL& alt_fallback_origin() const { |
| 83 return alt_fallback_origin_; |
| 84 } |
| 85 |
| 86 // Returns the URL to probe to decide if the primary origin should be used. |
| 87 const GURL& probe_url() const { |
| 88 return probe_url_; |
| 89 } |
| 90 |
| 91 // Set the proxy authentication key. |
| 92 void set_key(const std::string& key) { |
| 93 key_ = key; |
| 94 } |
| 95 |
| 96 // Returns the proxy authentication key. |
| 97 const std::string& key() const { |
| 98 return key_; |
| 99 } |
| 100 |
| 101 // Returns true if the data reduction proxy configuration may be used. |
| 102 bool allowed() const { |
| 103 return allowed_; |
| 104 } |
| 105 |
| 106 // Returns true if the fallback proxy may be used. |
| 107 bool fallback_allowed() const { |
| 108 return fallback_allowed_; |
| 109 } |
| 110 |
| 111 // Returns true if the alternative data reduction proxy configuration may be |
| 112 // used. |
| 113 bool alternative_allowed() const { |
| 114 return alt_allowed_; |
| 115 } |
| 116 |
| 117 // Returns true if the data reduction proxy promo may be shown. |
| 118 // This is idependent of whether the data reduction proxy is allowed. |
| 119 // TODO(bengr): maybe tie to whether proxy is allowed. |
| 120 bool promo_allowed() const { |
| 121 return promo_allowed_; |
| 122 } |
| 123 |
| 124 // Given |allowed_|, |fallback_allowed_|, and |alt_allowed_|, returns the |
| 125 // list of data reduction proxies that may be used. |
| 126 DataReductionProxyList GetAllowedProxies() const; |
| 127 |
| 128 protected: |
| 129 // Test constructor that optionally won't call Init(); |
| 130 DataReductionProxyParams(bool allowed, |
| 131 bool fallback_allowed, |
| 132 bool alt_allowed, |
| 133 bool promo_allowed, |
| 134 bool should_call_init); |
| 135 |
| 136 // Initialize the values of the proxies, probe URL, and key from command |
| 137 // line flags and preprocessor constants, and check that there are |
| 138 // corresponding definitions for the allowed configurations. |
| 139 bool Init(bool allowed, bool fallback_allowed, bool alt_allowed); |
| 140 |
| 141 // Initialize the values of the proxies, probe URL, and key from command |
| 142 // line flags and preprocessor constants. |
| 143 void InitWithoutChecks(); |
| 144 |
| 145 // Returns the corresponding string from preprocessor constants if defined, |
| 146 // and an empty string otherwise. |
| 147 virtual std::string GetDefaultKey() const; |
| 148 virtual std::string GetDefaultDevOrigin() const; |
| 149 virtual std::string GetDefaultOrigin() const; |
| 150 virtual std::string GetDefaultFallbackOrigin() const; |
| 151 virtual std::string GetDefaultSSLOrigin() const; |
| 152 virtual std::string GetDefaultAltOrigin() const; |
| 153 virtual std::string GetDefaultAltFallbackOrigin() const; |
| 154 virtual std::string GetDefaultProbeURL() const; |
| 155 |
| 156 private: |
| 157 GURL origin_; |
| 158 GURL fallback_origin_; |
| 159 GURL ssl_origin_; |
| 160 GURL alt_origin_; |
| 161 GURL alt_fallback_origin_; |
| 162 GURL probe_url_; |
| 163 |
| 164 std::string key_; |
| 165 |
| 166 bool allowed_; |
| 167 const bool fallback_allowed_; |
| 168 bool alt_allowed_; |
| 169 const bool promo_allowed_; |
| 170 |
| 171 |
| 172 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyParams); |
| 173 }; |
| 174 |
| 175 } // namespace data_reduction_proxy |
| 176 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PARAMS_H
_ |
OLD | NEW |