Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 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 CHROME_BROWSER_NET_PREF_PROXY_CONFIG_SERVICE_H_ | |
| 6 #define CHROME_BROWSER_NET_PREF_PROXY_CONFIG_SERVICE_H_ | |
| 7 | |
|
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.
| |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/observer_list.h" | |
| 10 #include "base/ref_counted.h" | |
| 11 #include "base/scoped_ptr.h" | |
| 12 #include "chrome/common/notification_observer.h" | |
| 13 #include "net/proxy/proxy_config.h" | |
| 14 #include "net/proxy/proxy_config_service.h" | |
| 15 | |
| 16 class PrefService; | |
| 17 class PrefSetObserver; | |
| 18 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.
| |
| 19 | |
| 20 // A helper class that tracks proxy preferences. It translates the configuration | |
| 21 // to net::ProxyConfig and proxies the result over to the IO thread for | |
| 22 // PrefProxyConfigService to use. | |
| 23 class PrefProxyConfigTracker | |
| 24 : public base::RefCountedThreadSafe<PrefProxyConfigTracker>, | |
| 25 public NotificationObserver { | |
| 26 public: | |
| 27 // Observer interface used to send out notifications on the IO thread about | |
| 28 // changes to the proxy configuration. | |
| 29 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.
| |
| 30 public: | |
| 31 virtual ~Observer() {} | |
| 32 virtual void OnPrefProxyConfigChanged() = 0; | |
| 33 }; | |
| 34 | |
| 35 explicit PrefProxyConfigTracker(PrefService* pref_service); | |
| 36 virtual ~PrefProxyConfigTracker(); | |
| 37 | |
| 38 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.
| |
| 39 void RemoveObserver(Observer* observer); | |
| 40 | |
| 41 // Get the proxy configuration currently defined by preferences. Writes the | |
| 42 // configuration to |config| and returns true on success. |config| is not | |
| 43 // touched and false is returned if there is no configuration defined. | |
| 44 bool GetProxyConfig(net::ProxyConfig* config); | |
| 45 | |
| 46 // Notifies the tracker that the pref service passed upon construction is | |
| 47 // about to go away. | |
| 48 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.
| |
| 49 | |
| 50 private: | |
| 51 // NotificationObserver implementation: | |
| 52 virtual void Observe(NotificationType type, | |
| 53 const NotificationSource& source, | |
| 54 const NotificationDetails& details); | |
| 55 | |
| 56 // 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.
| |
| 57 void InstallProxyConfig(const net::ProxyConfig& config, bool valid); | |
| 58 | |
| 59 // Creates a proxy configuration from proxy-related preferences. Configuration | |
| 60 // is stored in |config| and the return value indicates whether the | |
| 61 // configuration is valid. | |
| 62 bool ReadPrefConfig(net::ProxyConfig* config); | |
| 63 | |
| 64 // Configuration as defined by prefs. Only to be accessed from the IO thread | |
| 65 // (expect for construction). | |
| 66 net::ProxyConfig pref_config_; | |
| 67 | |
| 68 // Whether |pref_config_| is valid. | |
| 69 bool valid_; | |
| 70 | |
| 71 // List of observers, accessed exclusively from the IO thread. | |
| 72 ObserverList<Observer, true> observers_; | |
| 73 | |
| 74 // Pref-related members that should only be accessed from the UI thread. | |
| 75 PrefService* pref_service_; | |
| 76 scoped_ptr<PrefSetObserver> proxy_prefs_observer_; | |
| 77 | |
| 78 DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigTracker); | |
| 79 }; | |
| 80 | |
| 81 // A net::ProxyConfigService implementation that applies preference proxy | |
| 82 // settings as overrides to the proxy configuration determined by a baseline | |
| 83 // delegate ProxyConfigService. | |
| 84 class PrefProxyConfigService | |
| 85 : public net::ProxyConfigService, | |
| 86 public PrefProxyConfigTracker::Observer, | |
| 87 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.
| |
| 88 public: | |
| 89 // Takes ownership of the passed |base_service|. | |
| 90 PrefProxyConfigService(PrefProxyConfigTracker* tracker, | |
| 91 net::ProxyConfigService* base_service); | |
| 92 virtual ~PrefProxyConfigService(); | |
| 93 | |
| 94 // ProxyConfigService implementation: | |
| 95 virtual void AddObserver(net::ProxyConfigService::Observer* observer); | |
| 96 virtual void RemoveObserver(net::ProxyConfigService::Observer* observer); | |
| 97 virtual bool GetLatestProxyConfig(net::ProxyConfig* config); | |
| 98 virtual void OnLazyPoll(); | |
| 99 | |
| 100 private: | |
| 101 // ProxyConfigService::Observer implementation: | |
| 102 virtual void OnProxyConfigChanged(const net::ProxyConfig& config); | |
| 103 | |
| 104 // PrefProxyConfigTracker::Observer implementation: | |
| 105 virtual void OnPrefProxyConfigChanged(); | |
| 106 | |
| 107 // Makes sure that the observer registrations with the base service and the | |
| 108 // tracker object are set up. | |
| 109 void RegisterObservers(); | |
| 110 | |
| 111 scoped_ptr<net::ProxyConfigService> base_service_; | |
| 112 ObserverList<net::ProxyConfigService::Observer, true> observers_; | |
| 113 scoped_refptr<PrefProxyConfigTracker> pref_config_tracker_; | |
| 114 | |
| 115 // Indicates whether the base service and tracker registrations are done. | |
| 116 bool registered_observers_; | |
| 117 | |
| 118 DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigService); | |
| 119 }; | |
| 120 | |
| 121 #endif // CHROME_BROWSER_NET_PREF_PROXY_CONFIG_SERVICE_H_ | |
| OLD | NEW |