| 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/log/net_log.h" | 24 #include "net/log/net_log.h" |
| 25 #include "net/log/net_log_capture_mode.h" | 25 #include "net/log/net_log_capture_mode.h" |
| 26 #include "net/log/net_log_event_type.h" | 26 #include "net/log/net_log_event_type.h" |
| 27 #include "net/log/net_log_with_source.h" | 27 #include "net/log/net_log_with_source.h" |
| 28 #include "net/proxy/mojo_proxy_resolver_factory.h" | 28 #include "net/proxy/mojo_proxy_resolver_factory.h" |
| 29 #include "net/proxy/mojo_proxy_type_converters.h" | |
| 30 #include "net/proxy/proxy_info.h" | 29 #include "net/proxy/proxy_info.h" |
| 31 #include "net/proxy/proxy_resolver.h" | 30 #include "net/proxy/proxy_resolver.h" |
| 32 #include "net/proxy/proxy_resolver_error_observer.h" | 31 #include "net/proxy/proxy_resolver_error_observer.h" |
| 33 #include "net/proxy/proxy_resolver_script_data.h" | 32 #include "net/proxy/proxy_resolver_script_data.h" |
| 34 | 33 |
| 35 namespace net { | 34 namespace net { |
| 36 | 35 |
| 37 namespace { | 36 namespace { |
| 38 | 37 |
| 39 std::unique_ptr<base::Value> NetLogErrorCallback( | 38 std::unique_ptr<base::Value> NetLogErrorCallback( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 base::string16 message_str = message.To<base::string16>(); | 74 base::string16 message_str = message.To<base::string16>(); |
| 76 auto callback = base::Bind(&NetLogErrorCallback, line_number, &message_str); | 75 auto callback = base::Bind(&NetLogErrorCallback, line_number, &message_str); |
| 77 net_log_with_source_.AddEvent(NetLogEventType::PAC_JAVASCRIPT_ERROR, | 76 net_log_with_source_.AddEvent(NetLogEventType::PAC_JAVASCRIPT_ERROR, |
| 78 callback); | 77 callback); |
| 79 if (net_log_) | 78 if (net_log_) |
| 80 net_log_->AddGlobalEntry(NetLogEventType::PAC_JAVASCRIPT_ERROR, callback); | 79 net_log_->AddGlobalEntry(NetLogEventType::PAC_JAVASCRIPT_ERROR, callback); |
| 81 if (error_observer_) | 80 if (error_observer_) |
| 82 error_observer_->OnPACScriptError(line_number, message_str); | 81 error_observer_->OnPACScriptError(line_number, message_str); |
| 83 } | 82 } |
| 84 | 83 |
| 85 void ResolveDns(interfaces::HostResolverRequestInfoPtr request_info, | 84 void ResolveDns(std::unique_ptr<HostResolver::RequestInfo> request_info, |
| 86 interfaces::HostResolverRequestClientPtr client) override { | 85 interfaces::HostResolverRequestClientPtr client) override { |
| 87 host_resolver_.Resolve(std::move(request_info), std::move(client)); | 86 host_resolver_.Resolve(std::move(request_info), std::move(client)); |
| 88 } | 87 } |
| 89 | 88 |
| 90 protected: | 89 protected: |
| 91 bool dns_request_in_progress() { | 90 bool dns_request_in_progress() { |
| 92 return host_resolver_.request_in_progress(); | 91 return host_resolver_.request_in_progress(); |
| 93 } | 92 } |
| 94 | 93 |
| 95 private: | 94 private: |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 void Cancel(); | 169 void Cancel(); |
| 171 | 170 |
| 172 // Returns the LoadState of this job. | 171 // Returns the LoadState of this job. |
| 173 LoadState GetLoadState(); | 172 LoadState GetLoadState(); |
| 174 | 173 |
| 175 private: | 174 private: |
| 176 // Mojo error handler. | 175 // Mojo error handler. |
| 177 void OnConnectionError(); | 176 void OnConnectionError(); |
| 178 | 177 |
| 179 // Overridden from interfaces::ProxyResolverRequestClient: | 178 // Overridden from interfaces::ProxyResolverRequestClient: |
| 180 void ReportResult( | 179 void ReportResult(int32_t error, const net::ProxyInfo& proxy_info) override; |
| 181 int32_t error, | |
| 182 mojo::Array<interfaces::ProxyServerPtr> proxy_servers) override; | |
| 183 | 180 |
| 184 ProxyResolverMojo* resolver_; | 181 ProxyResolverMojo* resolver_; |
| 185 const GURL url_; | 182 const GURL url_; |
| 186 ProxyInfo* results_; | 183 ProxyInfo* results_; |
| 187 CompletionCallback callback_; | 184 CompletionCallback callback_; |
| 188 | 185 |
| 189 base::ThreadChecker thread_checker_; | 186 base::ThreadChecker thread_checker_; |
| 190 mojo::Binding<interfaces::ProxyResolverRequestClient> binding_; | 187 mojo::Binding<interfaces::ProxyResolverRequestClient> binding_; |
| 191 }; | 188 }; |
| 192 | 189 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 return dns_request_in_progress() ? LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT | 224 return dns_request_in_progress() ? LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT |
| 228 : LOAD_STATE_RESOLVING_PROXY_FOR_URL; | 225 : LOAD_STATE_RESOLVING_PROXY_FOR_URL; |
| 229 } | 226 } |
| 230 | 227 |
| 231 void ProxyResolverMojo::Job::OnConnectionError() { | 228 void ProxyResolverMojo::Job::OnConnectionError() { |
| 232 DCHECK(thread_checker_.CalledOnValidThread()); | 229 DCHECK(thread_checker_.CalledOnValidThread()); |
| 233 DVLOG(1) << "ProxyResolverMojo::Job::OnConnectionError"; | 230 DVLOG(1) << "ProxyResolverMojo::Job::OnConnectionError"; |
| 234 resolver_->RemoveJob(this); | 231 resolver_->RemoveJob(this); |
| 235 } | 232 } |
| 236 | 233 |
| 237 void ProxyResolverMojo::Job::ReportResult( | 234 void ProxyResolverMojo::Job::ReportResult(int32_t error, |
| 238 int32_t error, | 235 const ProxyInfo& proxy_info) { |
| 239 mojo::Array<interfaces::ProxyServerPtr> proxy_servers) { | |
| 240 DCHECK(thread_checker_.CalledOnValidThread()); | 236 DCHECK(thread_checker_.CalledOnValidThread()); |
| 241 DVLOG(1) << "ProxyResolverMojo::Job::ReportResult: " << error; | 237 DVLOG(1) << "ProxyResolverMojo::Job::ReportResult: " << error; |
| 242 | 238 |
| 243 if (error == OK) { | 239 if (error == OK) { |
| 244 *results_ = proxy_servers.To<ProxyInfo>(); | 240 *results_ = proxy_info; |
| 245 DVLOG(1) << "Servers: " << results_->ToPacString(); | 241 DVLOG(1) << "Servers: " << results_->ToPacString(); |
| 246 } | 242 } |
| 247 | 243 |
| 248 CompletionCallback callback = callback_; | 244 CompletionCallback callback = callback_; |
| 249 callback_.Reset(); | 245 callback_.Reset(); |
| 250 resolver_->RemoveJob(this); | 246 resolver_->RemoveJob(this); |
| 251 callback.Run(error); | 247 callback.Run(error); |
| 252 } | 248 } |
| 253 | 249 |
| 254 ProxyResolverMojo::ProxyResolverMojo( | 250 ProxyResolverMojo::ProxyResolverMojo( |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 return ERR_PAC_SCRIPT_FAILED; | 403 return ERR_PAC_SCRIPT_FAILED; |
| 408 } | 404 } |
| 409 request->reset(new Job(this, pac_script, resolver, callback, | 405 request->reset(new Job(this, pac_script, resolver, callback, |
| 410 error_observer_factory_.is_null() | 406 error_observer_factory_.is_null() |
| 411 ? nullptr | 407 ? nullptr |
| 412 : error_observer_factory_.Run())); | 408 : error_observer_factory_.Run())); |
| 413 return ERR_IO_PENDING; | 409 return ERR_IO_PENDING; |
| 414 } | 410 } |
| 415 | 411 |
| 416 } // namespace net | 412 } // namespace net |
| OLD | NEW |