| 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 #include "content/browser/resolve_proxy_msg_helper.h" | 5 #include "content/browser/resolve_proxy_msg_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 void ResolveProxyMsgHelper::OnResolveProxy(const GURL& url, | 35 void ResolveProxyMsgHelper::OnResolveProxy(const GURL& url, |
| 36 IPC::Message* reply_msg) { | 36 IPC::Message* reply_msg) { |
| 37 // Enqueue the pending request. | 37 // Enqueue the pending request. |
| 38 pending_requests_.push_back(PendingRequest(url, reply_msg)); | 38 pending_requests_.push_back(PendingRequest(url, reply_msg)); |
| 39 | 39 |
| 40 // If nothing is in progress, start. | 40 // If nothing is in progress, start. |
| 41 if (pending_requests_.size() == 1) | 41 if (pending_requests_.size() == 1) |
| 42 StartPendingRequest(); | 42 StartPendingRequest(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 ResolveProxyMsgHelper::~ResolveProxyMsgHelper() { |
| 46 // Clear all pending requests if the ProxyService is still alive (if we have a |
| 47 // default request context or override). |
| 48 if (!pending_requests_.empty()) { |
| 49 PendingRequest req = pending_requests_.front(); |
| 50 proxy_service_->CancelPacRequest(req.pac_req); |
| 51 } |
| 52 |
| 53 for (PendingRequestList::iterator it = pending_requests_.begin(); |
| 54 it != pending_requests_.end(); |
| 55 ++it) { |
| 56 delete it->reply_msg; |
| 57 } |
| 58 |
| 59 pending_requests_.clear(); |
| 60 } |
| 61 |
| 45 void ResolveProxyMsgHelper::OnResolveProxyCompleted(int result) { | 62 void ResolveProxyMsgHelper::OnResolveProxyCompleted(int result) { |
| 46 CHECK(!pending_requests_.empty()); | 63 CHECK(!pending_requests_.empty()); |
| 47 | 64 |
| 48 const PendingRequest& completed_req = pending_requests_.front(); | 65 const PendingRequest& completed_req = pending_requests_.front(); |
| 49 ViewHostMsg_ResolveProxy::WriteReplyParams( | 66 ViewHostMsg_ResolveProxy::WriteReplyParams( |
| 50 completed_req.reply_msg, result == net::OK, proxy_info_.ToPacString()); | 67 completed_req.reply_msg, result == net::OK, proxy_info_.ToPacString()); |
| 51 Send(completed_req.reply_msg); | 68 Send(completed_req.reply_msg); |
| 52 | 69 |
| 53 // Clear the current (completed) request. | 70 // Clear the current (completed) request. |
| 54 pending_requests_.pop_front(); | 71 pending_requests_.pop_front(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 73 int result = proxy_service_->ResolveProxy( | 90 int result = proxy_service_->ResolveProxy( |
| 74 req.url, &proxy_info_, | 91 req.url, &proxy_info_, |
| 75 base::Bind(&ResolveProxyMsgHelper::OnResolveProxyCompleted, | 92 base::Bind(&ResolveProxyMsgHelper::OnResolveProxyCompleted, |
| 76 base::Unretained(this)), | 93 base::Unretained(this)), |
| 77 &req.pac_req, net::BoundNetLog()); | 94 &req.pac_req, net::BoundNetLog()); |
| 78 | 95 |
| 79 // Completed synchronously. | 96 // Completed synchronously. |
| 80 if (result != net::ERR_IO_PENDING) | 97 if (result != net::ERR_IO_PENDING) |
| 81 OnResolveProxyCompleted(result); | 98 OnResolveProxyCompleted(result); |
| 82 } | 99 } |
| 83 | |
| 84 ResolveProxyMsgHelper::~ResolveProxyMsgHelper() { | |
| 85 // Clear all pending requests if the ProxyService is still alive (if we have a | |
| 86 // default request context or override). | |
| 87 if (!pending_requests_.empty()) { | |
| 88 PendingRequest req = pending_requests_.front(); | |
| 89 proxy_service_->CancelPacRequest(req.pac_req); | |
| 90 } | |
| 91 | |
| 92 for (PendingRequestList::iterator it = pending_requests_.begin(); | |
| 93 it != pending_requests_.end(); | |
| 94 ++it) { | |
| 95 delete it->reply_msg; | |
| 96 } | |
| 97 | |
| 98 pending_requests_.clear(); | |
| 99 } | |
| OLD | NEW |