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_RESOLUTION_PROXY_CONFIG_SERVICE_H_ 6 #define NET_PROXY_RESOLUTION_PROXY_CONFIG_SERVICE_H_ 7 8 #include "net/base/net_export.h" 9 10 namespace net { 11 12 class ProxyConfigWithAnnotation; 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: ~Observer()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 ProxyConfigWithAnnotation& config, 37 ConfigAvailability availability) = 0; 38 }; 39 ~ProxyConfigService()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( 55 ProxyConfigWithAnnotation* config) = 0; 56 57 // ConfiguredProxyResolutionService will call this periodically during periods 58 // of activity. It can be used as a signal for polling-based implementations. 59 // 60 // Note that this is purely used as an optimization -- polling 61 // implementations could simply set a global timer that goes off every 62 // X seconds at which point they check for changes. However that has 63 // the disadvantage of doing continuous work even during idle periods. OnLazyPoll()64 virtual void OnLazyPoll() {} 65 }; 66 67 } // namespace net 68 69 #endif // NET_PROXY_RESOLUTION_PROXY_CONFIG_SERVICE_H_ 70