blob: dc0db4880c66d6b5357faed0b64c0434fb4bef63 [file] [log] [blame]
[email protected]3b63f8f42011-03-28 01:54:151// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]119655002010-07-23 06:02:402// 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_POLLING_PROXY_CONFIG_SERVICE_H_
6#define NET_PROXY_POLLING_PROXY_CONFIG_SERVICE_H_
[email protected]119655002010-07-23 06:02:407
[email protected]c4c1b482011-07-22 17:24:268#include "base/compiler_specific.h"
[email protected]3b63f8f42011-03-28 01:54:159#include "base/memory/ref_counted.h"
[email protected]66e96c42013-06-28 15:20:3110#include "base/time/time.h"
[email protected]119655002010-07-23 06:02:4011#include "net/proxy/proxy_config_service.h"
12
13namespace net {
14
15// PollingProxyConfigService is a base class for creating ProxyConfigService
16// implementations that use polling to notice when settings have change.
17//
18// It runs code to get the current proxy settings on a background worker
19// thread, and notifies registered observers when the value changes.
[email protected]172da1b2011-08-12 15:52:2620class NET_EXPORT_PRIVATE PollingProxyConfigService : public ProxyConfigService {
[email protected]119655002010-07-23 06:02:4021 public:
22 // ProxyConfigService implementation:
mostynbba063d6032014-10-09 11:01:1323 virtual void AddObserver(Observer* observer) override;
24 virtual void RemoveObserver(Observer* observer) override;
25 virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) override;
26 virtual void OnLazyPoll() override;
[email protected]119655002010-07-23 06:02:4027
28 protected:
29 // Function for retrieving the current proxy configuration.
30 // Implementors must be threadsafe as the function will be invoked from
31 // worker threads.
32 typedef void (*GetConfigFunction)(ProxyConfig*);
33
34 // Creates a polling-based ProxyConfigService which will test for new
35 // settings at most every |poll_interval| time by calling |get_config_func|
36 // on a worker thread.
37 PollingProxyConfigService(
38 base::TimeDelta poll_interval,
39 GetConfigFunction get_config_func);
40
41 virtual ~PollingProxyConfigService();
42
[email protected]e9b8d0af2010-08-17 04:10:2943 // Polls for changes by posting a task to the worker pool.
44 void CheckForChangesNow();
45
[email protected]119655002010-07-23 06:02:4046 private:
47 class Core;
48 scoped_refptr<Core> core_;
[email protected]f4ffb7a2011-05-19 21:23:0049
50 DISALLOW_COPY_AND_ASSIGN(PollingProxyConfigService);
[email protected]119655002010-07-23 06:02:4051};
52
53} // namespace net
54
55#endif // NET_PROXY_POLLING_PROXY_CONFIG_SERVICE_H_