From 119655003d8f225282179043e990df879062e529 Mon Sep 17 00:00:00 2001 From: "eroman@chromium.org" Date: Fri, 23 Jul 2010 06:02:40 +0000 Subject: Change the ProxyConfigService interface to be asynchronous, and support observers. The Windows implementation is still using a polling mechanism under the hood, however that polling has been moved to the worker pool so it won't block the IO thread in case WinHttpGetIEProxyConfigForCurrentUser is slow (crbug.com/12189). BUG=12189 Review URL: http://codereview.chromium.org/3056011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53442 0039d316-1c4b-4281-b951-d872f2087c98 --- net/proxy/polling_proxy_config_service.h | 49 ++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 net/proxy/polling_proxy_config_service.h (limited to 'net/proxy/polling_proxy_config_service.h') diff --git a/net/proxy/polling_proxy_config_service.h b/net/proxy/polling_proxy_config_service.h new file mode 100644 index 0000000..1bf889b --- /dev/null +++ b/net/proxy/polling_proxy_config_service.h @@ -0,0 +1,49 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_PROXY_POLLING_PROXY_CONFIG_SERVICE_H_ +#define NET_PROXY_POLLING_PROXY_CONFIG_SERVICE_H_ + +#include "base/time.h" +#include "base/ref_counted.h" +#include "net/proxy/proxy_config_service.h" + +namespace net { + +// PollingProxyConfigService is a base class for creating ProxyConfigService +// implementations that use polling to notice when settings have change. +// +// It runs code to get the current proxy settings on a background worker +// thread, and notifies registered observers when the value changes. +class PollingProxyConfigService : public ProxyConfigService { + public: + // ProxyConfigService implementation: + virtual void AddObserver(Observer* observer); + virtual void RemoveObserver(Observer* observer); + virtual bool GetLatestProxyConfig(ProxyConfig* config); + virtual void OnLazyPoll(); + + protected: + // Function for retrieving the current proxy configuration. + // Implementors must be threadsafe as the function will be invoked from + // worker threads. + typedef void (*GetConfigFunction)(ProxyConfig*); + + // Creates a polling-based ProxyConfigService which will test for new + // settings at most every |poll_interval| time by calling |get_config_func| + // on a worker thread. + PollingProxyConfigService( + base::TimeDelta poll_interval, + GetConfigFunction get_config_func); + + virtual ~PollingProxyConfigService(); + + private: + class Core; + scoped_refptr core_; +}; + +} // namespace net + +#endif // NET_PROXY_POLLING_PROXY_CONFIG_SERVICE_H_ -- cgit v1.1