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 #pragma once 8 9 namespace net { 10 11 class ProxyConfig; 12 13 // Service for watching when the proxy settings have changed. 14 class ProxyConfigService { 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 26 // Observer for being notified when the proxy settings have changed. 27 class Observer { 28 public: 29 virtual ~Observer() {} 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; 37 }; 38 39 virtual ~ProxyConfigService() {} 40 41 // Adds/Removes an observer that will be called whenever the proxy 42 // configuration has changed. 43 virtual void AddObserver(Observer* observer) = 0; 44 virtual void RemoveObserver(Observer* observer) = 0; 45 46 // Gets the most recent availability status. If a configuration is present, 47 // the proxy configuration is written to |config| and CONFIG_VALID is 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 50 // some point in the future once the configuration is available. 51 // Note that to avoid re-entrancy problems, implementations should not 52 // dispatch any change notifications from within this function. 53 virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) = 0; 54 55 // ProxyService will call this periodically during periods of activity. 56 // It can be used as a signal for polling-based implementations. 57 // 58 // Note that this is purely used as an optimization -- polling 59 // implementations could simply set a global timer that goes off every 60 // X seconds at which point they check for changes. However that has 61 // the disadvantage of doing continuous work even during idle periods. 62 virtual void OnLazyPoll() {} 63 }; 64 65 } // namespace net 66 67 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_H_ 68