Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chromeos/dbus/services/proxy_resolution_service_provider.h" | 5 #include "chromeos/dbus/services/proxy_resolution_service_provider.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 | 156 |
| 157 // If signal information was supplied, emit a signal instead of including | 157 // If signal information was supplied, emit a signal instead of including |
| 158 // proxy information in the response. | 158 // proxy information in the response. |
| 159 std::unique_ptr<Request> request = | 159 std::unique_ptr<Request> request = |
| 160 !signal_interface.empty() | 160 !signal_interface.empty() |
| 161 ? base::MakeUnique<Request>(source_url, signal_interface, signal_name, | 161 ? base::MakeUnique<Request>(source_url, signal_interface, signal_name, |
| 162 context_getter) | 162 context_getter) |
| 163 : base::MakeUnique<Request>(source_url, std::move(response), | 163 : base::MakeUnique<Request>(source_url, std::move(response), |
| 164 response_sender, context_getter); | 164 response_sender, context_getter); |
| 165 | 165 |
| 166 NotifyCallback notify_callback = | |
| 167 base::Bind(&ProxyResolutionServiceProvider::NotifyProxyResolved, | |
| 168 weak_ptr_factory_.GetWeakPtr()); | |
| 169 | |
| 166 // This would ideally call PostTaskAndReply() instead of PostTask(), but | 170 // This would ideally call PostTaskAndReply() instead of PostTask(), but |
| 167 // ResolveProxyOnNetworkThread()'s call to net::ProxyService::ResolveProxy() | 171 // ResolveProxyOnNetworkThread()'s call to net::ProxyService::ResolveProxy() |
| 168 // can result in an asynchronous lookup, in which case the result won't be | 172 // can result in an asynchronous lookup, in which case the result won't be |
| 169 // available immediately. | 173 // available immediately. |
| 170 context_getter->GetNetworkTaskRunner()->PostTask( | 174 context_getter->GetNetworkTaskRunner()->PostTask( |
| 171 FROM_HERE, | 175 FROM_HERE, |
| 172 base::Bind(&ProxyResolutionServiceProvider::ResolveProxyOnNetworkThread, | 176 base::Bind(&ProxyResolutionServiceProvider::ResolveProxyOnNetworkThread, |
| 173 weak_ptr_factory_.GetWeakPtr(), | 177 base::Passed(std::move(request)), origin_thread_, |
| 174 base::Passed(std::move(request)))); | 178 notify_callback)); |
| 175 | 179 |
| 176 // If we didn't already pass the response to the Request object because we're | 180 // If we didn't already pass the response to the Request object because we're |
| 177 // returning data via a signal, send an empty response immediately. | 181 // returning data via a signal, send an empty response immediately. |
| 178 if (response) | 182 if (response) |
| 179 response_sender.Run(std::move(response)); | 183 response_sender.Run(std::move(response)); |
| 180 } | 184 } |
| 181 | 185 |
| 186 // static | |
| 182 void ProxyResolutionServiceProvider::ResolveProxyOnNetworkThread( | 187 void ProxyResolutionServiceProvider::ResolveProxyOnNetworkThread( |
| 183 std::unique_ptr<Request> request) { | 188 std::unique_ptr<Request> request, |
| 189 scoped_refptr<base::SingleThreadTaskRunner> notify_thread, | |
| 190 NotifyCallback notify_callback) { | |
| 184 DCHECK(request->context_getter->GetNetworkTaskRunner() | 191 DCHECK(request->context_getter->GetNetworkTaskRunner() |
| 185 ->BelongsToCurrentThread()); | 192 ->BelongsToCurrentThread()); |
| 186 | 193 |
| 187 net::ProxyService* proxy_service = | 194 net::ProxyService* proxy_service = |
| 188 request->context_getter->GetURLRequestContext()->proxy_service(); | 195 request->context_getter->GetURLRequestContext()->proxy_service(); |
| 189 if (!proxy_service) { | 196 if (!proxy_service) { |
| 190 request->error = "No proxy service in chrome"; | 197 request->error = "No proxy service in chrome"; |
| 191 OnResolutionComplete(std::move(request), net::ERR_UNEXPECTED); | 198 OnResolutionComplete(std::move(request), notify_thread, notify_callback, |
| 199 net::ERR_UNEXPECTED); | |
| 192 return; | 200 return; |
| 193 } | 201 } |
| 194 | 202 |
| 195 Request* request_ptr = request.get(); | 203 Request* request_ptr = request.get(); |
| 196 net::CompletionCallback callback = base::Bind( | 204 net::CompletionCallback callback = base::Bind( |
| 197 &ProxyResolutionServiceProvider::OnResolutionComplete, | 205 &ProxyResolutionServiceProvider::OnResolutionComplete, |
| 198 weak_ptr_factory_.GetWeakPtr(), base::Passed(std::move(request))); | 206 base::Passed(std::move(request)), notify_thread, notify_callback); |
|
James Cook
2017/04/03 15:30:23
optional: Add a comment near here (or in header?)
Daniel Erat
2017/04/04 00:01:37
Done.
| |
| 199 | 207 |
| 200 VLOG(1) << "Starting network proxy resolution for " | 208 VLOG(1) << "Starting network proxy resolution for " |
| 201 << request_ptr->source_url; | 209 << request_ptr->source_url; |
| 202 const int result = proxy_service->ResolveProxy( | 210 const int result = proxy_service->ResolveProxy( |
| 203 GURL(request_ptr->source_url), std::string(), &request_ptr->proxy_info, | 211 GURL(request_ptr->source_url), std::string(), &request_ptr->proxy_info, |
| 204 callback, nullptr, nullptr, net::NetLogWithSource()); | 212 callback, nullptr, nullptr, net::NetLogWithSource()); |
| 205 if (result != net::ERR_IO_PENDING) { | 213 if (result != net::ERR_IO_PENDING) { |
| 206 VLOG(1) << "Network proxy resolution completed synchronously."; | 214 VLOG(1) << "Network proxy resolution completed synchronously."; |
| 207 callback.Run(result); | 215 callback.Run(result); |
| 208 } | 216 } |
| 209 } | 217 } |
| 210 | 218 |
| 219 // static | |
| 211 void ProxyResolutionServiceProvider::OnResolutionComplete( | 220 void ProxyResolutionServiceProvider::OnResolutionComplete( |
| 212 std::unique_ptr<Request> request, | 221 std::unique_ptr<Request> request, |
| 222 scoped_refptr<base::SingleThreadTaskRunner> notify_thread, | |
| 223 NotifyCallback notify_callback, | |
| 213 int result) { | 224 int result) { |
| 214 DCHECK(request->context_getter->GetNetworkTaskRunner() | 225 DCHECK(request->context_getter->GetNetworkTaskRunner() |
| 215 ->BelongsToCurrentThread()); | 226 ->BelongsToCurrentThread()); |
| 216 | 227 |
| 217 if (request->error.empty() && result != net::OK) | 228 if (request->error.empty() && result != net::OK) |
| 218 request->error = net::ErrorToString(result); | 229 request->error = net::ErrorToString(result); |
| 219 | 230 |
| 220 origin_thread_->PostTask( | 231 notify_thread->PostTask( |
| 221 FROM_HERE, | 232 FROM_HERE, base::Bind(notify_callback, base::Passed(std::move(request)))); |
| 222 base::Bind(&ProxyResolutionServiceProvider::NotifyProxyResolved, | |
| 223 weak_ptr_factory_.GetWeakPtr(), | |
| 224 base::Passed(std::move(request)))); | |
| 225 } | 233 } |
| 226 | 234 |
| 227 void ProxyResolutionServiceProvider::NotifyProxyResolved( | 235 void ProxyResolutionServiceProvider::NotifyProxyResolved( |
| 228 std::unique_ptr<Request> request) { | 236 std::unique_ptr<Request> request) { |
| 229 DCHECK(OnOriginThread()); | 237 DCHECK(OnOriginThread()); |
| 230 | 238 |
| 231 if (request->response) { | 239 if (request->response) { |
| 232 // Reply to the original D-Bus method call. | 240 // Reply to the original D-Bus method call. |
| 233 dbus::MessageWriter writer(request->response.get()); | 241 dbus::MessageWriter writer(request->response.get()); |
| 234 writer.AppendString(request->proxy_info.ToPacString()); | 242 writer.AppendString(request->proxy_info.ToPacString()); |
| 235 writer.AppendString(request->error); | 243 writer.AppendString(request->error); |
| 236 request->response_sender.Run(std::move(request->response)); | 244 request->response_sender.Run(std::move(request->response)); |
| 237 } else { | 245 } else { |
| 238 // Send a signal to the client. | 246 // Send a signal to the client. |
| 239 dbus::Signal signal(request->signal_interface, request->signal_name); | 247 dbus::Signal signal(request->signal_interface, request->signal_name); |
| 240 dbus::MessageWriter writer(&signal); | 248 dbus::MessageWriter writer(&signal); |
| 241 writer.AppendString(request->source_url); | 249 writer.AppendString(request->source_url); |
| 242 writer.AppendString(request->proxy_info.ToPacString()); | 250 writer.AppendString(request->proxy_info.ToPacString()); |
| 243 writer.AppendString(request->error); | 251 writer.AppendString(request->error); |
| 244 exported_object_->SendSignal(&signal); | 252 exported_object_->SendSignal(&signal); |
| 245 VLOG(1) << "Sending signal: " << signal.ToString(); | 253 VLOG(1) << "Sending signal: " << signal.ToString(); |
| 246 } | 254 } |
| 247 } | 255 } |
| 248 | 256 |
| 249 } // namespace chromeos | 257 } // namespace chromeos |
| OLD | NEW |