1 // Copyright 2019 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 MEDIA_BLINK_BLINK_PLATFORM_WITH_TASK_ENVIRONMENT_H_
6 #define MEDIA_BLINK_BLINK_PLATFORM_WITH_TASK_ENVIRONMENT_H_
7 
8 #include "base/macros.h"
9 #include "base/test/task_environment.h"
10 #include "third_party/blink/public/platform/scheduler/web_thread_scheduler.h"
11 #include "third_party/blink/public/web/blink.h"
12 
13 namespace media {
14 
15 // We must use a custom blink::Platform that ensures the main thread scheduler
16 // knows about the TaskEnvironment.
17 class BlinkPlatformWithTaskEnvironment : public blink::Platform {
18  public:
19   BlinkPlatformWithTaskEnvironment();
20   ~BlinkPlatformWithTaskEnvironment() override;
21 
22   blink::scheduler::WebThreadScheduler* GetMainThreadScheduler();
23 
24   // Returns |task_environment_| from the current blink::Platform.
25   static base::test::TaskEnvironment* GetTaskEnvironment();
26 
27  private:
28   base::test::TaskEnvironment task_environment_;
29   std::unique_ptr<blink::scheduler::WebThreadScheduler> main_thread_scheduler_;
30 
31   DISALLOW_COPY_AND_ASSIGN(BlinkPlatformWithTaskEnvironment);
32 };
33 
34 }  // namespace media
35 
36 #endif  // MEDIA_BLINK_BLINK_PLATFORM_WITH_TASK_ENVIRONMENT_H_
37