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

Side by Side Diff: content/browser/resolve_proxy_msg_helper.cc

Issue 7791005: Stop using the default profile's proxy service for plugin proxy requests, and instead use the ass... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix test Created 9 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
OLDNEW
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 #include "content/browser/resolve_proxy_msg_helper.h" 5 #include "content/browser/resolve_proxy_msg_helper.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "content/browser/content_browser_client.h" 8 #include "content/common/view_messages.h"
9 #include "content/common/child_process_messages.h"
10 #include "content/common/content_client.h"
11 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
12 #include "net/url_request/url_request_context.h" 10 #include "net/url_request/url_request_context.h"
13 #include "net/url_request/url_request_context_getter.h" 11 #include "net/url_request/url_request_context_getter.h"
14 12
13 ResolveProxyMsgHelper::ResolveProxyMsgHelper(
14 net::URLRequestContextGetter* getter)
15 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
16 this, &ResolveProxyMsgHelper::OnResolveProxyCompleted)),
17 context_getter_(getter),
18 proxy_service_(NULL) {
19 }
20
15 ResolveProxyMsgHelper::ResolveProxyMsgHelper(net::ProxyService* proxy_service) 21 ResolveProxyMsgHelper::ResolveProxyMsgHelper(net::ProxyService* proxy_service)
16 : proxy_service_(NULL), 22 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
17 ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
18 this, &ResolveProxyMsgHelper::OnResolveProxyCompleted)), 23 this, &ResolveProxyMsgHelper::OnResolveProxyCompleted)),
19 proxy_service_override_(proxy_service) { 24 proxy_service_(proxy_service) {
20 } 25 }
21 26
22 bool ResolveProxyMsgHelper::OnMessageReceived(const IPC::Message& message, 27 bool ResolveProxyMsgHelper::OnMessageReceived(const IPC::Message& message,
23 bool* message_was_ok) { 28 bool* message_was_ok) {
24 bool handled = true; 29 bool handled = true;
25 IPC_BEGIN_MESSAGE_MAP_EX(ResolveProxyMsgHelper, message, *message_was_ok) 30 IPC_BEGIN_MESSAGE_MAP_EX(ResolveProxyMsgHelper, message, *message_was_ok)
26 IPC_MESSAGE_HANDLER_DELAY_REPLY(ChildProcessHostMsg_ResolveProxy, 31 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ResolveProxy, OnResolveProxy)
27 OnResolveProxy)
28 IPC_MESSAGE_UNHANDLED(handled = false) 32 IPC_MESSAGE_UNHANDLED(handled = false)
29 IPC_END_MESSAGE_MAP() 33 IPC_END_MESSAGE_MAP()
30 return handled; 34 return handled;
31 } 35 }
32 36
33 void ResolveProxyMsgHelper::OnResolveProxy(const GURL& url, 37 void ResolveProxyMsgHelper::OnResolveProxy(const GURL& url,
34 IPC::Message* reply_msg) { 38 IPC::Message* reply_msg) {
35 // Enqueue the pending request. 39 // Enqueue the pending request.
36 pending_requests_.push_back(PendingRequest(url, reply_msg)); 40 pending_requests_.push_back(PendingRequest(url, reply_msg));
37 41
38 // If nothing is in progress, start. 42 // If nothing is in progress, start.
39 if (pending_requests_.size() == 1) 43 if (pending_requests_.size() == 1)
40 StartPendingRequest(); 44 StartPendingRequest();
41 } 45 }
42 46
43 void ResolveProxyMsgHelper::OnResolveProxyCompleted(int result) { 47 void ResolveProxyMsgHelper::OnResolveProxyCompleted(int result) {
44 CHECK(!pending_requests_.empty()); 48 CHECK(!pending_requests_.empty());
45 49
46 const PendingRequest& completed_req = pending_requests_.front(); 50 const PendingRequest& completed_req = pending_requests_.front();
47 ChildProcessHostMsg_ResolveProxy::WriteReplyParams( 51 ViewHostMsg_ResolveProxy::WriteReplyParams(
48 completed_req.reply_msg, result, proxy_info_.ToPacString()); 52 completed_req.reply_msg, result == net::OK, proxy_info_.ToPacString());
49 Send(completed_req.reply_msg); 53 Send(completed_req.reply_msg);
50 54
51 // Clear the current (completed) request. 55 // Clear the current (completed) request.
52 pending_requests_.pop_front(); 56 pending_requests_.pop_front();
53 proxy_service_ = NULL;
54 57
55 // Start the next request. 58 // Start the next request.
56 if (!pending_requests_.empty()) 59 if (!pending_requests_.empty())
57 StartPendingRequest(); 60 StartPendingRequest();
58 } 61 }
59 62
60 void ResolveProxyMsgHelper::StartPendingRequest() { 63 void ResolveProxyMsgHelper::StartPendingRequest() {
61 PendingRequest& req = pending_requests_.front(); 64 PendingRequest& req = pending_requests_.front();
62 65
63 // Verify the request wasn't started yet. 66 // Verify the request wasn't started yet.
64 DCHECK(NULL == req.pac_req); 67 DCHECK(NULL == req.pac_req);
65 DCHECK(NULL == proxy_service_); 68
69 if (context_getter_.get()) {
70 proxy_service_ = context_getter_->GetURLRequestContext()->proxy_service();
71 context_getter_ = NULL;
72 }
66 73
67 // Start the request. 74 // Start the request.
68 bool ok = GetProxyService(&proxy_service_);
69
70 if (!ok) {
71 // During shutdown, there may be no ProxyService to use, because the
72 // default ChromeURLRequestContext has already been NULL-ed out.
73 LOG(WARNING) << "Failed getting default URLRequestContext";
74 OnResolveProxyCompleted(net::ERR_FAILED);
75 return;
76 }
77
78 int result = proxy_service_->ResolveProxy( 75 int result = proxy_service_->ResolveProxy(
79 req.url, &proxy_info_, &callback_, &req.pac_req, net::BoundNetLog()); 76 req.url, &proxy_info_, &callback_, &req.pac_req, net::BoundNetLog());
80 77
81 // Completed synchronously. 78 // Completed synchronously.
82 if (result != net::ERR_IO_PENDING) 79 if (result != net::ERR_IO_PENDING)
83 OnResolveProxyCompleted(result); 80 OnResolveProxyCompleted(result);
84 } 81 }
85 82
86 bool ResolveProxyMsgHelper::GetProxyService(net::ProxyService** out) const {
87 // Unit-tests specify their own proxy service to use.
88 if (proxy_service_override_) {
89 *out = proxy_service_override_;
90 return true;
91 }
92
93 // If there is no default request context (say during shut down).
94 // Deprecated; see http://crbug.com/92361
95 net::URLRequestContextGetter* context_getter =
96 content::GetContentClient()->browser()->
97 GetDefaultRequestContextDeprecatedCrBug64339();
98 if (!context_getter)
99 return false;
100
101 // Otherwise use the browser's global proxy service.
102 *out = context_getter->GetURLRequestContext()->proxy_service();
103 return true;
104 }
105
106 ResolveProxyMsgHelper::~ResolveProxyMsgHelper() { 83 ResolveProxyMsgHelper::~ResolveProxyMsgHelper() {
107 // Clear all pending requests if the ProxyService is still alive (if we have a 84 // Clear all pending requests if the ProxyService is still alive (if we have a
108 // default request context or override). 85 // default request context or override).
109 // Deprecated; see http://crbug.com/92361 86 if (!pending_requests_.empty()) {
110 net::URLRequestContextGetter* context_getter =
111 content::GetContentClient()->browser()->
112 GetDefaultRequestContextDeprecatedCrBug64339();
113 if (!pending_requests_.empty() &&
114 (context_getter || proxy_service_override_)) {
115 PendingRequest req = pending_requests_.front(); 87 PendingRequest req = pending_requests_.front();
116 proxy_service_->CancelPacRequest(req.pac_req); 88 proxy_service_->CancelPacRequest(req.pac_req);
117 } 89 }
118 90
119 for (PendingRequestList::iterator it = pending_requests_.begin(); 91 for (PendingRequestList::iterator it = pending_requests_.begin();
120 it != pending_requests_.end(); 92 it != pending_requests_.end();
121 ++it) { 93 ++it) {
122 delete it->reply_msg; 94 delete it->reply_msg;
123 } 95 }
124 96
125 proxy_service_ = NULL;
126 pending_requests_.clear(); 97 pending_requests_.clear();
127 } 98 }
OLDNEW
« no previous file with comments | « content/browser/resolve_proxy_msg_helper.h ('k') | content/browser/resolve_proxy_msg_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698