Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3888)

Unified Diff: chrome/browser/net/pref_proxy_config_tracker.h

Issue 8102019: redesign and reimplement proxy config service and tracker, revise proxy ui on cros (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/net/pref_proxy_config_tracker.h
===================================================================
--- chrome/browser/net/pref_proxy_config_tracker.h (revision 104725)
+++ chrome/browser/net/pref_proxy_config_tracker.h (working copy)
@@ -2,8 +2,8 @@
// 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_
+#ifndef CHROME_BROWSER_NET_PREF_PROXY_CONFIG_TRACKER_H_
+#define CHROME_BROWSER_NET_PREF_PROXY_CONFIG_TRACKER_H_
#pragma once
#include "base/basictypes.h"
@@ -11,138 +11,157 @@
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
#include "chrome/browser/prefs/proxy_config_dictionary.h"
-#include "content/common/notification_observer.h"
+#include "content/public/browser/notification_observer.h"
#include "net/proxy/proxy_config.h"
#include "net/proxy/proxy_config_service.h"
class PrefService;
class PrefSetObserver;
-// 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 {
+#if defined(OS_CHROMEOS)
+namespace chromeos {
+class ProxyConfigServiceImpl;
+}
+#endif // defined(OS_CHROMEOS)
+
+// A net::ProxyConfigService implementation that applies preference proxy
+// settings (pushed from PrefProxyConfigTracker) as overrides to the proxy
+// configuration determined by a baseline delegate ProxyConfigService on
+// non-ChromeOS platforms. ChromeOS has its own implementation of overrides in
+// chromeos::ProxyConfigServiceImpl.
+class ChromeProxyConfigService
+ : public net::ProxyConfigService,
+ public net::ProxyConfigService::Observer {
public:
- // Observer interface used to send out notifications on the IO thread about
- // changes to the proxy configuration.
- class Observer {
- public:
- virtual ~Observer() {}
- virtual void OnPrefProxyConfigChanged() = 0;
- };
+ // Takes ownership of the passed |base_service|.
+ explicit ChromeProxyConfigService(net::ProxyConfigService* base_service);
+ virtual ~ChromeProxyConfigService();
- // Return codes for GetProxyConfig.
- enum ConfigState {
- // Configuration is valid and present.
- CONFIG_PRESENT,
- // There is a fallback configuration present.
- CONFIG_FALLBACK,
- // Configuration is known to be not set.
- CONFIG_UNSET,
- };
+ // ProxyConfigService implementation:
+ virtual void AddObserver(net::ProxyConfigService::Observer* observer);
+ virtual void RemoveObserver(net::ProxyConfigService::Observer* observer);
+ virtual ConfigAvailability GetLatestProxyConfig(net::ProxyConfig* config);
+ virtual void OnLazyPoll();
+ // Method on IO thread that receives the preference proxy settings pushed from
+ // PrefProxyConfigTracker.
+ void UpdateProxyConfig(ProxyPrefs::ConfigState config_state,
+ const net::ProxyConfig& config);
+
+ private:
+ // ProxyConfigService::Observer implementation:
+ virtual void OnProxyConfigChanged(const net::ProxyConfig& config,
+ ConfigAvailability availability);
+
+ // Makes sure that the observer registration with the base service is set up.
+ void RegisterObserver();
+
+ scoped_ptr<net::ProxyConfigService> base_service_;
+ ObserverList<net::ProxyConfigService::Observer, true> observers_;
+
+ // Tracks configuration state of |pref_config_|. |pref_config_| is valid only
+ // if |pref_config_state_| is not CONFIG_UNSET.
+ ProxyPrefs::ConfigState pref_config_state_;
+
+ // Configuration as defined by prefs.
+ net::ProxyConfig pref_config_;
+
+ // Indicates whether the base service registration is done.
+ bool registered_observer_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChromeProxyConfigService);
+};
+
+// A class that tracks proxy preferences. It translates the configuration
+// to net::ProxyConfig and pushes the result over to the IO thread for
+// ChromeProxyConfigService::UpdateProxyConfig to use.
+class PrefProxyConfigTracker : public content::NotificationObserver {
+ public:
explicit PrefProxyConfigTracker(PrefService* pref_service);
+ virtual ~PrefProxyConfigTracker();
- // Observer manipulation is only valid on the IO thread.
- void AddObserver(Observer* observer);
- void RemoveObserver(Observer* observer);
+ // Sets the proxy config service to push the preference proxy to.
+ void SetChromeProxyConfigService(
+ ChromeProxyConfigService* proxy_config_service);
- // Get the proxy configuration currently defined by preferences. Status is
- // indicated in the return value. Writes the configuration to |config| unless
- // the return value is CONFIG_UNSET, in which case |config| is not touched.
- ConfigState GetProxyConfig(net::ProxyConfig* config);
-
// Notifies the tracker that the pref service passed upon construction is
// about to go away. This must be called from the UI thread.
void DetachFromPrefService();
- private:
- friend class base::RefCountedThreadSafe<PrefProxyConfigTracker>;
- virtual ~PrefProxyConfigTracker();
+ // Determines if |config_state| takes precedence regardless, which happens if
+ // config is from policy or extension or other-precede.
+ static bool PrefPrecedes(ProxyPrefs::ConfigState config_state);
- // NotificationObserver implementation:
- virtual void Observe(int type,
- const NotificationSource& source,
- const NotificationDetails& details);
+ // Determines the proxy configuration that should take effect in the network
+ // layer, based on prefs and system configurations.
+ // |pref_state| refers to state of |pref_config|.
+ // |system_availability| refers to availability of |system_config|.
+ // |ignore_fallback_config| indicates if fallback config from prefs should
+ // be ignored.
+ // Returns effective |effective_config| and its state in
+ // |effective_config_source|.
+ static net::ProxyConfigService::ConfigAvailability GetEffectiveProxyConfig(
+ ProxyPrefs::ConfigState pref_state,
+ const net::ProxyConfig& pref_config,
+ net::ProxyConfigService::ConfigAvailability system_availability,
+ const net::ProxyConfig& system_config,
+ bool ignore_fallback_config,
+ ProxyPrefs::ConfigState* effective_config_state,
+ net::ProxyConfig* effective_config);
- // Install a new configuration. This is invoked on the IO thread to update
- // the internal state after handling a pref change on the UI thread.
- // |config_state| indicates the new state we're switching to, and |config| is
- // the new preference-based proxy configuration if |config_state| is different
- // from CONFIG_UNSET.
- void InstallProxyConfig(const net::ProxyConfig& config, ConfigState state);
+ // Registers the proxy preference.
+ static void RegisterPrefs(PrefService* user_prefs);
- // Creates a proxy configuration from proxy-related preferences. Configuration
- // is stored in |config| and the return value indicates whether the
- // configuration is valid.
- ConfigState ReadPrefConfig(net::ProxyConfig* config);
+ protected:
+ // Get the proxy configuration currently defined by preferences.
+ // Status is indicated in the return value.
+ // Writes the configuration to |config| unless the return value is
+ // CONFIG_UNSET, in which case |config| and |config_source| are not touched.
+ ProxyPrefs::ConfigState GetProxyConfig(net::ProxyConfig* config);
+ // Called when there's a change in prefs proxy config.
+ // Subclasses can extend it for changes in other sources of proxy config.
+ virtual void OnProxyConfigChanged(ProxyPrefs::ConfigState config_state,
willchan no longer on Chromium 2011/11/02 23:08:17 Should this be private? Who calls this?
kuan 2011/11/03 20:20:14 chromeos variant extends this class and calls this
+ const net::ProxyConfig& config);
+
+ // content::NotificationObserver implementation:
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details);
+
// Converts a ProxyConfigDictionary to net::ProxyConfig representation.
// Returns true if the data from in the dictionary is valid, false otherwise.
- static bool PrefConfigToNetConfig(const ProxyConfigDictionary& proxy_dict,
- net::ProxyConfig* config);
+ bool PrefConfigToNetConfig(const ProxyConfigDictionary& proxy_dict,
+ net::ProxyConfig* config);
- // Configuration as defined by prefs. Only to be accessed from the IO thread
- // (except for construction).
- net::ProxyConfig pref_config_;
+ const PrefService* prefs() const { return pref_service_; }
+ bool update_pending() const { return update_pending_; }
+ private:
+ // Creates a proxy configuration from proxy-related preferences. Configuration
+ // is stored in |config|, return value indicates whether the configuration is
+ // valid.
+ ProxyPrefs::ConfigState ReadPrefConfig(net::ProxyConfig* config);
+
// Tracks configuration state. |pref_config_| is valid only if |config_state_|
// is not CONFIG_UNSET.
- ConfigState config_state_;
+ ProxyPrefs::ConfigState config_state_;
- // List of observers, accessed exclusively from the IO thread.
- ObserverList<Observer, true> observers_;
+ // Configuration as defined by prefs.
+ net::ProxyConfig pref_config_;
- // Pref-related members that should only be accessed from the UI thread.
PrefService* pref_service_;
+ ChromeProxyConfigService* chrome_proxy_config_service_; // Weak ptr.
+ bool update_pending_; // True if config has not been pushed to network stack.
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 net::ProxyConfigService::Observer,
- public PrefProxyConfigTracker::Observer {
- public:
- // Takes ownership of the passed |base_service|.
- PrefProxyConfigService(PrefProxyConfigTracker* tracker,
- net::ProxyConfigService* base_service);
- virtual ~PrefProxyConfigService();
+#if defined(OS_CHROMEOS)
+typedef chromeos::ProxyConfigServiceImpl PrefProxyConfigTrackerType;
willchan no longer on Chromium 2011/11/02 23:08:17 Is PrefProxyConfigTracker used in chromeos? If not
kuan 2011/11/03 20:20:14 chromeos variant extends PrefProxyConfigTracker, s
+#else
+typedef PrefProxyConfigTracker PrefProxyConfigTrackerType;
+#endif // defined(OS_CHROMEOS)
- // ProxyConfigService implementation:
- virtual void AddObserver(net::ProxyConfigService::Observer* observer);
- virtual void RemoveObserver(net::ProxyConfigService::Observer* observer);
- virtual ConfigAvailability GetLatestProxyConfig(net::ProxyConfig* config);
- virtual void OnLazyPoll();
-
- static void RegisterPrefs(PrefService* user_prefs);
-
- private:
- // ProxyConfigService::Observer implementation:
- virtual void OnProxyConfigChanged(const net::ProxyConfig& config,
- ConfigAvailability availability);
-
- // 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_
+#endif // CHROME_BROWSER_NET_PREF_PROXY_CONFIG_TRACKER_H_
Property changes on: chrome/browser/net/pref_proxy_config_tracker.h
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698