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

Unified Diff: components/scheduler/test/lazy_scheduler_message_loop_delegate_for_tests.cc

Issue 1152623008: scheduler: Always create a real scheduler in unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remember the message loop binding. Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: components/scheduler/test/lazy_scheduler_message_loop_delegate_for_tests.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
new file mode 100644
index 0000000000000000000000000000000000000000..999d8567a1f03be79f526b42b6aa6340254a80df
--- /dev/null
+++ b/components/scheduler/test/lazy_scheduler_message_loop_delegate_for_tests.cc
@@ -0,0 +1,86 @@
+// 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/test/lazy_scheduler_message_loop_delegate_for_tests.h"
+
+namespace scheduler {
+
+// static
+scoped_refptr<LazySchedulerMessageLoopDelegateForTests>
+LazySchedulerMessageLoopDelegateForTests::Create() {
+ return make_scoped_refptr(new LazySchedulerMessageLoopDelegateForTests());
+}
+
+LazySchedulerMessageLoopDelegateForTests::
+ LazySchedulerMessageLoopDelegateForTests()
+ : message_loop_(base::MessageLoop::current()),
+ thread_id_(base::PlatformThread::CurrentId()) {
+}
+
+LazySchedulerMessageLoopDelegateForTests::
+ ~LazySchedulerMessageLoopDelegateForTests() {
+}
+
+base::MessageLoop* LazySchedulerMessageLoopDelegateForTests::EnsureMessageLoop()
+ const {
+ if (message_loop_)
+ return message_loop_;
+ DCHECK(RunsTasksOnCurrentThread());
+ message_loop_ = base::MessageLoop::current();
+ DCHECK(message_loop_);
+ for (auto& observer : pending_observers_) {
+ message_loop_->AddTaskObserver(observer);
+ }
+ pending_observers_.clear();
+ return message_loop_;
+}
+
+bool LazySchedulerMessageLoopDelegateForTests::HasMessageLoop() const {
+ return message_loop_ != nullptr;
+}
+
+bool LazySchedulerMessageLoopDelegateForTests::PostDelayedTask(
+ const tracked_objects::Location& from_here,
+ const base::Closure& task,
+ base::TimeDelta 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) {
+ return EnsureMessageLoop()->task_runner()->PostNonNestableDelayedTask(
+ from_here, task, delay);
+}
+
+bool LazySchedulerMessageLoopDelegateForTests::RunsTasksOnCurrentThread()
+ const {
+ return thread_id_ == base::PlatformThread::CurrentId();
+}
+
+bool LazySchedulerMessageLoopDelegateForTests::IsNested() const {
+ return EnsureMessageLoop()->IsNested();
+}
+
+void LazySchedulerMessageLoopDelegateForTests::AddTaskObserver(
+ base::MessageLoop::TaskObserver* task_observer) {
+ if (!HasMessageLoop()) {
+ pending_observers_.insert(task_observer);
+ return;
+ }
+ EnsureMessageLoop()->AddTaskObserver(task_observer);
+}
+
+void LazySchedulerMessageLoopDelegateForTests::RemoveTaskObserver(
+ base::MessageLoop::TaskObserver* task_observer) {
+ if (!HasMessageLoop()) {
+ pending_observers_.erase(task_observer);
+ return;
+ }
+ EnsureMessageLoop()->RemoveTaskObserver(task_observer);
+}
+
+} // namespace scheduler
« no previous file with comments | « components/scheduler/test/lazy_scheduler_message_loop_delegate_for_tests.h ('k') | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698