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