[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 11965500 | 2010-07-23 06:02:40 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 5 | #ifndef NET_PROXY_RESOLUTION_POLLING_PROXY_CONFIG_SERVICE_H_ |
6 | #define NET_PROXY_RESOLUTION_POLLING_PROXY_CONFIG_SERVICE_H_ | ||||
[email protected] | 11965500 | 2010-07-23 06:02:40 | [diff] [blame] | 7 | |
[email protected] | c4c1b48 | 2011-07-22 17:24:26 | [diff] [blame] | 8 | #include "base/compiler_specific.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 9 | #include "base/memory/ref_counted.h" |
[email protected] | 66e96c4 | 2013-06-28 15:20:31 | [diff] [blame] | 10 | #include "base/time/time.h" |
bnc | 81c46c1f | 2016-10-04 16:25:59 | [diff] [blame] | 11 | #include "net/base/net_export.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 12 | #include "net/proxy_resolution/proxy_config_service.h" |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13 | #include "net/traffic_annotation/network_traffic_annotation.h" |
[email protected] | 11965500 | 2010-07-23 06:02:40 | [diff] [blame] | 14 | |
15 | namespace 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] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 22 | class NET_EXPORT_PRIVATE PollingProxyConfigService : public ProxyConfigService { |
[email protected] | 11965500 | 2010-07-23 06:02:40 | [diff] [blame] | 23 | public: |
Peter Boström | 407869b | 2021-10-07 04:42:48 | [diff] [blame] | 24 | PollingProxyConfigService(const PollingProxyConfigService&) = delete; |
25 | PollingProxyConfigService& operator=(const PollingProxyConfigService&) = | ||||
26 | delete; | ||||
27 | |||||
[email protected] | 11965500 | 2010-07-23 06:02:40 | [diff] [blame] | 28 | // ProxyConfigService implementation: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 29 | void AddObserver(Observer* observer) override; |
30 | void RemoveObserver(Observer* observer) override; | ||||
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 31 | ConfigAvailability GetLatestProxyConfig( |
32 | ProxyConfigWithAnnotation* config) override; | ||||
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 33 | void OnLazyPoll() override; |
[email protected] | 11965500 | 2010-07-23 06:02:40 | [diff] [blame] | 34 | |
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 Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 39 | typedef void (*GetConfigFunction)(NetworkTrafficAnnotationTag, |
40 | ProxyConfigWithAnnotation*); | ||||
[email protected] | 11965500 | 2010-07-23 06:02:40 | [diff] [blame] | 41 | |
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 Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 47 | GetConfigFunction get_config_func, |
48 | const NetworkTrafficAnnotationTag& traffic_annotation); | ||||
[email protected] | 11965500 | 2010-07-23 06:02:40 | [diff] [blame] | 49 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 50 | ~PollingProxyConfigService() override; |
[email protected] | 11965500 | 2010-07-23 06:02:40 | [diff] [blame] | 51 | |
[email protected] | e9b8d0af | 2010-08-17 04:10:29 | [diff] [blame] | 52 | // Polls for changes by posting a task to the worker pool. |
53 | void CheckForChangesNow(); | ||||
54 | |||||
[email protected] | 11965500 | 2010-07-23 06:02:40 | [diff] [blame] | 55 | private: |
56 | class Core; | ||||
57 | scoped_refptr<Core> core_; | ||||
[email protected] | 11965500 | 2010-07-23 06:02:40 | [diff] [blame] | 58 | }; |
59 | |||||
60 | } // namespace net | ||||
61 | |||||
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 62 | #endif // NET_PROXY_RESOLUTION_POLLING_PROXY_CONFIG_SERVICE_H_ |