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

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

Issue 8985012: base::Bind: Convert net/proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: One more include. Created 9 years 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/bind.h"
8 #include "base/bind_helpers.h"
7 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
8 #include "content/common/view_messages.h" 10 #include "content/common/view_messages.h"
9 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
10 #include "net/url_request/url_request_context.h" 12 #include "net/url_request/url_request_context.h"
11 #include "net/url_request/url_request_context_getter.h" 13 #include "net/url_request/url_request_context_getter.h"
12 14
13 ResolveProxyMsgHelper::ResolveProxyMsgHelper( 15 ResolveProxyMsgHelper::ResolveProxyMsgHelper(
14 net::URLRequestContextGetter* getter) 16 net::URLRequestContextGetter* getter)
15 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_( 17 : context_getter_(getter),
16 this, &ResolveProxyMsgHelper::OnResolveProxyCompleted)),
17 context_getter_(getter),
18 proxy_service_(NULL) { 18 proxy_service_(NULL) {
19 } 19 }
20 20
21 ResolveProxyMsgHelper::ResolveProxyMsgHelper(net::ProxyService* proxy_service) 21 ResolveProxyMsgHelper::ResolveProxyMsgHelper(net::ProxyService* proxy_service)
22 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_( 22 : proxy_service_(proxy_service) {
23 this, &ResolveProxyMsgHelper::OnResolveProxyCompleted)),
24 proxy_service_(proxy_service) {
25 } 23 }
26 24
27 bool ResolveProxyMsgHelper::OnMessageReceived(const IPC::Message& message, 25 bool ResolveProxyMsgHelper::OnMessageReceived(const IPC::Message& message,
28 bool* message_was_ok) { 26 bool* message_was_ok) {
29 bool handled = true; 27 bool handled = true;
30 IPC_BEGIN_MESSAGE_MAP_EX(ResolveProxyMsgHelper, message, *message_was_ok) 28 IPC_BEGIN_MESSAGE_MAP_EX(ResolveProxyMsgHelper, message, *message_was_ok)
31 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ResolveProxy, OnResolveProxy) 29 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ResolveProxy, OnResolveProxy)
32 IPC_MESSAGE_UNHANDLED(handled = false) 30 IPC_MESSAGE_UNHANDLED(handled = false)
33 IPC_END_MESSAGE_MAP() 31 IPC_END_MESSAGE_MAP()
34 return handled; 32 return handled;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // Verify the request wasn't started yet. 64 // Verify the request wasn't started yet.
67 DCHECK(NULL == req.pac_req); 65 DCHECK(NULL == req.pac_req);
68 66
69 if (context_getter_.get()) { 67 if (context_getter_.get()) {
70 proxy_service_ = context_getter_->GetURLRequestContext()->proxy_service(); 68 proxy_service_ = context_getter_->GetURLRequestContext()->proxy_service();
71 context_getter_ = NULL; 69 context_getter_ = NULL;
72 } 70 }
73 71
74 // Start the request. 72 // Start the request.
75 int result = proxy_service_->ResolveProxy( 73 int result = proxy_service_->ResolveProxy(
76 req.url, &proxy_info_, &callback_, &req.pac_req, net::BoundNetLog()); 74 req.url, &proxy_info_,
75 base::Bind(&ResolveProxyMsgHelper::OnResolveProxyCompleted,
76 base::Unretained(this)),
77 &req.pac_req, net::BoundNetLog());
77 78
78 // Completed synchronously. 79 // Completed synchronously.
79 if (result != net::ERR_IO_PENDING) 80 if (result != net::ERR_IO_PENDING)
80 OnResolveProxyCompleted(result); 81 OnResolveProxyCompleted(result);
81 } 82 }
82 83
83 ResolveProxyMsgHelper::~ResolveProxyMsgHelper() { 84 ResolveProxyMsgHelper::~ResolveProxyMsgHelper() {
84 // Clear all pending requests if the ProxyService is still alive (if we have a 85 // Clear all pending requests if the ProxyService is still alive (if we have a
85 // default request context or override). 86 // default request context or override).
86 if (!pending_requests_.empty()) { 87 if (!pending_requests_.empty()) {
87 PendingRequest req = pending_requests_.front(); 88 PendingRequest req = pending_requests_.front();
88 proxy_service_->CancelPacRequest(req.pac_req); 89 proxy_service_->CancelPacRequest(req.pac_req);
89 } 90 }
90 91
91 for (PendingRequestList::iterator it = pending_requests_.begin(); 92 for (PendingRequestList::iterator it = pending_requests_.begin();
92 it != pending_requests_.end(); 93 it != pending_requests_.end();
93 ++it) { 94 ++it) {
94 delete it->reply_msg; 95 delete it->reply_msg;
95 } 96 }
96 97
97 pending_requests_.clear(); 98 pending_requests_.clear();
98 } 99 }
OLDNEW
« no previous file with comments | « content/browser/resolve_proxy_msg_helper.h ('k') | net/http/http_network_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698