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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 // seems to be misbehaving under the tracing optimization. | 68 // seems to be misbehaving under the tracing optimization. |
69 // | 69 // |
70 // Note that this class runs on both the origin thread and a worker | 70 // Note that this class runs on both the origin thread and a worker |
71 // thread. Most methods are expected to be used exclusively on one thread | 71 // thread. Most methods are expected to be used exclusively on one thread |
72 // or the other. | 72 // or the other. |
73 // | 73 // |
74 // The lifetime of Jobs does not exceed that of the ProxyResolverV8TracingImpl | 74 // The lifetime of Jobs does not exceed that of the ProxyResolverV8TracingImpl |
75 // that spawned it. Destruction might happen on either the origin thread or the | 75 // that spawned it. Destruction might happen on either the origin thread or the |
76 // worker thread. | 76 // worker thread. |
77 class Job : public base::RefCountedThreadSafe<Job>, | 77 class Job : public base::RefCountedThreadSafe<Job>, |
78 public base::SupportsWeakPtr<Job>, | |
78 public ProxyResolverV8::JSBindings { | 79 public ProxyResolverV8::JSBindings { |
79 public: | 80 public: |
80 struct Params { | 81 struct Params { |
81 Params( | 82 Params( |
82 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner, | 83 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner, |
83 int* num_outstanding_callbacks) | 84 int* num_outstanding_callbacks) |
84 : v8_resolver(nullptr), | 85 : v8_resolver(nullptr), |
85 worker_task_runner(worker_task_runner), | 86 worker_task_runner(worker_task_runner), |
86 num_outstanding_callbacks(num_outstanding_callbacks) {} | 87 num_outstanding_callbacks(num_outstanding_callbacks) {} |
87 | 88 |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 ProxyResolverV8TracingImpl(scoped_ptr<base::Thread> thread, | 305 ProxyResolverV8TracingImpl(scoped_ptr<base::Thread> thread, |
305 scoped_ptr<ProxyResolverV8> resolver, | 306 scoped_ptr<ProxyResolverV8> resolver, |
306 scoped_ptr<Job::Params> job_params); | 307 scoped_ptr<Job::Params> job_params); |
307 | 308 |
308 ~ProxyResolverV8TracingImpl() override; | 309 ~ProxyResolverV8TracingImpl() override; |
309 | 310 |
310 // ProxyResolverV8Tracing overrides. | 311 // ProxyResolverV8Tracing overrides. |
311 void GetProxyForURL(const GURL& url, | 312 void GetProxyForURL(const GURL& url, |
312 ProxyInfo* results, | 313 ProxyInfo* results, |
313 const CompletionCallback& callback, | 314 const CompletionCallback& callback, |
314 ProxyResolver::RequestHandle* request, | 315 scoped_ptr<ProxyResolver::Request>* request, |
315 scoped_ptr<Bindings> bindings) override; | 316 scoped_ptr<Bindings> bindings) override; |
316 void CancelRequest(ProxyResolver::RequestHandle request) override; | 317 |
317 LoadState GetLoadState(ProxyResolver::RequestHandle request) const override; | 318 class RequestImpl : public ProxyResolverV8Tracing::Request { |
319 public: | |
320 RequestImpl(base::WeakPtr<Job> job); | |
321 ~RequestImpl() override; | |
322 LoadState GetLoadState() override; | |
323 | |
324 private: | |
325 base::WeakPtr<Job> job_; | |
326 }; | |
318 | 327 |
319 private: | 328 private: |
320 // The worker thread on which the ProxyResolverV8 will be run. | 329 // The worker thread on which the ProxyResolverV8 will be run. |
321 scoped_ptr<base::Thread> thread_; | 330 scoped_ptr<base::Thread> thread_; |
322 scoped_ptr<ProxyResolverV8> v8_resolver_; | 331 scoped_ptr<ProxyResolverV8> v8_resolver_; |
323 | 332 |
324 scoped_ptr<Job::Params> job_params_; | 333 scoped_ptr<Job::Params> job_params_; |
325 | 334 |
326 // The number of outstanding (non-cancelled) jobs. | 335 // The number of outstanding (non-cancelled) jobs. |
327 int num_outstanding_callbacks_; | 336 int num_outstanding_callbacks_; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
427 } | 436 } |
428 | 437 |
429 void Job::SetCallback(const CompletionCallback& callback) { | 438 void Job::SetCallback(const CompletionCallback& callback) { |
430 CheckIsOnOriginThread(); | 439 CheckIsOnOriginThread(); |
431 DCHECK(callback_.is_null()); | 440 DCHECK(callback_.is_null()); |
432 (*params_->num_outstanding_callbacks)++; | 441 (*params_->num_outstanding_callbacks)++; |
433 callback_ = callback; | 442 callback_ = callback; |
434 } | 443 } |
435 | 444 |
436 void Job::ReleaseCallback() { | 445 void Job::ReleaseCallback() { |
446 if (callback_.is_null()) | |
447 return; | |
437 CheckIsOnOriginThread(); | 448 CheckIsOnOriginThread(); |
438 DCHECK(!callback_.is_null()); | 449 DCHECK(!callback_.is_null()); |
439 CHECK_GT(*params_->num_outstanding_callbacks, 0); | 450 CHECK_GT(*params_->num_outstanding_callbacks, 0); |
440 (*params_->num_outstanding_callbacks)--; | 451 (*params_->num_outstanding_callbacks)--; |
441 callback_.Reset(); | 452 callback_.Reset(); |
442 | 453 |
443 // For good measure, clear this other user-owned pointer. | 454 // For good measure, clear this other user-owned pointer. |
444 user_results_ = NULL; | 455 user_results_ = NULL; |
445 } | 456 } |
446 | 457 |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
927 | 938 |
928 ProxyResolverV8TracingImpl::~ProxyResolverV8TracingImpl() { | 939 ProxyResolverV8TracingImpl::~ProxyResolverV8TracingImpl() { |
929 // Note, all requests should have been cancelled. | 940 // Note, all requests should have been cancelled. |
930 CHECK_EQ(0, num_outstanding_callbacks_); | 941 CHECK_EQ(0, num_outstanding_callbacks_); |
931 | 942 |
932 // Join the worker thread. See http://crbug.com/69710. | 943 // Join the worker thread. See http://crbug.com/69710. |
933 base::ThreadRestrictions::ScopedAllowIO allow_io; | 944 base::ThreadRestrictions::ScopedAllowIO allow_io; |
934 thread_.reset(); | 945 thread_.reset(); |
935 } | 946 } |
936 | 947 |
948 ProxyResolverV8TracingImpl::RequestImpl::RequestImpl(base::WeakPtr<Job> job) | |
949 : job_(job) {} | |
eroman
2016/01/23 02:17:01
Same comment as for MultiThreadedProxyResolver. I
| |
950 | |
951 ProxyResolverV8TracingImpl::RequestImpl::~RequestImpl() { | |
952 if (job_) | |
eroman
2016/01/23 02:17:01
Shouldn't need this check once making job_ a stron
| |
953 job_->Cancel(); | |
954 } | |
955 | |
956 LoadState ProxyResolverV8TracingImpl::RequestImpl::GetLoadState() { | |
957 return job_->GetLoadState(); | |
958 } | |
959 | |
937 void ProxyResolverV8TracingImpl::GetProxyForURL( | 960 void ProxyResolverV8TracingImpl::GetProxyForURL( |
938 const GURL& url, | 961 const GURL& url, |
939 ProxyInfo* results, | 962 ProxyInfo* results, |
940 const CompletionCallback& callback, | 963 const CompletionCallback& callback, |
941 ProxyResolver::RequestHandle* request, | 964 scoped_ptr<ProxyResolver::Request>* request, |
942 scoped_ptr<Bindings> bindings) { | 965 scoped_ptr<Bindings> bindings) { |
943 DCHECK(CalledOnValidThread()); | 966 DCHECK(CalledOnValidThread()); |
944 DCHECK(!callback.is_null()); | 967 DCHECK(!callback.is_null()); |
945 | 968 |
946 scoped_refptr<Job> job = new Job(job_params_.get(), std::move(bindings)); | 969 scoped_refptr<Job> job = new Job(job_params_.get(), std::move(bindings)); |
947 | 970 |
948 if (request) | 971 if (request) |
eroman
2016/01/23 02:17:01
I wonder if we actually use this check (should at
| |
949 *request = job.get(); | 972 request->reset(new RequestImpl(job->AsWeakPtr())); |
950 | 973 |
951 job->StartGetProxyForURL(url, results, callback); | 974 job->StartGetProxyForURL(url, results, callback); |
952 } | 975 } |
953 | 976 |
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 | 977 |
966 class ProxyResolverV8TracingFactoryImpl : public ProxyResolverV8TracingFactory { | 978 class ProxyResolverV8TracingFactoryImpl : public ProxyResolverV8TracingFactory { |
967 public: | 979 public: |
968 ProxyResolverV8TracingFactoryImpl(); | 980 ProxyResolverV8TracingFactoryImpl(); |
969 ~ProxyResolverV8TracingFactoryImpl() override; | 981 ~ProxyResolverV8TracingFactoryImpl() override; |
970 | 982 |
971 void CreateProxyResolverV8Tracing( | 983 void CreateProxyResolverV8Tracing( |
972 const scoped_refptr<ProxyResolverScriptData>& pac_script, | 984 const scoped_refptr<ProxyResolverScriptData>& pac_script, |
973 scoped_ptr<ProxyResolverV8Tracing::Bindings> bindings, | 985 scoped_ptr<ProxyResolverV8Tracing::Bindings> bindings, |
974 scoped_ptr<ProxyResolverV8Tracing>* resolver, | 986 scoped_ptr<ProxyResolverV8Tracing>* resolver, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1093 | 1105 |
1094 } // namespace | 1106 } // namespace |
1095 | 1107 |
1096 // static | 1108 // static |
1097 scoped_ptr<ProxyResolverV8TracingFactory> | 1109 scoped_ptr<ProxyResolverV8TracingFactory> |
1098 ProxyResolverV8TracingFactory::Create() { | 1110 ProxyResolverV8TracingFactory::Create() { |
1099 return make_scoped_ptr(new ProxyResolverV8TracingFactoryImpl()); | 1111 return make_scoped_ptr(new ProxyResolverV8TracingFactoryImpl()); |
1100 } | 1112 } |
1101 | 1113 |
1102 } // namespace net | 1114 } // namespace net |
OLD | NEW |