Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_H_ | 5 #ifndef CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_H_ |
| 6 #define CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_H_ | 6 #define CHROME_BROWSER_NET_SPDYPROXY_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" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/prefs/pref_member.h" | 14 #include "base/prefs/pref_member.h" |
| 15 #include "net/base/network_change_notifier.h" | 15 #include "net/base/network_change_notifier.h" |
| 16 #include "net/url_request/url_fetcher_delegate.h" | 16 #include "net/url_request/url_fetcher_delegate.h" |
| 17 | 17 |
| 18 class PrefService; | 18 class PrefService; |
| 19 | 19 |
| 20 namespace net { | 20 namespace net { |
| 21 class AuthChallengeInfo; | |
| 22 class HostPortPair; | |
| 23 class HttpNetworkSession; | |
| 21 class URLFetcher; | 24 class URLFetcher; |
| 22 } | 25 } |
| 23 | 26 |
| 24 namespace spdyproxy { | 27 namespace spdyproxy { |
| 25 | 28 |
| 26 // The number of days of bandwidth usage statistics that are tracked. | 29 // The number of days of bandwidth usage statistics that are tracked. |
| 27 const unsigned int kNumDaysInHistory = 60; | 30 const unsigned int kNumDaysInHistory = 60; |
| 28 | 31 |
| 29 // The number of days of bandwidth usage statistics that are presented. | 32 // The number of days of bandwidth usage statistics that are presented. |
| 30 const unsigned int kNumDaysInHistorySummary = 30; | 33 const unsigned int kNumDaysInHistorySummary = 30; |
| 31 | 34 |
| 32 COMPILE_ASSERT(kNumDaysInHistorySummary <= kNumDaysInHistory, | 35 COMPILE_ASSERT(kNumDaysInHistorySummary <= kNumDaysInHistory, |
| 33 DataReductionProxySettings_summary_too_long); | 36 DataReductionProxySettings_summary_too_long); |
| 34 | 37 |
| 35 } // namespace spdyproxy | 38 } // namespace spdyproxy |
| 36 | 39 |
| 37 // Central point for configuring the data reduction proxy. | 40 // Central point for configuring the data reduction proxy. |
| 38 // This object lives on the UI thread and all of its methods are expected to | 41 // This object lives on the UI thread and all of its methods are expected to |
| 39 // be called from there. | 42 // be called from there. |
| 40 class DataReductionProxySettings | 43 class DataReductionProxySettings |
| 41 : public net::URLFetcherDelegate, | 44 : public net::URLFetcherDelegate, |
| 42 public net::NetworkChangeNotifier::IPAddressObserver { | 45 public net::NetworkChangeNotifier::IPAddressObserver { |
| 43 public: | 46 public: |
| 44 typedef std::vector<long long> ContentLengthList; | 47 typedef std::vector<long long> ContentLengthList; |
| 48 typedef std::vector<net::HostPortPair> DataReductionProxyList; | |
| 45 | 49 |
| 46 DataReductionProxySettings(); | 50 DataReductionProxySettings(); |
| 47 virtual ~DataReductionProxySettings(); | 51 virtual ~DataReductionProxySettings(); |
| 48 | 52 |
| 49 void InitDataReductionProxySettings(); | 53 void InitDataReductionProxySettings(); |
| 50 | 54 |
| 55 // If proxy authentication is compiled in, pre-cache authentication | |
| 56 // keys for all configured proxies in |session|. | |
| 57 void InitDataReductionProxySession(net::HttpNetworkSession* session); | |
| 58 | |
| 51 // Add a host pattern to bypass. This should follow the same syntax used | 59 // Add a host pattern to bypass. This should follow the same syntax used |
| 52 // in net::ProxyBypassRules; that is, a hostname pattern, a hostname suffix | 60 // in net::ProxyBypassRules; that is, a hostname pattern, a hostname suffix |
| 53 // pattern, an IP literal, a CIDR block, or the magic string '<local>'. | 61 // pattern, an IP literal, a CIDR block, or the magic string '<local>'. |
| 54 // Bypass settings persist for the life of this object and are applied | 62 // Bypass settings persist for the life of this object and are applied |
| 55 // each time the proxy is enabled, but are not updated while it is enabled. | 63 // each time the proxy is enabled, but are not updated while it is enabled. |
| 56 void AddHostPatternToBypass(const std::string& pattern); | 64 void AddHostPatternToBypass(const std::string& pattern); |
| 57 | 65 |
| 58 // Add a URL pattern to bypass the proxy. The base implementation strips | 66 // Add a URL pattern to bypass the proxy. The base implementation strips |
| 59 // everything in |pattern| after the first single slash and then treats it | 67 // everything in |pattern| after the first single slash and then treats it |
| 60 // as a hostname pattern. Subclasses may implement other semantics. | 68 // as a hostname pattern. Subclasses may implement other semantics. |
| 61 virtual void AddURLPatternToBypass(const std::string& pattern); | 69 virtual void AddURLPatternToBypass(const std::string& pattern); |
| 62 | 70 |
| 63 // Returns true if the data reduction proxy is allowed to be used on this | 71 // Returns true if the data reduction proxy is allowed to be used on this |
| 64 // instance of Chrome. This could return false, for example, if this instance | 72 // instance of Chrome. This could return false, for example, if this instance |
| 65 // is not part of the field trial, or if the proxy name is not configured | 73 // is not part of the field trial, or if the proxy name is not configured |
| 66 // via gyp. | 74 // via gyp. |
| 67 bool IsDataReductionProxyAllowed(); | 75 bool IsDataReductionProxyAllowed(); |
| 68 | 76 |
| 69 // Returns true if a screen promoting the data reduction proxy is allowed to | 77 // Returns true if a screen promoting the data reduction proxy is allowed to |
| 70 // be shown. Logic that decides when to show the promo should check its | 78 // be shown. Logic that decides when to show the promo should check its |
| 71 // availability. This would return false if not part of a separate field | 79 // availability. This would return false if not part of a separate field |
| 72 // trial that governs the use of the promotion. | 80 // trial that governs the use of the promotion. |
| 73 bool IsDataReductionProxyPromoAllowed(); | 81 bool IsDataReductionProxyPromoAllowed(); |
| 74 | 82 |
| 75 // Returns the URL of the data reduction proxy. | 83 // Returns the URL of the data reduction proxy. |
| 76 std::string GetDataReductionProxyOrigin(); | 84 std::string GetDataReductionProxyOrigin(); |
| 77 | 85 |
| 78 // Returns a configuration string for the proxy. | 86 // Returns the URL of the fallback data reduction proxy. |
| 79 std::string GetDataReductionProxyAuth(); | 87 std::string GetDataReductionProxyFallback(); |
| 88 | |
| 89 // Returns a vector of HostPortPairs for all configured proxies. | |
|
bengr
2013/10/22 17:49:30
It seems a little strange to return a vector when
marq (ping after 24h)
2013/10/22 21:18:01
It's somewhat cleaner (to my mind) to write generi
| |
| 90 DataReductionProxyList GetDataReductionProxies(); | |
| 91 | |
| 92 // Returns true if |auth_info| represents an authentication challenge from | |
| 93 // a compatible, configured proxy. | |
| 94 bool IsAcceptableAuthChallenge(net::AuthChallengeInfo* auth_info); | |
| 95 | |
| 96 // Returns a UTF16 string suitable for use as an authentication token in | |
| 97 // response to the challenge represented by |auth_info|. If the token can't | |
| 98 // be correctly generated for |auth_info|, returns an empty UTF16 string. | |
| 99 base::string16 GetTokenForAuthChallenge(net::AuthChallengeInfo* auth_info); | |
| 80 | 100 |
| 81 // Returns true if the proxy is enabled. | 101 // Returns true if the proxy is enabled. |
| 82 bool IsDataReductionProxyEnabled(); | 102 bool IsDataReductionProxyEnabled(); |
| 83 | 103 |
| 84 // Returns true if the proxy is managed by an adminstrator's policy. | 104 // Returns true if the proxy is managed by an adminstrator's policy. |
| 85 bool IsDataReductionProxyManaged(); | 105 bool IsDataReductionProxyManaged(); |
| 86 | 106 |
| 87 // Enables or disables the data reduction proxy. If a probe URL is available, | 107 // Enables or disables the data reduction proxy. If a probe URL is available, |
| 88 // and a probe request fails at some point, the proxy won't be used until a | 108 // and a probe request fails at some point, the proxy won't be used until a |
| 89 // probe succeeds. | 109 // probe succeeds. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 106 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 126 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 107 | 127 |
| 108 protected: | 128 protected: |
| 109 void InitPrefMembers(); | 129 void InitPrefMembers(); |
| 110 virtual net::URLFetcher* GetURLFetcher(); | 130 virtual net::URLFetcher* GetURLFetcher(); |
| 111 | 131 |
| 112 // Virtualized for unit test support. | 132 // Virtualized for unit test support. |
| 113 virtual PrefService* GetOriginalProfilePrefs(); | 133 virtual PrefService* GetOriginalProfilePrefs(); |
| 114 virtual PrefService* GetLocalStatePrefs(); | 134 virtual PrefService* GetLocalStatePrefs(); |
| 115 | 135 |
| 116 std::string GetDataReductionProxyOriginHostPort(); | |
| 117 | |
| 118 bool IsProxyOriginSetOnCommandLine(); | 136 bool IsProxyOriginSetOnCommandLine(); |
| 119 void GetContentLengths(unsigned int days, | 137 void GetContentLengths(unsigned int days, |
| 120 int64* original_content_length, | 138 int64* original_content_length, |
| 121 int64* received_content_length, | 139 int64* received_content_length, |
| 122 int64* last_update_time); | 140 int64* last_update_time); |
| 123 ContentLengthList GetDailyContentLengths(const char* pref_name); | 141 ContentLengthList GetDailyContentLengths(const char* pref_name); |
| 124 | 142 |
| 125 // Sets the proxy configs, enabling or disabling the proxy according to | 143 // Sets the proxy configs, enabling or disabling the proxy according to |
| 126 // the value of |enabled|. |at_startup| is true when this method is called | 144 // the value of |enabled|. |at_startup| is true when this method is called |
| 127 // from InitDataReductionProxySettings. | 145 // from InitDataReductionProxySettings. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 139 | 157 |
| 140 bool HasTurnedOn() { return has_turned_on_; } | 158 bool HasTurnedOn() { return has_turned_on_; } |
| 141 bool HasTurnedOff() { return has_turned_off_; } | 159 bool HasTurnedOff() { return has_turned_off_; } |
| 142 // Note that these flags may only be toggled to true, never back to false. | 160 // Note that these flags may only be toggled to true, never back to false. |
| 143 void SetHasTurnedOn() { has_turned_on_ = true; } | 161 void SetHasTurnedOn() { has_turned_on_ = true; } |
| 144 void SetHasTurnedOff() { has_turned_off_ = true; } | 162 void SetHasTurnedOff() { has_turned_off_ = true; } |
| 145 | 163 |
| 146 // Accessor for unit tests. | 164 // Accessor for unit tests. |
| 147 std::vector<std::string> BypassRules() { return bypass_rules_;} | 165 std::vector<std::string> BypassRules() { return bypass_rules_;} |
| 148 | 166 |
| 167 // Accessors for default hostnames, virtual for testing. | |
| 168 virtual std::string GetDefaultProxyHost(); | |
| 169 virtual std::string GetDefaultFallbackProxyHost(); | |
| 170 | |
| 149 private: | 171 private: |
| 150 friend class DataReductionProxySettingsTestBase; | 172 friend class DataReductionProxySettingsTestBase; |
| 151 friend class DataReductionProxySettingsTest; | 173 friend class DataReductionProxySettingsTest; |
| 152 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, | 174 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, |
| 175 TestAuthHashGeneration); | |
| 176 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, | |
| 177 TestAuthHashGenerationWithOriginSetViaSwitch); | |
| 178 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, | |
| 153 TestResetDataReductionStatistics); | 179 TestResetDataReductionStatistics); |
| 154 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, | 180 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, |
| 155 TestIsProxyEnabledOrManaged); | 181 TestIsProxyEnabledOrManaged); |
| 156 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, | 182 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, |
| 157 TestContentLengths); | 183 TestContentLengths); |
| 158 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, | 184 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, |
| 159 TestGetDailyContentLengths); | 185 TestGetDailyContentLengths); |
| 160 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, | 186 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, |
| 161 TestMaybeActivateDataReductionProxy); | 187 TestMaybeActivateDataReductionProxy); |
| 162 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, | 188 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 178 void ResetDataReductionStatistics(); | 204 void ResetDataReductionStatistics(); |
| 179 | 205 |
| 180 void MaybeActivateDataReductionProxy(bool at_startup); | 206 void MaybeActivateDataReductionProxy(bool at_startup); |
| 181 | 207 |
| 182 // Requests the proxy probe URL, if one is set. If unable to do so, disables | 208 // Requests the proxy probe URL, if one is set. If unable to do so, disables |
| 183 // the proxy, if enabled. Otherwise enables the proxy if disabled by a probe | 209 // the proxy, if enabled. Otherwise enables the proxy if disabled by a probe |
| 184 // failure. | 210 // failure. |
| 185 void ProbeWhetherDataReductionProxyIsAvailable(); | 211 void ProbeWhetherDataReductionProxyIsAvailable(); |
| 186 std::string GetProxyCheckURL(); | 212 std::string GetProxyCheckURL(); |
| 187 | 213 |
| 214 // Returns a UTF16 string that's the hash of the configured authentication | |
| 215 // key and |salt|. Returns an empty UTF16 string if no key is configured or | |
| 216 // the data reduction proxy feature isn't available. | |
| 217 base::string16 AuthHashForSalt(int64 salt); | |
| 218 | |
| 188 std::vector<std::string> bypass_rules_; | 219 std::vector<std::string> bypass_rules_; |
| 189 | 220 |
| 190 // Indicate whether a user has turned on the data reduction proxy previously | 221 // Indicate whether a user has turned on the data reduction proxy previously |
| 191 // in this session. | 222 // in this session. |
| 192 bool has_turned_on_; | 223 bool has_turned_on_; |
| 193 | 224 |
| 194 // Indicate whether a user has turned off the data reduction proxy previously | 225 // Indicate whether a user has turned off the data reduction proxy previously |
| 195 // in this session. | 226 // in this session. |
| 196 bool has_turned_off_; | 227 bool has_turned_off_; |
| 197 | 228 |
| 198 bool disabled_by_carrier_; | 229 bool disabled_by_carrier_; |
| 199 bool enabled_by_user_; | 230 bool enabled_by_user_; |
| 200 | 231 |
| 201 scoped_ptr<net::URLFetcher> fetcher_; | 232 scoped_ptr<net::URLFetcher> fetcher_; |
| 202 BooleanPrefMember spdy_proxy_auth_enabled_; | 233 BooleanPrefMember spdy_proxy_auth_enabled_; |
| 203 | 234 |
| 204 DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettings); | 235 DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettings); |
| 205 }; | 236 }; |
| 206 | 237 |
| 207 #endif // CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_H_ | 238 #endif // CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_H_ |
| OLD | NEW |