Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / browser / resolve_proxy_msg_helper.h
blob167d946e545a89c4519ccdca756bfcbf9eed7fdc
1 // Copyright (c) 2012 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.
5 #ifndef CONTENT_BROWSER_RESOLVE_PROXY_MSG_HELPER_H_
6 #define CONTENT_BROWSER_RESOLVE_PROXY_MSG_HELPER_H_
8 #include <deque>
9 #include <string>
11 #include "base/memory/ref_counted.h"
12 #include "content/common/content_export.h"
13 #include "content/public/browser/browser_message_filter.h"
14 #include "net/base/completion_callback.h"
15 #include "net/proxy/proxy_service.h"
16 #include "url/gurl.h"
18 namespace net {
19 class URLRequestContextGetter;
22 namespace content {
24 // Responds to ChildProcessHostMsg_ResolveProxy, kicking off a ProxyResolve
25 // request on the IO thread using the specified proxy service. Completion is
26 // notified through the delegate. If multiple requests are started at the same
27 // time, they will run in FIFO order, with only 1 being outstanding at a time.
29 // When an instance of ResolveProxyMsgHelper is destroyed, it cancels any
30 // outstanding proxy resolve requests with the proxy service. It also deletes
31 // the stored IPC::Message pointers for pending requests.
33 // This object is expected to live on the IO thread.
34 class CONTENT_EXPORT ResolveProxyMsgHelper : public BrowserMessageFilter {
35 public:
36 explicit ResolveProxyMsgHelper(net::URLRequestContextGetter* getter);
37 // Constructor used by unittests.
38 explicit ResolveProxyMsgHelper(net::ProxyService* proxy_service);
40 // BrowserMessageFilter implementation
41 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
43 void OnResolveProxy(const GURL& url, IPC::Message* reply_msg);
45 protected:
46 // Destruction cancels the current outstanding request, and clears the
47 // pending queue.
48 virtual ~ResolveProxyMsgHelper();
50 private:
51 // Callback for the ProxyService (bound to |callback_|).
52 void OnResolveProxyCompleted(int result);
54 // Starts the first pending request.
55 void StartPendingRequest();
57 // A PendingRequest is a resolve request that is in progress, or queued.
58 struct PendingRequest {
59 public:
60 PendingRequest(const GURL& url, IPC::Message* reply_msg) :
61 url(url), reply_msg(reply_msg), pac_req(NULL) { }
63 // The URL of the request.
64 GURL url;
66 // Data to pass back to the delegate on completion (we own it until then).
67 IPC::Message* reply_msg;
69 // Handle for cancelling the current request if it has started (else NULL).
70 net::ProxyService::PacRequest* pac_req;
73 // Info about the current outstanding proxy request.
74 net::ProxyInfo proxy_info_;
76 // FIFO queue of pending requests. The first entry is always the current one.
77 typedef std::deque<PendingRequest> PendingRequestList;
78 PendingRequestList pending_requests_;
80 scoped_refptr<net::URLRequestContextGetter> context_getter_;
81 net::ProxyService* proxy_service_;
84 } // namespace content
86 #endif // CONTENT_BROWSER_RESOLVE_PROXY_MSG_HELPER_H_