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

Side by Side Diff: net/proxy/proxy_service.h

Issue 19502: Get rid of synchronous ResolveProxy API. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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
« no previous file with comments | « no previous file | net/proxy/proxy_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 NET_PROXY_PROXY_SERVICE_H_ 5 #ifndef NET_PROXY_PROXY_SERVICE_H_
6 #define NET_PROXY_PROXY_SERVICE_H_ 6 #define NET_PROXY_PROXY_SERVICE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/ref_counted.h" 11 #include "base/ref_counted.h"
12 #include "base/scoped_ptr.h" 12 #include "base/scoped_ptr.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/thread.h" 14 #include "base/thread.h"
15 #include "base/time.h" 15 #include "base/time.h"
16 #include "base/waitable_event.h"
16 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
17 #include "net/base/completion_callback.h" 18 #include "net/base/completion_callback.h"
18 19
19 #if defined(OS_WIN)
20 typedef LPVOID HINTERNET; // From winhttp.h
21 #endif
22
23 class GURL; 20 class GURL;
24 21
25 namespace net { 22 namespace net {
26 23
27 class ProxyConfigService; 24 class ProxyConfigService;
28 class ProxyInfo; 25 class ProxyInfo;
29 class ProxyResolver; 26 class ProxyResolver;
30 27
31 // Proxy configuration used to by the ProxyService. 28 // Proxy configuration used to by the ProxyService.
32 class ProxyConfig { 29 class ProxyConfig {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // resolution. See ProxyResolverWinHttp for example. 83 // resolution. See ProxyResolverWinHttp for example.
87 class ProxyService { 84 class ProxyService {
88 public: 85 public:
89 // The instance takes ownership of |config_service| and |resolver|. 86 // The instance takes ownership of |config_service| and |resolver|.
90 ProxyService(ProxyConfigService* config_service, 87 ProxyService(ProxyConfigService* config_service,
91 ProxyResolver* resolver); 88 ProxyResolver* resolver);
92 89
93 // Used internally to handle PAC queries. 90 // Used internally to handle PAC queries.
94 class PacRequest; 91 class PacRequest;
95 92
96 // Returns OK if proxy information could be provided synchronously. Else, 93 // Returns ERR_IO_PENDING if the proxy information could not be provided
wtc 2009/01/30 23:06:06 Ah, so this block comment still needs to be update
97 // ERR_IO_PENDING is returned to indicate that the result will be available 94 // synchronously, to indicate that the result will be available when the
98 // when the callback is run. The callback is run on the thread that calls 95 // callback is run. The callback is run on the thread that calls
99 // ResolveProxy. 96 // ResolveProxy.
100 // 97 //
101 // The caller is responsible for ensuring that |results| and |callback| 98 // The caller is responsible for ensuring that |results| and |callback|
102 // remain valid until the callback is run or until |pac_request| is cancelled 99 // remain valid until the callback is run or until |pac_request| is cancelled
103 // via CancelPacRequest. |pac_request| is only valid while the completion 100 // via CancelPacRequest. |pac_request| is only valid while the completion
104 // callback is still pending. NULL can be passed for |pac_request| if 101 // callback is still pending. NULL can be passed for |pac_request| if
105 // the caller will not need to cancel the request. 102 // the caller will not need to cancel the request.
106 // 103 //
107 // We use the three possible proxy access types in the following order, and 104 // We use the three possible proxy access types in the following order, and
108 // we only use one of them (no falling back to other access types if the 105 // we only use one of them (no falling back to other access types if the
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 // Use the same proxy server as the given |proxy_info|. 235 // Use the same proxy server as the given |proxy_info|.
239 void Use(const ProxyInfo& proxy_info); 236 void Use(const ProxyInfo& proxy_info);
240 237
241 // Use a direct connection. 238 // Use a direct connection.
242 void UseDirect(); 239 void UseDirect();
243 240
244 // Use a specific proxy server, of the form: <hostname> [":" <port>] 241 // Use a specific proxy server, of the form: <hostname> [":" <port>]
245 // This may optionally be a semi-colon delimited list of proxy servers. 242 // This may optionally be a semi-colon delimited list of proxy servers.
246 void UseNamedProxy(const std::string& proxy_server); 243 void UseNamedProxy(const std::string& proxy_server);
247 244
248 #if defined(OS_WIN)
249 // Apply this proxy information to the given WinHTTP request handle.
250 void Apply(HINTERNET request_handle);
251 #endif
252
253 // Returns true if this proxy info specifies a direct connection. 245 // Returns true if this proxy info specifies a direct connection.
254 bool is_direct() const { return proxy_list_.Get().empty(); } 246 bool is_direct() const { return proxy_list_.Get().empty(); }
255 247
256 // Returns the first valid proxy server. 248 // Returns the first valid proxy server.
257 std::string proxy_server() const { return proxy_list_.Get(); } 249 std::string proxy_server() const { return proxy_list_.Get(); }
258 250
259 // See description in ProxyList::GetAnnotatedList(). 251 // See description in ProxyList::GetAnnotatedList().
260 std::string GetAnnotatedProxyList(); 252 std::string GetAnnotatedProxyList();
261 253
262 // Marks the current proxy as bad. Returns true if there is another proxy 254 // Marks the current proxy as bad. Returns true if there is another proxy
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 virtual ~ProxyResolver() {} 297 virtual ~ProxyResolver() {}
306 298
307 // Query the proxy auto-config file (specified by |pac_url|) for the proxy to 299 // Query the proxy auto-config file (specified by |pac_url|) for the proxy to
308 // use to load the given |query_url|. Returns OK if successful or an error 300 // use to load the given |query_url|. Returns OK if successful or an error
309 // code otherwise. 301 // code otherwise.
310 virtual int GetProxyForURL(const GURL& query_url, 302 virtual int GetProxyForURL(const GURL& query_url,
311 const GURL& pac_url, 303 const GURL& pac_url,
312 ProxyInfo* results) = 0; 304 ProxyInfo* results) = 0;
313 }; 305 };
314 306
307 // Wrapper for invoking methods on a ProxyService synchronously.
308 class SyncProxyServiceHelper
309 : public base::RefCountedThreadSafe<SyncProxyServiceHelper> {
310 public:
311 SyncProxyServiceHelper(MessageLoop* io_message_loop,
312 ProxyService* proxy_service);
313
314 int ResolveProxy(const GURL& url, ProxyInfo* proxy_info);
315 int ReconsiderProxyAfterError(const GURL& url, ProxyInfo* proxy_info);
316
317 private:
318 void StartAsyncResolve(const GURL& url);
319 void StartAsyncReconsider(const GURL& url);
320
321 void OnCompletion(int result);
322
323 MessageLoop* io_message_loop_;
324 ProxyService* proxy_service_;
325
326 base::WaitableEvent event_;
327 CompletionCallbackImpl<SyncProxyServiceHelper> callback_;
328 ProxyInfo proxy_info_;
329 int result_;
330 };
331
315 } // namespace net 332 } // namespace net
316 333
317 #endif // NET_PROXY_PROXY_SERVICE_H_ 334 #endif // NET_PROXY_PROXY_SERVICE_H_
318 335
OLDNEW
« no previous file with comments | « no previous file | net/proxy/proxy_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698