| 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/proxy_resolver_factory_mojo.h" | 5 #include "net/proxy/proxy_resolver_factory_mojo.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "mojo/common/common_type_converters.h" | 17 #include "mojo/common/common_type_converters.h" |
| 18 #include "mojo/public/cpp/bindings/binding.h" | 18 #include "mojo/public/cpp/bindings/binding.h" |
| 19 #include "net/base/load_states.h" | 19 #include "net/base/load_states.h" |
| 20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 21 #include "net/dns/mojo_host_resolver_impl.h" | 21 #include "net/dns/mojo_host_resolver_impl.h" |
| 22 #include "net/interfaces/host_resolver_service.mojom.h" | 22 #include "net/interfaces/host_resolver_service.mojom.h" |
| 23 #include "net/interfaces/proxy_resolver_service.mojom.h" | 23 #include "net/interfaces/proxy_resolver_service.mojom.h" |
| 24 #include "net/proxy/mojo_proxy_resolver_factory.h" | 24 #include "net/proxy/mojo_proxy_resolver_factory.h" |
| 25 #include "net/proxy/mojo_proxy_type_converters.h" | |
| 26 #include "net/proxy/proxy_info.h" | 25 #include "net/proxy/proxy_info.h" |
| 27 #include "net/proxy/proxy_resolver.h" | 26 #include "net/proxy/proxy_resolver.h" |
| 28 #include "net/proxy/proxy_resolver_error_observer.h" | 27 #include "net/proxy/proxy_resolver_error_observer.h" |
| 29 #include "net/proxy/proxy_resolver_script_data.h" | 28 #include "net/proxy/proxy_resolver_script_data.h" |
| 30 | 29 |
| 31 namespace net { | 30 namespace net { |
| 32 namespace { | 31 namespace { |
| 33 | 32 |
| 34 std::unique_ptr<base::Value> NetLogErrorCallback( | 33 std::unique_ptr<base::Value> NetLogErrorCallback( |
| 35 int line_number, | 34 int line_number, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 void OnError(int32_t line_number, const mojo::String& message) override { | 67 void OnError(int32_t line_number, const mojo::String& message) override { |
| 69 base::string16 message_str = message.To<base::string16>(); | 68 base::string16 message_str = message.To<base::string16>(); |
| 70 auto callback = base::Bind(&NetLogErrorCallback, line_number, &message_str); | 69 auto callback = base::Bind(&NetLogErrorCallback, line_number, &message_str); |
| 71 bound_net_log_.AddEvent(NetLog::TYPE_PAC_JAVASCRIPT_ERROR, callback); | 70 bound_net_log_.AddEvent(NetLog::TYPE_PAC_JAVASCRIPT_ERROR, callback); |
| 72 if (net_log_) | 71 if (net_log_) |
| 73 net_log_->AddGlobalEntry(NetLog::TYPE_PAC_JAVASCRIPT_ERROR, callback); | 72 net_log_->AddGlobalEntry(NetLog::TYPE_PAC_JAVASCRIPT_ERROR, callback); |
| 74 if (error_observer_) | 73 if (error_observer_) |
| 75 error_observer_->OnPACScriptError(line_number, message_str); | 74 error_observer_->OnPACScriptError(line_number, message_str); |
| 76 } | 75 } |
| 77 | 76 |
| 78 void ResolveDns(interfaces::HostResolverRequestInfoPtr request_info, | 77 void ResolveDns(std::unique_ptr<HostResolver::RequestInfo> request_info, |
| 79 interfaces::HostResolverRequestClientPtr client) override { | 78 interfaces::HostResolverRequestClientPtr client) override { |
| 80 host_resolver_.Resolve(std::move(request_info), std::move(client)); | 79 host_resolver_.Resolve(std::move(request_info), std::move(client)); |
| 81 } | 80 } |
| 82 | 81 |
| 83 protected: | 82 protected: |
| 84 bool dns_request_in_progress() { | 83 bool dns_request_in_progress() { |
| 85 return host_resolver_.request_in_progress(); | 84 return host_resolver_.request_in_progress(); |
| 86 } | 85 } |
| 87 | 86 |
| 88 private: | 87 private: |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 void Cancel(); | 162 void Cancel(); |
| 164 | 163 |
| 165 // Returns the LoadState of this job. | 164 // Returns the LoadState of this job. |
| 166 LoadState GetLoadState(); | 165 LoadState GetLoadState(); |
| 167 | 166 |
| 168 private: | 167 private: |
| 169 // Mojo error handler. | 168 // Mojo error handler. |
| 170 void OnConnectionError(); | 169 void OnConnectionError(); |
| 171 | 170 |
| 172 // Overridden from interfaces::ProxyResolverRequestClient: | 171 // Overridden from interfaces::ProxyResolverRequestClient: |
| 173 void ReportResult( | 172 void ReportResult(int32_t error, const net::ProxyInfo& proxy_info) override; |
| 174 int32_t error, | |
| 175 mojo::Array<interfaces::ProxyServerPtr> proxy_servers) override; | |
| 176 | 173 |
| 177 ProxyResolverMojo* resolver_; | 174 ProxyResolverMojo* resolver_; |
| 178 const GURL url_; | 175 const GURL url_; |
| 179 ProxyInfo* results_; | 176 ProxyInfo* results_; |
| 180 CompletionCallback callback_; | 177 CompletionCallback callback_; |
| 181 | 178 |
| 182 base::ThreadChecker thread_checker_; | 179 base::ThreadChecker thread_checker_; |
| 183 mojo::Binding<interfaces::ProxyResolverRequestClient> binding_; | 180 mojo::Binding<interfaces::ProxyResolverRequestClient> binding_; |
| 184 }; | 181 }; |
| 185 | 182 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 return dns_request_in_progress() ? LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT | 217 return dns_request_in_progress() ? LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT |
| 221 : LOAD_STATE_RESOLVING_PROXY_FOR_URL; | 218 : LOAD_STATE_RESOLVING_PROXY_FOR_URL; |
| 222 } | 219 } |
| 223 | 220 |
| 224 void ProxyResolverMojo::Job::OnConnectionError() { | 221 void ProxyResolverMojo::Job::OnConnectionError() { |
| 225 DCHECK(thread_checker_.CalledOnValidThread()); | 222 DCHECK(thread_checker_.CalledOnValidThread()); |
| 226 DVLOG(1) << "ProxyResolverMojo::Job::OnConnectionError"; | 223 DVLOG(1) << "ProxyResolverMojo::Job::OnConnectionError"; |
| 227 resolver_->RemoveJob(this); | 224 resolver_->RemoveJob(this); |
| 228 } | 225 } |
| 229 | 226 |
| 230 void ProxyResolverMojo::Job::ReportResult( | 227 void ProxyResolverMojo::Job::ReportResult(int32_t error, |
| 231 int32_t error, | 228 const ProxyInfo& proxy_info) { |
| 232 mojo::Array<interfaces::ProxyServerPtr> proxy_servers) { | |
| 233 DCHECK(thread_checker_.CalledOnValidThread()); | 229 DCHECK(thread_checker_.CalledOnValidThread()); |
| 234 DVLOG(1) << "ProxyResolverMojo::Job::ReportResult: " << error; | 230 DVLOG(1) << "ProxyResolverMojo::Job::ReportResult: " << error; |
| 235 | 231 |
| 236 if (error == OK) { | 232 if (error == OK) { |
| 237 *results_ = proxy_servers.To<ProxyInfo>(); | 233 *results_ = proxy_info; |
| 238 DVLOG(1) << "Servers: " << results_->ToPacString(); | 234 DVLOG(1) << "Servers: " << results_->ToPacString(); |
| 239 } | 235 } |
| 240 | 236 |
| 241 CompletionCallback callback = callback_; | 237 CompletionCallback callback = callback_; |
| 242 callback_.Reset(); | 238 callback_.Reset(); |
| 243 resolver_->RemoveJob(this); | 239 resolver_->RemoveJob(this); |
| 244 callback.Run(error); | 240 callback.Run(error); |
| 245 } | 241 } |
| 246 | 242 |
| 247 ProxyResolverMojo::ProxyResolverMojo( | 243 ProxyResolverMojo::ProxyResolverMojo( |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 return ERR_PAC_SCRIPT_FAILED; | 396 return ERR_PAC_SCRIPT_FAILED; |
| 401 } | 397 } |
| 402 request->reset(new Job(this, pac_script, resolver, callback, | 398 request->reset(new Job(this, pac_script, resolver, callback, |
| 403 error_observer_factory_.is_null() | 399 error_observer_factory_.is_null() |
| 404 ? nullptr | 400 ? nullptr |
| 405 : error_observer_factory_.Run())); | 401 : error_observer_factory_.Run())); |
| 406 return ERR_IO_PENDING; | 402 return ERR_IO_PENDING; |
| 407 } | 403 } |
| 408 | 404 |
| 409 } // namespace net | 405 } // namespace net |
| OLD | NEW |