OLD | NEW |
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 CONTENT_BROWSER_RESOLVE_PROXY_MSG_HELPER_H_ | 5 #ifndef CONTENT_BROWSER_RESOLVE_PROXY_MSG_HELPER_H_ |
6 #define CONTENT_BROWSER_RESOLVE_PROXY_MSG_HELPER_H_ | 6 #define CONTENT_BROWSER_RESOLVE_PROXY_MSG_HELPER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <deque> | 9 #include <deque> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "content/browser/browser_message_filter.h" | 13 #include "content/browser/browser_message_filter.h" |
14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
15 #include "net/base/completion_callback.h" | 15 #include "net/base/completion_callback.h" |
16 #include "net/proxy/proxy_service.h" | 16 #include "net/proxy/proxy_service.h" |
17 | 17 |
| 18 namespace net { |
| 19 class URLRequestContextGetter; |
| 20 } |
| 21 |
18 // Responds to ChildProcessHostMsg_ResolveProxy, kicking off a ProxyResolve | 22 // Responds to ChildProcessHostMsg_ResolveProxy, kicking off a ProxyResolve |
19 // request on the IO thread using the specified proxy service. Completion is | 23 // request on the IO thread using the specified proxy service. Completion is |
20 // notified through the delegate. If multiple requests are started at the same | 24 // notified through the delegate. If multiple requests are started at the same |
21 // time, they will run in FIFO order, with only 1 being outstanding at a time. | 25 // time, they will run in FIFO order, with only 1 being outstanding at a time. |
22 // | 26 // |
23 // When an instance of ResolveProxyMsgHelper is destroyed, it cancels any | 27 // When an instance of ResolveProxyMsgHelper is destroyed, it cancels any |
24 // outstanding proxy resolve requests with the proxy service. It also deletes | 28 // outstanding proxy resolve requests with the proxy service. It also deletes |
25 // the stored IPC::Message pointers for pending requests. | 29 // the stored IPC::Message pointers for pending requests. |
26 // | 30 // |
27 // This object is expected to live on the IO thread. | 31 // This object is expected to live on the IO thread. |
28 class ResolveProxyMsgHelper : public BrowserMessageFilter { | 32 class ResolveProxyMsgHelper : public BrowserMessageFilter { |
29 public: | 33 public: |
30 // If |proxy_service| is NULL, then the main browser context's proxy service | 34 explicit ResolveProxyMsgHelper(net::URLRequestContextGetter* getter); |
31 // will be used. | 35 // Constructor used by unittests. |
32 explicit ResolveProxyMsgHelper(net::ProxyService* proxy_service); | 36 explicit ResolveProxyMsgHelper(net::ProxyService* proxy_service); |
33 | 37 |
34 // Destruction cancels the current outstanding request, and clears the | 38 // Destruction cancels the current outstanding request, and clears the |
35 // pending queue. | 39 // pending queue. |
36 virtual ~ResolveProxyMsgHelper(); | 40 virtual ~ResolveProxyMsgHelper(); |
37 | 41 |
38 // BrowserMessageFilter implementation | 42 // BrowserMessageFilter implementation |
39 virtual bool OnMessageReceived(const IPC::Message& message, | 43 virtual bool OnMessageReceived(const IPC::Message& message, |
40 bool* message_was_ok); | 44 bool* message_was_ok); |
41 | 45 |
42 void OnResolveProxy(const GURL& url, IPC::Message* reply_msg); | 46 void OnResolveProxy(const GURL& url, IPC::Message* reply_msg); |
43 | 47 |
44 private: | 48 private: |
45 // Callback for the ProxyService (bound to |callback_|). | 49 // Callback for the ProxyService (bound to |callback_|). |
46 void OnResolveProxyCompleted(int result); | 50 void OnResolveProxyCompleted(int result); |
47 | 51 |
48 // Starts the first pending request. | 52 // Starts the first pending request. |
49 void StartPendingRequest(); | 53 void StartPendingRequest(); |
50 | 54 |
51 // Get the proxy service instance to use. On success returns true and | |
52 // sets |*out|. Otherwise returns false. | |
53 bool GetProxyService(net::ProxyService** out) const; | |
54 | |
55 // A PendingRequest is a resolve request that is in progress, or queued. | 55 // A PendingRequest is a resolve request that is in progress, or queued. |
56 struct PendingRequest { | 56 struct PendingRequest { |
57 public: | 57 public: |
58 PendingRequest(const GURL& url, IPC::Message* reply_msg) : | 58 PendingRequest(const GURL& url, IPC::Message* reply_msg) : |
59 url(url), reply_msg(reply_msg), pac_req(NULL) { } | 59 url(url), reply_msg(reply_msg), pac_req(NULL) { } |
60 | 60 |
61 // The URL of the request. | 61 // The URL of the request. |
62 GURL url; | 62 GURL url; |
63 | 63 |
64 // Data to pass back to the delegate on completion (we own it until then). | 64 // Data to pass back to the delegate on completion (we own it until then). |
65 IPC::Message* reply_msg; | 65 IPC::Message* reply_msg; |
66 | 66 |
67 // Handle for cancelling the current request if it has started (else NULL). | 67 // Handle for cancelling the current request if it has started (else NULL). |
68 net::ProxyService::PacRequest* pac_req; | 68 net::ProxyService::PacRequest* pac_req; |
69 }; | 69 }; |
70 | 70 |
71 // Members for the current outstanding proxy request. | 71 // Members for the current outstanding proxy request. |
72 net::ProxyService* proxy_service_; | |
73 net::CompletionCallbackImpl<ResolveProxyMsgHelper> callback_; | 72 net::CompletionCallbackImpl<ResolveProxyMsgHelper> callback_; |
74 net::ProxyInfo proxy_info_; | 73 net::ProxyInfo proxy_info_; |
75 | 74 |
76 // FIFO queue of pending requests. The first entry is always the current one. | 75 // FIFO queue of pending requests. The first entry is always the current one. |
77 typedef std::deque<PendingRequest> PendingRequestList; | 76 typedef std::deque<PendingRequest> PendingRequestList; |
78 PendingRequestList pending_requests_; | 77 PendingRequestList pending_requests_; |
79 | 78 |
80 // Specified by unit-tests, to use this proxy service in place of the | 79 scoped_refptr<net::URLRequestContextGetter> context_getter_; |
81 // global one. | 80 net::ProxyService* proxy_service_; |
82 net::ProxyService* proxy_service_override_; | |
83 }; | 81 }; |
84 | 82 |
85 #endif // CONTENT_BROWSER_RESOLVE_PROXY_MSG_HELPER_H_ | 83 #endif // CONTENT_BROWSER_RESOLVE_PROXY_MSG_HELPER_H_ |
OLD | NEW |