• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_TEST_SCOPED_MOCK_TIME_MESSAGE_LOOP_TASK_RUNNER_H_
6 #define BASE_TEST_SCOPED_MOCK_TIME_MESSAGE_LOOP_TASK_RUNNER_H_
7 
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/test/test_mock_time_task_runner.h"
11 
12 namespace base {
13 
14 class SingleThreadTaskRunner;
15 
16 // A scoped wrapper around TestMockTimeTaskRunner that replaces
17 // MessageLoopCurrent::Get()'s task runner (and consequently
18 // ThreadTaskRunnerHandle) with a TestMockTimeTaskRunner and resets it back at
19 // the end of its scope.
20 //
21 // Note: RunLoop() will not work in the scope of a
22 // ScopedMockTimeMessageLoopTaskRunner, the underlying TestMockTimeTaskRunner's
23 // methods must be used instead to pump tasks.
24 //
25 // DEPRECATED: Use a TestMockTimeTaskRunner::Type::kBoundToThread instead of a
26 // MessageLoop + ScopedMockTimeMessageLoopTaskRunner.
27 // TODO(gab): Remove usage of this API and delete it.
28 class ScopedMockTimeMessageLoopTaskRunner {
29  public:
30   ScopedMockTimeMessageLoopTaskRunner();
31   ~ScopedMockTimeMessageLoopTaskRunner();
32 
task_runner()33   TestMockTimeTaskRunner* task_runner() { return task_runner_.get(); }
34   TestMockTimeTaskRunner* operator->() { return task_runner_.get(); }
35 
36  private:
37   const scoped_refptr<TestMockTimeTaskRunner> task_runner_;
38   scoped_refptr<SingleThreadTaskRunner> previous_task_runner_;
39 
40   DISALLOW_COPY_AND_ASSIGN(ScopedMockTimeMessageLoopTaskRunner);
41 };
42 
43 }  // namespace base
44 
45 #endif  // BASE_TEST_SCOPED_MOCK_TIME_MESSAGE_LOOP_TASK_RUNNER_H_
46