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

Side by Side Diff: chrome/browser/net/resolve_proxy_msg_helper.cc

Issue 14142: Start using the proxy resolve IPC for plugins.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 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.
4
5 #include "chrome/browser/net/resolve_proxy_msg_helper.h"
6
7 #include "base/compiler_specific.h"
8 #include "chrome/browser/profile.h"
9 #include "net/base/net_errors.h"
10 #include "net/url_request/url_request_context.h"
11
12 ResolveProxyMsgHelper::ResolveProxyMsgHelper(Delegate* delegate,
13 net::ProxyService* proxy_service)
14 : proxy_service_(NULL),
15 ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
16 this, &ResolveProxyMsgHelper::OnResolveProxyCompleted)),
17 delegate_(delegate),
18 proxy_service_override_(proxy_service) {
19 }
20
21 void ResolveProxyMsgHelper::Start(const GURL& url, IPC::Message* reply_msg) {
22 // Enqueue the pending request.
23 pending_requests_.push_back(PendingRequest(url, reply_msg));
24
25 // If nothing is in progress, start.
26 if (pending_requests_.size() == 1)
27 StartPendingRequest();
28 }
29
30 void ResolveProxyMsgHelper::OnResolveProxyCompleted(int result) {
31 CHECK(!pending_requests_.empty());
32
33 // Notify the delegate of completion.
34 const PendingRequest& completed_req = pending_requests_.front();
35 delegate_->OnResolveProxyCompleted(completed_req.reply_msg,
36 result,
37 proxy_info_.GetAnnotatedProxyList());
38
39 // Clear the current (completed) request.
40 pending_requests_.pop_front();
41 proxy_service_ = NULL;
42
43 // Start the next request.
44 if (!pending_requests_.empty())
45 StartPendingRequest();
46 }
47
48 void ResolveProxyMsgHelper::StartPendingRequest() {
49 PendingRequest& req = pending_requests_.front();
50
51 // Verify the request wasn't started yet.
52 DCHECK(NULL == req.pac_req);
53 DCHECK(NULL == proxy_service_);
54
55 // Start the request.
56 proxy_service_ = GetProxyService();
57 int result = proxy_service_->ResolveProxy(
58 req.url, &proxy_info_, &callback_, &req.pac_req);
59
60 // Completed synchronously.
61 if (result != net::ERR_IO_PENDING)
62 OnResolveProxyCompleted(result);
63 }
64
65 net::ProxyService* ResolveProxyMsgHelper::GetProxyService() const {
66 // Unit-tests specify their own proxy service to use.
67 if (proxy_service_override_)
68 return proxy_service_override_;
69
70 // Otherwise use the browser's global proxy service.
71 return Profile::GetDefaultRequestContext()->proxy_service();
72 }
73
74 ResolveProxyMsgHelper::~ResolveProxyMsgHelper() {
75 // Clear all pending requests.
76 if (!pending_requests_.empty()) {
77 PendingRequest req = pending_requests_.front();
78 proxy_service_->CancelPacRequest(req.pac_req);
79 }
80
81 for (PendingRequestList::iterator it = pending_requests_.begin();
82 it != pending_requests_.end();
83 ++it) {
84 delete it->reply_msg;
85 }
86
87 proxy_service_ = NULL;
88 pending_requests_.clear();
89 }
OLDNEW
« no previous file with comments | « chrome/browser/net/resolve_proxy_msg_helper.h ('k') | chrome/browser/net/resolve_proxy_msg_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698