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

Side by Side Diff: chrome/browser/net/pref_proxy_config_service.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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_NET_PREF_PROXY_CONFIG_SERVICE_H_ 5 #ifndef CHROME_BROWSER_NET_PREF_PROXY_CONFIG_SERVICE_H_
6 #define CHROME_BROWSER_NET_PREF_PROXY_CONFIG_SERVICE_H_ 6 #define CHROME_BROWSER_NET_PREF_PROXY_CONFIG_SERVICE_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 25 matching lines...) Expand all
36 // Return codes for GetProxyConfig. 36 // Return codes for GetProxyConfig.
37 enum ConfigState { 37 enum ConfigState {
38 // Configuration is valid and present. 38 // Configuration is valid and present.
39 CONFIG_PRESENT, 39 CONFIG_PRESENT,
40 // There is a fallback configuration present. 40 // There is a fallback configuration present.
41 CONFIG_FALLBACK, 41 CONFIG_FALLBACK,
42 // Configuration is known to be not set. 42 // Configuration is known to be not set.
43 CONFIG_UNSET, 43 CONFIG_UNSET,
44 }; 44 };
45 45
46 // Source of proxy configuration, returned togther when proxy config is
47 // retrieved.
48 enum ConfigSource {
Mattias Nissler (ping if slow) 2011/10/07 13:32:10 ConfigState and ConfigSource are basically doing t
kuan 2011/10/18 16:25:35 Done.
49 // Configuration souce is not set.
50 CONFIG_SOURCE_UNSET,
51 // Configuration is from policy.
52 CONFIG_SOURCE_POLICY,
53 // Configuration is from extension.
54 CONFIG_SOURCE_EXTENSION,
55 // Configuration is from recommended i..e fallback.
56 CONFIG_SOURCE_FALLBACK,
57 // Configuration is from sytem. (PrefProxyConfigTracker doesn't use this,
58 // but we define it so that system proxy config services can use it).
59 CONFIG_SOURCE_SYSTEM,
60 };
61
46 explicit PrefProxyConfigTracker(PrefService* pref_service); 62 explicit PrefProxyConfigTracker(PrefService* pref_service);
47 63
48 // Observer manipulation is only valid on the IO thread. 64 // Observer manipulation is only valid on the IO thread.
49 void AddObserver(Observer* observer); 65 void AddObserver(Observer* observer);
50 void RemoveObserver(Observer* observer); 66 void RemoveObserver(Observer* observer);
51 67
52 // Get the proxy configuration currently defined by preferences. Status is 68 // Get the proxy configuration currently defined by preferences on the IO
53 // indicated in the return value. Writes the configuration to |config| unless 69 // UI threads respectively. Status is indicated in the return value.
54 // the return value is CONFIG_UNSET, in which case |config| is not touched. 70 // Writes the configuration to |config| and its source to |config_source|
55 ConfigState GetProxyConfig(net::ProxyConfig* config); 71 // unless the return value is CONFIG_UNSET, in which case |config| and
72 // |config_source| are not touched.
73 ConfigState IOGetProxyConfig(net::ProxyConfig* config,
74 ConfigSource* config_source);
75 ConfigState UIGetProxyConfig(net::ProxyConfig* config,
76 ConfigSource* config_source);
56 77
57 // Notifies the tracker that the pref service passed upon construction is 78 // Notifies the tracker that the pref service passed upon construction is
58 // about to go away. This must be called from the UI thread. 79 // about to go away. This must be called from the UI thread.
59 void DetachFromPrefService(); 80 void DetachFromPrefService();
60 81
82 // Converts a ProxyConfigDictionary to net::ProxyConfig representation.
83 // Returns true if the data from in the dictionary is valid, false otherwise.
84 static bool PrefConfigToNetConfig(const ProxyConfigDictionary& proxy_dict,
85 net::ProxyConfig* config);
86
61 private: 87 private:
62 friend class base::RefCountedThreadSafe<PrefProxyConfigTracker>; 88 friend class base::RefCountedThreadSafe<PrefProxyConfigTracker>;
63 virtual ~PrefProxyConfigTracker(); 89 virtual ~PrefProxyConfigTracker();
64 90
65 // NotificationObserver implementation: 91 // NotificationObserver implementation:
66 virtual void Observe(int type, 92 virtual void Observe(int type,
67 const NotificationSource& source, 93 const NotificationSource& source,
68 const NotificationDetails& details); 94 const NotificationDetails& details);
69 95
70 // Install a new configuration. This is invoked on the IO thread to update 96 // Install a new configuration. This is invoked on the IO thread to update
71 // the internal state after handling a pref change on the UI thread. 97 // the internal state after handling a pref change on the UI thread.
72 // |config_state| indicates the new state we're switching to, and |config| is 98 // |config_state| indicates the new state we're switching to, and |config| is
73 // the new preference-based proxy configuration if |config_state| is different 99 // the new preference-based proxy configuration if |config_state| is different
74 // from CONFIG_UNSET. 100 // from CONFIG_UNSET, |source| is the new source of |config|.
75 void InstallProxyConfig(const net::ProxyConfig& config, ConfigState state); 101 void InstallProxyConfig(const net::ProxyConfig& config, ConfigState state,
102 ConfigSource source);
76 103
77 // Creates a proxy configuration from proxy-related preferences. Configuration 104 // Creates a proxy configuration from proxy-related preferences. Configuration
78 // is stored in |config| and the return value indicates whether the 105 // is stored in |config| and its source in |config_source|, return value
79 // configuration is valid. 106 // indicates whether the configuration is valid.
80 ConfigState ReadPrefConfig(net::ProxyConfig* config); 107 ConfigState ReadPrefConfig(net::ProxyConfig* config,
108 ConfigSource* config_source);
81 109
82 // Converts a ProxyConfigDictionary to net::ProxyConfig representation. 110 // Configuration as defined by prefs. Only to be accessed from UI thread.
83 // Returns true if the data from in the dictionary is valid, false otherwise. 111 net::ProxyConfig ui_pref_config_;
84 static bool PrefConfigToNetConfig(const ProxyConfigDictionary& proxy_dict,
85 net::ProxyConfig* config);
86 112
87 // Configuration as defined by prefs. Only to be accessed from the IO thread 113 // Tracks configuration state. |ui_pref_config_| is valid only if
88 // (except for construction). 114 // |ui_config_state_| is not CONFIG_UNSET.
89 net::ProxyConfig pref_config_; 115 ConfigState ui_config_state_;
90 116
91 // Tracks configuration state. |pref_config_| is valid only if |config_state_| 117 // Tracks source of |ui_pref_config_|.
92 // is not CONFIG_UNSET. 118 ConfigSource ui_config_source_;
93 ConfigState config_state_; 119
120 // Configuration as defined by prefs. Only to be accessed from
121 // IO thread, except for construction on UI thread.
122 net::ProxyConfig io_pref_config_;
123
124 // Tracks configuration state. |io_pref_config_| is valid only if
125 // |io_config_state_| is not CONFIG_UNSET.
126 ConfigState io_config_state_;
127
128 // Tracks source of |io_pref_config_|.
129 ConfigSource io_config_source_;
94 130
95 // List of observers, accessed exclusively from the IO thread. 131 // List of observers, accessed exclusively from the IO thread.
96 ObserverList<Observer, true> observers_; 132 ObserverList<Observer, true> observers_;
97 133
98 // Pref-related members that should only be accessed from the UI thread. 134 // Pref-related members that should only be accessed from the UI thread.
99 PrefService* pref_service_; 135 PrefService* pref_service_;
100 scoped_ptr<PrefSetObserver> proxy_prefs_observer_; 136 scoped_ptr<PrefSetObserver> proxy_prefs_observer_;
101 137
102 DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigTracker); 138 DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigTracker);
103 }; 139 };
104 140
141 class ProxyConfigDecider {
142 public:
143 ProxyConfigDecider() {}
144 virtual ~ProxyConfigDecider() {}
145
146 net::ProxyConfigService::ConfigAvailability GetEffectiveProxyConfig(
147 PrefProxyConfigTracker::ConfigState pref_state,
148 const net::ProxyConfig& pref_config,
149 PrefProxyConfigTracker::ConfigSource pref_source,
150 net::ProxyConfigService::ConfigAvailability system_availability,
151 const net::ProxyConfig& system_config,
152 bool ignore_fallback_config,
153 net::ProxyConfig* config,
154 PrefProxyConfigTracker::ConfigSource* config_source);
155
156 private:
157 DISALLOW_COPY_AND_ASSIGN(ProxyConfigDecider);
158 };
159
105 // A net::ProxyConfigService implementation that applies preference proxy 160 // A net::ProxyConfigService implementation that applies preference proxy
106 // settings as overrides to the proxy configuration determined by a baseline 161 // settings as overrides to the proxy configuration determined by a baseline
107 // delegate ProxyConfigService. 162 // delegate ProxyConfigService.
108 class PrefProxyConfigService 163 class PrefProxyConfigService
109 : public net::ProxyConfigService, 164 : public net::ProxyConfigService,
110 public net::ProxyConfigService::Observer, 165 public net::ProxyConfigService::Observer,
111 public PrefProxyConfigTracker::Observer { 166 public PrefProxyConfigTracker::Observer,
167 public ProxyConfigDecider {
112 public: 168 public:
113 // Takes ownership of the passed |base_service|. 169 // Takes ownership of the passed |base_service|.
114 PrefProxyConfigService(PrefProxyConfigTracker* tracker, 170 PrefProxyConfigService(PrefProxyConfigTracker* tracker,
115 net::ProxyConfigService* base_service); 171 net::ProxyConfigService* base_service);
116 virtual ~PrefProxyConfigService(); 172 virtual ~PrefProxyConfigService();
117 173
118 // ProxyConfigService implementation: 174 // ProxyConfigService implementation:
119 virtual void AddObserver(net::ProxyConfigService::Observer* observer); 175 virtual void AddObserver(net::ProxyConfigService::Observer* observer);
120 virtual void RemoveObserver(net::ProxyConfigService::Observer* observer); 176 virtual void RemoveObserver(net::ProxyConfigService::Observer* observer);
121 virtual ConfigAvailability GetLatestProxyConfig(net::ProxyConfig* config); 177 virtual ConfigAvailability GetLatestProxyConfig(net::ProxyConfig* config);
(...skipping 17 matching lines...) Expand all
139 ObserverList<net::ProxyConfigService::Observer, true> observers_; 195 ObserverList<net::ProxyConfigService::Observer, true> observers_;
140 scoped_refptr<PrefProxyConfigTracker> pref_config_tracker_; 196 scoped_refptr<PrefProxyConfigTracker> pref_config_tracker_;
141 197
142 // Indicates whether the base service and tracker registrations are done. 198 // Indicates whether the base service and tracker registrations are done.
143 bool registered_observers_; 199 bool registered_observers_;
144 200
145 DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigService); 201 DISALLOW_COPY_AND_ASSIGN(PrefProxyConfigService);
146 }; 202 };
147 203
148 #endif // CHROME_BROWSER_NET_PREF_PROXY_CONFIG_SERVICE_H_ 204 #endif // CHROME_BROWSER_NET_PREF_PROXY_CONFIG_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698