Chromium Code Reviews| Index: chrome/browser/net/pref_proxy_config_service.h |
| diff --git a/chrome/browser/net/pref_proxy_config_service.h b/chrome/browser/net/pref_proxy_config_service.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d221c62b16f92fe3290f38c9b1bfa2d93238d810 |
| --- /dev/null |
| +++ b/chrome/browser/net/pref_proxy_config_service.h |
| @@ -0,0 +1,121 @@ |
| +// 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 CHROME_BROWSER_NET_PREF_PROXY_CONFIG_SERVICE_H_ |
| +#define CHROME_BROWSER_NET_PREF_PROXY_CONFIG_SERVICE_H_ |
| + |
|
jochen (gone - plz use gerrit)
2010/11/24 10:04:52
#pragma once
Mattias Nissler (ping if slow)
2010/11/24 11:19:29
Done.
|
| +#include "base/basictypes.h" |
| +#include "base/observer_list.h" |
| +#include "base/ref_counted.h" |
| +#include "base/scoped_ptr.h" |
| +#include "chrome/common/notification_observer.h" |
| +#include "net/proxy/proxy_config.h" |
| +#include "net/proxy/proxy_config_service.h" |
| + |
| +class PrefService; |
| +class PrefSetObserver; |
| +class PrefProxyConfigTracker; |
|
jochen (gone - plz use gerrit)
2010/11/24 10:04:52
alphabetical ordering
Mattias Nissler (ping if slow)
2010/11/24 11:19:29
Done.
|
| + |
| +// A helper class that tracks proxy preferences. It translates the configuration |
| +// to net::ProxyConfig and proxies the result over to the IO thread for |
| +// PrefProxyConfigService to use. |
| +class PrefProxyConfigTracker |
| + : public base::RefCountedThreadSafe<PrefProxyConfigTracker>, |
| + public NotificationObserver { |
| + public: |
| + // Observer interface used to send out notifications on the IO thread about |
| + // changes to the proxy configuration. |
| + class Observer { |
|
jochen (gone - plz use gerrit)
2010/11/24 10:04:52
nit ObserverInterface :)
Mattias Nissler (ping if slow)
2010/11/24 11:19:29
Done.
|
| + public: |
| + virtual ~Observer() {} |
| + virtual void OnPrefProxyConfigChanged() = 0; |
| + }; |
| + |
| + explicit PrefProxyConfigTracker(PrefService* pref_service); |
| + virtual ~PrefProxyConfigTracker(); |
| + |
| + void AddObserver(Observer* observer); |
|
jochen (gone - plz use gerrit)
2010/11/24 10:04:52
annotate with the thread to invoke the method on (
Mattias Nissler (ping if slow)
2010/11/24 11:19:29
Done.
|
| + void RemoveObserver(Observer* observer); |
| + |
| + // Get the proxy configuration currently defined by preferences. Writes the |
| + // configuration to |config| and returns true on success. |config| is not |
| + // touched and false is returned if there is no configuration defined. |
| + bool GetProxyConfig(net::ProxyConfig* config); |
| + |
| + // Notifies the tracker that the pref service passed upon construction is |
| + // about to go away. |
| + void DestroyingPrefService(); |
|
jochen (gone - plz use gerrit)
2010/11/24 10:04:52
nit. maybe name DetachFromPrefService?
Mattias Nissler (ping if slow)
2010/11/24 11:19:29
Done.
|
| + |
| + private: |
| + // NotificationObserver implementation: |
| + virtual void Observe(NotificationType type, |
| + const NotificationSource& source, |
| + const NotificationDetails& details); |
| + |
| + // Install a new configuration (to be called on the IO thread). |
|
jochen (gone - plz use gerrit)
2010/11/24 10:04:52
what's |valid| doing? maybe you should have a sepa
Mattias Nissler (ping if slow)
2010/11/24 11:19:29
Wrote better documentation.
|
| + void InstallProxyConfig(const net::ProxyConfig& config, bool valid); |
| + |
| + // Creates a proxy configuration from proxy-related preferences. Configuration |
| + // is stored in |config| and the return value indicates whether the |
| + // configuration is valid. |
| + bool ReadPrefConfig(net::ProxyConfig* config); |
| + |
| + // Configuration as defined by prefs. Only to be accessed from the IO thread |
| + // (expect for construction). |
| + net::ProxyConfig pref_config_; |
| + |
| + // Whether |pref_config_| is valid. |
| + bool valid_; |
| + |
| + // List of observers, accessed exclusively from the IO thread. |
| + ObserverList<Observer, true> observers_; |
| + |
| + // Pref-related members that should only be accessed from the UI thread. |
| + PrefService* pref_service_; |
| + scoped_ptr<PrefSetObserver> proxy_prefs_observer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigTracker); |
| +}; |
| + |
| +// A net::ProxyConfigService implementation that applies preference proxy |
| +// settings as overrides to the proxy configuration determined by a baseline |
| +// delegate ProxyConfigService. |
| +class PrefProxyConfigService |
| + : public net::ProxyConfigService, |
| + public PrefProxyConfigTracker::Observer, |
| + public net::ProxyConfigService::Observer { |
|
jochen (gone - plz use gerrit)
2010/11/24 10:04:52
nit alphabetical ordering
Mattias Nissler (ping if slow)
2010/11/24 11:19:29
Done.
|
| + public: |
| + // Takes ownership of the passed |base_service|. |
| + PrefProxyConfigService(PrefProxyConfigTracker* tracker, |
| + net::ProxyConfigService* base_service); |
| + virtual ~PrefProxyConfigService(); |
| + |
| + // ProxyConfigService implementation: |
| + virtual void AddObserver(net::ProxyConfigService::Observer* observer); |
| + virtual void RemoveObserver(net::ProxyConfigService::Observer* observer); |
| + virtual bool GetLatestProxyConfig(net::ProxyConfig* config); |
| + virtual void OnLazyPoll(); |
| + |
| + private: |
| + // ProxyConfigService::Observer implementation: |
| + virtual void OnProxyConfigChanged(const net::ProxyConfig& config); |
| + |
| + // PrefProxyConfigTracker::Observer implementation: |
| + virtual void OnPrefProxyConfigChanged(); |
| + |
| + // Makes sure that the observer registrations with the base service and the |
| + // tracker object are set up. |
| + void RegisterObservers(); |
| + |
| + scoped_ptr<net::ProxyConfigService> base_service_; |
| + ObserverList<net::ProxyConfigService::Observer, true> observers_; |
| + scoped_refptr<PrefProxyConfigTracker> pref_config_tracker_; |
| + |
| + // Indicates whether the base service and tracker registrations are done. |
| + bool registered_observers_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigService); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_NET_PREF_PROXY_CONFIG_SERVICE_H_ |