OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "net/proxy/proxy_service.h" | 5 #include "net/proxy/proxy_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 // network.proxy.autoconfig_retry_interval_max. The defaults are 5 seconds and | 114 // network.proxy.autoconfig_retry_interval_max. The defaults are 5 seconds and |
115 // 5 minutes respectively. It doubles the interval at each attempt. | 115 // 5 minutes respectively. It doubles the interval at each attempt. |
116 // | 116 // |
117 // TODO(eroman): Figure out what Internet Explorer does. | 117 // TODO(eroman): Figure out what Internet Explorer does. |
118 class DefaultPollPolicy : public ProxyService::PacPollPolicy { | 118 class DefaultPollPolicy : public ProxyService::PacPollPolicy { |
119 public: | 119 public: |
120 DefaultPollPolicy() {} | 120 DefaultPollPolicy() {} |
121 | 121 |
122 virtual Mode GetNextDelay(int initial_error, | 122 virtual Mode GetNextDelay(int initial_error, |
123 TimeDelta current_delay, | 123 TimeDelta current_delay, |
124 TimeDelta* next_delay) const OVERRIDE { | 124 TimeDelta* next_delay) const override { |
125 if (initial_error != OK) { | 125 if (initial_error != OK) { |
126 // Re-try policy for failures. | 126 // Re-try policy for failures. |
127 const int kDelay1Seconds = 8; | 127 const int kDelay1Seconds = 8; |
128 const int kDelay2Seconds = 32; | 128 const int kDelay2Seconds = 32; |
129 const int kDelay3Seconds = 2 * 60; // 2 minutes | 129 const int kDelay3Seconds = 2 * 60; // 2 minutes |
130 const int kDelay4Seconds = 4 * 60 * 60; // 4 Hours | 130 const int kDelay4Seconds = 4 * 60 * 60; // 4 Hours |
131 | 131 |
132 // Initial poll. | 132 // Initial poll. |
133 if (current_delay < TimeDelta()) { | 133 if (current_delay < TimeDelta()) { |
134 *next_delay = TimeDelta::FromSeconds(kDelay1Seconds); | 134 *next_delay = TimeDelta::FromSeconds(kDelay1Seconds); |
(...skipping 18 matching lines...) Expand all Loading... |
153 } | 153 } |
154 | 154 |
155 private: | 155 private: |
156 DISALLOW_COPY_AND_ASSIGN(DefaultPollPolicy); | 156 DISALLOW_COPY_AND_ASSIGN(DefaultPollPolicy); |
157 }; | 157 }; |
158 | 158 |
159 // Config getter that always returns direct settings. | 159 // Config getter that always returns direct settings. |
160 class ProxyConfigServiceDirect : public ProxyConfigService { | 160 class ProxyConfigServiceDirect : public ProxyConfigService { |
161 public: | 161 public: |
162 // ProxyConfigService implementation: | 162 // ProxyConfigService implementation: |
163 virtual void AddObserver(Observer* observer) OVERRIDE {} | 163 virtual void AddObserver(Observer* observer) override {} |
164 virtual void RemoveObserver(Observer* observer) OVERRIDE {} | 164 virtual void RemoveObserver(Observer* observer) override {} |
165 virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) | 165 virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) |
166 OVERRIDE { | 166 override { |
167 *config = ProxyConfig::CreateDirect(); | 167 *config = ProxyConfig::CreateDirect(); |
168 config->set_source(PROXY_CONFIG_SOURCE_UNKNOWN); | 168 config->set_source(PROXY_CONFIG_SOURCE_UNKNOWN); |
169 return CONFIG_VALID; | 169 return CONFIG_VALID; |
170 } | 170 } |
171 }; | 171 }; |
172 | 172 |
173 // Proxy resolver that fails every time. | 173 // Proxy resolver that fails every time. |
174 class ProxyResolverNull : public ProxyResolver { | 174 class ProxyResolverNull : public ProxyResolver { |
175 public: | 175 public: |
176 ProxyResolverNull() : ProxyResolver(false /*expects_pac_bytes*/) {} | 176 ProxyResolverNull() : ProxyResolver(false /*expects_pac_bytes*/) {} |
177 | 177 |
178 // ProxyResolver implementation. | 178 // ProxyResolver implementation. |
179 virtual int GetProxyForURL(const GURL& url, | 179 virtual int GetProxyForURL(const GURL& url, |
180 ProxyInfo* results, | 180 ProxyInfo* results, |
181 const CompletionCallback& callback, | 181 const CompletionCallback& callback, |
182 RequestHandle* request, | 182 RequestHandle* request, |
183 const BoundNetLog& net_log) OVERRIDE { | 183 const BoundNetLog& net_log) override { |
184 return ERR_NOT_IMPLEMENTED; | 184 return ERR_NOT_IMPLEMENTED; |
185 } | 185 } |
186 | 186 |
187 virtual void CancelRequest(RequestHandle request) OVERRIDE { | 187 virtual void CancelRequest(RequestHandle request) override { |
188 NOTREACHED(); | 188 NOTREACHED(); |
189 } | 189 } |
190 | 190 |
191 virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE { | 191 virtual LoadState GetLoadState(RequestHandle request) const override { |
192 NOTREACHED(); | 192 NOTREACHED(); |
193 return LOAD_STATE_IDLE; | 193 return LOAD_STATE_IDLE; |
194 } | 194 } |
195 | 195 |
196 virtual void CancelSetPacScript() OVERRIDE { | 196 virtual void CancelSetPacScript() override { |
197 NOTREACHED(); | 197 NOTREACHED(); |
198 } | 198 } |
199 | 199 |
200 virtual int SetPacScript( | 200 virtual int SetPacScript( |
201 const scoped_refptr<ProxyResolverScriptData>& /*script_data*/, | 201 const scoped_refptr<ProxyResolverScriptData>& /*script_data*/, |
202 const CompletionCallback& /*callback*/) OVERRIDE { | 202 const CompletionCallback& /*callback*/) override { |
203 return ERR_NOT_IMPLEMENTED; | 203 return ERR_NOT_IMPLEMENTED; |
204 } | 204 } |
205 }; | 205 }; |
206 | 206 |
207 // ProxyResolver that simulates a PAC script which returns | 207 // ProxyResolver that simulates a PAC script which returns |
208 // |pac_string| for every single URL. | 208 // |pac_string| for every single URL. |
209 class ProxyResolverFromPacString : public ProxyResolver { | 209 class ProxyResolverFromPacString : public ProxyResolver { |
210 public: | 210 public: |
211 explicit ProxyResolverFromPacString(const std::string& pac_string) | 211 explicit ProxyResolverFromPacString(const std::string& pac_string) |
212 : ProxyResolver(false /*expects_pac_bytes*/), | 212 : ProxyResolver(false /*expects_pac_bytes*/), |
213 pac_string_(pac_string) {} | 213 pac_string_(pac_string) {} |
214 | 214 |
215 virtual int GetProxyForURL(const GURL& url, | 215 virtual int GetProxyForURL(const GURL& url, |
216 ProxyInfo* results, | 216 ProxyInfo* results, |
217 const CompletionCallback& callback, | 217 const CompletionCallback& callback, |
218 RequestHandle* request, | 218 RequestHandle* request, |
219 const BoundNetLog& net_log) OVERRIDE { | 219 const BoundNetLog& net_log) override { |
220 results->UsePacString(pac_string_); | 220 results->UsePacString(pac_string_); |
221 return OK; | 221 return OK; |
222 } | 222 } |
223 | 223 |
224 virtual void CancelRequest(RequestHandle request) OVERRIDE { | 224 virtual void CancelRequest(RequestHandle request) override { |
225 NOTREACHED(); | 225 NOTREACHED(); |
226 } | 226 } |
227 | 227 |
228 virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE { | 228 virtual LoadState GetLoadState(RequestHandle request) const override { |
229 NOTREACHED(); | 229 NOTREACHED(); |
230 return LOAD_STATE_IDLE; | 230 return LOAD_STATE_IDLE; |
231 } | 231 } |
232 | 232 |
233 virtual void CancelSetPacScript() OVERRIDE { | 233 virtual void CancelSetPacScript() override { |
234 NOTREACHED(); | 234 NOTREACHED(); |
235 } | 235 } |
236 | 236 |
237 virtual int SetPacScript( | 237 virtual int SetPacScript( |
238 const scoped_refptr<ProxyResolverScriptData>& pac_script, | 238 const scoped_refptr<ProxyResolverScriptData>& pac_script, |
239 const CompletionCallback& callback) OVERRIDE { | 239 const CompletionCallback& callback) override { |
240 return OK; | 240 return OK; |
241 } | 241 } |
242 | 242 |
243 private: | 243 private: |
244 const std::string pac_string_; | 244 const std::string pac_string_; |
245 }; | 245 }; |
246 | 246 |
247 // Creates ProxyResolvers using a platform-specific implementation. | 247 // Creates ProxyResolvers using a platform-specific implementation. |
248 class ProxyResolverFactoryForSystem : public ProxyResolverFactory { | 248 class ProxyResolverFactoryForSystem : public ProxyResolverFactory { |
249 public: | 249 public: |
250 ProxyResolverFactoryForSystem() | 250 ProxyResolverFactoryForSystem() |
251 : ProxyResolverFactory(false /*expects_pac_bytes*/) {} | 251 : ProxyResolverFactory(false /*expects_pac_bytes*/) {} |
252 | 252 |
253 virtual ProxyResolver* CreateProxyResolver() OVERRIDE { | 253 virtual ProxyResolver* CreateProxyResolver() override { |
254 DCHECK(IsSupported()); | 254 DCHECK(IsSupported()); |
255 #if defined(OS_WIN) | 255 #if defined(OS_WIN) |
256 return new ProxyResolverWinHttp(); | 256 return new ProxyResolverWinHttp(); |
257 #elif defined(OS_MACOSX) | 257 #elif defined(OS_MACOSX) |
258 return new ProxyResolverMac(); | 258 return new ProxyResolverMac(); |
259 #else | 259 #else |
260 NOTREACHED(); | 260 NOTREACHED(); |
261 return NULL; | 261 return NULL; |
262 #endif | 262 #endif |
263 } | 263 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 dict->SetString("pac_string", result->ToPacString()); | 306 dict->SetString("pac_string", result->ToPacString()); |
307 return dict; | 307 return dict; |
308 } | 308 } |
309 | 309 |
310 #if defined(OS_CHROMEOS) | 310 #if defined(OS_CHROMEOS) |
311 class UnsetProxyConfigService : public ProxyConfigService { | 311 class UnsetProxyConfigService : public ProxyConfigService { |
312 public: | 312 public: |
313 UnsetProxyConfigService() {} | 313 UnsetProxyConfigService() {} |
314 virtual ~UnsetProxyConfigService() {} | 314 virtual ~UnsetProxyConfigService() {} |
315 | 315 |
316 virtual void AddObserver(Observer* observer) OVERRIDE {} | 316 virtual void AddObserver(Observer* observer) override {} |
317 virtual void RemoveObserver(Observer* observer) OVERRIDE {} | 317 virtual void RemoveObserver(Observer* observer) override {} |
318 virtual ConfigAvailability GetLatestProxyConfig( | 318 virtual ConfigAvailability GetLatestProxyConfig( |
319 ProxyConfig* config) OVERRIDE { | 319 ProxyConfig* config) override { |
320 return CONFIG_UNSET; | 320 return CONFIG_UNSET; |
321 } | 321 } |
322 }; | 322 }; |
323 #endif | 323 #endif |
324 | 324 |
325 } // namespace | 325 } // namespace |
326 | 326 |
327 // ProxyService::InitProxyResolver -------------------------------------------- | 327 // ProxyService::InitProxyResolver -------------------------------------------- |
328 | 328 |
329 // This glues together two asynchronous steps: | 329 // This glues together two asynchronous steps: |
(...skipping 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1556 State previous_state = ResetProxyConfig(false); | 1556 State previous_state = ResetProxyConfig(false); |
1557 if (previous_state != STATE_NONE) | 1557 if (previous_state != STATE_NONE) |
1558 ApplyProxyConfigIfAvailable(); | 1558 ApplyProxyConfigIfAvailable(); |
1559 } | 1559 } |
1560 | 1560 |
1561 void ProxyService::OnDNSChanged() { | 1561 void ProxyService::OnDNSChanged() { |
1562 OnIPAddressChanged(); | 1562 OnIPAddressChanged(); |
1563 } | 1563 } |
1564 | 1564 |
1565 } // namespace net | 1565 } // namespace net |
OLD | NEW |