| 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_mojo.h" | 5 #include "net/proxy/proxy_resolver_mojo.h" | 
| 6 | 6 | 
| 7 #include "base/bind.h" | 7 #include "base/bind.h" | 
| 8 #include "base/logging.h" | 8 #include "base/logging.h" | 
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" | 
| 10 #include "mojo/common/common_type_converters.h" | 10 #include "mojo/common/common_type_converters.h" | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 24  public: | 24  public: | 
| 25   Job(ProxyResolverMojo* resolver, | 25   Job(ProxyResolverMojo* resolver, | 
| 26       const GURL& url, | 26       const GURL& url, | 
| 27       ProxyInfo* results, | 27       ProxyInfo* results, | 
| 28       const net::CompletionCallback& callback); | 28       const net::CompletionCallback& callback); | 
| 29   ~Job() override; | 29   ~Job() override; | 
| 30 | 30 | 
| 31   // Cancels the job and prevents the callback from being run. | 31   // Cancels the job and prevents the callback from being run. | 
| 32   void Cancel(); | 32   void Cancel(); | 
| 33 | 33 | 
|  | 34   // Returns the LoadState of this job. | 
|  | 35   LoadState load_state() { return load_state_; } | 
|  | 36 | 
| 34  private: | 37  private: | 
| 35   // Overridden from mojo::ErrorHandler: | 38   // Overridden from mojo::ErrorHandler: | 
| 36   void OnConnectionError() override; | 39   void OnConnectionError() override; | 
| 37 | 40 | 
| 38   // Overridden from interfaces::ProxyResolverRequestClient: | 41   // Overridden from interfaces::ProxyResolverRequestClient: | 
| 39   void ReportResult( | 42   void ReportResult( | 
| 40       int32_t error, | 43       int32_t error, | 
| 41       mojo::Array<interfaces::ProxyServerPtr> proxy_servers) override; | 44       mojo::Array<interfaces::ProxyServerPtr> proxy_servers) override; | 
|  | 45   void LoadStateChanged(int32_t load_state) override; | 
| 42 | 46 | 
| 43   ProxyResolverMojo* resolver_; | 47   ProxyResolverMojo* resolver_; | 
| 44   const GURL url_; | 48   const GURL url_; | 
| 45   ProxyInfo* results_; | 49   ProxyInfo* results_; | 
| 46   net::CompletionCallback callback_; | 50   net::CompletionCallback callback_; | 
|  | 51   LoadState load_state_ = LOAD_STATE_RESOLVING_PROXY_FOR_URL; | 
| 47 | 52 | 
| 48   base::ThreadChecker thread_checker_; | 53   base::ThreadChecker thread_checker_; | 
| 49   mojo::Binding<interfaces::ProxyResolverRequestClient> binding_; | 54   mojo::Binding<interfaces::ProxyResolverRequestClient> binding_; | 
| 50 }; | 55 }; | 
| 51 | 56 | 
| 52 ProxyResolverMojo::Job::Job(ProxyResolverMojo* resolver, | 57 ProxyResolverMojo::Job::Job(ProxyResolverMojo* resolver, | 
| 53                             const GURL& url, | 58                             const GURL& url, | 
| 54                             ProxyInfo* results, | 59                             ProxyInfo* results, | 
| 55                             const net::CompletionCallback& callback) | 60                             const net::CompletionCallback& callback) | 
| 56     : resolver_(resolver), | 61     : resolver_(resolver), | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 93   if (error == OK) { | 98   if (error == OK) { | 
| 94     *results_ = proxy_servers.To<ProxyInfo>(); | 99     *results_ = proxy_servers.To<ProxyInfo>(); | 
| 95     DVLOG(1) << "Servers: " << results_->ToPacString(); | 100     DVLOG(1) << "Servers: " << results_->ToPacString(); | 
| 96   } | 101   } | 
| 97 | 102 | 
| 98   callback_.Run(error); | 103   callback_.Run(error); | 
| 99   callback_.Reset(); | 104   callback_.Reset(); | 
| 100   resolver_->RemoveJob(this); | 105   resolver_->RemoveJob(this); | 
| 101 } | 106 } | 
| 102 | 107 | 
|  | 108 void ProxyResolverMojo::Job::LoadStateChanged(int32_t load_state) { | 
|  | 109   load_state_ = static_cast<LoadState>(load_state); | 
|  | 110 } | 
|  | 111 | 
| 103 ProxyResolverMojo::ProxyResolverMojo( | 112 ProxyResolverMojo::ProxyResolverMojo( | 
| 104     MojoProxyResolverFactory* mojo_proxy_resolver_factory, | 113     MojoProxyResolverFactory* mojo_proxy_resolver_factory, | 
| 105     HostResolver* host_resolver) | 114     HostResolver* host_resolver) | 
| 106     : ProxyResolver(true /* |expects_pac_bytes| */), | 115     : ProxyResolver(true /* |expects_pac_bytes| */), | 
| 107       mojo_proxy_resolver_factory_(mojo_proxy_resolver_factory), | 116       mojo_proxy_resolver_factory_(mojo_proxy_resolver_factory), | 
| 108       host_resolver_(host_resolver) { | 117       host_resolver_(host_resolver) { | 
| 109 } | 118 } | 
| 110 | 119 | 
| 111 ProxyResolverMojo::~ProxyResolverMojo() { | 120 ProxyResolverMojo::~ProxyResolverMojo() { | 
| 112   DCHECK(thread_checker_.CalledOnValidThread()); | 121   DCHECK(thread_checker_.CalledOnValidThread()); | 
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 240 | 249 | 
| 241 void ProxyResolverMojo::CancelRequest(RequestHandle request) { | 250 void ProxyResolverMojo::CancelRequest(RequestHandle request) { | 
| 242   DCHECK(thread_checker_.CalledOnValidThread()); | 251   DCHECK(thread_checker_.CalledOnValidThread()); | 
| 243   Job* job = static_cast<Job*>(request); | 252   Job* job = static_cast<Job*>(request); | 
| 244   DCHECK(job); | 253   DCHECK(job); | 
| 245   job->Cancel(); | 254   job->Cancel(); | 
| 246   RemoveJob(job); | 255   RemoveJob(job); | 
| 247 } | 256 } | 
| 248 | 257 | 
| 249 LoadState ProxyResolverMojo::GetLoadState(RequestHandle request) const { | 258 LoadState ProxyResolverMojo::GetLoadState(RequestHandle request) const { | 
| 250   // TODO(amistry): Implement real LoadState. | 259   Job* job = static_cast<Job*>(request); | 
| 251   return LOAD_STATE_RESOLVING_PROXY_FOR_URL; | 260   CHECK_EQ(1u, pending_jobs_.count(job)); | 
|  | 261   return job->load_state(); | 
| 252 } | 262 } | 
| 253 | 263 | 
| 254 }  // namespace net | 264 }  // namespace net | 
| OLD | NEW | 
|---|