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 | |
|
wtc
2012/01/13 01:08:45
Nit: this line is too short.
eroman
2012/01/13 20:05:27
Done.
| |
| 66 // a stale version of the PAC script until the background polling gets a | |
| 67 // chance to update things. | |
| 68 class NET_EXPORT_PRIVATE PacPollPolicy { | |
| 69 public: | |
| 70 enum Mode { | |
| 71 MODE_USE_TIMER, | |
| 72 MODE_START_AFTER_ACTIVITY, | |
| 73 }; | |
| 74 | |
| 75 virtual ~PacPollPolicy(); | |
| 76 virtual Mode GetInitialDelay(int error, int64* next_delay_ms) const = 0; | |
| 77 virtual Mode GetNextDelay(int64 current_delay_ms, | |
| 78 int64* next_delay_ms) const = 0; | |
|
wtc
2012/01/13 01:08:45
You didn't document these two methods.
eroman
2012/01/13 20:05:27
Done.
| |
| 51 }; | 79 }; |
| 52 | 80 |
| 53 // The instance takes ownership of |config_service| and |resolver|. | 81 // The instance takes ownership of |config_service| and |resolver|. |
| 54 // |net_log| is a possibly NULL destination to send log events to. It must | 82 // |net_log| is a possibly NULL destination to send log events to. It must |
| 55 // remain alive for the lifetime of this ProxyService. | 83 // remain alive for the lifetime of this ProxyService. |
| 56 ProxyService(ProxyConfigService* config_service, | 84 ProxyService(ProxyConfigService* config_service, |
| 57 ProxyResolver* resolver, | 85 ProxyResolver* resolver, |
| 58 NetLog* net_log); | 86 NetLog* net_log); |
| 59 | 87 |
| 60 virtual ~ProxyService(); | 88 virtual ~ProxyService(); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 static ProxyConfigService* CreateSystemProxyConfigService( | 267 static ProxyConfigService* CreateSystemProxyConfigService( |
| 240 MessageLoop* io_loop, MessageLoop* file_loop); | 268 MessageLoop* io_loop, MessageLoop* file_loop); |
| 241 | 269 |
| 242 // This method should only be used by unit tests. | 270 // This method should only be used by unit tests. |
| 243 void set_stall_proxy_auto_config_delay(base::TimeDelta delay) { | 271 void set_stall_proxy_auto_config_delay(base::TimeDelta delay) { |
| 244 stall_proxy_auto_config_delay_ = delay; | 272 stall_proxy_auto_config_delay_ = delay; |
| 245 } | 273 } |
| 246 | 274 |
| 247 // This method should only be used by unit tests. Returns the previously | 275 // This method should only be used by unit tests. Returns the previously |
| 248 // active policy. | 276 // active policy. |
| 249 static PollPolicy set_pac_script_poll_policy(PollPolicy policy); | 277 static const PacPollPolicy* set_pac_script_poll_policy( |
| 278 const PacPollPolicy* policy); | |
| 279 | |
| 280 // This method should only be used by unit tests. Creates an instance | |
| 281 // of the default internal PacPollPolicy used by ProxyService. | |
| 282 static scoped_ptr<PacPollPolicy> CreateDefaultPacPollPolicy(); | |
| 250 | 283 |
| 251 private: | 284 private: |
| 252 FRIEND_TEST_ALL_PREFIXES(ProxyServiceTest, UpdateConfigAfterFailedAutodetect); | 285 FRIEND_TEST_ALL_PREFIXES(ProxyServiceTest, UpdateConfigAfterFailedAutodetect); |
| 253 FRIEND_TEST_ALL_PREFIXES(ProxyServiceTest, UpdateConfigFromPACToDirect); | 286 FRIEND_TEST_ALL_PREFIXES(ProxyServiceTest, UpdateConfigFromPACToDirect); |
| 254 friend class PacRequest; | 287 friend class PacRequest; |
| 255 class InitProxyResolver; | 288 class InitProxyResolver; |
| 256 class ProxyScriptDeciderPoller; | 289 class ProxyScriptDeciderPoller; |
| 257 | 290 |
| 258 // TODO(eroman): change this to a std::set. Note that this requires updating | 291 // TODO(eroman): change this to a std::set. Note that this requires updating |
| 259 // some tests in proxy_service_unittest.cc such as: | 292 // some tests in proxy_service_unittest.cc such as: |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 | 452 |
| 420 base::WaitableEvent event_; | 453 base::WaitableEvent event_; |
| 421 CompletionCallback callback_; | 454 CompletionCallback callback_; |
| 422 ProxyInfo proxy_info_; | 455 ProxyInfo proxy_info_; |
| 423 int result_; | 456 int result_; |
| 424 }; | 457 }; |
| 425 | 458 |
| 426 } // namespace net | 459 } // namespace net |
| 427 | 460 |
| 428 #endif // NET_PROXY_PROXY_SERVICE_H_ | 461 #endif // NET_PROXY_PROXY_SERVICE_H_ |
| OLD | NEW |