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