OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_CONFIG_SERVICE_H_ | 5 #ifndef NET_PROXY_PROXY_CONFIG_SERVICE_H_ |
6 #define NET_PROXY_PROXY_CONFIG_SERVICE_H_ | 6 #define NET_PROXY_PROXY_CONFIG_SERVICE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 namespace net { | 9 namespace net { |
10 | 10 |
11 class ProxyConfig; | 11 class ProxyConfig; |
12 | 12 |
13 // Service for watching when the proxy settings have changed. | 13 // Service for watching when the proxy settings have changed. |
14 class ProxyConfigService { | 14 class ProxyConfigService { |
15 public: | 15 public: |
| 16 // Indicates whether proxy configuration is valid, and if not, why. |
| 17 enum ConfigAvailability { |
| 18 // Configuration is pending, observers will be notified later. |
| 19 CONFIG_PENDING, |
| 20 // Configuration is present and valid. |
| 21 CONFIG_VALID, |
| 22 // No configuration is set. |
| 23 CONFIG_UNSET |
| 24 }; |
| 25 |
16 // Observer for being notified when the proxy settings have changed. | 26 // Observer for being notified when the proxy settings have changed. |
17 class Observer { | 27 class Observer { |
18 public: | 28 public: |
19 virtual ~Observer() {} | 29 virtual ~Observer() {} |
20 virtual void OnProxyConfigChanged(const ProxyConfig& config) = 0; | 30 // Notification callback that should be invoked by ProxyConfigService |
| 31 // implementors whenever the configuration changes. |availability| indicates |
| 32 // the new availability status and can be CONFIG_UNSET or CONFIG_VALID (in |
| 33 // which case |config| contains the configuration). Implementors must not |
| 34 // pass CONFIG_PENDING. |
| 35 virtual void OnProxyConfigChanged(const ProxyConfig& config, |
| 36 ConfigAvailability availability) = 0; |
21 }; | 37 }; |
22 | 38 |
23 virtual ~ProxyConfigService() {} | 39 virtual ~ProxyConfigService() {} |
24 | 40 |
25 // Adds/Removes an observer that will be called whenever the proxy | 41 // Adds/Removes an observer that will be called whenever the proxy |
26 // configuration has changed. | 42 // configuration has changed. |
27 virtual void AddObserver(Observer* observer) = 0; | 43 virtual void AddObserver(Observer* observer) = 0; |
28 virtual void RemoveObserver(Observer* observer) = 0; | 44 virtual void RemoveObserver(Observer* observer) = 0; |
29 | 45 |
30 // Gets the most recent value of the proxy configuration. Returns false if | 46 // Gets the most recent availability status. If a configuration is present, |
31 // it is not available yet. In the case where we returned false, it is | 47 // the proxy configuration is written to |config| and CONFIG_VALID is |
32 // guaranteed that subscribed observers will be notified of a change at | 48 // returned. Returns CONFIG_PENDING if it is not available yet. In this case, |
| 49 // it is guaranteed that subscribed observers will be notified of a change at |
33 // some point in the future once the configuration is available. | 50 // some point in the future once the configuration is available. |
34 // Note that to avoid re-entrancy problems, implementations should not | 51 // Note that to avoid re-entrancy problems, implementations should not |
35 // dispatch any change notifications from within this function. | 52 // dispatch any change notifications from within this function. |
36 virtual bool GetLatestProxyConfig(ProxyConfig* config) = 0; | 53 virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) = 0; |
37 | 54 |
38 // ProxyService will call this periodically during periods of activity. | 55 // ProxyService will call this periodically during periods of activity. |
39 // It can be used as a signal for polling-based implementations. | 56 // It can be used as a signal for polling-based implementations. |
40 // | 57 // |
41 // Note that this is purely used as an optimization -- polling | 58 // Note that this is purely used as an optimization -- polling |
42 // implementations could simply set a global timer that goes off every | 59 // implementations could simply set a global timer that goes off every |
43 // X seconds at which point they check for changes. However that has | 60 // X seconds at which point they check for changes. However that has |
44 // the disadvantage of doing continuous work even during idle periods. | 61 // the disadvantage of doing continuous work even during idle periods. |
45 virtual void OnLazyPoll() {} | 62 virtual void OnLazyPoll() {} |
46 }; | 63 }; |
47 | 64 |
48 } // namespace net | 65 } // namespace net |
49 | 66 |
50 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_H_ | 67 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_H_ |
OLD | NEW |