blob: 0a00618c1a6e0055681238c971f2b85831556a36 [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"
[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"
bnc81c46c1f2016-10-04 16:25:5911#include "net/base/net_export.h"
Lily Houghton582d4622018-01-22 22:43:4012#include "net/proxy_resolution/proxy_config_service.h"
Ramin Halavatica8d5252018-03-12 05:33:4913#include "net/traffic_annotation/network_traffic_annotation.h"
[email protected]119655002010-07-23 06:02:4014
15namespace net {
16
17// PollingProxyConfigService is a base class for creating ProxyConfigService
18// implementations that use polling to notice when settings have change.
19//
20// It runs code to get the current proxy settings on a background worker
21// thread, and notifies registered observers when the value changes.
[email protected]172da1b2011-08-12 15:52:2622class NET_EXPORT_PRIVATE PollingProxyConfigService : public ProxyConfigService {
[email protected]119655002010-07-23 06:02:4023 public:
Peter Boström407869b2021-10-07 04:42:4824 PollingProxyConfigService(const PollingProxyConfigService&) = delete;
25 PollingProxyConfigService& operator=(const PollingProxyConfigService&) =
26 delete;
27
[email protected]119655002010-07-23 06:02:4028 // ProxyConfigService implementation:
dchengb03027d2014-10-21 12:00:2029 void AddObserver(Observer* observer) override;
30 void RemoveObserver(Observer* observer) override;
Ramin Halavatica8d5252018-03-12 05:33:4931 ConfigAvailability GetLatestProxyConfig(
32 ProxyConfigWithAnnotation* config) override;
dchengb03027d2014-10-21 12:00:2033 void OnLazyPoll() override;
[email protected]119655002010-07-23 06:02:4034
35 protected:
36 // Function for retrieving the current proxy configuration.
37 // Implementors must be threadsafe as the function will be invoked from
38 // worker threads.
Ramin Halavatica8d5252018-03-12 05:33:4939 typedef void (*GetConfigFunction)(NetworkTrafficAnnotationTag,
40 ProxyConfigWithAnnotation*);
[email protected]119655002010-07-23 06:02:4041
42 // Creates a polling-based ProxyConfigService which will test for new
43 // settings at most every |poll_interval| time by calling |get_config_func|
44 // on a worker thread.
45 PollingProxyConfigService(
46 base::TimeDelta poll_interval,
Ramin Halavatica8d5252018-03-12 05:33:4947 GetConfigFunction get_config_func,
48 const NetworkTrafficAnnotationTag& traffic_annotation);
[email protected]119655002010-07-23 06:02:4049
dchengb03027d2014-10-21 12:00:2050 ~PollingProxyConfigService() override;
[email protected]119655002010-07-23 06:02:4051
[email protected]e9b8d0af2010-08-17 04:10:2952 // Polls for changes by posting a task to the worker pool.
53 void CheckForChangesNow();
54
[email protected]119655002010-07-23 06:02:4055 private:
56 class Core;
57 scoped_refptr<Core> core_;
[email protected]119655002010-07-23 06:02:4058};
59
60} // namespace net
61
Lily Houghton582d4622018-01-22 22:43:4062#endif // NET_PROXY_RESOLUTION_POLLING_PROXY_CONFIG_SERVICE_H_