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