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