Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(522)

Side by Side Diff: net/base/host_resolver_impl.cc

Issue 6094005: Create "Prebind" a wrapper to tr1::bind. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/base
Patch Set: Remove closure.h and ThunkState Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/base/host_resolver_impl.h" 5 #include "net/base/host_resolver_impl.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <Winsock2.h> 8 #include <Winsock2.h>
9 #elif defined(OS_POSIX) 9 #elif defined(OS_POSIX)
10 #include <netdb.h> 10 #include <netdb.h>
11 #endif 11 #endif
12 12
13 #include <cmath> 13 #include <cmath>
14 #include <deque> 14 #include <deque>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/basictypes.h" 17 #include "base/basictypes.h"
18 #include "base/prebind.h"
18 #include "base/compiler_specific.h" 19 #include "base/compiler_specific.h"
19 #include "base/debug/debugger.h" 20 #include "base/debug/debugger.h"
20 #include "base/debug/stack_trace.h" 21 #include "base/debug/stack_trace.h"
21 #include "base/lock.h" 22 #include "base/lock.h"
22 #include "base/message_loop.h" 23 #include "base/message_loop.h"
23 #include "base/metrics/field_trial.h" 24 #include "base/metrics/field_trial.h"
24 #include "base/metrics/histogram.h" 25 #include "base/metrics/histogram.h"
25 #include "base/stl_util-inl.h" 26 #include "base/stl_util-inl.h"
26 #include "base/string_util.h" 27 #include "base/string_util.h"
27 #include "base/time.h" 28 #include "base/time.h"
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 376
376 if (!req->info().is_speculative()) 377 if (!req->info().is_speculative())
377 had_non_speculative_request_ = true; 378 had_non_speculative_request_ = true;
378 } 379 }
379 380
380 // Called from origin loop. 381 // Called from origin loop.
381 void Start() { 382 void Start() {
382 start_time_ = base::TimeTicks::Now(); 383 start_time_ = base::TimeTicks::Now();
383 384
384 // Dispatch the job to a worker thread. 385 // Dispatch the job to a worker thread.
385 if (!WorkerPool::PostTask(FROM_HERE, 386 if (!WorkerPool::PostThunk(FROM_HERE,
386 NewRunnableMethod(this, &Job::DoLookup), true)) { 387 base::Prebind(&Job::DoLookup, this), true)) {
387 NOTREACHED(); 388 NOTREACHED();
388 389
389 // Since we could be running within Resolve() right now, we can't just 390 // Since we could be running within Resolve() right now, we can't just
390 // call OnLookupComplete(). Instead we must wait until Resolve() has 391 // call OnLookupComplete(). Instead we must wait until Resolve() has
391 // returned (IO_PENDING). 392 // returned (IO_PENDING).
392 error_ = ERR_UNEXPECTED; 393 error_ = ERR_UNEXPECTED;
393 MessageLoop::current()->PostTask( 394 MessageLoop::current()->PostThunk(
394 FROM_HERE, NewRunnableMethod(this, &Job::OnLookupComplete)); 395 FROM_HERE, base::Prebind(&Job::OnLookupComplete, this));
395 } 396 }
396 } 397 }
397 398
398 // Cancels the current job. Callable from origin thread. 399 // Cancels the current job. Callable from origin thread.
399 void Cancel() { 400 void Cancel() {
400 net_log_.AddEvent(NetLog::TYPE_CANCELLED, NULL); 401 net_log_.AddEvent(NetLog::TYPE_CANCELLED, NULL);
401 402
402 HostResolver* resolver = resolver_; 403 HostResolver* resolver = resolver_;
403 resolver_ = NULL; 404 resolver_ = NULL;
404 405
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 key_.address_family, 478 key_.address_family,
478 key_.host_resolver_flags, 479 key_.host_resolver_flags,
479 &results_, 480 &results_,
480 &os_error_); 481 &os_error_);
481 482
482 // The origin loop could go away while we are trying to post to it, so we 483 // The origin loop could go away while we are trying to post to it, so we
483 // need to call its PostTask method inside a lock. See ~HostResolver. 484 // need to call its PostTask method inside a lock. See ~HostResolver.
484 { 485 {
485 AutoLock locked(origin_loop_lock_); 486 AutoLock locked(origin_loop_lock_);
486 if (origin_loop_) { 487 if (origin_loop_) {
487 origin_loop_->PostTask(FROM_HERE, 488 origin_loop_->PostThunk(FROM_HERE,
488 NewRunnableMethod(this, &Job::OnLookupComplete)); 489 base::Prebind(&Job::OnLookupComplete, this));
489 } 490 }
490 } 491 }
491 } 492 }
492 493
493 // Callback for when DoLookup() completes (runs on origin thread). 494 // Callback for when DoLookup() completes (runs on origin thread).
494 void OnLookupComplete() { 495 void OnLookupComplete() {
495 // Should be running on origin loop. 496 // Should be running on origin loop.
496 // TODO(eroman): this is being hit by URLRequestTest.CancelTest*, 497 // TODO(eroman): this is being hit by URLRequestTest.CancelTest*,
497 // because MessageLoop::current() == NULL. 498 // because MessageLoop::current() == NULL.
498 //DCHECK_EQ(origin_loop_, MessageLoop::current()); 499 //DCHECK_EQ(origin_loop_, MessageLoop::current());
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 : resolver_(resolver), 644 : resolver_(resolver),
644 origin_loop_(MessageLoop::current()) { 645 origin_loop_(MessageLoop::current()) {
645 DCHECK(!was_cancelled()); 646 DCHECK(!was_cancelled());
646 } 647 }
647 648
648 void Start() { 649 void Start() {
649 if (was_cancelled()) 650 if (was_cancelled())
650 return; 651 return;
651 DCHECK(IsOnOriginThread()); 652 DCHECK(IsOnOriginThread());
652 const bool kIsSlow = true; 653 const bool kIsSlow = true;
653 WorkerPool::PostTask( 654 WorkerPool::PostThunk(
654 FROM_HERE, NewRunnableMethod(this, &IPv6ProbeJob::DoProbe), kIsSlow); 655 FROM_HERE, base::Prebind(&IPv6ProbeJob::DoProbe, this), kIsSlow);
655 } 656 }
656 657
657 // Cancels the current job. 658 // Cancels the current job.
658 void Cancel() { 659 void Cancel() {
659 if (was_cancelled()) 660 if (was_cancelled())
660 return; 661 return;
661 DCHECK(IsOnOriginThread()); 662 DCHECK(IsOnOriginThread());
662 resolver_ = NULL; // Read/write ONLY on origin thread. 663 resolver_ = NULL; // Read/write ONLY on origin thread.
663 { 664 {
664 AutoLock locked(origin_loop_lock_); 665 AutoLock locked(origin_loop_lock_);
(...skipping 17 matching lines...) Expand all
682 } 683 }
683 return false; 684 return false;
684 } 685 }
685 686
686 // Run on worker thread. 687 // Run on worker thread.
687 void DoProbe() { 688 void DoProbe() {
688 // Do actual testing on this thread, as it takes 40-100ms. 689 // Do actual testing on this thread, as it takes 40-100ms.
689 AddressFamily family = IPv6Supported() ? ADDRESS_FAMILY_UNSPECIFIED 690 AddressFamily family = IPv6Supported() ? ADDRESS_FAMILY_UNSPECIFIED
690 : ADDRESS_FAMILY_IPV4; 691 : ADDRESS_FAMILY_IPV4;
691 692
692 Task* reply = NewRunnableMethod(this, &IPv6ProbeJob::OnProbeComplete, 693 base::Thunk<void(void)> reply =
693 family); 694 base::Prebind(&IPv6ProbeJob::OnProbeComplete, this, family);
694 695
695 // The origin loop could go away while we are trying to post to it, so we 696 // The origin loop could go away while we are trying to post to it, so we
696 // need to call its PostTask method inside a lock. See ~HostResolver. 697 // need to call its PostTask method inside a lock. See ~HostResolver.
697 { 698 {
698 AutoLock locked(origin_loop_lock_); 699 AutoLock locked(origin_loop_lock_);
699 if (origin_loop_) { 700 if (origin_loop_) {
700 origin_loop_->PostTask(FROM_HERE, reply); 701 origin_loop_->PostThunk(FROM_HERE, reply);
701 return; 702 return;
702 } 703 }
703 } 704 }
704 705
705 // We didn't post, so delete the reply.
706 delete reply;
707 } 706 }
708 707
709 // Callback for when DoProbe() completes (runs on origin thread). 708 // Callback for when DoProbe() completes (runs on origin thread).
710 void OnProbeComplete(AddressFamily address_family) { 709 void OnProbeComplete(AddressFamily address_family) {
711 if (was_cancelled()) 710 if (was_cancelled())
712 return; 711 return;
713 DCHECK(IsOnOriginThread()); 712 DCHECK(IsOnOriginThread());
714 resolver_->IPv6ProbeSetDefaultAddressFamily(address_family); 713 resolver_->IPv6ProbeSetDefaultAddressFamily(address_family);
715 } 714 }
716 715
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 job_pools_[i]->ResetNumOutstandingJobs(); 1451 job_pools_[i]->ResetNumOutstandingJobs();
1453 JobMap jobs; 1452 JobMap jobs;
1454 jobs.swap(jobs_); 1453 jobs.swap(jobs_);
1455 for (JobMap::iterator it = jobs.begin(); it != jobs.end(); ++it) { 1454 for (JobMap::iterator it = jobs.begin(); it != jobs.end(); ++it) {
1456 AbortJob(it->second); 1455 AbortJob(it->second);
1457 it->second->Cancel(); 1456 it->second->Cancel();
1458 } 1457 }
1459 } 1458 }
1460 1459
1461 } // namespace net 1460 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698