blob: 382e5b38d465f02b9222a028702e49906475519c [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
Lily Houghton582d4622018-01-22 22:43:405#ifndef NET_PROXY_RESOLUTION_POLLING_PROXY_CONFIG_SERVICE_H_
6#define NET_PROXY_RESOLUTION_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"
Avi Drissman13fc8932015-12-20 04:40:469#include "base/macros.h"
[email protected]3b63f8f42011-03-28 01:54:1510#include "base/memory/ref_counted.h"
[email protected]66e96c42013-06-28 15:20:3111#include "base/time/time.h"
bnc81c46c1f2016-10-04 16:25:5912#include "net/base/net_export.h"
Lily Houghton582d4622018-01-22 22:43:4013#include "net/proxy_resolution/proxy_config_service.h"
Ramin Halavatica8d5252018-03-12 05:33:4914#include "net/traffic_annotation/network_traffic_annotation.h"
[email protected]119655002010-07-23 06:02:4015
16namespace net {
17
18// PollingProxyConfigService is a base class for creating ProxyConfigService
19// implementations that use polling to notice when settings have change.
20//
21// It runs code to get the current proxy settings on a background worker
22// thread, and notifies registered observers when the value changes.
[email protected]172da1b2011-08-12 15:52:2623class NET_EXPORT_PRIVATE PollingProxyConfigService : public ProxyConfigService {
[email protected]119655002010-07-23 06:02:4024 public:
25 // ProxyConfigService implementation:
dchengb03027d2014-10-21 12:00:2026 void AddObserver(Observer* observer) override;
27 void RemoveObserver(Observer* observer) override;
Ramin Halavatica8d5252018-03-12 05:33:4928 ConfigAvailability GetLatestProxyConfig(
29 ProxyConfigWithAnnotation* config) override;
dchengb03027d2014-10-21 12:00:2030 void OnLazyPoll() override;
[email protected]119655002010-07-23 06:02:4031
32 protected:
33 // Function for retrieving the current proxy configuration.
34 // Implementors must be threadsafe as the function will be invoked from
35 // worker threads.
Ramin Halavatica8d5252018-03-12 05:33:4936 typedef void (*GetConfigFunction)(NetworkTrafficAnnotationTag,
37 ProxyConfigWithAnnotation*);
[email protected]119655002010-07-23 06:02:4038
39 // Creates a polling-based ProxyConfigService which will test for new
40 // settings at most every |poll_interval| time by calling |get_config_func|
41 // on a worker thread.
42 PollingProxyConfigService(
43 base::TimeDelta poll_interval,
Ramin Halavatica8d5252018-03-12 05:33:4944 GetConfigFunction get_config_func,
45 const NetworkTrafficAnnotationTag& traffic_annotation);
[email protected]119655002010-07-23 06:02:4046
dchengb03027d2014-10-21 12:00:2047 ~PollingProxyConfigService() override;
[email protected]119655002010-07-23 06:02:4048
[email protected]e9b8d0af2010-08-17 04:10:2949 // Polls for changes by posting a task to the worker pool.
50 void CheckForChangesNow();
51
[email protected]119655002010-07-23 06:02:4052 private:
53 class Core;
54 scoped_refptr<Core> core_;
[email protected]f4ffb7a2011-05-19 21:23:0055
56 DISALLOW_COPY_AND_ASSIGN(PollingProxyConfigService);
[email protected]119655002010-07-23 06:02:4057};
58
59} // namespace net
60
Lily Houghton582d4622018-01-22 22:43:4061#endif // NET_PROXY_RESOLUTION_POLLING_PROXY_CONFIG_SERVICE_H_