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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/synchronization/cancellation_flag.h" | 10 #include "base/synchronization/cancellation_flag.h" |
11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "base/thread_task_runner_handle.h" |
12 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
13 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "net/base/address_list.h" | 16 #include "net/base/address_list.h" |
16 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
17 #include "net/dns/host_resolver.h" | 18 #include "net/dns/host_resolver.h" |
18 #include "net/log/net_log.h" | 19 #include "net/log/net_log.h" |
19 #include "net/proxy/proxy_info.h" | 20 #include "net/proxy/proxy_info.h" |
20 #include "net/proxy/proxy_resolver_error_observer.h" | 21 #include "net/proxy/proxy_resolver_error_observer.h" |
21 #include "net/proxy/proxy_resolver_v8.h" | 22 #include "net/proxy/proxy_resolver_v8.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 void DispatchBufferedAlertsAndErrors(); | 194 void DispatchBufferedAlertsAndErrors(); |
194 void DispatchAlertOrError(bool is_alert, int line_number, | 195 void DispatchAlertOrError(bool is_alert, int line_number, |
195 const base::string16& message); | 196 const base::string16& message); |
196 | 197 |
197 void LogEventToCurrentRequestAndGlobally( | 198 void LogEventToCurrentRequestAndGlobally( |
198 NetLog::EventType type, | 199 NetLog::EventType type, |
199 const NetLog::ParametersCallback& parameters_callback); | 200 const NetLog::ParametersCallback& parameters_callback); |
200 | 201 |
201 // The thread which called into ProxyResolverV8Tracing, and on which the | 202 // The thread which called into ProxyResolverV8Tracing, and on which the |
202 // completion callback is expected to run. | 203 // completion callback is expected to run. |
203 scoped_refptr<base::MessageLoopProxy> origin_loop_; | 204 scoped_refptr<base::SingleThreadTaskRunner> origin_runner_; |
204 | 205 |
205 // The ProxyResolverV8Tracing which spawned this Job. | 206 // The ProxyResolverV8Tracing which spawned this Job. |
206 // Initialized on origin thread and then accessed from both threads. | 207 // Initialized on origin thread and then accessed from both threads. |
207 ProxyResolverV8Tracing* parent_; | 208 ProxyResolverV8Tracing* parent_; |
208 | 209 |
209 // The callback to run (on the origin thread) when the Job finishes. | 210 // The callback to run (on the origin thread) when the Job finishes. |
210 // Should only be accessed from origin thread. | 211 // Should only be accessed from origin thread. |
211 CompletionCallback callback_; | 212 CompletionCallback callback_; |
212 | 213 |
213 // Flag to indicate whether the request has been cancelled. | 214 // Flag to indicate whether the request has been cancelled. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 // read by the origin thread. | 289 // read by the origin thread. |
289 std::string pending_dns_host_; | 290 std::string pending_dns_host_; |
290 ResolveDnsOperation pending_dns_op_; | 291 ResolveDnsOperation pending_dns_op_; |
291 | 292 |
292 // This contains the resolved address list that DoDnsOperation() fills in. | 293 // This contains the resolved address list that DoDnsOperation() fills in. |
293 // Used exclusively on the origin thread. | 294 // Used exclusively on the origin thread. |
294 AddressList pending_dns_addresses_; | 295 AddressList pending_dns_addresses_; |
295 }; | 296 }; |
296 | 297 |
297 ProxyResolverV8Tracing::Job::Job(ProxyResolverV8Tracing* parent) | 298 ProxyResolverV8Tracing::Job::Job(ProxyResolverV8Tracing* parent) |
298 : origin_loop_(base::MessageLoopProxy::current()), | 299 : origin_runner_(base::ThreadTaskRunnerHandle::Get()), |
299 parent_(parent), | 300 parent_(parent), |
300 event_(true, false), | 301 event_(true, false), |
301 last_num_dns_(0), | 302 last_num_dns_(0), |
302 pending_dns_(NULL) { | 303 pending_dns_(NULL) { |
303 CheckIsOnOriginThread(); | 304 CheckIsOnOriginThread(); |
304 } | 305 } |
305 | 306 |
306 void ProxyResolverV8Tracing::Job::StartSetPacScript( | 307 void ProxyResolverV8Tracing::Job::StartSetPacScript( |
307 const scoped_refptr<ProxyResolverScriptData>& script_data, | 308 const scoped_refptr<ProxyResolverScriptData>& script_data, |
308 const CompletionCallback& callback) { | 309 const CompletionCallback& callback) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 ProxyResolverV8Tracing::Job::~Job() { | 379 ProxyResolverV8Tracing::Job::~Job() { |
379 DCHECK(!pending_dns_); | 380 DCHECK(!pending_dns_); |
380 DCHECK(callback_.is_null()); | 381 DCHECK(callback_.is_null()); |
381 } | 382 } |
382 | 383 |
383 void ProxyResolverV8Tracing::Job::CheckIsOnWorkerThread() const { | 384 void ProxyResolverV8Tracing::Job::CheckIsOnWorkerThread() const { |
384 DCHECK_EQ(base::MessageLoop::current(), parent_->thread_->message_loop()); | 385 DCHECK_EQ(base::MessageLoop::current(), parent_->thread_->message_loop()); |
385 } | 386 } |
386 | 387 |
387 void ProxyResolverV8Tracing::Job::CheckIsOnOriginThread() const { | 388 void ProxyResolverV8Tracing::Job::CheckIsOnOriginThread() const { |
388 DCHECK(origin_loop_->BelongsToCurrentThread()); | 389 DCHECK(origin_runner_->BelongsToCurrentThread()); |
389 } | 390 } |
390 | 391 |
391 void ProxyResolverV8Tracing::Job::SetCallback( | 392 void ProxyResolverV8Tracing::Job::SetCallback( |
392 const CompletionCallback& callback) { | 393 const CompletionCallback& callback) { |
393 CheckIsOnOriginThread(); | 394 CheckIsOnOriginThread(); |
394 DCHECK(callback_.is_null()); | 395 DCHECK(callback_.is_null()); |
395 parent_->num_outstanding_callbacks_++; | 396 parent_->num_outstanding_callbacks_++; |
396 callback_ = callback; | 397 callback_ = callback; |
397 } | 398 } |
398 | 399 |
(...skipping 24 matching lines...) Expand all Loading... |
423 return parent_->error_observer_.get(); | 424 return parent_->error_observer_.get(); |
424 } | 425 } |
425 | 426 |
426 NetLog* ProxyResolverV8Tracing::Job::net_log() { | 427 NetLog* ProxyResolverV8Tracing::Job::net_log() { |
427 return parent_->net_log_; | 428 return parent_->net_log_; |
428 } | 429 } |
429 | 430 |
430 void ProxyResolverV8Tracing::Job::NotifyCaller(int result) { | 431 void ProxyResolverV8Tracing::Job::NotifyCaller(int result) { |
431 CheckIsOnWorkerThread(); | 432 CheckIsOnWorkerThread(); |
432 | 433 |
433 origin_loop_->PostTask( | 434 origin_runner_->PostTask( |
434 FROM_HERE, | 435 FROM_HERE, base::Bind(&Job::NotifyCallerOnOriginLoop, this, result)); |
435 base::Bind(&Job::NotifyCallerOnOriginLoop, this, result)); | |
436 } | 436 } |
437 | 437 |
438 void ProxyResolverV8Tracing::Job::NotifyCallerOnOriginLoop(int result) { | 438 void ProxyResolverV8Tracing::Job::NotifyCallerOnOriginLoop(int result) { |
439 CheckIsOnOriginThread(); | 439 CheckIsOnOriginThread(); |
440 | 440 |
441 if (cancelled_.IsSet()) | 441 if (cancelled_.IsSet()) |
442 return; | 442 return; |
443 | 443 |
444 DCHECK(!callback_.is_null()); | 444 DCHECK(!callback_.is_null()); |
445 DCHECK(!pending_dns_); | 445 DCHECK(!pending_dns_); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 } | 655 } |
656 | 656 |
657 bool ProxyResolverV8Tracing::Job::PostDnsOperationAndWait( | 657 bool ProxyResolverV8Tracing::Job::PostDnsOperationAndWait( |
658 const std::string& host, ResolveDnsOperation op, | 658 const std::string& host, ResolveDnsOperation op, |
659 bool* completed_synchronously) { | 659 bool* completed_synchronously) { |
660 | 660 |
661 // Post the DNS request to the origin thread. | 661 // Post the DNS request to the origin thread. |
662 DCHECK(!pending_dns_); | 662 DCHECK(!pending_dns_); |
663 pending_dns_host_ = host; | 663 pending_dns_host_ = host; |
664 pending_dns_op_ = op; | 664 pending_dns_op_ = op; |
665 origin_loop_->PostTask(FROM_HERE, base::Bind(&Job::DoDnsOperation, this)); | 665 origin_runner_->PostTask(FROM_HERE, base::Bind(&Job::DoDnsOperation, this)); |
666 | 666 |
667 event_.Wait(); | 667 event_.Wait(); |
668 event_.Reset(); | 668 event_.Reset(); |
669 | 669 |
670 if (cancelled_.IsSet()) | 670 if (cancelled_.IsSet()) |
671 return false; | 671 return false; |
672 | 672 |
673 if (completed_synchronously) | 673 if (completed_synchronously) |
674 *completed_synchronously = pending_dns_completed_synchronously_; | 674 *completed_synchronously = pending_dns_completed_synchronously_; |
675 | 675 |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 DCHECK(!set_pac_script_job_.get()); | 1025 DCHECK(!set_pac_script_job_.get()); |
1026 CHECK_EQ(0, num_outstanding_callbacks_); | 1026 CHECK_EQ(0, num_outstanding_callbacks_); |
1027 | 1027 |
1028 set_pac_script_job_ = new Job(this); | 1028 set_pac_script_job_ = new Job(this); |
1029 set_pac_script_job_->StartSetPacScript(script_data, callback); | 1029 set_pac_script_job_->StartSetPacScript(script_data, callback); |
1030 | 1030 |
1031 return ERR_IO_PENDING; | 1031 return ERR_IO_PENDING; |
1032 } | 1032 } |
1033 | 1033 |
1034 } // namespace net | 1034 } // namespace net |
OLD | NEW |