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

Side by Side Diff: net/proxy/mojo_proxy_resolver_impl.cc

Issue 1439053002: Change ProxyResolver::GetProxyForURL() to take a scoped_ptr<Request>* rather than a RequestHandle* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restore scoped_ptr to mock and nits Created 4 years, 9 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "net/proxy/mojo_proxy_resolver_impl.h" 5 #include "net/proxy/mojo_proxy_resolver_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 22 matching lines...) Expand all
33 // disconnecting, indicating cancellation. 33 // disconnecting, indicating cancellation.
34 void OnConnectionError(); 34 void OnConnectionError();
35 35
36 void GetProxyDone(int error); 36 void GetProxyDone(int error);
37 37
38 MojoProxyResolverImpl* resolver_; 38 MojoProxyResolverImpl* resolver_;
39 39
40 interfaces::ProxyResolverRequestClientPtr client_; 40 interfaces::ProxyResolverRequestClientPtr client_;
41 ProxyInfo result_; 41 ProxyInfo result_;
42 GURL url_; 42 GURL url_;
43 net::ProxyResolver::RequestHandle request_handle_; 43 scoped_ptr<net::ProxyResolver::Request> request_;
44 bool done_; 44 bool done_;
45 45
46 DISALLOW_COPY_AND_ASSIGN(Job); 46 DISALLOW_COPY_AND_ASSIGN(Job);
47 }; 47 };
48 48
49 MojoProxyResolverImpl::MojoProxyResolverImpl( 49 MojoProxyResolverImpl::MojoProxyResolverImpl(
50 scoped_ptr<ProxyResolverV8Tracing> resolver) 50 scoped_ptr<ProxyResolverV8Tracing> resolver)
51 : resolver_(std::move(resolver)) {} 51 : resolver_(std::move(resolver)) {}
52 52
53 MojoProxyResolverImpl::~MojoProxyResolverImpl() { 53 MojoProxyResolverImpl::~MojoProxyResolverImpl() {
(...skipping 16 matching lines...) Expand all
70 delete job; 70 delete job;
71 } 71 }
72 72
73 MojoProxyResolverImpl::Job::Job( 73 MojoProxyResolverImpl::Job::Job(
74 interfaces::ProxyResolverRequestClientPtr client, 74 interfaces::ProxyResolverRequestClientPtr client,
75 MojoProxyResolverImpl* resolver, 75 MojoProxyResolverImpl* resolver,
76 const GURL& url) 76 const GURL& url)
77 : resolver_(resolver), 77 : resolver_(resolver),
78 client_(std::move(client)), 78 client_(std::move(client)),
79 url_(url), 79 url_(url),
80 request_handle_(nullptr),
81 done_(false) {} 80 done_(false) {}
82 81
83 MojoProxyResolverImpl::Job::~Job() { 82 MojoProxyResolverImpl::Job::~Job() {}
84 if (request_handle_ && !done_)
85 resolver_->resolver_->CancelRequest(request_handle_);
86 }
87 83
88 void MojoProxyResolverImpl::Job::Start() { 84 void MojoProxyResolverImpl::Job::Start() {
89 resolver_->resolver_->GetProxyForURL( 85 resolver_->resolver_->GetProxyForURL(
90 url_, &result_, base::Bind(&Job::GetProxyDone, base::Unretained(this)), 86 url_, &result_, base::Bind(&Job::GetProxyDone, base::Unretained(this)),
91 &request_handle_, 87 &request_,
92 make_scoped_ptr(new MojoProxyResolverV8TracingBindings< 88 make_scoped_ptr(new MojoProxyResolverV8TracingBindings<
93 interfaces::ProxyResolverRequestClient>(client_.get()))); 89 interfaces::ProxyResolverRequestClient>(client_.get())));
94 client_.set_connection_error_handler(base::Bind( 90 client_.set_connection_error_handler(base::Bind(
95 &MojoProxyResolverImpl::Job::OnConnectionError, base::Unretained(this))); 91 &MojoProxyResolverImpl::Job::OnConnectionError, base::Unretained(this)));
96 } 92 }
97 93
98 void MojoProxyResolverImpl::Job::GetProxyDone(int error) { 94 void MojoProxyResolverImpl::Job::GetProxyDone(int error) {
99 done_ = true; 95 done_ = true;
100 DVLOG(1) << "GetProxyForUrl(" << url_ << ") finished with error " << error 96 DVLOG(1) << "GetProxyForUrl(" << url_ << ") finished with error " << error
101 << ". " << result_.proxy_list().size() << " Proxies returned:"; 97 << ". " << result_.proxy_list().size() << " Proxies returned:";
102 for (const auto& proxy : result_.proxy_list().GetAll()) { 98 for (const auto& proxy : result_.proxy_list().GetAll()) {
103 DVLOG(1) << proxy.ToURI(); 99 DVLOG(1) << proxy.ToURI();
104 } 100 }
105 mojo::Array<interfaces::ProxyServerPtr> result; 101 mojo::Array<interfaces::ProxyServerPtr> result;
106 if (error == OK) { 102 if (error == OK) {
107 result = mojo::Array<interfaces::ProxyServerPtr>::From( 103 result = mojo::Array<interfaces::ProxyServerPtr>::From(
108 result_.proxy_list().GetAll()); 104 result_.proxy_list().GetAll());
109 } 105 }
110 client_->ReportResult(error, std::move(result)); 106 client_->ReportResult(error, std::move(result));
111 resolver_->DeleteJob(this); 107 resolver_->DeleteJob(this);
112 } 108 }
113 109
114 void MojoProxyResolverImpl::Job::OnConnectionError() { 110 void MojoProxyResolverImpl::Job::OnConnectionError() {
115 resolver_->DeleteJob(this); 111 resolver_->DeleteJob(this);
116 } 112 }
117 113
118 } // namespace net 114 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/mojo_proxy_resolver_factory_impl_unittest.cc ('k') | net/proxy/mojo_proxy_resolver_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698