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

Side by Side Diff: chrome/browser/net/resolve_proxy_msg_helper.h

Issue 14142: Start using the proxy resolve IPC for plugins.... (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 | « chrome/browser/browser.vcproj ('k') | chrome/browser/net/resolve_proxy_msg_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 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_RESOLVE_PROXY_MSG_HELPER_
6 #define CHROME_BROWSER_NET_RESOLVE_PROXY_MSG_HELPER_
7
8 #include <deque>
9 #include <string>
10
11 #include "chrome/common/ipc_message.h"
12 #include "net/base/completion_callback.h"
13 #include "googleurl/src/gurl.h"
14 #include "net/proxy/proxy_service.h"
15
16 // This class holds the common logic used to respond to the messages:
17 // {PluginProcessHostMsg_ResolveProxy, ViewHostMsg_ResolveProxy}.
18 //
19 // This involves kicking off a ProxyResolve request on the IO thread using
20 // the specified proxy service.
21 //
22 // When the request completes, it calls the delegate's OnProxyResolveCompleted()
23 // method, passing it the result (error code + proxy list), as well as the
24 // IPC::Message pointer that had been stored.
25 //
26 // When an instance of ResolveProxyMsgHelper is destroyed, it cancels any
27 // outstanding proxy resolve requests with the proxy service. It also deletes
28 // the stored IPC::Message pointers for pending requests.
29 //
30 // This object is expected to live on the IO thread.
31 class ResolveProxyMsgHelper {
32 public:
33 class Delegate {
34 public:
35 // Callback for when the proxy resolve request has completed.
36 // |reply_msg| -- The same pointer that the request was started with.
37 // |result| -- The network error code from ProxyService.
38 // |proxy_list| -- The PAC string result from ProxyService.
39 virtual void OnResolveProxyCompleted(IPC::Message* reply_msg,
40 int result,
41 const std::string& proxy_list) = 0;
42 virtual ~Delegate() {}
43 };
44
45 // Construct a ResolveProxyMsgHelper instance that notifies request
46 // completion to |delegate|. Note that |delegate| must be live throughout
47 // our lifespan. If |proxy_service| is NULL, then the current profile's
48 // proxy service will be used.
49 explicit ResolveProxyMsgHelper(Delegate* delegate,
50 net::ProxyService* proxy_service);
51
52 // Resolve proxies for |url|. Completion is notified through the delegate.
53 // If multiple requests are started at the same time, they will run in
54 // FIFO order, with only 1 being outstanding at a time.
55 void Start(const GURL& url, IPC::Message* reply_msg);
56
57 // Destruction cancels the current outstanding request, and clears the
58 // pending queue.
59 ~ResolveProxyMsgHelper();
60
61 private:
62 // Callback for the ProxyService (bound to |callback_|).
63 void OnResolveProxyCompleted(int result);
64
65 // Start the first pending request.
66 void StartPendingRequest();
67
68 // Get the proxy service instance to use.
69 net::ProxyService* GetProxyService() const;
70
71 // A PendingRequest is a resolve request that is in progress, or queued.
72 struct PendingRequest {
73 public:
74 PendingRequest(const GURL& url, IPC::Message* reply_msg) :
75 url(url), reply_msg(reply_msg), pac_req(NULL) { }
76
77 // The URL of the request.
78 GURL url;
79
80 // Data to pass back to the delegate on completion (we own it until then).
81 IPC::Message* reply_msg;
82
83 // Handle for cancelling the current request if it has started (else NULL).
84 net::ProxyService::PacRequest* pac_req;
85 };
86
87 // Members for the current outstanding proxy request.
88 net::ProxyService* proxy_service_;
89 net::CompletionCallbackImpl<ResolveProxyMsgHelper> callback_;
90 net::ProxyInfo proxy_info_;
91
92 // FIFO queue of pending requests. The first entry is always the current one.
93 typedef std::deque<PendingRequest> PendingRequestList;
94 PendingRequestList pending_requests_;
95
96 Delegate* delegate_;
97
98 // Specified by unit-tests, to use this proxy service in place of the
99 // global one.
100 net::ProxyService* proxy_service_override_;
101 };
102
103 #endif // CHROME_BROWSER_NET_RESOLVE_PROXY_MSG_HELPER_
OLDNEW
« no previous file with comments | « chrome/browser/browser.vcproj ('k') | chrome/browser/net/resolve_proxy_msg_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698