| OLD | NEW |
| 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 Loading... |
| 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 scoped_ptr<net::ProxyResolver::Request> request_; | 43 net::ProxyResolver::RequestHandle request_handle_; |
| 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 Loading... |
| 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), |
| 80 done_(false) {} | 81 done_(false) {} |
| 81 | 82 |
| 82 MojoProxyResolverImpl::Job::~Job() {} | 83 MojoProxyResolverImpl::Job::~Job() { |
| 84 if (request_handle_ && !done_) |
| 85 resolver_->resolver_->CancelRequest(request_handle_); |
| 86 } |
| 83 | 87 |
| 84 void MojoProxyResolverImpl::Job::Start() { | 88 void MojoProxyResolverImpl::Job::Start() { |
| 85 resolver_->resolver_->GetProxyForURL( | 89 resolver_->resolver_->GetProxyForURL( |
| 86 url_, &result_, base::Bind(&Job::GetProxyDone, base::Unretained(this)), | 90 url_, &result_, base::Bind(&Job::GetProxyDone, base::Unretained(this)), |
| 87 &request_, | 91 &request_handle_, |
| 88 make_scoped_ptr(new MojoProxyResolverV8TracingBindings< | 92 make_scoped_ptr(new MojoProxyResolverV8TracingBindings< |
| 89 interfaces::ProxyResolverRequestClient>(client_.get()))); | 93 interfaces::ProxyResolverRequestClient>(client_.get()))); |
| 90 client_.set_connection_error_handler(base::Bind( | 94 client_.set_connection_error_handler(base::Bind( |
| 91 &MojoProxyResolverImpl::Job::OnConnectionError, base::Unretained(this))); | 95 &MojoProxyResolverImpl::Job::OnConnectionError, base::Unretained(this))); |
| 92 } | 96 } |
| 93 | 97 |
| 94 void MojoProxyResolverImpl::Job::GetProxyDone(int error) { | 98 void MojoProxyResolverImpl::Job::GetProxyDone(int error) { |
| 95 done_ = true; | 99 done_ = true; |
| 96 DVLOG(1) << "GetProxyForUrl(" << url_ << ") finished with error " << error | 100 DVLOG(1) << "GetProxyForUrl(" << url_ << ") finished with error " << error |
| 97 << ". " << result_.proxy_list().size() << " Proxies returned:"; | 101 << ". " << result_.proxy_list().size() << " Proxies returned:"; |
| 98 for (const auto& proxy : result_.proxy_list().GetAll()) { | 102 for (const auto& proxy : result_.proxy_list().GetAll()) { |
| 99 DVLOG(1) << proxy.ToURI(); | 103 DVLOG(1) << proxy.ToURI(); |
| 100 } | 104 } |
| 101 mojo::Array<interfaces::ProxyServerPtr> result; | 105 mojo::Array<interfaces::ProxyServerPtr> result; |
| 102 if (error == OK) { | 106 if (error == OK) { |
| 103 result = mojo::Array<interfaces::ProxyServerPtr>::From( | 107 result = mojo::Array<interfaces::ProxyServerPtr>::From( |
| 104 result_.proxy_list().GetAll()); | 108 result_.proxy_list().GetAll()); |
| 105 } | 109 } |
| 106 client_->ReportResult(error, std::move(result)); | 110 client_->ReportResult(error, std::move(result)); |
| 107 resolver_->DeleteJob(this); | 111 resolver_->DeleteJob(this); |
| 108 } | 112 } |
| 109 | 113 |
| 110 void MojoProxyResolverImpl::Job::OnConnectionError() { | 114 void MojoProxyResolverImpl::Job::OnConnectionError() { |
| 111 resolver_->DeleteJob(this); | 115 resolver_->DeleteJob(this); |
| 112 } | 116 } |
| 113 | 117 |
| 114 } // namespace net | 118 } // namespace net |
| OLD | NEW |