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

Side by Side Diff: chrome/browser/chromeos/proxy_config_service_impl.h

Issue 3047052: chromeos: 1st draft of ProxyConfigService for chromeos... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_
6 #define CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_
7 #pragma once
8
9 #include <string>
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "base/observer_list.h"
14 #include "base/ref_counted.h"
15 #include "base/scoped_ptr.h"
16 #include "net/proxy/proxy_config.h"
17 #include "net/proxy/proxy_config_service.h"
18 #include "net/proxy/proxy_server.h"
19
20 namespace chromeos {
21
22 // Implementation of proxy config service for chromeos that:
23 // - is RefCountedThreadSafe
24 // - is wrapped by chromeos::ProxyConfigService which implements
25 // net::ProxyConfigService interface by fowarding the methods to this class
26 // - retrieves initial system proxy configuration from cros settings persisted
27 // on chromeos device
28 // - provides network stack with latest system proxy configuration for use on
29 // IO thread
30 // - provides UI with methods to retrieve and modify system proxy configuration
31 // on UI thread
32 // - TODO(kuan): persists proxy configuration settings on chromeos device using
33 // cros settings
34 class ProxyConfigServiceImpl
35 : public base::RefCountedThreadSafe<ProxyConfigServiceImpl> {
36 public:
37 // ProxyConfigServiceImpl is created on the UI thread in
38 // chrome/browser/net/chrome_url_request_context.cc::CreateProxyConfigService
39 // via ProfileImpl::GetChromeOSProxyConfigServiceImpl, and stored in Profile
40 // as a scoped_refptr (because it's RefCountedThreadSafe).
41 //
42 // Past that point, it can be accessed from the IO or UI threads.
43 //
44 // From the IO thread, it is accessed periodically through the wrapper class
45 // chromeos::ProxyConfigService via net::ProxyConfigService interface
46 // (GetLatestProxyConfig, AddObserver, RemoveObserver).
47 //
48 // From the UI thread, it is accessed via
49 // DOMUI::GetProfile::GetChromeOSProxyConfigServiceImpl to allow user to read
50 // or modify the proxy configuration via UIGetProxyConfig or
51 // UISetProxyConfigTo* respectively.
52 // The new modified proxy config is posted to the IO thread through
53 // SetNewProxyConfig(). We then notify observers on the IO thread of the
54 // configuration change.
55
56 // In contrary to other platforms which simply use the systems' UI to allow
57 // users to configure proxies, we have to implement our own UI on the chromeos
58 // device. This requires extra and specific UI requirements that
59 // net::ProxyConfig does not suffice. So we create an augmented analog to
60 // net:ProxyConfig here to include and handle these UI requirements, e.g.
61 // - where configuration was picked up from - policy or owner
62 // - the read/write access of a proxy setting
63 // - may add more stuff later.
64 // This is then converted to the common net::ProxyConfig before being returned
65 // to ProxyService::GetLatestProxyConfig on the IO thread to be used on the
66 // network stack.
67 struct ProxyConfig {
68 // Specifies if proxy config is direct, auto-detect, using pac script,
69 // single-proxy, or proxy-per-scheme.
70 enum Mode {
71 MODE_DIRECT,
72 MODE_AUTO_DETECT,
73 MODE_PAC_SCRIPT,
74 MODE_SINGLE_PROXY,
75 MODE_PROXY_PER_SCHEME,
76 };
77
78 // Specifies where proxy configuration was picked up from.
79 enum Source {
80 SOURCE_NONE, // No default configuration.
81 SOURCE_POLICY, // Configuration is from policy.
82 SOURCE_OWNER, // Configuration is from owner.
83 };
84
85 struct Setting {
86 Setting() : source(SOURCE_NONE) {}
87
88 Source source;
89 bool CanBeWrittenByUser(bool user_is_owner);
90 };
91
92 // Proxy setting for mode = direct or auto-detect or using pac script.
93 struct AutomaticProxy : public Setting {
94 GURL pac_url; // Set if proxy is using pac script.
95 };
96
97 // Proxy setting for mode = single-proxy or proxy-per-scheme.
98 struct ManualProxy : public Setting {
99 net::ProxyServer server;
100 };
101
102 ProxyConfig() : mode(MODE_DIRECT) {}
103
104 // Converts |this| to net::ProxyConfig.
105 void ConvertToNetProxyConfig(net::ProxyConfig* net_config);
106
107 // Creates a textual dump of the configuration.
108 std::string ToString() const;
109
110 Mode mode;
111
112 // Set if mode is MODE_DIRECT or MODE_AUTO_DETECT or MODE_PAC_SCRIPT.
113 AutomaticProxy automatic_proxy;
114 // Set if mode is MODE_SINGLE_PROXY.
115 ManualProxy single_proxy;
116 // Set if mode is MODE_PROXY_PER_SCHEME and has http proxy.
117 ManualProxy http_proxy;
118 // Set if mode is MODE_PROXY_PER_SCHEME and has https proxy.
119 ManualProxy https_proxy;
120 // Set if mode is MODE_PROXY_PER_SCHEME and has ftp proxy.
121 ManualProxy ftp_proxy;
122 // Set if mode is MODE_PROXY_PER_SCHEME and has socks proxy.
123 ManualProxy socks_proxy;
124
125 // Exceptions for when not to use a proxy.
126 net::ProxyBypassRules bypass_rules;
127 };
128
129 // Usual constructor.
130 ProxyConfigServiceImpl();
131 // Constructor for testing.
132 // |init_config| specifies the ProxyConfig to use for initialization.
133 explicit ProxyConfigServiceImpl(const ProxyConfig& init_config);
134 virtual ~ProxyConfigServiceImpl();
135
136 // Methods called on IO thread from wrapper class chromeos::ProxyConfigService
137 // as ProxyConfigService methods.
138 void AddObserver(net::ProxyConfigService::Observer* observer);
139 void RemoveObserver(net::ProxyConfigService::Observer* observer);
140 // Called from GetLatestProxyConfig.
141 bool IOGetProxyConfig(net::ProxyConfig* config);
142
143 // Called from UI thread to retrieve proxy configuration in |config|.
144 void UIGetProxyConfig(ProxyConfig* config);
145
146 // Called from UI thread to update proxy configuration for different modes.
147 void UISetProxyConfigToDirect();
148 void UISetProxyConfigToAutoDetect();
149 void UISetProxyConfigToPACScript(const GURL& url);
150 void UISetProxyConfigToSingleProxy(const net::ProxyServer& server);
151 void UISetProxyConfigToProxyPerScheme(const std::string& scheme,
152 const net::ProxyServer& server);
153 // Only valid for MODE_SINGLE_PROXY or MODE_PROXY_PER_SCHEME.
154 void UISetProxyConfigBypassRules(const net::ProxyBypassRules& bypass_rules);
155
156 private:
157 friend class base::RefCountedThreadSafe<ProxyConfigServiceImpl>;
158
159 // Called from UI thread from the various UISetProxyConfigTo*
160 void OnUISetProxyConfig();
161
162 // Posted from UI thread to IO thread to carry the new config information.
163 void IOSetProxyConfig(const ProxyConfig& new_config);
164
165 // Checks that method is called on ChromeThread::IO thread.
166 void CheckCurrentlyOnIOThread();
167
168 // Checks that method is called on ChromeThread::UI thread.
169 void CheckCurrentlyOnUIThread();
170
171 // Data members.
172
173 // Cached proxy configuration, to be converted to net::ProxyConfig and
174 // returned by IOGetProxyConfig.
175 // Initially populated from the UI thread, but afterwards only accessed from
176 // the IO thread.
177 ProxyConfig cached_config_;
178
179 // Copy of the proxy configuration kept on the UI thread of the last seen
180 // proxy config, so as to avoid posting a call to SetNewProxyConfig when we
181 // are called by UI to set new proxy but the config has not actually changed.
182 ProxyConfig reference_config_;
183
184 ObserverList<net::ProxyConfigService::Observer> observers_;
185
186 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceImpl);
187 };
188
189 } // namespace chromeos
190
191 #endif // CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/proxy_config_service.h ('k') | chrome/browser/chromeos/proxy_config_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698