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

Side by Side Diff: content/browser/browser_thread_impl.cc

Issue 2637843002: Migrate base::TaskRunner from Closure to OnceClosure (Closed)
Patch Set: rebase Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/browser_thread_impl.h" 5 #include "content/browser/browser_thread_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/atomicops.h" 10 #include "base/atomicops.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // with BrowserThread. 55 // with BrowserThread.
56 // TODO(gab): Consider replacing this with |g_globals->task_runners| -- only 56 // TODO(gab): Consider replacing this with |g_globals->task_runners| -- only
57 // works if none are requested before starting the threads. 57 // works if none are requested before starting the threads.
58 class BrowserThreadTaskRunner : public base::SingleThreadTaskRunner { 58 class BrowserThreadTaskRunner : public base::SingleThreadTaskRunner {
59 public: 59 public:
60 explicit BrowserThreadTaskRunner(BrowserThread::ID identifier) 60 explicit BrowserThreadTaskRunner(BrowserThread::ID identifier)
61 : id_(identifier) {} 61 : id_(identifier) {}
62 62
63 // SingleThreadTaskRunner implementation. 63 // SingleThreadTaskRunner implementation.
64 bool PostDelayedTask(const tracked_objects::Location& from_here, 64 bool PostDelayedTask(const tracked_objects::Location& from_here,
65 base::Closure task, 65 base::OnceClosure task,
66 base::TimeDelta delay) override { 66 base::TimeDelta delay) override {
67 return BrowserThread::PostDelayedTask(id_, from_here, std::move(task), 67 return BrowserThread::PostDelayedTask(id_, from_here, std::move(task),
68 delay); 68 delay);
69 } 69 }
70 70
71 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 71 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
72 base::Closure task, 72 base::OnceClosure task,
73 base::TimeDelta delay) override { 73 base::TimeDelta delay) override {
74 return BrowserThread::PostNonNestableDelayedTask(id_, from_here, 74 return BrowserThread::PostNonNestableDelayedTask(id_, from_here,
75 std::move(task), delay); 75 std::move(task), delay);
76 } 76 }
77 77
78 bool RunsTasksOnCurrentThread() const override { 78 bool RunsTasksOnCurrentThread() const override {
79 return BrowserThread::CurrentlyOn(id_); 79 return BrowserThread::CurrentlyOn(id_);
80 } 80 }
81 81
82 protected: 82 protected:
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 // succeed to post to B. This is pretty much the only observable difference 483 // succeed to post to B. This is pretty much the only observable difference
484 // between a redirected thread and a real one and is one we're willing to live 484 // between a redirected thread and a real one and is one we're willing to live
485 // with for this experiment. TODO(gab): fix this before enabling the 485 // with for this experiment. TODO(gab): fix this before enabling the
486 // experiment by default on trunk, http://crbug.com/653916. 486 // experiment by default on trunk, http://crbug.com/653916.
487 } 487 }
488 488
489 // static 489 // static
490 bool BrowserThreadImpl::PostTaskHelper( 490 bool BrowserThreadImpl::PostTaskHelper(
491 BrowserThread::ID identifier, 491 BrowserThread::ID identifier,
492 const tracked_objects::Location& from_here, 492 const tracked_objects::Location& from_here,
493 base::Closure task, 493 base::OnceClosure task,
494 base::TimeDelta delay, 494 base::TimeDelta delay,
495 bool nestable) { 495 bool nestable) {
496 DCHECK_GE(identifier, 0); 496 DCHECK_GE(identifier, 0);
497 DCHECK_LT(identifier, ID_COUNT); 497 DCHECK_LT(identifier, ID_COUNT);
498 // Optimization: to avoid unnecessary locks, we listed the ID enumeration in 498 // Optimization: to avoid unnecessary locks, we listed the ID enumeration in
499 // order of lifetime. So no need to lock if we know that the target thread 499 // order of lifetime. So no need to lock if we know that the target thread
500 // outlives current thread as that implies the current thread only ever sees 500 // outlives current thread as that implies the current thread only ever sees
501 // the target thread in its RUNNING state. 501 // the target thread in its RUNNING state.
502 // Note: since the array is so small, ok to loop instead of creating a map, 502 // Note: since the array is so small, ok to loop instead of creating a map,
503 // which would require a lock because std::map isn't thread safe, defeating 503 // which would require a lock because std::map isn't thread safe, defeating
(...skipping 23 matching lines...) Expand all
527 527
528 if (!target_thread_outlives_current) 528 if (!target_thread_outlives_current)
529 globals.lock.Release(); 529 globals.lock.Release();
530 530
531 return accepting_tasks; 531 return accepting_tasks;
532 } 532 }
533 533
534 // static 534 // static
535 bool BrowserThread::PostBlockingPoolTask( 535 bool BrowserThread::PostBlockingPoolTask(
536 const tracked_objects::Location& from_here, 536 const tracked_objects::Location& from_here,
537 base::Closure task) { 537 base::OnceClosure task) {
538 return g_globals.Get().blocking_pool->PostWorkerTask(from_here, 538 return g_globals.Get().blocking_pool->PostWorkerTask(from_here,
539 std::move(task)); 539 std::move(task));
540 } 540 }
541 541
542 // static 542 // static
543 bool BrowserThread::PostBlockingPoolTaskAndReply( 543 bool BrowserThread::PostBlockingPoolTaskAndReply(
544 const tracked_objects::Location& from_here, 544 const tracked_objects::Location& from_here,
545 base::Closure task, 545 base::OnceClosure task,
546 base::Closure reply) { 546 base::OnceClosure reply) {
547 return g_globals.Get().blocking_pool->PostTaskAndReply( 547 return g_globals.Get().blocking_pool->PostTaskAndReply(
548 from_here, std::move(task), std::move(reply)); 548 from_here, std::move(task), std::move(reply));
549 } 549 }
550 550
551 // static 551 // static
552 bool BrowserThread::PostBlockingPoolSequencedTask( 552 bool BrowserThread::PostBlockingPoolSequencedTask(
553 const std::string& sequence_token_name, 553 const std::string& sequence_token_name,
554 const tracked_objects::Location& from_here, 554 const tracked_objects::Location& from_here,
555 base::Closure task) { 555 base::OnceClosure task) {
556 return g_globals.Get().blocking_pool->PostNamedSequencedWorkerTask( 556 return g_globals.Get().blocking_pool->PostNamedSequencedWorkerTask(
557 sequence_token_name, from_here, std::move(task)); 557 sequence_token_name, from_here, std::move(task));
558 } 558 }
559 559
560 // static 560 // static
561 void BrowserThread::PostAfterStartupTask( 561 void BrowserThread::PostAfterStartupTask(
562 const tracked_objects::Location& from_here, 562 const tracked_objects::Location& from_here,
563 const scoped_refptr<base::TaskRunner>& task_runner, 563 const scoped_refptr<base::TaskRunner>& task_runner,
564 base::Closure task) { 564 base::OnceClosure task) {
565 GetContentClient()->browser()->PostAfterStartupTask(from_here, task_runner, 565 GetContentClient()->browser()->PostAfterStartupTask(from_here, task_runner,
566 std::move(task)); 566 std::move(task));
567 } 567 }
568 568
569 // static 569 // static
570 base::SequencedWorkerPool* BrowserThread::GetBlockingPool() { 570 base::SequencedWorkerPool* BrowserThread::GetBlockingPool() {
571 return g_globals.Get().blocking_pool.get(); 571 return g_globals.Get().blocking_pool.get();
572 } 572 }
573 573
574 // static 574 // static
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 BrowserThreadGlobals& globals = g_globals.Get(); 616 BrowserThreadGlobals& globals = g_globals.Get();
617 base::AutoLock lock(globals.lock); 617 base::AutoLock lock(globals.lock);
618 DCHECK_GE(identifier, 0); 618 DCHECK_GE(identifier, 0);
619 DCHECK_LT(identifier, ID_COUNT); 619 DCHECK_LT(identifier, ID_COUNT);
620 return globals.states[identifier] == BrowserThreadState::RUNNING; 620 return globals.states[identifier] == BrowserThreadState::RUNNING;
621 } 621 }
622 622
623 // static 623 // static
624 bool BrowserThread::PostTask(ID identifier, 624 bool BrowserThread::PostTask(ID identifier,
625 const tracked_objects::Location& from_here, 625 const tracked_objects::Location& from_here,
626 base::Closure task) { 626 base::OnceClosure task) {
627 return BrowserThreadImpl::PostTaskHelper( 627 return BrowserThreadImpl::PostTaskHelper(
628 identifier, from_here, std::move(task), base::TimeDelta(), true); 628 identifier, from_here, std::move(task), base::TimeDelta(), true);
629 } 629 }
630 630
631 // static 631 // static
632 bool BrowserThread::PostDelayedTask(ID identifier, 632 bool BrowserThread::PostDelayedTask(ID identifier,
633 const tracked_objects::Location& from_here, 633 const tracked_objects::Location& from_here,
634 base::Closure task, 634 base::OnceClosure task,
635 base::TimeDelta delay) { 635 base::TimeDelta delay) {
636 return BrowserThreadImpl::PostTaskHelper(identifier, from_here, 636 return BrowserThreadImpl::PostTaskHelper(identifier, from_here,
637 std::move(task), delay, true); 637 std::move(task), delay, true);
638 } 638 }
639 639
640 // static 640 // static
641 bool BrowserThread::PostNonNestableTask( 641 bool BrowserThread::PostNonNestableTask(
642 ID identifier, 642 ID identifier,
643 const tracked_objects::Location& from_here, 643 const tracked_objects::Location& from_here,
644 base::Closure task) { 644 base::OnceClosure task) {
645 return BrowserThreadImpl::PostTaskHelper( 645 return BrowserThreadImpl::PostTaskHelper(
646 identifier, from_here, std::move(task), base::TimeDelta(), false); 646 identifier, from_here, std::move(task), base::TimeDelta(), false);
647 } 647 }
648 648
649 // static 649 // static
650 bool BrowserThread::PostNonNestableDelayedTask( 650 bool BrowserThread::PostNonNestableDelayedTask(
651 ID identifier, 651 ID identifier,
652 const tracked_objects::Location& from_here, 652 const tracked_objects::Location& from_here,
653 base::Closure task, 653 base::OnceClosure task,
654 base::TimeDelta delay) { 654 base::TimeDelta delay) {
655 return BrowserThreadImpl::PostTaskHelper(identifier, from_here, 655 return BrowserThreadImpl::PostTaskHelper(identifier, from_here,
656 std::move(task), delay, false); 656 std::move(task), delay, false);
657 } 657 }
658 658
659 // static 659 // static
660 bool BrowserThread::PostTaskAndReply(ID identifier, 660 bool BrowserThread::PostTaskAndReply(ID identifier,
661 const tracked_objects::Location& from_here, 661 const tracked_objects::Location& from_here,
662 base::Closure task, 662 base::OnceClosure task,
663 base::Closure reply) { 663 base::OnceClosure reply) {
664 return GetTaskRunnerForThread(identifier) 664 return GetTaskRunnerForThread(identifier)
665 ->PostTaskAndReply(from_here, std::move(task), std::move(reply)); 665 ->PostTaskAndReply(from_here, std::move(task), std::move(reply));
666 } 666 }
667 667
668 // static 668 // static
669 bool BrowserThread::GetCurrentThreadIdentifier(ID* identifier) { 669 bool BrowserThread::GetCurrentThreadIdentifier(ID* identifier) {
670 if (g_globals == nullptr) 670 if (g_globals == nullptr)
671 return false; 671 return false;
672 672
673 BrowserThreadGlobals& globals = g_globals.Get(); 673 BrowserThreadGlobals& globals = g_globals.Get();
(...skipping 25 matching lines...) Expand all
699 BrowserThreadDelegateAtomicPtr old_delegate = 699 BrowserThreadDelegateAtomicPtr old_delegate =
700 base::subtle::NoBarrier_AtomicExchange( 700 base::subtle::NoBarrier_AtomicExchange(
701 &globals.io_thread_delegate, 701 &globals.io_thread_delegate,
702 reinterpret_cast<BrowserThreadDelegateAtomicPtr>(delegate)); 702 reinterpret_cast<BrowserThreadDelegateAtomicPtr>(delegate));
703 703
704 // This catches registration when previously registered. 704 // This catches registration when previously registered.
705 DCHECK(!delegate || !old_delegate); 705 DCHECK(!delegate || !old_delegate);
706 } 706 }
707 707
708 } // namespace content 708 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_thread_impl.h ('k') | content/browser/compositor/reflector_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698