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; | |
bengr
2013/10/22 01:02:09
alphabetize.
marq (ping after 24h)
2013/10/22 14:44:20
? Au < Ho < Ht, right?
bengr
2013/10/22 17:49:30
Right. I don't know what I was looking at.
| |
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 void InitDataReductionProxySession(net::HttpNetworkSession* session); | |
bengr
2013/10/22 01:02:09
Add a comment.
marq (ping after 24h)
2013/10/22 14:44:20
Done.
| |
56 | |
51 // Add a host pattern to bypass. This should follow the same syntax used | 57 // 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 | 58 // in net::ProxyBypassRules; that is, a hostname pattern, a hostname suffix |
53 // pattern, an IP literal, a CIDR block, or the magic string '<local>'. | 59 // 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 | 60 // 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. | 61 // each time the proxy is enabled, but are not updated while it is enabled. |
56 void AddHostPatternToBypass(const std::string& pattern); | 62 void AddHostPatternToBypass(const std::string& pattern); |
57 | 63 |
58 // Add a URL pattern to bypass the proxy. The base implementation strips | 64 // 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 | 65 // everything in |pattern| after the first single slash and then treats it |
60 // as a hostname pattern. Subclasses may implement other semantics. | 66 // as a hostname pattern. Subclasses may implement other semantics. |
61 virtual void AddURLPatternToBypass(const std::string& pattern); | 67 virtual void AddURLPatternToBypass(const std::string& pattern); |
62 | 68 |
63 // Returns true if the data reduction proxy is allowed to be used on this | 69 // 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 | 70 // 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 | 71 // is not part of the field trial, or if the proxy name is not configured |
66 // via gyp. | 72 // via gyp. |
67 bool IsDataReductionProxyAllowed(); | 73 bool IsDataReductionProxyAllowed(); |
68 | 74 |
69 // Returns true if a screen promoting the data reduction proxy is allowed to | 75 // 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 | 76 // 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 | 77 // availability. This would return false if not part of a separate field |
72 // trial that governs the use of the promotion. | 78 // trial that governs the use of the promotion. |
73 bool IsDataReductionProxyPromoAllowed(); | 79 bool IsDataReductionProxyPromoAllowed(); |
74 | 80 |
75 // Returns the URL of the data reduction proxy. | 81 // Returns the URL of the data reduction proxy. |
76 std::string GetDataReductionProxyOrigin(); | 82 std::string GetDataReductionProxyOrigin(); |
77 | 83 |
78 // Returns a configuration string for the proxy. | 84 // Returns the URL of the fallback data reduction proxy. |
79 std::string GetDataReductionProxyAuth(); | 85 std::string GetDataReductionProxyFallback(); |
86 | |
87 DataReductionProxyList GetDataReductionProxies(); | |
bengr
2013/10/22 01:02:09
Comment.
marq (ping after 24h)
2013/10/22 14:44:20
Done.
| |
88 | |
89 bool IsAcceptableAuthChallenge(net::AuthChallengeInfo* auth_info); | |
bengr
2013/10/22 01:02:09
Comment.
marq (ping after 24h)
2013/10/22 14:44:20
Done.
| |
90 base::string16 GetTokenForAuthChallenge(net::AuthChallengeInfo* auth_info); | |
bengr
2013/10/22 01:02:09
Comment.
marq (ping after 24h)
2013/10/22 14:44:20
Done.
| |
80 | 91 |
81 // Returns true if the proxy is enabled. | 92 // Returns true if the proxy is enabled. |
82 bool IsDataReductionProxyEnabled(); | 93 bool IsDataReductionProxyEnabled(); |
83 | 94 |
84 // Returns true if the proxy is managed by an adminstrator's policy. | 95 // Returns true if the proxy is managed by an adminstrator's policy. |
85 bool IsDataReductionProxyManaged(); | 96 bool IsDataReductionProxyManaged(); |
86 | 97 |
87 // Enables or disables the data reduction proxy. If a probe URL is available, | 98 // 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 | 99 // and a probe request fails at some point, the proxy won't be used until a |
89 // probe succeeds. | 100 // probe succeeds. |
(...skipping 16 matching lines...) Expand all Loading... | |
106 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 117 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
107 | 118 |
108 protected: | 119 protected: |
109 void InitPrefMembers(); | 120 void InitPrefMembers(); |
110 virtual net::URLFetcher* GetURLFetcher(); | 121 virtual net::URLFetcher* GetURLFetcher(); |
111 | 122 |
112 // Virtualized for unit test support. | 123 // Virtualized for unit test support. |
113 virtual PrefService* GetOriginalProfilePrefs(); | 124 virtual PrefService* GetOriginalProfilePrefs(); |
114 virtual PrefService* GetLocalStatePrefs(); | 125 virtual PrefService* GetLocalStatePrefs(); |
115 | 126 |
116 std::string GetDataReductionProxyOriginHostPort(); | |
117 | |
118 bool IsProxyOriginSetOnCommandLine(); | 127 bool IsProxyOriginSetOnCommandLine(); |
119 void GetContentLengths(unsigned int days, | 128 void GetContentLengths(unsigned int days, |
120 int64* original_content_length, | 129 int64* original_content_length, |
121 int64* received_content_length, | 130 int64* received_content_length, |
122 int64* last_update_time); | 131 int64* last_update_time); |
123 ContentLengthList GetDailyContentLengths(const char* pref_name); | 132 ContentLengthList GetDailyContentLengths(const char* pref_name); |
124 | 133 |
125 // Sets the proxy configs, enabling or disabling the proxy according to | 134 // 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 | 135 // the value of |enabled|. |at_startup| is true when this method is called |
127 // from InitDataReductionProxySettings. | 136 // from InitDataReductionProxySettings. |
(...skipping 15 matching lines...) Expand all Loading... | |
143 void SetHasTurnedOn() { has_turned_on_ = true; } | 152 void SetHasTurnedOn() { has_turned_on_ = true; } |
144 void SetHasTurnedOff() { has_turned_off_ = true; } | 153 void SetHasTurnedOff() { has_turned_off_ = true; } |
145 | 154 |
146 // Accessor for unit tests. | 155 // Accessor for unit tests. |
147 std::vector<std::string> BypassRules() { return bypass_rules_;} | 156 std::vector<std::string> BypassRules() { return bypass_rules_;} |
148 | 157 |
149 private: | 158 private: |
150 friend class DataReductionProxySettingsTestBase; | 159 friend class DataReductionProxySettingsTestBase; |
151 friend class DataReductionProxySettingsTest; | 160 friend class DataReductionProxySettingsTest; |
152 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, | 161 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, |
162 TestAuthHashGeneration); | |
163 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, | |
164 TestAuthHashGenerationWithOriginSetViaSwitch); | |
165 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, | |
153 TestResetDataReductionStatistics); | 166 TestResetDataReductionStatistics); |
154 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, | 167 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, |
155 TestIsProxyEnabledOrManaged); | 168 TestIsProxyEnabledOrManaged); |
156 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, | 169 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, |
157 TestContentLengths); | 170 TestContentLengths); |
158 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, | 171 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, |
159 TestGetDailyContentLengths); | 172 TestGetDailyContentLengths); |
160 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, | 173 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, |
161 TestMaybeActivateDataReductionProxy); | 174 TestMaybeActivateDataReductionProxy); |
162 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, | 175 FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, |
(...skipping 15 matching lines...) Expand all Loading... | |
178 void ResetDataReductionStatistics(); | 191 void ResetDataReductionStatistics(); |
179 | 192 |
180 void MaybeActivateDataReductionProxy(bool at_startup); | 193 void MaybeActivateDataReductionProxy(bool at_startup); |
181 | 194 |
182 // Requests the proxy probe URL, if one is set. If unable to do so, disables | 195 // 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 | 196 // the proxy, if enabled. Otherwise enables the proxy if disabled by a probe |
184 // failure. | 197 // failure. |
185 void ProbeWhetherDataReductionProxyIsAvailable(); | 198 void ProbeWhetherDataReductionProxyIsAvailable(); |
186 std::string GetProxyCheckURL(); | 199 std::string GetProxyCheckURL(); |
187 | 200 |
201 base::string16 AuthHashForSalt(int64 salt); | |
bengr
2013/10/22 01:02:09
Comment.
marq (ping after 24h)
2013/10/22 14:44:20
Done.
| |
202 | |
188 std::vector<std::string> bypass_rules_; | 203 std::vector<std::string> bypass_rules_; |
189 | 204 |
190 // Indicate whether a user has turned on the data reduction proxy previously | 205 // Indicate whether a user has turned on the data reduction proxy previously |
191 // in this session. | 206 // in this session. |
192 bool has_turned_on_; | 207 bool has_turned_on_; |
193 | 208 |
194 // Indicate whether a user has turned off the data reduction proxy previously | 209 // Indicate whether a user has turned off the data reduction proxy previously |
195 // in this session. | 210 // in this session. |
196 bool has_turned_off_; | 211 bool has_turned_off_; |
197 | 212 |
198 bool disabled_by_carrier_; | 213 bool disabled_by_carrier_; |
199 bool enabled_by_user_; | 214 bool enabled_by_user_; |
200 | 215 |
201 scoped_ptr<net::URLFetcher> fetcher_; | 216 scoped_ptr<net::URLFetcher> fetcher_; |
202 BooleanPrefMember spdy_proxy_auth_enabled_; | 217 BooleanPrefMember spdy_proxy_auth_enabled_; |
203 | 218 |
204 DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettings); | 219 DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettings); |
205 }; | 220 }; |
206 | 221 |
207 #endif // CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_H_ | 222 #endif // CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_H_ |
OLD | NEW |