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_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_SETTINGS_H_ | 5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_SETTINGS_H_ |
6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_SETTINGS_H_ | 6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_SETTINGS_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 94 |
95 // Returns true if the data reduction proxy key is set on the command line. | 95 // Returns true if the data reduction proxy key is set on the command line. |
96 static bool IsProxyKeySetOnCommandLine(); | 96 static bool IsProxyKeySetOnCommandLine(); |
97 | 97 |
98 // Returns true if this application instance is part of the data reduction | 98 // Returns true if this application instance is part of the data reduction |
99 // proxy field trial, or if it a proxy origin is set in flags. This is a | 99 // proxy field trial, or if it a proxy origin is set in flags. This is a |
100 // convenience method for platforms like Chrome on Android and iOS, to | 100 // convenience method for platforms like Chrome on Android and iOS, to |
101 // determine if the data reduction proxy is allowed. | 101 // determine if the data reduction proxy is allowed. |
102 static bool IsIncludedInFieldTrialOrFlags(); | 102 static bool IsIncludedInFieldTrialOrFlags(); |
103 | 103 |
104 static void SetKey(const std::string& key); | |
105 static void SetAllowed(bool allowed); | 104 static void SetAllowed(bool allowed); |
106 static void SetPromoAllowed(bool promo_allowed); | 105 static void SetPromoAllowed(bool promo_allowed); |
107 | 106 |
108 DataReductionProxySettings(); | 107 DataReductionProxySettings(); |
109 virtual ~DataReductionProxySettings(); | 108 virtual ~DataReductionProxySettings(); |
110 | 109 |
| 110 // Set and get the key to be used for data reduction proxy authentication. |
| 111 void set_key(const std::string& key) { |
| 112 key_ = key; |
| 113 } |
| 114 |
| 115 const std::string& key() const { |
| 116 return key_; |
| 117 } |
| 118 |
111 // Initializes the data reduction proxy with profile and local state prefs, | 119 // Initializes the data reduction proxy with profile and local state prefs, |
112 // and a |UrlRequestContextGetter| for canary probes. The caller must ensure | 120 // and a |UrlRequestContextGetter| for canary probes. The caller must ensure |
113 // that all parameters remain alive for the lifetime of the | 121 // that all parameters remain alive for the lifetime of the |
114 // |DataReductionProxySettings| instance. | 122 // |DataReductionProxySettings| instance. |
115 void InitDataReductionProxySettings( | 123 void InitDataReductionProxySettings( |
116 PrefService* prefs, | 124 PrefService* prefs, |
117 PrefService* local_state_prefs, | 125 PrefService* local_state_prefs, |
118 net::URLRequestContextGetter* url_request_context_getter); | 126 net::URLRequestContextGetter* url_request_context_getter); |
119 | 127 |
120 // Initializes the data reduction proxy with profile and local state prefs, | 128 // Initializes the data reduction proxy with profile and local state prefs, |
121 // a |UrlRequestContextGetter| for canary probes, and a proxy configurator. | 129 // a |UrlRequestContextGetter| for canary probes, and a proxy configurator. |
122 // The caller must ensure that all parameters remain alive for the lifetime of | 130 // The caller must ensure that all parameters remain alive for the lifetime of |
123 // the |DataReductionProxySettings| instance. | 131 // the |DataReductionProxySettings| instance. |
124 // TODO(marq): Remove when iOS supports the new interface above. | 132 // TODO(marq): Remove when iOS supports the new interface above. |
125 void InitDataReductionProxySettings( | 133 void InitDataReductionProxySettings( |
126 PrefService* prefs, | 134 PrefService* prefs, |
127 PrefService* local_state_prefs, | 135 PrefService* local_state_prefs, |
128 net::URLRequestContextGetter* url_request_context_getter, | 136 net::URLRequestContextGetter* url_request_context_getter, |
129 scoped_ptr<DataReductionProxyConfigurator> config); | 137 scoped_ptr<DataReductionProxyConfigurator> config); |
130 | 138 |
131 // Sets the logic the embedder uses to set the networking configuration that | 139 // Sets the logic the embedder uses to set the networking configuration that |
132 // causes traffic to be proxied. | 140 // causes traffic to be proxied. |
133 void SetProxyConfigurator( | 141 void SetProxyConfigurator( |
134 scoped_ptr<DataReductionProxyConfigurator> configurator); | 142 scoped_ptr<DataReductionProxyConfigurator> configurator); |
135 | 143 |
136 // If proxy authentication is compiled in, pre-cache authentication | 144 // If proxy authentication is compiled in, pre-cache an authentication |
137 // keys for all configured proxies in |session|. | 145 // |key| for all configured proxies in |session|. |
138 static void InitDataReductionProxySession(net::HttpNetworkSession* session); | 146 static void InitDataReductionProxySession(net::HttpNetworkSession* session, |
| 147 const std::string& key); |
139 | 148 |
140 // Returns true if the data reduction proxy is allowed to be used. This could | 149 // Returns true if the data reduction proxy is allowed to be used. This could |
141 // return false, for example, if this instance is not part of the field trial, | 150 // return false, for example, if this instance is not part of the field trial, |
142 // or if the proxy name is not configured via gyp. | 151 // or if the proxy name is not configured via gyp. |
143 static bool IsDataReductionProxyAllowed(); | 152 static bool IsDataReductionProxyAllowed(); |
144 | 153 |
145 // Returns true if a screen promoting the data reduction proxy is allowed to | 154 // Returns true if a screen promoting the data reduction proxy is allowed to |
146 // be shown. Logic that decides when to show the promo should check its | 155 // be shown. Logic that decides when to show the promo should check its |
147 // availability. This would return false if not part of a separate field | 156 // availability. This would return false if not part of a separate field |
148 // trial that governs the use of the promotion. | 157 // trial that governs the use of the promotion. |
(...skipping 12 matching lines...) Expand all Loading... |
161 // Returns a vector of GURLs for all configured proxies. | 170 // Returns a vector of GURLs for all configured proxies. |
162 static DataReductionProxyList GetDataReductionProxies(); | 171 static DataReductionProxyList GetDataReductionProxies(); |
163 | 172 |
164 // Returns true if |auth_info| represents an authentication challenge from | 173 // Returns true if |auth_info| represents an authentication challenge from |
165 // a compatible, configured proxy. | 174 // a compatible, configured proxy. |
166 static bool IsAcceptableAuthChallenge(net::AuthChallengeInfo* auth_info); | 175 static bool IsAcceptableAuthChallenge(net::AuthChallengeInfo* auth_info); |
167 | 176 |
168 // Returns a UTF16 string suitable for use as an authentication token in | 177 // Returns a UTF16 string suitable for use as an authentication token in |
169 // response to the challenge represented by |auth_info|. If the token can't | 178 // response to the challenge represented by |auth_info|. If the token can't |
170 // be correctly generated for |auth_info|, returns an empty UTF16 string. | 179 // be correctly generated for |auth_info|, returns an empty UTF16 string. |
171 static base::string16 GetTokenForAuthChallenge( | 180 base::string16 GetTokenForAuthChallenge(net::AuthChallengeInfo* auth_info); |
172 net::AuthChallengeInfo* auth_info); | |
173 | 181 |
174 // Returns true if the proxy is enabled. | 182 // Returns true if the proxy is enabled. |
175 bool IsDataReductionProxyEnabled(); | 183 bool IsDataReductionProxyEnabled(); |
176 | 184 |
177 // Returns true if the proxy is managed by an adminstrator's policy. | 185 // Returns true if the proxy is managed by an adminstrator's policy. |
178 bool IsDataReductionProxyManaged(); | 186 bool IsDataReductionProxyManaged(); |
179 | 187 |
180 // Enables or disables the data reduction proxy. If a probe URL is available, | 188 // Enables or disables the data reduction proxy. If a probe URL is available, |
181 // and a probe request fails at some point, the proxy won't be used until a | 189 // and a probe request fails at some point, the proxy won't be used until a |
182 // probe succeeds. | 190 // probe succeeds. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, | 287 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, |
280 TestBypassList); | 288 TestBypassList); |
281 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, | 289 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, |
282 CheckInitMetricsWhenNotAllowed); | 290 CheckInitMetricsWhenNotAllowed); |
283 | 291 |
284 // NetworkChangeNotifier::IPAddressObserver: | 292 // NetworkChangeNotifier::IPAddressObserver: |
285 virtual void OnIPAddressChanged() OVERRIDE; | 293 virtual void OnIPAddressChanged() OVERRIDE; |
286 | 294 |
287 // Underlying implementation of InitDataReductionProxySession(), factored | 295 // Underlying implementation of InitDataReductionProxySession(), factored |
288 // out to be testable without creating a full HttpNetworkSession. | 296 // out to be testable without creating a full HttpNetworkSession. |
289 static void InitDataReductionAuthentication(net::HttpAuthCache* auth_cache); | 297 static void InitDataReductionAuthentication(net::HttpAuthCache* auth_cache, |
| 298 const std::string& key); |
290 | 299 |
291 void OnProxyEnabledPrefChange(); | 300 void OnProxyEnabledPrefChange(); |
292 | 301 |
293 void ResetDataReductionStatistics(); | 302 void ResetDataReductionStatistics(); |
294 | 303 |
295 void MaybeActivateDataReductionProxy(bool at_startup); | 304 void MaybeActivateDataReductionProxy(bool at_startup); |
296 | 305 |
297 // Requests the proxy probe URL, if one is set. If unable to do so, disables | 306 // Requests the proxy probe URL, if one is set. If unable to do so, disables |
298 // the proxy, if enabled. Otherwise enables the proxy if disabled by a probe | 307 // the proxy, if enabled. Otherwise enables the proxy if disabled by a probe |
299 // failure. | 308 // failure. |
300 void ProbeWhetherDataReductionProxyIsAvailable(); | 309 void ProbeWhetherDataReductionProxyIsAvailable(); |
301 std::string GetProxyCheckURL(); | 310 std::string GetProxyCheckURL(); |
302 | 311 |
303 // Returns a UTF16 string that's the hash of the configured authentication | 312 // Returns a UTF16 string that's the hash of the configured authentication |
304 // key and |salt|. Returns an empty UTF16 string if no key is configured or | 313 // |key| and |salt|. Returns an empty UTF16 string if no key is configured or |
305 // the data reduction proxy feature isn't available. | 314 // the data reduction proxy feature isn't available. |
306 static base::string16 AuthHashForSalt(int64 salt); | 315 static base::string16 AuthHashForSalt(int64 salt, const std::string& key); |
307 | 316 |
308 static std::string key_; | |
309 static bool allowed_; | 317 static bool allowed_; |
310 static bool promo_allowed_; | 318 static bool promo_allowed_; |
311 | 319 |
| 320 std::string key_; |
312 bool restricted_by_carrier_; | 321 bool restricted_by_carrier_; |
313 bool enabled_by_user_; | 322 bool enabled_by_user_; |
314 | 323 |
315 scoped_ptr<net::URLFetcher> fetcher_; | 324 scoped_ptr<net::URLFetcher> fetcher_; |
316 BooleanPrefMember spdy_proxy_auth_enabled_; | 325 BooleanPrefMember spdy_proxy_auth_enabled_; |
317 | 326 |
318 PrefService* prefs_; | 327 PrefService* prefs_; |
319 PrefService* local_state_prefs_; | 328 PrefService* local_state_prefs_; |
320 | 329 |
321 net::URLRequestContextGetter* url_request_context_getter_; | 330 net::URLRequestContextGetter* url_request_context_getter_; |
322 | 331 |
323 scoped_ptr<DataReductionProxyConfigurator> config_; | 332 scoped_ptr<DataReductionProxyConfigurator> config_; |
324 | 333 |
325 base::ThreadChecker thread_checker_; | 334 base::ThreadChecker thread_checker_; |
326 | 335 |
327 bool fallback_allowed_; | 336 bool fallback_allowed_; |
328 | 337 |
329 DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettings); | 338 DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettings); |
330 }; | 339 }; |
331 | 340 |
332 } // namespace data_reduction_proxy | 341 } // namespace data_reduction_proxy |
333 | 342 |
334 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_SETTINGS
_H_ | 343 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_SETTINGS
_H_ |
OLD | NEW |