| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_v8_tracing.h" | 5 #include "net/proxy/proxy_resolver_v8_tracing.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 ProxyResolverV8TracingImpl(scoped_ptr<base::Thread> thread, | 304 ProxyResolverV8TracingImpl(scoped_ptr<base::Thread> thread, |
| 305 scoped_ptr<ProxyResolverV8> resolver, | 305 scoped_ptr<ProxyResolverV8> resolver, |
| 306 scoped_ptr<Job::Params> job_params); | 306 scoped_ptr<Job::Params> job_params); |
| 307 | 307 |
| 308 ~ProxyResolverV8TracingImpl() override; | 308 ~ProxyResolverV8TracingImpl() override; |
| 309 | 309 |
| 310 // ProxyResolverV8Tracing overrides. | 310 // ProxyResolverV8Tracing overrides. |
| 311 void GetProxyForURL(const GURL& url, | 311 void GetProxyForURL(const GURL& url, |
| 312 ProxyInfo* results, | 312 ProxyInfo* results, |
| 313 const CompletionCallback& callback, | 313 const CompletionCallback& callback, |
| 314 scoped_ptr<ProxyResolver::Request>* request, | 314 ProxyResolver::RequestHandle* request, |
| 315 scoped_ptr<Bindings> bindings) override; | 315 scoped_ptr<Bindings> bindings) override; |
| 316 | 316 void CancelRequest(ProxyResolver::RequestHandle request) override; |
| 317 class RequestImpl : public ProxyResolver::Request { | 317 LoadState GetLoadState(ProxyResolver::RequestHandle request) const override; |
| 318 public: | |
| 319 explicit RequestImpl(scoped_refptr<Job> job); | |
| 320 ~RequestImpl() override; | |
| 321 LoadState GetLoadState() override; | |
| 322 | |
| 323 private: | |
| 324 scoped_refptr<Job> job_; | |
| 325 }; | |
| 326 | 318 |
| 327 private: | 319 private: |
| 328 // The worker thread on which the ProxyResolverV8 will be run. | 320 // The worker thread on which the ProxyResolverV8 will be run. |
| 329 scoped_ptr<base::Thread> thread_; | 321 scoped_ptr<base::Thread> thread_; |
| 330 scoped_ptr<ProxyResolverV8> v8_resolver_; | 322 scoped_ptr<ProxyResolverV8> v8_resolver_; |
| 331 | 323 |
| 332 scoped_ptr<Job::Params> job_params_; | 324 scoped_ptr<Job::Params> job_params_; |
| 333 | 325 |
| 334 // The number of outstanding (non-cancelled) jobs. | 326 // The number of outstanding (non-cancelled) jobs. |
| 335 int num_outstanding_callbacks_; | 327 int num_outstanding_callbacks_; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 // (b) The script is executing on the worker thread. | 376 // (b) The script is executing on the worker thread. |
| 385 // (c) The script is executing on the worker thread, however is blocked inside | 377 // (c) The script is executing on the worker thread, however is blocked inside |
| 386 // of dnsResolve() waiting for a response from the origin thread. | 378 // of dnsResolve() waiting for a response from the origin thread. |
| 387 // (d) Nothing is running on the worker thread, however the host resolver has | 379 // (d) Nothing is running on the worker thread, however the host resolver has |
| 388 // a pending DNS request which upon completion will restart the script | 380 // a pending DNS request which upon completion will restart the script |
| 389 // execution. | 381 // execution. |
| 390 // (e) The worker thread has a pending task to restart execution, which was | 382 // (e) The worker thread has a pending task to restart execution, which was |
| 391 // posted after the DNS dependency was resolved and saved to local cache. | 383 // posted after the DNS dependency was resolved and saved to local cache. |
| 392 // (f) The script execution completed entirely, and posted a task to the | 384 // (f) The script execution completed entirely, and posted a task to the |
| 393 // origin thread to notify the caller. | 385 // origin thread to notify the caller. |
| 394 // (g) The job is already completed. | |
| 395 // | 386 // |
| 396 // |cancelled_| is read on both the origin thread and worker thread. The | 387 // |cancelled_| is read on both the origin thread and worker thread. The |
| 397 // code that runs on the worker thread is littered with checks on | 388 // code that runs on the worker thread is littered with checks on |
| 398 // |cancelled_| to break out early. | 389 // |cancelled_| to break out early. |
| 399 | |
| 400 // If the job already completed, there is nothing to be cancelled. | |
| 401 if (callback_.is_null()) | |
| 402 return; | |
| 403 | |
| 404 cancelled_.Set(); | 390 cancelled_.Set(); |
| 405 | 391 |
| 406 ReleaseCallback(); | 392 ReleaseCallback(); |
| 407 | 393 |
| 408 if (pending_dns_) { | 394 if (pending_dns_) { |
| 409 host_resolver()->CancelRequest(pending_dns_); | 395 host_resolver()->CancelRequest(pending_dns_); |
| 410 pending_dns_ = NULL; | 396 pending_dns_ = NULL; |
| 411 } | 397 } |
| 412 | 398 |
| 413 // The worker thread might be blocked waiting for DNS. | 399 // The worker thread might be blocked waiting for DNS. |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 | 927 |
| 942 ProxyResolverV8TracingImpl::~ProxyResolverV8TracingImpl() { | 928 ProxyResolverV8TracingImpl::~ProxyResolverV8TracingImpl() { |
| 943 // Note, all requests should have been cancelled. | 929 // Note, all requests should have been cancelled. |
| 944 CHECK_EQ(0, num_outstanding_callbacks_); | 930 CHECK_EQ(0, num_outstanding_callbacks_); |
| 945 | 931 |
| 946 // Join the worker thread. See http://crbug.com/69710. | 932 // Join the worker thread. See http://crbug.com/69710. |
| 947 base::ThreadRestrictions::ScopedAllowIO allow_io; | 933 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 948 thread_.reset(); | 934 thread_.reset(); |
| 949 } | 935 } |
| 950 | 936 |
| 951 ProxyResolverV8TracingImpl::RequestImpl::RequestImpl(scoped_refptr<Job> job) | |
| 952 : job_(std::move(job)) {} | |
| 953 | |
| 954 ProxyResolverV8TracingImpl::RequestImpl::~RequestImpl() { | |
| 955 job_->Cancel(); | |
| 956 } | |
| 957 | |
| 958 LoadState ProxyResolverV8TracingImpl::RequestImpl::GetLoadState() { | |
| 959 return job_->GetLoadState(); | |
| 960 } | |
| 961 | |
| 962 void ProxyResolverV8TracingImpl::GetProxyForURL( | 937 void ProxyResolverV8TracingImpl::GetProxyForURL( |
| 963 const GURL& url, | 938 const GURL& url, |
| 964 ProxyInfo* results, | 939 ProxyInfo* results, |
| 965 const CompletionCallback& callback, | 940 const CompletionCallback& callback, |
| 966 scoped_ptr<ProxyResolver::Request>* request, | 941 ProxyResolver::RequestHandle* request, |
| 967 scoped_ptr<Bindings> bindings) { | 942 scoped_ptr<Bindings> bindings) { |
| 968 DCHECK(CalledOnValidThread()); | 943 DCHECK(CalledOnValidThread()); |
| 969 DCHECK(!callback.is_null()); | 944 DCHECK(!callback.is_null()); |
| 970 | 945 |
| 971 scoped_refptr<Job> job = new Job(job_params_.get(), std::move(bindings)); | 946 scoped_refptr<Job> job = new Job(job_params_.get(), std::move(bindings)); |
| 972 | 947 |
| 973 request->reset(new RequestImpl(job)); | 948 if (request) |
| 949 *request = job.get(); |
| 974 | 950 |
| 975 job->StartGetProxyForURL(url, results, callback); | 951 job->StartGetProxyForURL(url, results, callback); |
| 976 } | 952 } |
| 977 | 953 |
| 954 void ProxyResolverV8TracingImpl::CancelRequest( |
| 955 ProxyResolver::RequestHandle request) { |
| 956 Job* job = reinterpret_cast<Job*>(request); |
| 957 job->Cancel(); |
| 958 } |
| 959 |
| 960 LoadState ProxyResolverV8TracingImpl::GetLoadState( |
| 961 ProxyResolver::RequestHandle request) const { |
| 962 Job* job = reinterpret_cast<Job*>(request); |
| 963 return job->GetLoadState(); |
| 964 } |
| 978 | 965 |
| 979 class ProxyResolverV8TracingFactoryImpl : public ProxyResolverV8TracingFactory { | 966 class ProxyResolverV8TracingFactoryImpl : public ProxyResolverV8TracingFactory { |
| 980 public: | 967 public: |
| 981 ProxyResolverV8TracingFactoryImpl(); | 968 ProxyResolverV8TracingFactoryImpl(); |
| 982 ~ProxyResolverV8TracingFactoryImpl() override; | 969 ~ProxyResolverV8TracingFactoryImpl() override; |
| 983 | 970 |
| 984 void CreateProxyResolverV8Tracing( | 971 void CreateProxyResolverV8Tracing( |
| 985 const scoped_refptr<ProxyResolverScriptData>& pac_script, | 972 const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 986 scoped_ptr<ProxyResolverV8Tracing::Bindings> bindings, | 973 scoped_ptr<ProxyResolverV8Tracing::Bindings> bindings, |
| 987 scoped_ptr<ProxyResolverV8Tracing>* resolver, | 974 scoped_ptr<ProxyResolverV8Tracing>* resolver, |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1106 | 1093 |
| 1107 } // namespace | 1094 } // namespace |
| 1108 | 1095 |
| 1109 // static | 1096 // static |
| 1110 scoped_ptr<ProxyResolverV8TracingFactory> | 1097 scoped_ptr<ProxyResolverV8TracingFactory> |
| 1111 ProxyResolverV8TracingFactory::Create() { | 1098 ProxyResolverV8TracingFactory::Create() { |
| 1112 return make_scoped_ptr(new ProxyResolverV8TracingFactoryImpl()); | 1099 return make_scoped_ptr(new ProxyResolverV8TracingFactoryImpl()); |
| 1113 } | 1100 } |
| 1114 | 1101 |
| 1115 } // namespace net | 1102 } // namespace net |
| OLD | NEW |