diff options
author | rtoy <rtoy@chromium.org> | 2015-07-14 14:13:57 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-14 21:14:38 +0000 |
commit | 70d1a346ddf711d2dc3261b607b375c629888f8a (patch) | |
tree | 90d34ef7762780ae1074ad9286c69e7842639936 | |
parent | ec34450ee9059cedc3fd0576bd964d06a319d7d3 (diff) | |
download | chromium_src-70d1a346ddf711d2dc3261b607b375c629888f8a.zip chromium_src-70d1a346ddf711d2dc3261b607b375c629888f8a.tar.gz chromium_src-70d1a346ddf711d2dc3261b607b375c629888f8a.tar.bz2 |
Revert of Redirect the MessageLoop's task runner to the renderer scheduler (patchset #11 id:220001 of https://codereview.chromium.org/987193002/)
Reason for revert:
Speculatively reverting. It seems to be causing flakiness on the decodeOnOtherThread test: http://test-results.appspot.com/dashboards/flakiness_dashboard.html#testType=webkit_unit_tests&tests=decodeOnOtherThread
Original issue's description:
> Redirect the MessageLoop's task runner to the renderer scheduler
>
> Configure MessageLoop::task_runner() to post tasks through the scheduler to ensure consistent task ordering.
>
> BUG=465354
>
> Committed: https://crrev.com/f14dd762c01730a81d4a94b64ceba42eaad2d5f2
> Cr-Commit-Position: refs/heads/master@{#338706}
TBR=alexclarke@chromium.org,skyostil@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=465354
Review URL: https://codereview.chromium.org/1238483003
Cr-Commit-Position: refs/heads/master@{#338736}
31 files changed, 154 insertions, 418 deletions
diff --git a/components/components_tests.gyp b/components/components_tests.gyp index 7fbc233..02c39b3 100644 --- a/components/components_tests.gyp +++ b/components/components_tests.gyp @@ -499,9 +499,6 @@ 'scheduler/child/nestable_task_runner_for_test.h', 'scheduler/child/prioritizing_task_queue_selector_unittest.cc', 'scheduler/child/scheduler_helper_unittest.cc', - 'scheduler/child/scheduler_task_runner_delegate_for_test.cc', - 'scheduler/child/scheduler_task_runner_delegate_for_test.h', - 'scheduler/child/scheduler_task_runner_delegate_impl_unittest.cc', 'scheduler/child/task_queue_manager_unittest.cc', 'scheduler/child/test_time_source.cc', 'scheduler/child/test_time_source.h', diff --git a/components/scheduler/BUILD.gn b/components/scheduler/BUILD.gn index b165812..c822116 100644 --- a/components/scheduler/BUILD.gn +++ b/components/scheduler/BUILD.gn @@ -43,9 +43,6 @@ source_set("unit_tests") { "child/nestable_task_runner_for_test.h", "child/prioritizing_task_queue_selector_unittest.cc", "child/scheduler_helper_unittest.cc", - "child/scheduler_task_runner_delegate_for_test.cc", - "child/scheduler_task_runner_delegate_for_test.h", - "child/scheduler_task_runner_delegate_impl_unittest.cc", "child/task_queue_manager_unittest.cc", "child/test_time_source.cc", "child/test_time_source.h", diff --git a/components/scheduler/child/idle_helper_unittest.cc b/components/scheduler/child/idle_helper_unittest.cc index 38b5e29..20ae1b5 100644 --- a/components/scheduler/child/idle_helper_unittest.cc +++ b/components/scheduler/child/idle_helper_unittest.cc @@ -7,9 +7,9 @@ #include "base/callback.h" #include "base/test/simple_test_tick_clock.h" #include "cc/test/ordered_simple_task_runner.h" +#include "components/scheduler/child/nestable_task_runner_for_test.h" #include "components/scheduler/child/scheduler_helper.h" -#include "components/scheduler/child/scheduler_task_runner_delegate_for_test.h" -#include "components/scheduler/child/scheduler_task_runner_delegate_impl.h" +#include "components/scheduler/child/scheduler_message_loop_delegate.h" #include "components/scheduler/child/task_queue_manager.h" #include "components/scheduler/child/test_time_source.h" #include "testing/gmock/include/gmock/gmock.h" @@ -125,13 +125,14 @@ void EndIdlePeriodIdleTask(IdleHelper* idle_helper, base::TimeTicks deadline) { idle_helper->EndIdlePeriod(); } -scoped_refptr<SchedulerTaskRunnerDelegate> CreateTaskRunnerDelegate( +scoped_refptr<NestableSingleThreadTaskRunner> +CreateNestableSingleThreadTaskRunner( base::MessageLoop* message_loop, scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner) { if (message_loop) - return SchedulerTaskRunnerDelegateImpl::Create(message_loop); + return SchedulerMessageLoopDelegate::Create(message_loop); - return SchedulerTaskRunnerDelegateForTest::Create(mock_task_runner); + return NestableTaskRunnerForTest::Create(mock_task_runner); } }; // namespace @@ -172,10 +173,11 @@ class BaseIdleHelperTest : public testing::Test { ? nullptr : new cc::OrderedSimpleTaskRunner(clock_.get(), false)), message_loop_(message_loop), - main_task_runner_( - CreateTaskRunnerDelegate(message_loop, mock_task_runner_)), + nestable_task_runner_( + CreateNestableSingleThreadTaskRunner(message_loop, + mock_task_runner_)), scheduler_helper_( - new SchedulerHelper(main_task_runner_, + new SchedulerHelper(nestable_task_runner_, "test.idle", TRACE_DISABLED_BY_DEFAULT("test.idle"), TRACE_DISABLED_BY_DEFAULT("test.idle.debug"), @@ -275,7 +277,7 @@ class BaseIdleHelperTest : public testing::Test { scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; scoped_ptr<base::MessageLoop> message_loop_; - scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner_; + scoped_refptr<NestableSingleThreadTaskRunner> nestable_task_runner_; scoped_ptr<SchedulerHelper> scheduler_helper_; scoped_ptr<IdleHelperForTest> idle_helper_; scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; diff --git a/components/scheduler/child/nestable_task_runner_for_test.cc b/components/scheduler/child/nestable_task_runner_for_test.cc index ac33695..5bcfde8 100644 --- a/components/scheduler/child/nestable_task_runner_for_test.cc +++ b/components/scheduler/child/nestable_task_runner_for_test.cc @@ -63,7 +63,11 @@ bool NestableTaskRunnerForTest::RunsTasksOnCurrentThread() const { } bool NestableTaskRunnerForTest::IsNested() const { - return false; + return is_nested_; +} + +void NestableTaskRunnerForTest::SetNested(bool is_nested) { + is_nested_ = is_nested; } void NestableTaskRunnerForTest::AddTaskObserver( diff --git a/components/scheduler/child/nestable_task_runner_for_test.h b/components/scheduler/child/nestable_task_runner_for_test.h index 09ed852..120fe00 100644 --- a/components/scheduler/child/nestable_task_runner_for_test.h +++ b/components/scheduler/child/nestable_task_runner_for_test.h @@ -14,6 +14,8 @@ class NestableTaskRunnerForTest : public NestableSingleThreadTaskRunner { static scoped_refptr<NestableTaskRunnerForTest> Create( scoped_refptr<base::SingleThreadTaskRunner> task_runner); + void SetNested(bool is_nested); + // NestableSingleThreadTaskRunner implementation bool PostDelayedTask(const tracked_objects::Location& from_here, const base::Closure& task, diff --git a/components/scheduler/child/scheduler_helper.cc b/components/scheduler/child/scheduler_helper.cc index fb1185d..0e13c76 100644 --- a/components/scheduler/child/scheduler_helper.cc +++ b/components/scheduler/child/scheduler_helper.cc @@ -7,18 +7,17 @@ #include "base/time/default_tick_clock.h" #include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event_argument.h" -#include "components/scheduler/child/scheduler_task_runner_delegate.h" +#include "components/scheduler/child/nestable_single_thread_task_runner.h" namespace scheduler { SchedulerHelper::SchedulerHelper( - scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner, + scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner, const char* tracing_category, const char* disabled_by_default_tracing_category, const char* disabled_by_default_verbose_tracing_category, size_t total_task_queue_count) - : main_task_runner_(main_task_runner), - task_queue_selector_(new PrioritizingTaskQueueSelector()), + : task_queue_selector_(new PrioritizingTaskQueueSelector()), task_queue_manager_( new TaskQueueManager(total_task_queue_count, main_task_runner, @@ -65,19 +64,14 @@ SchedulerHelper::SchedulerHelper( // TODO(skyostil): Increase this to 4 (crbug.com/444764). task_queue_manager_->SetWorkBatchSize(1); - - main_task_runner_->SetDefaultTaskRunner( - task_queue_manager_->TaskRunnerForQueue(QueueId::DEFAULT_TASK_QUEUE)); } SchedulerHelper::~SchedulerHelper() { - Shutdown(); } void SchedulerHelper::Shutdown() { CheckOnValidThread(); task_queue_manager_.reset(); - main_task_runner_->RestoreDefaultTaskRunner(); } scoped_refptr<base::SingleThreadTaskRunner> diff --git a/components/scheduler/child/scheduler_helper.h b/components/scheduler/child/scheduler_helper.h index 5b3c0ee..3c439c7 100644 --- a/components/scheduler/child/scheduler_helper.h +++ b/components/scheduler/child/scheduler_helper.h @@ -15,7 +15,7 @@ class TickClock; namespace scheduler { -class SchedulerTaskRunnerDelegate; +class NestableSingleThreadTaskRunner; // Common scheduler functionality for default tasks. class SCHEDULER_EXPORT SchedulerHelper { @@ -23,11 +23,12 @@ class SCHEDULER_EXPORT SchedulerHelper { // NOTE |total_task_queue_count| must be >= TASK_QUEUE_COUNT. // Category strings must have application lifetime (statics or // literals). They may not include " chars. - SchedulerHelper(scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner, - const char* tracing_category, - const char* disabled_by_default_tracing_category, - const char* disabled_by_default_verbose_tracing_category, - size_t total_task_queue_count); + SchedulerHelper( + scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner, + const char* tracing_category, + const char* disabled_by_default_tracing_category, + const char* disabled_by_default_verbose_tracing_category, + size_t total_task_queue_count); ~SchedulerHelper(); // Returns the default task runner. @@ -104,7 +105,6 @@ class SCHEDULER_EXPORT SchedulerHelper { friend class SchedulerHelperTest; base::ThreadChecker thread_checker_; - scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner_; scoped_ptr<PrioritizingTaskQueueSelector> task_queue_selector_; scoped_ptr<TaskQueueManager> task_queue_manager_; diff --git a/components/scheduler/child/scheduler_helper_unittest.cc b/components/scheduler/child/scheduler_helper_unittest.cc index 5dcf6ec..85c811a 100644 --- a/components/scheduler/child/scheduler_helper_unittest.cc +++ b/components/scheduler/child/scheduler_helper_unittest.cc @@ -7,7 +7,8 @@ #include "base/callback.h" #include "base/test/simple_test_tick_clock.h" #include "cc/test/ordered_simple_task_runner.h" -#include "components/scheduler/child/scheduler_task_runner_delegate_for_test.h" +#include "components/scheduler/child/nestable_task_runner_for_test.h" +#include "components/scheduler/child/scheduler_message_loop_delegate.h" #include "components/scheduler/child/test_time_source.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -45,10 +46,10 @@ class SchedulerHelperTest : public testing::Test { SchedulerHelperTest() : clock_(new base::SimpleTestTickClock()), mock_task_runner_(new cc::OrderedSimpleTaskRunner(clock_.get(), false)), - main_task_runner_( - SchedulerTaskRunnerDelegateForTest::Create(mock_task_runner_)), + nestable_task_runner_( + NestableTaskRunnerForTest::Create(mock_task_runner_)), scheduler_helper_( - new SchedulerHelper(main_task_runner_, + new SchedulerHelper(nestable_task_runner_, "test.scheduler", TRACE_DISABLED_BY_DEFAULT("test.scheduler"), TRACE_DISABLED_BY_DEFAULT("test.scheduler.dbg"), @@ -92,7 +93,7 @@ class SchedulerHelperTest : public testing::Test { scoped_ptr<base::SimpleTestTickClock> clock_; scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; - scoped_refptr<SchedulerTaskRunnerDelegateForTest> main_task_runner_; + scoped_refptr<NestableSingleThreadTaskRunner> nestable_task_runner_; scoped_ptr<SchedulerHelper> scheduler_helper_; scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; @@ -138,11 +139,4 @@ TEST_F(SchedulerHelperTest, TaskQueueIdToString) { CheckAllTaskQueueIdToString(); } -TEST_F(SchedulerHelperTest, DefaultTaskRunnerRegistration) { - EXPECT_EQ(main_task_runner_->default_task_runner(), - scheduler_helper_->DefaultTaskRunner()); - scheduler_helper_->Shutdown(); - EXPECT_EQ(nullptr, main_task_runner_->default_task_runner()); -} - } // namespace scheduler diff --git a/components/scheduler/child/scheduler_message_loop_delegate.cc b/components/scheduler/child/scheduler_message_loop_delegate.cc new file mode 100644 index 0000000..ba0d6b4 --- /dev/null +++ b/components/scheduler/child/scheduler_message_loop_delegate.cc @@ -0,0 +1,56 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/scheduler/child/scheduler_message_loop_delegate.h" + +namespace scheduler { + +// static +scoped_refptr<SchedulerMessageLoopDelegate> +SchedulerMessageLoopDelegate::Create(base::MessageLoop* message_loop) { + return make_scoped_refptr(new SchedulerMessageLoopDelegate(message_loop)); +} + +SchedulerMessageLoopDelegate::SchedulerMessageLoopDelegate( + base::MessageLoop* message_loop) + : message_loop_(message_loop) { +} + +SchedulerMessageLoopDelegate::~SchedulerMessageLoopDelegate() { +} + +bool SchedulerMessageLoopDelegate::PostDelayedTask( + const tracked_objects::Location& from_here, + const base::Closure& task, + base::TimeDelta delay) { + return message_loop_->task_runner()->PostDelayedTask(from_here, task, delay); +} + +bool SchedulerMessageLoopDelegate::PostNonNestableDelayedTask( + const tracked_objects::Location& from_here, + const base::Closure& task, + base::TimeDelta delay) { + return message_loop_->task_runner()->PostNonNestableDelayedTask(from_here, + task, delay); +} + +bool SchedulerMessageLoopDelegate::RunsTasksOnCurrentThread() const { + return message_loop_->task_runner()->RunsTasksOnCurrentThread(); +} + +bool SchedulerMessageLoopDelegate::IsNested() const { + return message_loop_->IsNested(); +} + +void SchedulerMessageLoopDelegate::AddTaskObserver( + base::MessageLoop::TaskObserver* task_observer) { + return message_loop_->AddTaskObserver(task_observer); +} + +void SchedulerMessageLoopDelegate::RemoveTaskObserver( + base::MessageLoop::TaskObserver* task_observer) { + return message_loop_->RemoveTaskObserver(task_observer); +} + +} // namespace scheduler diff --git a/components/scheduler/child/scheduler_task_runner_delegate_impl.h b/components/scheduler/child/scheduler_message_loop_delegate.h index 60b7571..164ab31 100644 --- a/components/scheduler/child/scheduler_task_runner_delegate_impl.h +++ b/components/scheduler/child/scheduler_message_loop_delegate.h @@ -2,26 +2,23 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef COMPONENTS_SCHEDULER_CHILD_SCHEDULER_TASK_RUNNER_DELEGATE_IMPL_H_ -#define COMPONENTS_SCHEDULER_CHILD_SCHEDULER_TASK_RUNNER_DELEGATE_IMPL_H_ +#ifndef COMPONENTS_SCHEDULER_CHILD_SCHEDULER_MESSAGE_LOOP_DELEGATE_H_ +#define COMPONENTS_SCHEDULER_CHILD_SCHEDULER_MESSAGE_LOOP_DELEGATE_H_ #include "base/message_loop/message_loop.h" -#include "components/scheduler/child/scheduler_task_runner_delegate.h" +#include "components/scheduler/child/nestable_single_thread_task_runner.h" #include "components/scheduler/scheduler_export.h" namespace scheduler { -class SCHEDULER_EXPORT SchedulerTaskRunnerDelegateImpl - : public SchedulerTaskRunnerDelegate { +class SCHEDULER_EXPORT SchedulerMessageLoopDelegate + : public NestableSingleThreadTaskRunner { public: // |message_loop| is not owned and must outlive the lifetime of this object. - static scoped_refptr<SchedulerTaskRunnerDelegateImpl> Create( + static scoped_refptr<SchedulerMessageLoopDelegate> Create( base::MessageLoop* message_loop); - // SchedulerTaskRunnerDelegate implementation - void SetDefaultTaskRunner( - scoped_refptr<base::SingleThreadTaskRunner> task_runner) override; - void RestoreDefaultTaskRunner() override; + // NestableSingleThreadTaskRunner implementation bool PostDelayedTask(const tracked_objects::Location& from_here, const base::Closure& task, base::TimeDelta delay) override; @@ -35,18 +32,17 @@ class SCHEDULER_EXPORT SchedulerTaskRunnerDelegateImpl base::MessageLoop::TaskObserver* task_observer) override; protected: - ~SchedulerTaskRunnerDelegateImpl() override; + ~SchedulerMessageLoopDelegate() override; private: - explicit SchedulerTaskRunnerDelegateImpl(base::MessageLoop* message_loop); + SchedulerMessageLoopDelegate(base::MessageLoop* message_loop); // Not owned. base::MessageLoop* message_loop_; - scoped_refptr<SingleThreadTaskRunner> message_loop_task_runner_; - DISALLOW_COPY_AND_ASSIGN(SchedulerTaskRunnerDelegateImpl); + DISALLOW_COPY_AND_ASSIGN(SchedulerMessageLoopDelegate); }; } // namespace scheduler -#endif // COMPONENTS_SCHEDULER_CHILD_SCHEDULER_TASK_RUNNER_DELEGATE_IMPL_H_ +#endif // COMPONENTS_SCHEDULER_CHILD_SCHEDULER_MESSAGE_LOOP_DELEGATE_H_ diff --git a/components/scheduler/child/scheduler_task_runner_delegate.h b/components/scheduler/child/scheduler_task_runner_delegate.h deleted file mode 100644 index ef95e1e..0000000 --- a/components/scheduler/child/scheduler_task_runner_delegate.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef COMPONENTS_SCHEDULER_CHILD_SCHEDULER_TASK_RUNNER_DELEGATE_H_ -#define COMPONENTS_SCHEDULER_CHILD_SCHEDULER_TASK_RUNNER_DELEGATE_H_ - -#include "base/message_loop/message_loop.h" -#include "components/scheduler/child/nestable_single_thread_task_runner.h" -#include "components/scheduler/scheduler_export.h" - -namespace scheduler { - -class SCHEDULER_EXPORT SchedulerTaskRunnerDelegate - : public NestableSingleThreadTaskRunner { - public: - SchedulerTaskRunnerDelegate() {} - - // If the underlying task runner supports the concept of a default task - // runner, the delegate should implement this function to redirect that task - // runner to the scheduler. - virtual void SetDefaultTaskRunner( - scoped_refptr<base::SingleThreadTaskRunner> task_runner) = 0; - - // Similarly this method can be used to restore the original task runner when - // the scheduler no longer wants to intercept tasks. - virtual void RestoreDefaultTaskRunner() = 0; - - protected: - ~SchedulerTaskRunnerDelegate() override {} - - DISALLOW_COPY_AND_ASSIGN(SchedulerTaskRunnerDelegate); -}; - -} // namespace scheduler - -#endif // COMPONENTS_SCHEDULER_CHILD_SCHEDULER_TASK_RUNNER_DELEGATE_H_ diff --git a/components/scheduler/child/scheduler_task_runner_delegate_for_test.cc b/components/scheduler/child/scheduler_task_runner_delegate_for_test.cc deleted file mode 100644 index 08a79b2..0000000 --- a/components/scheduler/child/scheduler_task_runner_delegate_for_test.cc +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "components/scheduler/child/scheduler_task_runner_delegate_for_test.h" - -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "components/scheduler/child/nestable_task_runner_for_test.h" - -namespace scheduler { - -// static -scoped_refptr<SchedulerTaskRunnerDelegateForTest> -SchedulerTaskRunnerDelegateForTest::Create( - scoped_refptr<base::SingleThreadTaskRunner> task_runner) { - return make_scoped_refptr( - new SchedulerTaskRunnerDelegateForTest(task_runner)); -} - -SchedulerTaskRunnerDelegateForTest::SchedulerTaskRunnerDelegateForTest( - scoped_refptr<base::SingleThreadTaskRunner> task_runner) - : task_runner_(NestableTaskRunnerForTest::Create(task_runner)) { -} - -SchedulerTaskRunnerDelegateForTest::~SchedulerTaskRunnerDelegateForTest() { -} - -void SchedulerTaskRunnerDelegateForTest::SetDefaultTaskRunner( - scoped_refptr<base::SingleThreadTaskRunner> task_runner) { - default_task_runner_ = task_runner.Pass(); -} - -void SchedulerTaskRunnerDelegateForTest::RestoreDefaultTaskRunner() { - default_task_runner_ = nullptr; -} - -bool SchedulerTaskRunnerDelegateForTest::PostDelayedTask( - const tracked_objects::Location& from_here, - const base::Closure& task, - base::TimeDelta delay) { - return task_runner_->PostDelayedTask(from_here, task, delay); -} - -bool SchedulerTaskRunnerDelegateForTest::PostNonNestableDelayedTask( - const tracked_objects::Location& from_here, - const base::Closure& task, - base::TimeDelta delay) { - return task_runner_->PostNonNestableDelayedTask(from_here, task, delay); -} - -bool SchedulerTaskRunnerDelegateForTest::RunsTasksOnCurrentThread() const { - return task_runner_->RunsTasksOnCurrentThread(); -} - -bool SchedulerTaskRunnerDelegateForTest::IsNested() const { - return task_runner_->IsNested(); -} - -void SchedulerTaskRunnerDelegateForTest::AddTaskObserver( - base::MessageLoop::TaskObserver* task_observer) { - task_runner_->AddTaskObserver(task_observer); -} - -void SchedulerTaskRunnerDelegateForTest::RemoveTaskObserver( - base::MessageLoop::TaskObserver* task_observer) { - task_runner_->RemoveTaskObserver(task_observer); -} - -} // namespace scheduler diff --git a/components/scheduler/child/scheduler_task_runner_delegate_for_test.h b/components/scheduler/child/scheduler_task_runner_delegate_for_test.h deleted file mode 100644 index e1e72bb..0000000 --- a/components/scheduler/child/scheduler_task_runner_delegate_for_test.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_RENDERER_SCHEDULER_TASK_RUNNER_DELEGATE_FOR_TEST_H_ -#define CONTENT_RENDERER_SCHEDULER_TASK_RUNNER_DELEGATE_FOR_TEST_H_ - -#include "components/scheduler/child/scheduler_task_runner_delegate.h" - -namespace scheduler { - -class NestableTaskRunnerForTest; - -class SchedulerTaskRunnerDelegateForTest : public SchedulerTaskRunnerDelegate { - public: - static scoped_refptr<SchedulerTaskRunnerDelegateForTest> Create( - scoped_refptr<base::SingleThreadTaskRunner> task_runner); - - // SchedulerTaskRunnerDelegate implementation - void SetDefaultTaskRunner( - scoped_refptr<base::SingleThreadTaskRunner> task_runner) override; - void RestoreDefaultTaskRunner() override; - bool PostDelayedTask(const tracked_objects::Location& from_here, - const base::Closure& task, - base::TimeDelta delay) override; - bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, - const base::Closure& task, - base::TimeDelta delay) override; - bool RunsTasksOnCurrentThread() const override; - bool IsNested() const override; - void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override; - void RemoveTaskObserver( - base::MessageLoop::TaskObserver* task_observer) override; - - base::SingleThreadTaskRunner* default_task_runner() const { - return default_task_runner_.get(); - } - - protected: - ~SchedulerTaskRunnerDelegateForTest() override; - - private: - explicit SchedulerTaskRunnerDelegateForTest( - scoped_refptr<base::SingleThreadTaskRunner> task_runner); - - scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; - - scoped_refptr<NestableTaskRunnerForTest> task_runner_; - - DISALLOW_COPY_AND_ASSIGN(SchedulerTaskRunnerDelegateForTest); -}; - -} // namespace scheduler - -#endif // CONTENT_RENDERER_SCHEDULER_SCHEDULER_TASK_RUNNER_DELEGATE_FOR_TEST_H_ diff --git a/components/scheduler/child/scheduler_task_runner_delegate_impl.cc b/components/scheduler/child/scheduler_task_runner_delegate_impl.cc deleted file mode 100644 index 73a6772..0000000 --- a/components/scheduler/child/scheduler_task_runner_delegate_impl.cc +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "components/scheduler/child/scheduler_task_runner_delegate_impl.h" - -namespace scheduler { - -// static -scoped_refptr<SchedulerTaskRunnerDelegateImpl> -SchedulerTaskRunnerDelegateImpl::Create(base::MessageLoop* message_loop) { - return make_scoped_refptr(new SchedulerTaskRunnerDelegateImpl(message_loop)); -} - -SchedulerTaskRunnerDelegateImpl::SchedulerTaskRunnerDelegateImpl( - base::MessageLoop* message_loop) - : message_loop_(message_loop), - message_loop_task_runner_(message_loop->task_runner()) { -} - -SchedulerTaskRunnerDelegateImpl::~SchedulerTaskRunnerDelegateImpl() { - RestoreDefaultTaskRunner(); -} - -void SchedulerTaskRunnerDelegateImpl::SetDefaultTaskRunner( - scoped_refptr<base::SingleThreadTaskRunner> task_runner) { - message_loop_->SetTaskRunner(task_runner); -} - -void SchedulerTaskRunnerDelegateImpl::RestoreDefaultTaskRunner() { - if (base::MessageLoop::current() == message_loop_) - message_loop_->SetTaskRunner(message_loop_task_runner_); -} - -bool SchedulerTaskRunnerDelegateImpl::PostDelayedTask( - const tracked_objects::Location& from_here, - const base::Closure& task, - base::TimeDelta delay) { - return message_loop_task_runner_->PostDelayedTask(from_here, task, delay); -} - -bool SchedulerTaskRunnerDelegateImpl::PostNonNestableDelayedTask( - const tracked_objects::Location& from_here, - const base::Closure& task, - base::TimeDelta delay) { - return message_loop_task_runner_->PostNonNestableDelayedTask(from_here, task, - delay); -} - -bool SchedulerTaskRunnerDelegateImpl::RunsTasksOnCurrentThread() const { - return message_loop_task_runner_->RunsTasksOnCurrentThread(); -} - -bool SchedulerTaskRunnerDelegateImpl::IsNested() const { - return message_loop_->IsNested(); -} - -void SchedulerTaskRunnerDelegateImpl::AddTaskObserver( - base::MessageLoop::TaskObserver* task_observer) { - message_loop_->AddTaskObserver(task_observer); -} - -void SchedulerTaskRunnerDelegateImpl::RemoveTaskObserver( - base::MessageLoop::TaskObserver* task_observer) { - message_loop_->RemoveTaskObserver(task_observer); -} - -} // namespace scheduler diff --git a/components/scheduler/child/scheduler_task_runner_delegate_impl_unittest.cc b/components/scheduler/child/scheduler_task_runner_delegate_impl_unittest.cc deleted file mode 100644 index 7e55a12..0000000 --- a/components/scheduler/child/scheduler_task_runner_delegate_impl_unittest.cc +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "components/scheduler/child/scheduler_task_runner_delegate_impl.h" - -#include "base/message_loop/message_loop.h" -#include "base/test/test_simple_task_runner.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace scheduler { - -TEST(SchedulerTaskRunnerDelegateImplTest, TestTaskRunnerOverriding) { - base::MessageLoop loop; - scoped_refptr<base::SingleThreadTaskRunner> original_runner( - loop.task_runner()); - scoped_refptr<base::SingleThreadTaskRunner> custom_runner( - new base::TestSimpleTaskRunner()); - { - scoped_refptr<SchedulerTaskRunnerDelegateImpl> delegate( - SchedulerTaskRunnerDelegateImpl::Create(&loop)); - delegate->SetDefaultTaskRunner(custom_runner); - DCHECK_EQ(custom_runner, loop.task_runner()); - } - DCHECK_EQ(original_runner, loop.task_runner()); -} - -} // namespace scheduler diff --git a/components/scheduler/child/task_queue_manager_perftest.cc b/components/scheduler/child/task_queue_manager_perftest.cc index 036a010..7855557 100644 --- a/components/scheduler/child/task_queue_manager_perftest.cc +++ b/components/scheduler/child/task_queue_manager_perftest.cc @@ -6,7 +6,7 @@ #include "base/bind.h" #include "base/threading/thread.h" -#include "components/scheduler/child/scheduler_task_runner_delegate_impl.h" +#include "components/scheduler/child/scheduler_message_loop_delegate.h" #include "components/scheduler/child/task_queue_selector.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/perf/perf_test.h" @@ -68,8 +68,7 @@ class TaskQueueManagerPerfTest : public testing::Test { message_loop_.reset(new base::MessageLoop()); selector_ = make_scoped_ptr(new SelectorForTest); manager_ = make_scoped_ptr(new TaskQueueManager( - num_queues, - SchedulerTaskRunnerDelegateImpl::Create(message_loop_.get()), + num_queues, SchedulerMessageLoopDelegate::Create(message_loop_.get()), selector_.get(), "fake.category", "fake.category.debug")); } diff --git a/components/scheduler/child/task_queue_manager_unittest.cc b/components/scheduler/child/task_queue_manager_unittest.cc index 5585a13..55f738f 100644 --- a/components/scheduler/child/task_queue_manager_unittest.cc +++ b/components/scheduler/child/task_queue_manager_unittest.cc @@ -10,7 +10,7 @@ #include "base/threading/thread.h" #include "cc/test/ordered_simple_task_runner.h" #include "components/scheduler/child/nestable_task_runner_for_test.h" -#include "components/scheduler/child/scheduler_task_runner_delegate_impl.h" +#include "components/scheduler/child/scheduler_message_loop_delegate.h" #include "components/scheduler/child/task_queue_selector.h" #include "components/scheduler/child/test_time_source.h" #include "components/scheduler/test/test_always_fail_time_source.h" @@ -133,12 +133,10 @@ class TaskQueueManagerTest : public testing::Test { now_src_->Advance(base::TimeDelta::FromMicroseconds(1000)); test_task_runner_ = make_scoped_refptr( new cc::OrderedSimpleTaskRunner(now_src_.get(), false)); - main_task_runner_ = - NestableTaskRunnerForTest::Create(test_task_runner_.get()); selector_ = make_scoped_ptr(createSelectorForTest(type)); - manager_ = make_scoped_ptr( - new TaskQueueManager(num_queues, main_task_runner_, selector_.get(), - "test.scheduler", "test.scheduler.debug")); + manager_ = make_scoped_ptr(new TaskQueueManager( + num_queues, NestableTaskRunnerForTest::Create(test_task_runner_.get()), + selector_.get(), "test.scheduler", "test.scheduler.debug")); manager_->SetTimeSourceForTesting( make_scoped_ptr(new TestTimeSource(now_src_.get()))); @@ -149,8 +147,7 @@ class TaskQueueManagerTest : public testing::Test { message_loop_.reset(new base::MessageLoop()); selector_ = make_scoped_ptr(createSelectorForTest(type)); manager_ = make_scoped_ptr(new TaskQueueManager( - num_queues, - SchedulerTaskRunnerDelegateImpl::Create(message_loop_.get()), + num_queues, SchedulerMessageLoopDelegate::Create(message_loop_.get()), selector_.get(), "test.scheduler", "test.scheduler.debug")); EXPECT_EQ(num_queues, selector_->work_queues().size()); } @@ -191,12 +188,11 @@ class TaskQueueManagerTest : public testing::Test { &TaskQueueManager::WakeupPolicyToString); } - scoped_ptr<base::MessageLoop> message_loop_; scoped_ptr<base::SimpleTestTickClock> now_src_; - scoped_refptr<NestableTaskRunnerForTest> main_task_runner_; scoped_refptr<cc::OrderedSimpleTaskRunner> test_task_runner_; scoped_ptr<SelectorForTest> selector_; scoped_ptr<TaskQueueManager> manager_; + scoped_ptr<base::MessageLoop> message_loop_; }; void PostFromNestedRunloop(base::MessageLoop* message_loop, diff --git a/components/scheduler/child/webthread_impl_for_worker_scheduler.cc b/components/scheduler/child/webthread_impl_for_worker_scheduler.cc index 0b906a64..87ac820 100644 --- a/components/scheduler/child/webthread_impl_for_worker_scheduler.cc +++ b/components/scheduler/child/webthread_impl_for_worker_scheduler.cc @@ -8,6 +8,7 @@ #include "base/location.h" #include "base/single_thread_task_runner.h" #include "base/synchronization/waitable_event.h" +#include "components/scheduler/child/scheduler_message_loop_delegate.h" #include "components/scheduler/child/web_scheduler_impl.h" #include "components/scheduler/child/worker_scheduler_impl.h" #include "third_party/WebKit/public/platform/WebTraceLocation.h" @@ -18,23 +19,15 @@ WebThreadImplForWorkerScheduler::WebThreadImplForWorkerScheduler( const char* name) : thread_(new base::Thread(name)) { thread_->Start(); - thread_task_runner_ = thread_->task_runner(); base::WaitableEvent completion(false, false); - thread_task_runner_->PostTask( + thread_->task_runner()->PostTask( FROM_HERE, base::Bind(&WebThreadImplForWorkerScheduler::InitOnThread, base::Unretained(this), &completion)); completion.Wait(); } WebThreadImplForWorkerScheduler::~WebThreadImplForWorkerScheduler() { - base::WaitableEvent completion(false, false); - // Shut down the scheduler on the thread to restore the original task runner - // so that the thread can tear itself down. - thread_task_runner_->PostTask( - FROM_HERE, base::Bind(&WebThreadImplForWorkerScheduler::ShutdownOnThread, - base::Unretained(this), &completion)); - completion.Wait(); thread_->Stop(); } @@ -52,12 +45,6 @@ void WebThreadImplForWorkerScheduler::InitOnThread( completion->Signal(); } -void WebThreadImplForWorkerScheduler::ShutdownOnThread( - base::WaitableEvent* completion) { - worker_scheduler_->Shutdown(); - completion->Signal(); -} - void WebThreadImplForWorkerScheduler::WillDestroyCurrentMessageLoop() { task_runner_ = nullptr; idle_task_runner_ = nullptr; diff --git a/components/scheduler/child/webthread_impl_for_worker_scheduler.h b/components/scheduler/child/webthread_impl_for_worker_scheduler.h index 13d1596..1c0f0ed 100644 --- a/components/scheduler/child/webthread_impl_for_worker_scheduler.h +++ b/components/scheduler/child/webthread_impl_for_worker_scheduler.h @@ -46,12 +46,10 @@ class SCHEDULER_EXPORT WebThreadImplForWorkerScheduler base::MessageLoop::TaskObserver* observer) override; void InitOnThread(base::WaitableEvent* completion); - void ShutdownOnThread(base::WaitableEvent* completion); scoped_ptr<base::Thread> thread_; scoped_ptr<scheduler::WorkerScheduler> worker_scheduler_; scoped_ptr<scheduler::WebSchedulerImpl> web_scheduler_; - scoped_refptr<base::SingleThreadTaskRunner> thread_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> task_runner_; scoped_refptr<scheduler::SingleThreadIdleTaskRunner> idle_task_runner_; }; diff --git a/components/scheduler/child/worker_scheduler.cc b/components/scheduler/child/worker_scheduler.cc index bcd5020..a1ddc98 100644 --- a/components/scheduler/child/worker_scheduler.cc +++ b/components/scheduler/child/worker_scheduler.cc @@ -7,7 +7,7 @@ #include "base/command_line.h" #include "base/message_loop/message_loop.h" #include "components/scheduler/child/null_worker_scheduler.h" -#include "components/scheduler/child/scheduler_task_runner_delegate_impl.h" +#include "components/scheduler/child/scheduler_message_loop_delegate.h" #include "components/scheduler/child/worker_scheduler_impl.h" #include "components/scheduler/common/scheduler_switches.h" @@ -27,7 +27,7 @@ scoped_ptr<WorkerScheduler> WorkerScheduler::Create( return make_scoped_ptr(new NullWorkerScheduler()); } else { return make_scoped_ptr(new WorkerSchedulerImpl( - SchedulerTaskRunnerDelegateImpl::Create(message_loop))); + SchedulerMessageLoopDelegate::Create(message_loop))); } } diff --git a/components/scheduler/child/worker_scheduler_impl.cc b/components/scheduler/child/worker_scheduler_impl.cc index a972137..b5b9c83 100644 --- a/components/scheduler/child/worker_scheduler_impl.cc +++ b/components/scheduler/child/worker_scheduler_impl.cc @@ -7,12 +7,12 @@ #include "base/bind.h" #include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event_argument.h" -#include "components/scheduler/child/scheduler_task_runner_delegate.h" +#include "components/scheduler/child/nestable_single_thread_task_runner.h" namespace scheduler { WorkerSchedulerImpl::WorkerSchedulerImpl( - scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner) + scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner) : helper_(main_task_runner, "worker.scheduler", TRACE_DISABLED_BY_DEFAULT("worker.scheduler"), diff --git a/components/scheduler/child/worker_scheduler_impl.h b/components/scheduler/child/worker_scheduler_impl.h index 2f90217..5616a54 100644 --- a/components/scheduler/child/worker_scheduler_impl.h +++ b/components/scheduler/child/worker_scheduler_impl.h @@ -18,13 +18,13 @@ class ConvertableToTraceFormat; namespace scheduler { -class SchedulerTaskRunnerDelegate; +class NestableSingleThreadTaskRunner; class SCHEDULER_EXPORT WorkerSchedulerImpl : public WorkerScheduler, public IdleHelper::Delegate { public: explicit WorkerSchedulerImpl( - scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner); + scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner); ~WorkerSchedulerImpl() override; // WorkerScheduler implementation: diff --git a/components/scheduler/child/worker_scheduler_impl_unittest.cc b/components/scheduler/child/worker_scheduler_impl_unittest.cc index 9b17b15..451d861 100644 --- a/components/scheduler/child/worker_scheduler_impl_unittest.cc +++ b/components/scheduler/child/worker_scheduler_impl_unittest.cc @@ -8,7 +8,8 @@ #include "base/strings/stringprintf.h" #include "base/test/simple_test_tick_clock.h" #include "cc/test/ordered_simple_task_runner.h" -#include "components/scheduler/child/scheduler_task_runner_delegate_for_test.h" +#include "components/scheduler/child/nestable_task_runner_for_test.h" +#include "components/scheduler/child/scheduler_message_loop_delegate.h" #include "components/scheduler/child/test_time_source.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -53,7 +54,7 @@ void TimelineIdleTestTask(std::vector<std::string>* timeline, class WorkerSchedulerImplForTest : public WorkerSchedulerImpl { public: WorkerSchedulerImplForTest( - scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner, + scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner, base::SimpleTestTickClock* clock_) : WorkerSchedulerImpl(main_task_runner), clock_(clock_), @@ -92,10 +93,10 @@ class WorkerSchedulerImplTest : public testing::Test { WorkerSchedulerImplTest() : clock_(new base::SimpleTestTickClock()), mock_task_runner_(new cc::OrderedSimpleTaskRunner(clock_.get(), true)), - main_task_runner_( - SchedulerTaskRunnerDelegateForTest::Create(mock_task_runner_)), - scheduler_( - new WorkerSchedulerImplForTest(main_task_runner_, clock_.get())), + nestable_task_runner_( + NestableTaskRunnerForTest::Create(mock_task_runner_)), + scheduler_(new WorkerSchedulerImplForTest(nestable_task_runner_, + clock_.get())), timeline_(nullptr) { clock_->Advance(base::TimeDelta::FromMicroseconds(5000)); scheduler_->GetSchedulerHelperForTesting()->SetTimeSourceForTesting( @@ -175,7 +176,7 @@ class WorkerSchedulerImplTest : public testing::Test { // Only one of mock_task_runner_ or message_loop_ will be set. scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; - scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner_; + scoped_refptr<NestableSingleThreadTaskRunner> nestable_task_runner_; scoped_ptr<WorkerSchedulerImplForTest> scheduler_; scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; diff --git a/components/scheduler/renderer/renderer_scheduler.cc b/components/scheduler/renderer/renderer_scheduler.cc index 81f3ccb..914b802 100644 --- a/components/scheduler/renderer/renderer_scheduler.cc +++ b/components/scheduler/renderer/renderer_scheduler.cc @@ -8,7 +8,7 @@ #include "base/message_loop/message_loop.h" #include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event_impl.h" -#include "components/scheduler/child/scheduler_task_runner_delegate_impl.h" +#include "components/scheduler/child/scheduler_message_loop_delegate.h" #include "components/scheduler/common/scheduler_switches.h" #include "components/scheduler/renderer/null_renderer_scheduler.h" #include "components/scheduler/renderer/renderer_scheduler_impl.h" @@ -38,7 +38,7 @@ scoped_ptr<RendererScheduler> RendererScheduler::Create() { } else { base::MessageLoop* message_loop = base::MessageLoop::current(); return make_scoped_ptr(new RendererSchedulerImpl( - SchedulerTaskRunnerDelegateImpl::Create(message_loop))); + SchedulerMessageLoopDelegate::Create(message_loop))); } } diff --git a/components/scheduler/renderer/renderer_scheduler_impl.cc b/components/scheduler/renderer/renderer_scheduler_impl.cc index a632dcf..51c51ae 100644 --- a/components/scheduler/renderer/renderer_scheduler_impl.cc +++ b/components/scheduler/renderer/renderer_scheduler_impl.cc @@ -9,13 +9,13 @@ #include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event_argument.h" #include "cc/output/begin_frame_args.h" +#include "components/scheduler/child/nestable_single_thread_task_runner.h" #include "components/scheduler/child/prioritizing_task_queue_selector.h" -#include "components/scheduler/child/scheduler_task_runner_delegate.h" namespace scheduler { RendererSchedulerImpl::RendererSchedulerImpl( - scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner) + scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner) : helper_(main_task_runner, "renderer.scheduler", TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), diff --git a/components/scheduler/renderer/renderer_scheduler_impl.h b/components/scheduler/renderer/renderer_scheduler_impl.h index c7d4216..a6c2138 100644 --- a/components/scheduler/renderer/renderer_scheduler_impl.h +++ b/components/scheduler/renderer/renderer_scheduler_impl.h @@ -26,7 +26,7 @@ class SCHEDULER_EXPORT RendererSchedulerImpl : public RendererScheduler, public IdleHelper::Delegate { public: RendererSchedulerImpl( - scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner); + scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner); ~RendererSchedulerImpl() override; // RendererScheduler implementation: diff --git a/components/scheduler/renderer/renderer_scheduler_impl_unittest.cc b/components/scheduler/renderer/renderer_scheduler_impl_unittest.cc index 97d8ae1..b860b19 100644 --- a/components/scheduler/renderer/renderer_scheduler_impl_unittest.cc +++ b/components/scheduler/renderer/renderer_scheduler_impl_unittest.cc @@ -8,8 +8,8 @@ #include "base/test/simple_test_tick_clock.h" #include "cc/output/begin_frame_args.h" #include "cc/test/ordered_simple_task_runner.h" -#include "components/scheduler/child/scheduler_task_runner_delegate_for_test.h" -#include "components/scheduler/child/scheduler_task_runner_delegate_impl.h" +#include "components/scheduler/child/nestable_task_runner_for_test.h" +#include "components/scheduler/child/scheduler_message_loop_delegate.h" #include "components/scheduler/child/test_time_source.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -148,7 +148,7 @@ class RendererSchedulerImplForTest : public RendererSchedulerImpl { using RendererSchedulerImpl::PolicyToString; RendererSchedulerImplForTest( - scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner) + scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner) : RendererSchedulerImpl(main_task_runner), update_policy_count_(0) {} void UpdatePolicyLocked(UpdateType update_type) override { @@ -197,16 +197,16 @@ class RendererSchedulerImplTest : public testing::Test { void SetUp() override { if (message_loop_) { - main_task_runner_ = - SchedulerTaskRunnerDelegateImpl::Create(message_loop_.get()); + nestable_task_runner_ = + SchedulerMessageLoopDelegate::Create(message_loop_.get()); } else { mock_task_runner_ = make_scoped_refptr( new cc::OrderedSimpleTaskRunner(clock_.get(), false)); - main_task_runner_ = - SchedulerTaskRunnerDelegateForTest::Create(mock_task_runner_); + nestable_task_runner_ = + NestableTaskRunnerForTest::Create(mock_task_runner_); } - Initialize( - make_scoped_ptr(new RendererSchedulerImplForTest(main_task_runner_))); + Initialize(make_scoped_ptr( + new RendererSchedulerImplForTest(nestable_task_runner_))); } void Initialize(scoped_ptr<RendererSchedulerImplForTest> scheduler) { @@ -352,7 +352,7 @@ class RendererSchedulerImplTest : public testing::Test { scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_; scoped_ptr<base::MessageLoop> message_loop_; - scoped_refptr<SchedulerTaskRunnerDelegate> main_task_runner_; + scoped_refptr<NestableSingleThreadTaskRunner> nestable_task_runner_; scoped_ptr<RendererSchedulerImplForTest> scheduler_; scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; @@ -1204,9 +1204,9 @@ class RendererSchedulerImplWithMockSchedulerTest void SetUp() override { mock_task_runner_ = make_scoped_refptr( new cc::OrderedSimpleTaskRunner(clock_.get(), false)); - main_task_runner_ = - SchedulerTaskRunnerDelegateForTest::Create(mock_task_runner_); - mock_scheduler_ = new RendererSchedulerImplForTest(main_task_runner_); + nestable_task_runner_ = + NestableTaskRunnerForTest::Create(mock_task_runner_); + mock_scheduler_ = new RendererSchedulerImplForTest(nestable_task_runner_); Initialize(make_scoped_ptr(mock_scheduler_)); } diff --git a/components/scheduler/renderer/webthread_impl_for_renderer_scheduler_unittest.cc b/components/scheduler/renderer/webthread_impl_for_renderer_scheduler_unittest.cc index 6999da71..d67c4b4e 100644 --- a/components/scheduler/renderer/webthread_impl_for_renderer_scheduler_unittest.cc +++ b/components/scheduler/renderer/webthread_impl_for_renderer_scheduler_unittest.cc @@ -7,7 +7,7 @@ #include "base/location.h" #include "base/run_loop.h" #include "base/single_thread_task_runner.h" -#include "components/scheduler/child/scheduler_task_runner_delegate_impl.h" +#include "components/scheduler/child/scheduler_message_loop_delegate.h" #include "components/scheduler/renderer/renderer_scheduler_impl.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -33,7 +33,7 @@ class MockTaskObserver : public blink::WebThread::TaskObserver { class WebThreadImplForRendererSchedulerTest : public testing::Test { public: WebThreadImplForRendererSchedulerTest() - : scheduler_(SchedulerTaskRunnerDelegateImpl::Create(&message_loop_)), + : scheduler_(SchedulerMessageLoopDelegate::Create(&message_loop_)), default_task_runner_(scheduler_.DefaultTaskRunner()), thread_(&scheduler_) {} diff --git a/components/scheduler/scheduler.gypi b/components/scheduler/scheduler.gypi index 78dc48e..e0d4bee 100644 --- a/components/scheduler/scheduler.gypi +++ b/components/scheduler/scheduler.gypi @@ -25,9 +25,8 @@ 'child/prioritizing_task_queue_selector.h', 'child/scheduler_helper.cc', 'child/scheduler_helper.h', - 'child/scheduler_task_runner_delegate.h', - 'child/scheduler_task_runner_delegate_impl.cc', - 'child/scheduler_task_runner_delegate_impl.h', + 'child/scheduler_message_loop_delegate.cc', + 'child/scheduler_message_loop_delegate.h', 'child/single_thread_idle_task_runner.cc', 'child/single_thread_idle_task_runner.h', 'child/task_queue_manager.cc', diff --git a/components/scheduler/test/lazy_scheduler_message_loop_delegate_for_tests.cc b/components/scheduler/test/lazy_scheduler_message_loop_delegate_for_tests.cc index 9d613d6..999d856 100644 --- a/components/scheduler/test/lazy_scheduler_message_loop_delegate_for_tests.cc +++ b/components/scheduler/test/lazy_scheduler_message_loop_delegate_for_tests.cc @@ -16,13 +16,10 @@ LazySchedulerMessageLoopDelegateForTests:: LazySchedulerMessageLoopDelegateForTests() : message_loop_(base::MessageLoop::current()), thread_id_(base::PlatformThread::CurrentId()) { - if (message_loop_) - original_task_runner_ = message_loop_->task_runner(); } LazySchedulerMessageLoopDelegateForTests:: ~LazySchedulerMessageLoopDelegateForTests() { - RestoreDefaultTaskRunner(); } base::MessageLoop* LazySchedulerMessageLoopDelegateForTests::EnsureMessageLoop() @@ -32,30 +29,13 @@ base::MessageLoop* LazySchedulerMessageLoopDelegateForTests::EnsureMessageLoop() DCHECK(RunsTasksOnCurrentThread()); message_loop_ = base::MessageLoop::current(); DCHECK(message_loop_); - original_task_runner_ = message_loop_->task_runner(); for (auto& observer : pending_observers_) { message_loop_->AddTaskObserver(observer); } pending_observers_.clear(); - if (pending_task_runner_) - message_loop_->SetTaskRunner(pending_task_runner_.Pass()); return message_loop_; } -void LazySchedulerMessageLoopDelegateForTests::SetDefaultTaskRunner( - scoped_refptr<base::SingleThreadTaskRunner> task_runner) { - if (!HasMessageLoop()) { - pending_task_runner_ = task_runner.Pass(); - return; - } - message_loop_->SetTaskRunner(task_runner.Pass()); -} - -void LazySchedulerMessageLoopDelegateForTests::RestoreDefaultTaskRunner() { - if (HasMessageLoop() && base::MessageLoop::current() == message_loop_) - message_loop_->SetTaskRunner(original_task_runner_); -} - bool LazySchedulerMessageLoopDelegateForTests::HasMessageLoop() const { return message_loop_ != nullptr; } @@ -64,17 +44,16 @@ bool LazySchedulerMessageLoopDelegateForTests::PostDelayedTask( const tracked_objects::Location& from_here, const base::Closure& task, base::TimeDelta delay) { - EnsureMessageLoop(); - return original_task_runner_->PostDelayedTask(from_here, task, delay); + return EnsureMessageLoop()->task_runner()->PostDelayedTask(from_here, task, + delay); } bool LazySchedulerMessageLoopDelegateForTests::PostNonNestableDelayedTask( const tracked_objects::Location& from_here, const base::Closure& task, base::TimeDelta delay) { - EnsureMessageLoop(); - return original_task_runner_->PostNonNestableDelayedTask(from_here, task, - delay); + return EnsureMessageLoop()->task_runner()->PostNonNestableDelayedTask( + from_here, task, delay); } bool LazySchedulerMessageLoopDelegateForTests::RunsTasksOnCurrentThread() diff --git a/components/scheduler/test/lazy_scheduler_message_loop_delegate_for_tests.h b/components/scheduler/test/lazy_scheduler_message_loop_delegate_for_tests.h index 5f2eaec..a727a6d 100644 --- a/components/scheduler/test/lazy_scheduler_message_loop_delegate_for_tests.h +++ b/components/scheduler/test/lazy_scheduler_message_loop_delegate_for_tests.h @@ -6,7 +6,7 @@ #define COMPONENTS_SCHEDULER_TEST_LAZY_SCHEDULER_MESSAGE_LOOP_DELEGATE_FOR_TESTS_H_ #include "base/message_loop/message_loop.h" -#include "components/scheduler/child/scheduler_task_runner_delegate.h" +#include "components/scheduler/child/nestable_single_thread_task_runner.h" namespace scheduler { @@ -18,14 +18,11 @@ namespace scheduler { // TODO(skyostil): Fix the relevant test suites and remove this class // (crbug.com/495659). class LazySchedulerMessageLoopDelegateForTests - : public SchedulerTaskRunnerDelegate { + : public NestableSingleThreadTaskRunner { public: static scoped_refptr<LazySchedulerMessageLoopDelegateForTests> Create(); - // SchedulerTaskRunnerDelegate implementation - void SetDefaultTaskRunner( - scoped_refptr<base::SingleThreadTaskRunner> task_runner) override; - void RestoreDefaultTaskRunner() override; + // NestableSingleThreadTaskRunner implementation bool PostDelayedTask(const tracked_objects::Location& from_here, const base::Closure& task, base::TimeDelta delay) override; @@ -52,10 +49,6 @@ class LazySchedulerMessageLoopDelegateForTests // owned. mutable base::hash_set<base::MessageLoop::TaskObserver*> pending_observers_; - // A task runner which hasn't yet been overridden in the message loop. - mutable scoped_refptr<base::SingleThreadTaskRunner> pending_task_runner_; - mutable scoped_refptr<base::SingleThreadTaskRunner> original_task_runner_; - DISALLOW_COPY_AND_ASSIGN(LazySchedulerMessageLoopDelegateForTests); }; |