| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/sequence_checker.h" |
| 15 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 17 #include "base/synchronization/cancellation_flag.h" | 18 #include "base/synchronization/cancellation_flag.h" |
| 18 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
| 19 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
| 20 #include "base/threading/thread_restrictions.h" | 21 #include "base/threading/thread_restrictions.h" |
| 21 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "base/trace_event/trace_event.h" | 23 #include "base/trace_event/trace_event.h" |
| 23 #include "net/base/address_list.h" | 24 #include "net/base/address_list.h" |
| 24 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 // These are the inputs to DoDnsOperation(). Written on the worker thread, | 296 // These are the inputs to DoDnsOperation(). Written on the worker thread, |
| 296 // read by the origin thread. | 297 // read by the origin thread. |
| 297 std::string pending_dns_host_; | 298 std::string pending_dns_host_; |
| 298 ResolveDnsOperation pending_dns_op_; | 299 ResolveDnsOperation pending_dns_op_; |
| 299 | 300 |
| 300 // This contains the resolved address list that DoDnsOperation() fills in. | 301 // This contains the resolved address list that DoDnsOperation() fills in. |
| 301 // Used exclusively on the origin thread. | 302 // Used exclusively on the origin thread. |
| 302 AddressList pending_dns_addresses_; | 303 AddressList pending_dns_addresses_; |
| 303 }; | 304 }; |
| 304 | 305 |
| 305 class ProxyResolverV8TracingImpl : public ProxyResolverV8Tracing, | 306 class ProxyResolverV8TracingImpl : public ProxyResolverV8Tracing { |
| 306 public base::NonThreadSafe { | |
| 307 public: | 307 public: |
| 308 ProxyResolverV8TracingImpl(std::unique_ptr<base::Thread> thread, | 308 ProxyResolverV8TracingImpl(std::unique_ptr<base::Thread> thread, |
| 309 std::unique_ptr<ProxyResolverV8> resolver, | 309 std::unique_ptr<ProxyResolverV8> resolver, |
| 310 std::unique_ptr<Job::Params> job_params); | 310 std::unique_ptr<Job::Params> job_params); |
| 311 | 311 |
| 312 ~ProxyResolverV8TracingImpl() override; | 312 ~ProxyResolverV8TracingImpl() override; |
| 313 | 313 |
| 314 // ProxyResolverV8Tracing overrides. | 314 // ProxyResolverV8Tracing overrides. |
| 315 void GetProxyForURL(const GURL& url, | 315 void GetProxyForURL(const GURL& url, |
| 316 ProxyInfo* results, | 316 ProxyInfo* results, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 331 private: | 331 private: |
| 332 // The worker thread on which the ProxyResolverV8 will be run. | 332 // The worker thread on which the ProxyResolverV8 will be run. |
| 333 std::unique_ptr<base::Thread> thread_; | 333 std::unique_ptr<base::Thread> thread_; |
| 334 std::unique_ptr<ProxyResolverV8> v8_resolver_; | 334 std::unique_ptr<ProxyResolverV8> v8_resolver_; |
| 335 | 335 |
| 336 std::unique_ptr<Job::Params> job_params_; | 336 std::unique_ptr<Job::Params> job_params_; |
| 337 | 337 |
| 338 // The number of outstanding (non-cancelled) jobs. | 338 // The number of outstanding (non-cancelled) jobs. |
| 339 int num_outstanding_callbacks_; | 339 int num_outstanding_callbacks_; |
| 340 | 340 |
| 341 SEQUENCE_CHECKER(sequence_checker_); |
| 342 |
| 341 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8TracingImpl); | 343 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8TracingImpl); |
| 342 }; | 344 }; |
| 343 | 345 |
| 344 Job::Job(const Job::Params* params, | 346 Job::Job(const Job::Params* params, |
| 345 std::unique_ptr<ProxyResolverV8Tracing::Bindings> bindings) | 347 std::unique_ptr<ProxyResolverV8Tracing::Bindings> bindings) |
| 346 : origin_runner_(base::ThreadTaskRunnerHandle::Get()), | 348 : origin_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 347 params_(params), | 349 params_(params), |
| 348 bindings_(std::move(bindings)), | 350 bindings_(std::move(bindings)), |
| 349 event_(base::WaitableEvent::ResetPolicy::MANUAL, | 351 event_(base::WaitableEvent::ResetPolicy::MANUAL, |
| 350 base::WaitableEvent::InitialState::NOT_SIGNALED), | 352 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 std::unique_ptr<ProxyResolverV8> resolver, | 937 std::unique_ptr<ProxyResolverV8> resolver, |
| 936 std::unique_ptr<Job::Params> job_params) | 938 std::unique_ptr<Job::Params> job_params) |
| 937 : thread_(std::move(thread)), | 939 : thread_(std::move(thread)), |
| 938 v8_resolver_(std::move(resolver)), | 940 v8_resolver_(std::move(resolver)), |
| 939 job_params_(std::move(job_params)), | 941 job_params_(std::move(job_params)), |
| 940 num_outstanding_callbacks_(0) { | 942 num_outstanding_callbacks_(0) { |
| 941 job_params_->num_outstanding_callbacks = &num_outstanding_callbacks_; | 943 job_params_->num_outstanding_callbacks = &num_outstanding_callbacks_; |
| 942 } | 944 } |
| 943 | 945 |
| 944 ProxyResolverV8TracingImpl::~ProxyResolverV8TracingImpl() { | 946 ProxyResolverV8TracingImpl::~ProxyResolverV8TracingImpl() { |
| 947 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 945 // Note, all requests should have been cancelled. | 948 // Note, all requests should have been cancelled. |
| 946 CHECK_EQ(0, num_outstanding_callbacks_); | 949 CHECK_EQ(0, num_outstanding_callbacks_); |
| 947 | 950 |
| 948 // Join the worker thread. See http://crbug.com/69710. | 951 // Join the worker thread. See http://crbug.com/69710. |
| 949 base::ThreadRestrictions::ScopedAllowIO allow_io; | 952 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 950 thread_.reset(); | 953 thread_.reset(); |
| 951 } | 954 } |
| 952 | 955 |
| 953 ProxyResolverV8TracingImpl::RequestImpl::RequestImpl(scoped_refptr<Job> job) | 956 ProxyResolverV8TracingImpl::RequestImpl::RequestImpl(scoped_refptr<Job> job) |
| 954 : job_(std::move(job)) {} | 957 : job_(std::move(job)) {} |
| 955 | 958 |
| 956 ProxyResolverV8TracingImpl::RequestImpl::~RequestImpl() { | 959 ProxyResolverV8TracingImpl::RequestImpl::~RequestImpl() { |
| 957 job_->Cancel(); | 960 job_->Cancel(); |
| 958 } | 961 } |
| 959 | 962 |
| 960 LoadState ProxyResolverV8TracingImpl::RequestImpl::GetLoadState() { | 963 LoadState ProxyResolverV8TracingImpl::RequestImpl::GetLoadState() { |
| 961 return job_->GetLoadState(); | 964 return job_->GetLoadState(); |
| 962 } | 965 } |
| 963 | 966 |
| 964 void ProxyResolverV8TracingImpl::GetProxyForURL( | 967 void ProxyResolverV8TracingImpl::GetProxyForURL( |
| 965 const GURL& url, | 968 const GURL& url, |
| 966 ProxyInfo* results, | 969 ProxyInfo* results, |
| 967 const CompletionCallback& callback, | 970 const CompletionCallback& callback, |
| 968 std::unique_ptr<ProxyResolver::Request>* request, | 971 std::unique_ptr<ProxyResolver::Request>* request, |
| 969 std::unique_ptr<Bindings> bindings) { | 972 std::unique_ptr<Bindings> bindings) { |
| 970 DCHECK(CalledOnValidThread()); | 973 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 971 DCHECK(!callback.is_null()); | 974 DCHECK(!callback.is_null()); |
| 972 | 975 |
| 973 scoped_refptr<Job> job = new Job(job_params_.get(), std::move(bindings)); | 976 scoped_refptr<Job> job = new Job(job_params_.get(), std::move(bindings)); |
| 974 | 977 |
| 975 request->reset(new RequestImpl(job)); | 978 request->reset(new RequestImpl(job)); |
| 976 | 979 |
| 977 job->StartGetProxyForURL(url, results, callback); | 980 job->StartGetProxyForURL(url, results, callback); |
| 978 } | 981 } |
| 979 | 982 |
| 980 | 983 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 | 1111 |
| 1109 } // namespace | 1112 } // namespace |
| 1110 | 1113 |
| 1111 // static | 1114 // static |
| 1112 std::unique_ptr<ProxyResolverV8TracingFactory> | 1115 std::unique_ptr<ProxyResolverV8TracingFactory> |
| 1113 ProxyResolverV8TracingFactory::Create() { | 1116 ProxyResolverV8TracingFactory::Create() { |
| 1114 return base::WrapUnique(new ProxyResolverV8TracingFactoryImpl()); | 1117 return base::WrapUnique(new ProxyResolverV8TracingFactoryImpl()); |
| 1115 } | 1118 } |
| 1116 | 1119 |
| 1117 } // namespace net | 1120 } // namespace net |
| OLD | NEW |