Kaido Kert | 25902c6 | 2024-06-17 17:10:28 -0700 | [diff] [blame^] | 1 | // Copyright 2011 The Chromium Authors |
Andrew Top | 0d1858f | 2019-05-15 22:01:47 -0700 | [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 | |
| 5 | #ifndef NET_PROXY_RESOLUTION_POLLING_PROXY_CONFIG_SERVICE_H_ |
| 6 | #define NET_PROXY_RESOLUTION_POLLING_PROXY_CONFIG_SERVICE_H_ |
| 7 | |
| 8 | #include "base/compiler_specific.h" |
Kaido Kert | 25902c6 | 2024-06-17 17:10:28 -0700 | [diff] [blame^] | 9 | #include "base/memory/scoped_refptr.h" |
Andrew Top | 0d1858f | 2019-05-15 22:01:47 -0700 | [diff] [blame] | 10 | #include "base/time/time.h" |
| 11 | #include "net/base/net_export.h" |
| 12 | #include "net/proxy_resolution/proxy_config_service.h" |
| 13 | #include "net/traffic_annotation/network_traffic_annotation.h" |
| 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. |
| 22 | class NET_EXPORT_PRIVATE PollingProxyConfigService : public ProxyConfigService { |
| 23 | public: |
Kaido Kert | 25902c6 | 2024-06-17 17:10:28 -0700 | [diff] [blame^] | 24 | PollingProxyConfigService(const PollingProxyConfigService&) = delete; |
| 25 | PollingProxyConfigService& operator=(const PollingProxyConfigService&) = |
| 26 | delete; |
| 27 | |
Andrew Top | 0d1858f | 2019-05-15 22:01:47 -0700 | [diff] [blame] | 28 | // ProxyConfigService implementation: |
| 29 | void AddObserver(Observer* observer) override; |
| 30 | void RemoveObserver(Observer* observer) override; |
| 31 | ConfigAvailability GetLatestProxyConfig( |
| 32 | ProxyConfigWithAnnotation* config) override; |
| 33 | void OnLazyPoll() override; |
Kaido Kert | 25902c6 | 2024-06-17 17:10:28 -0700 | [diff] [blame^] | 34 | bool UsesPolling() override; |
Andrew Top | 0d1858f | 2019-05-15 22:01:47 -0700 | [diff] [blame] | 35 | |
| 36 | protected: |
| 37 | // Function for retrieving the current proxy configuration. |
| 38 | // Implementors must be threadsafe as the function will be invoked from |
| 39 | // worker threads. |
| 40 | typedef void (*GetConfigFunction)(NetworkTrafficAnnotationTag, |
| 41 | ProxyConfigWithAnnotation*); |
| 42 | |
| 43 | // Creates a polling-based ProxyConfigService which will test for new |
| 44 | // settings at most every |poll_interval| time by calling |get_config_func| |
| 45 | // on a worker thread. |
| 46 | PollingProxyConfigService( |
| 47 | base::TimeDelta poll_interval, |
| 48 | GetConfigFunction get_config_func, |
| 49 | const NetworkTrafficAnnotationTag& traffic_annotation); |
| 50 | |
| 51 | ~PollingProxyConfigService() override; |
| 52 | |
| 53 | // Polls for changes by posting a task to the worker pool. |
| 54 | void CheckForChangesNow(); |
| 55 | |
| 56 | private: |
| 57 | class Core; |
| 58 | scoped_refptr<Core> core_; |
Andrew Top | 0d1858f | 2019-05-15 22:01:47 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | } // namespace net |
| 62 | |
| 63 | #endif // NET_PROXY_RESOLUTION_POLLING_PROXY_CONFIG_SERVICE_H_ |