Chromium Code Reviews| 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 "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "mojo/common/common_type_converters.h" | 8 #include "mojo/common/common_type_converters.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "net/base/net_log.h" | 10 #include "net/base/net_log.h" |
| 11 #include "net/proxy/mojo_type_converters.h" | 11 #include "net/proxy/mojo_type_converters.h" |
| 12 #include "net/proxy/proxy_info.h" | 12 #include "net/proxy/proxy_info.h" |
| 13 #include "net/proxy/proxy_resolver.h" | 13 #include "net/proxy/proxy_resolver.h" |
| 14 #include "net/proxy/proxy_resolver_script_data.h" | 14 #include "net/proxy/proxy_resolver_script_data.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 | 17 |
| 18 class MojoProxyResolverImpl::Job : public mojo::ErrorHandler { | 18 class MojoProxyResolverImpl::Job : public mojo::ErrorHandler { |
| 19 public: | 19 public: |
| 20 Job(interfaces::ProxyResolverRequestClientPtr client, | 20 Job(interfaces::ProxyResolverRequestClientPtr client, |
| 21 MojoProxyResolverImpl* resolver, | 21 MojoProxyResolverImpl* resolver, |
| 22 const GURL& url); | 22 const GURL& url); |
| 23 ~Job() override; | 23 ~Job() override; |
| 24 | 24 |
| 25 void Start(); | 25 void Start(); |
| 26 | 26 |
| 27 // Invoked when the LoadState for this job changes. | |
| 28 void LoadStateChanged(LoadState load_state); | |
| 29 | |
| 27 private: | 30 private: |
| 28 // mojo::ErrorHandler override. | 31 // mojo::ErrorHandler override. |
| 29 // This is invoked in response to the client disconnecting, indicating | 32 // This is invoked in response to the client disconnecting, indicating |
| 30 // cancellation. | 33 // cancellation. |
| 31 void OnConnectionError() override; | 34 void OnConnectionError() override; |
| 32 | 35 |
| 33 void GetProxyDone(int error); | 36 void GetProxyDone(int error); |
| 34 | 37 |
| 35 MojoProxyResolverImpl* resolver_; | 38 MojoProxyResolverImpl* resolver_; |
| 36 | 39 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 59 : resolver_(resolver.Pass()) { | 62 : resolver_(resolver.Pass()) { |
| 60 DCHECK(resolver_->expects_pac_bytes()); | 63 DCHECK(resolver_->expects_pac_bytes()); |
| 61 } | 64 } |
| 62 | 65 |
| 63 MojoProxyResolverImpl::~MojoProxyResolverImpl() { | 66 MojoProxyResolverImpl::~MojoProxyResolverImpl() { |
| 64 if (!set_pac_script_requests_.empty()) | 67 if (!set_pac_script_requests_.empty()) |
| 65 resolver_->CancelSetPacScript(); | 68 resolver_->CancelSetPacScript(); |
| 66 STLDeleteElements(&resolve_jobs_); | 69 STLDeleteElements(&resolve_jobs_); |
| 67 } | 70 } |
| 68 | 71 |
| 72 void MojoProxyResolverImpl::LoadStateChanged( | |
| 73 net::ProxyResolver::RequestHandle handle, | |
| 74 LoadState load_state) { | |
| 75 auto it = request_handle_to_job_.find(handle); | |
| 76 if (it == request_handle_to_job_.end()) | |
| 77 return; | |
| 78 | |
| 79 it->second->LoadStateChanged(load_state); | |
| 80 } | |
| 81 | |
| 69 void MojoProxyResolverImpl::SetPacScript( | 82 void MojoProxyResolverImpl::SetPacScript( |
| 70 const mojo::String& data, | 83 const mojo::String& data, |
| 71 const mojo::Callback<void(int32_t)>& callback) { | 84 const mojo::Callback<void(int32_t)>& callback) { |
| 72 DVLOG(1) << "SetPacScript(" << data << ")"; | 85 DVLOG(1) << "SetPacScript(" << data << ")"; |
| 73 set_pac_script_requests_.push( | 86 set_pac_script_requests_.push( |
| 74 SetPacScriptRequest(ProxyResolverScriptData::FromUTF8(data), callback)); | 87 SetPacScriptRequest(ProxyResolverScriptData::FromUTF8(data), callback)); |
| 75 if (set_pac_script_requests_.size() == 1) | 88 if (set_pac_script_requests_.size() == 1) |
| 76 StartSetPacScript(); | 89 StartSetPacScript(); |
| 77 } | 90 } |
| 78 | 91 |
| 79 void MojoProxyResolverImpl::GetProxyForUrl( | 92 void MojoProxyResolverImpl::GetProxyForUrl( |
| 80 const mojo::String& url, | 93 const mojo::String& url, |
| 81 interfaces::ProxyResolverRequestClientPtr client) { | 94 interfaces::ProxyResolverRequestClientPtr client) { |
| 82 DVLOG(1) << "GetProxyForUrl(" << url << ")"; | 95 DVLOG(1) << "GetProxyForUrl(" << url << ")"; |
| 83 Job* job = new Job(client.Pass(), this, url.To<GURL>()); | 96 Job* job = new Job(client.Pass(), this, url.To<GURL>()); |
| 84 bool inserted = resolve_jobs_.insert(job).second; | 97 bool inserted = resolve_jobs_.insert(job).second; |
| 85 DCHECK(inserted); | 98 DCHECK(inserted); |
| 86 job->Start(); | 99 job->Start(); |
| 87 } | 100 } |
| 88 | 101 |
| 89 void MojoProxyResolverImpl::DeleteJob(Job* job) { | 102 void MojoProxyResolverImpl::DeleteJob( |
| 103 Job* job, | |
| 104 net::ProxyResolver::RequestHandle handle) { | |
|
eroman
2015/02/25 00:08:05
Does this need another parameter? the handle is al
Sam McNally
2015/02/26 04:00:00
Done.
| |
| 105 if (handle) | |
| 106 request_handle_to_job_.erase(handle); | |
| 90 size_t num_erased = resolve_jobs_.erase(job); | 107 size_t num_erased = resolve_jobs_.erase(job); |
| 91 DCHECK(num_erased); | 108 DCHECK(num_erased); |
| 92 delete job; | 109 delete job; |
| 93 } | 110 } |
| 94 | 111 |
| 95 void MojoProxyResolverImpl::StartSetPacScript() { | 112 void MojoProxyResolverImpl::StartSetPacScript() { |
| 96 DCHECK(!set_pac_script_requests_.empty()); | 113 DCHECK(!set_pac_script_requests_.empty()); |
| 97 int result = resolver_->SetPacScript( | 114 int result = resolver_->SetPacScript( |
| 98 set_pac_script_requests_.front().script_data, | 115 set_pac_script_requests_.front().script_data, |
| 99 base::Bind(&MojoProxyResolverImpl::SetPacScriptDone, | 116 base::Bind(&MojoProxyResolverImpl::SetPacScriptDone, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 128 | 145 |
| 129 void MojoProxyResolverImpl::Job::Start() { | 146 void MojoProxyResolverImpl::Job::Start() { |
| 130 int result = resolver_->resolver_->GetProxyForURL( | 147 int result = resolver_->resolver_->GetProxyForURL( |
| 131 url_, &result_, base::Bind(&Job::GetProxyDone, base::Unretained(this)), | 148 url_, &result_, base::Bind(&Job::GetProxyDone, base::Unretained(this)), |
| 132 &request_handle_, BoundNetLog()); | 149 &request_handle_, BoundNetLog()); |
| 133 if (result != ERR_IO_PENDING) { | 150 if (result != ERR_IO_PENDING) { |
| 134 GetProxyDone(result); | 151 GetProxyDone(result); |
| 135 return; | 152 return; |
| 136 } | 153 } |
| 137 client_.set_error_handler(this); | 154 client_.set_error_handler(this); |
| 155 resolver_->request_handle_to_job_.insert( | |
| 156 std::make_pair(request_handle_, this)); | |
| 157 } | |
| 158 | |
| 159 void MojoProxyResolverImpl::Job::LoadStateChanged(LoadState load_state) { | |
| 160 client_->LoadStateChanged(load_state); | |
|
eroman
2015/02/25 00:08:05
What is the implication of calling this? Other cal
Anand Mistry (off Chromium)
2015/02/25 04:42:27
As an optimisation, I wonder if we should try to c
Sam McNally
2015/02/26 04:00:00
client_ is the mojo binding so it only sends a mes
| |
| 138 } | 161 } |
| 139 | 162 |
| 140 void MojoProxyResolverImpl::Job::GetProxyDone(int error) { | 163 void MojoProxyResolverImpl::Job::GetProxyDone(int error) { |
| 141 request_handle_ = nullptr; | |
| 142 DVLOG(1) << "GetProxyForUrl(" << url_ << ") finished with error " << error | 164 DVLOG(1) << "GetProxyForUrl(" << url_ << ") finished with error " << error |
| 143 << ". " << result_.proxy_list().size() << " Proxies returned:"; | 165 << ". " << result_.proxy_list().size() << " Proxies returned:"; |
| 144 for (const auto& proxy : result_.proxy_list().GetAll()) { | 166 for (const auto& proxy : result_.proxy_list().GetAll()) { |
| 145 DVLOG(1) << proxy.ToURI(); | 167 DVLOG(1) << proxy.ToURI(); |
| 146 } | 168 } |
| 147 mojo::Array<interfaces::ProxyServerPtr> result; | 169 mojo::Array<interfaces::ProxyServerPtr> result; |
| 148 if (error == OK) { | 170 if (error == OK) { |
| 149 result = mojo::Array<interfaces::ProxyServerPtr>::From( | 171 result = mojo::Array<interfaces::ProxyServerPtr>::From( |
| 150 result_.proxy_list().GetAll()); | 172 result_.proxy_list().GetAll()); |
| 151 } | 173 } |
| 152 client_->ReportResult(error, result.Pass()); | 174 client_->ReportResult(error, result.Pass()); |
| 153 resolver_->DeleteJob(this); | 175 auto request_handle = request_handle_; |
| 176 request_handle_ = nullptr; | |
| 177 resolver_->DeleteJob(this, request_handle); | |
| 154 } | 178 } |
| 155 | 179 |
| 156 void MojoProxyResolverImpl::Job::OnConnectionError() { | 180 void MojoProxyResolverImpl::Job::OnConnectionError() { |
| 157 resolver_->DeleteJob(this); | 181 resolver_->DeleteJob(this, request_handle_); |
| 158 } | 182 } |
| 159 | 183 |
| 160 MojoProxyResolverImpl::SetPacScriptRequest::SetPacScriptRequest( | 184 MojoProxyResolverImpl::SetPacScriptRequest::SetPacScriptRequest( |
| 161 const scoped_refptr<ProxyResolverScriptData>& script_data, | 185 const scoped_refptr<ProxyResolverScriptData>& script_data, |
| 162 const mojo::Callback<void(int32_t)>& callback) | 186 const mojo::Callback<void(int32_t)>& callback) |
| 163 : script_data(script_data), callback(callback) { | 187 : script_data(script_data), callback(callback) { |
| 164 } | 188 } |
| 165 | 189 |
| 166 } // namespace net | 190 } // namespace net |
| OLD | NEW |