Chromium Code Reviews| 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 #ifndef NET_PROXY_PROXY_SERVICE_H_ | 5 #ifndef NET_PROXY_PROXY_SERVICE_H_ |
| 6 #define NET_PROXY_PROXY_SERVICE_H_ | 6 #define NET_PROXY_PROXY_SERVICE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 class ProxyScriptDecider; | 36 class ProxyScriptDecider; |
| 37 class ProxyScriptFetcher; | 37 class ProxyScriptFetcher; |
| 38 | 38 |
| 39 // This class can be used to resolve the proxy server to use when loading a | 39 // This class can be used to resolve the proxy server to use when loading a |
| 40 // HTTP(S) URL. It uses the given ProxyResolver to handle the actual proxy | 40 // HTTP(S) URL. It uses the given ProxyResolver to handle the actual proxy |
| 41 // resolution. See ProxyResolverV8 for example. | 41 // resolution. See ProxyResolverV8 for example. |
| 42 class NET_EXPORT ProxyService : public NetworkChangeNotifier::IPAddressObserver, | 42 class NET_EXPORT ProxyService : public NetworkChangeNotifier::IPAddressObserver, |
| 43 public ProxyConfigService::Observer, | 43 public ProxyConfigService::Observer, |
| 44 NON_EXPORTED_BASE(public base::NonThreadSafe) { | 44 NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| 45 public: | 45 public: |
| 46 // Only used by unit-tests. | 46 // This interface defines the set of policies for when to poll the PAC |
| 47 enum PollPolicy { | 47 // script for changes. |
| 48 POLL_POLICY_REGULAR, // Normal PAC poll policy (retry periodically). | 48 // |
| 49 POLL_POLICY_NEVER, // Don't re-fetch PAC scripts for changes. | 49 // The polling policy decides what the next poll delay should be in |
| 50 POLL_POLICY_IMMEDIATE, // Check every 1 ms. | 50 // milliseconds. It also decides how to wait for this delay -- either |
| 51 // by starting a timer to do the poll at exactly |next_delay_ms| | |
| 52 // (MODE_USE_TIMER) or by waiting for the first network request issued after | |
| 53 // |next_delay_ms| (MODE_START_AFTER_ACTIVITY). | |
| 54 // | |
| 55 // The timer method is more precise and guarantees that polling happens when | |
| 56 // it was requested. However it has the disadvantage of causing spurious CPU | |
| 57 // and network activity. It is a reasonable choice to use for short poll | |
| 58 // intervals which only happen a couple times. | |
| 59 // | |
| 60 // However for repeated timers this will prevent the browser from going | |
| 61 // idle. MODE_START_AFTER_ACTIVITY solves this problem by only polling in | |
| 62 // direct response to network activity. The drawback to | |
| 63 // MODE_START_AFTER_ACTIVITY is since the poll is initiated only after the | |
| 64 // request is received, the first couple requests initiated after a long | |
| 65 // period of inactivity will likely see a stale version of the PAC script | |
| 66 // until the background polling gets a chance to update things. | |
| 67 class NET_EXPORT_PRIVATE PacPollPolicy { | |
| 68 public: | |
| 69 enum Mode { | |
| 70 MODE_USE_TIMER, | |
| 71 MODE_START_AFTER_ACTIVITY, | |
| 72 }; | |
| 73 | |
| 74 virtual ~PacPollPolicy() {} | |
| 75 | |
| 76 // Decides the initial poll delay. |error| is the network error | |
| 77 // code that the most last PAC fetch failed with (or OK if it was a | |
|
wtc
2012/01/17 22:42:53
Nit: remove "most"?
eroman
2012/01/17 22:47:21
Will do.
| |
| 78 // success). Implementations must set |next_delay_ms|. | |
| 79 virtual Mode GetInitialDelay(int error, int64* next_delay_ms) const = 0; | |
| 80 | |
| 81 // Decides the next poll delay. |current_delay_ms| is the delay used | |
| 82 // by the preceding poll. Implementations must set |next_delay_ms|. | |
|
wtc
2012/01/17 22:42:53
preceding => current ? The parameter is named cur
eroman
2012/01/17 22:47:21
There are two parameters, one called current_delay
| |
| 83 virtual Mode GetNextDelay(int64 current_delay_ms, | |
| 84 int64* next_delay_ms) const = 0; | |
| 51 }; | 85 }; |
| 52 | 86 |
| 53 // The instance takes ownership of |config_service| and |resolver|. | 87 // The instance takes ownership of |config_service| and |resolver|. |
| 54 // |net_log| is a possibly NULL destination to send log events to. It must | 88 // |net_log| is a possibly NULL destination to send log events to. It must |
| 55 // remain alive for the lifetime of this ProxyService. | 89 // remain alive for the lifetime of this ProxyService. |
| 56 ProxyService(ProxyConfigService* config_service, | 90 ProxyService(ProxyConfigService* config_service, |
| 57 ProxyResolver* resolver, | 91 ProxyResolver* resolver, |
| 58 NetLog* net_log); | 92 NetLog* net_log); |
| 59 | 93 |
| 60 virtual ~ProxyService(); | 94 virtual ~ProxyService(); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 static ProxyConfigService* CreateSystemProxyConfigService( | 273 static ProxyConfigService* CreateSystemProxyConfigService( |
| 240 MessageLoop* io_loop, MessageLoop* file_loop); | 274 MessageLoop* io_loop, MessageLoop* file_loop); |
| 241 | 275 |
| 242 // This method should only be used by unit tests. | 276 // This method should only be used by unit tests. |
| 243 void set_stall_proxy_auto_config_delay(base::TimeDelta delay) { | 277 void set_stall_proxy_auto_config_delay(base::TimeDelta delay) { |
| 244 stall_proxy_auto_config_delay_ = delay; | 278 stall_proxy_auto_config_delay_ = delay; |
| 245 } | 279 } |
| 246 | 280 |
| 247 // This method should only be used by unit tests. Returns the previously | 281 // This method should only be used by unit tests. Returns the previously |
| 248 // active policy. | 282 // active policy. |
| 249 static PollPolicy set_pac_script_poll_policy(PollPolicy policy); | 283 static const PacPollPolicy* set_pac_script_poll_policy( |
| 284 const PacPollPolicy* policy); | |
| 285 | |
| 286 // This method should only be used by unit tests. Creates an instance | |
| 287 // of the default internal PacPollPolicy used by ProxyService. | |
| 288 static scoped_ptr<PacPollPolicy> CreateDefaultPacPollPolicy(); | |
| 250 | 289 |
| 251 private: | 290 private: |
| 252 FRIEND_TEST_ALL_PREFIXES(ProxyServiceTest, UpdateConfigAfterFailedAutodetect); | 291 FRIEND_TEST_ALL_PREFIXES(ProxyServiceTest, UpdateConfigAfterFailedAutodetect); |
| 253 FRIEND_TEST_ALL_PREFIXES(ProxyServiceTest, UpdateConfigFromPACToDirect); | 292 FRIEND_TEST_ALL_PREFIXES(ProxyServiceTest, UpdateConfigFromPACToDirect); |
| 254 friend class PacRequest; | 293 friend class PacRequest; |
| 255 class InitProxyResolver; | 294 class InitProxyResolver; |
| 256 class ProxyScriptDeciderPoller; | 295 class ProxyScriptDeciderPoller; |
| 257 | 296 |
| 258 // TODO(eroman): change this to a std::set. Note that this requires updating | 297 // TODO(eroman): change this to a std::set. Note that this requires updating |
| 259 // some tests in proxy_service_unittest.cc such as: | 298 // some tests in proxy_service_unittest.cc such as: |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 | 458 |
| 420 base::WaitableEvent event_; | 459 base::WaitableEvent event_; |
| 421 CompletionCallback callback_; | 460 CompletionCallback callback_; |
| 422 ProxyInfo proxy_info_; | 461 ProxyInfo proxy_info_; |
| 423 int result_; | 462 int result_; |
| 424 }; | 463 }; |
| 425 | 464 |
| 426 } // namespace net | 465 } // namespace net |
| 427 | 466 |
| 428 #endif // NET_PROXY_PROXY_SERVICE_H_ | 467 #endif // NET_PROXY_PROXY_SERVICE_H_ |
| OLD | NEW |