Patrik Höglund | d8f3c17 | 2018-09-26 14:39:17 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 11 | #include "api/test/test_dependency_factory.h" |
| 12 | |
Patrik Höglund | d8f3c17 | 2018-09-26 14:39:17 +0200 | [diff] [blame] | 13 | #include <memory> |
| 14 | #include <utility> |
| 15 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 16 | #include "rtc_base/checks.h" |
Tommi | 9b7232a | 2020-05-15 10:09:27 +0200 | [diff] [blame] | 17 | #include "rtc_base/platform_thread_types.h" |
Patrik Höglund | d8f3c17 | 2018-09-26 14:39:17 +0200 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | |
Tommi | 9b7232a | 2020-05-15 10:09:27 +0200 | [diff] [blame] | 21 | namespace { |
Patrik Höglund | d8f3c17 | 2018-09-26 14:39:17 +0200 | [diff] [blame] | 22 | // This checks everything in this file gets called on the same thread. It's |
| 23 | // static because it needs to look at the static methods too. |
Tommi | 9b7232a | 2020-05-15 10:09:27 +0200 | [diff] [blame] | 24 | bool IsValidTestDependencyFactoryThread() { |
| 25 | const rtc::PlatformThreadRef main_thread = rtc::CurrentThreadRef(); |
| 26 | return rtc::IsThreadRefEqual(main_thread, rtc::CurrentThreadRef()); |
Patrik Höglund | d8f3c17 | 2018-09-26 14:39:17 +0200 | [diff] [blame] | 27 | } |
Tommi | 9b7232a | 2020-05-15 10:09:27 +0200 | [diff] [blame] | 28 | } // namespace |
Patrik Höglund | d8f3c17 | 2018-09-26 14:39:17 +0200 | [diff] [blame] | 29 | |
| 30 | std::unique_ptr<TestDependencyFactory> TestDependencyFactory::instance_ = |
| 31 | nullptr; |
| 32 | |
| 33 | const TestDependencyFactory& TestDependencyFactory::GetInstance() { |
Tommi | 9b7232a | 2020-05-15 10:09:27 +0200 | [diff] [blame] | 34 | RTC_DCHECK(IsValidTestDependencyFactoryThread()); |
Patrik Höglund | d8f3c17 | 2018-09-26 14:39:17 +0200 | [diff] [blame] | 35 | if (instance_ == nullptr) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 36 | instance_ = std::make_unique<TestDependencyFactory>(); |
Patrik Höglund | d8f3c17 | 2018-09-26 14:39:17 +0200 | [diff] [blame] | 37 | } |
| 38 | return *instance_; |
| 39 | } |
| 40 | |
| 41 | void TestDependencyFactory::SetInstance( |
| 42 | std::unique_ptr<TestDependencyFactory> instance) { |
Tommi | 9b7232a | 2020-05-15 10:09:27 +0200 | [diff] [blame] | 43 | RTC_DCHECK(IsValidTestDependencyFactoryThread()); |
Patrik Höglund | d8f3c17 | 2018-09-26 14:39:17 +0200 | [diff] [blame] | 44 | RTC_CHECK(instance_ == nullptr); |
| 45 | instance_ = std::move(instance); |
| 46 | } |
| 47 | |
| 48 | std::unique_ptr<VideoQualityTestFixtureInterface::InjectionComponents> |
| 49 | TestDependencyFactory::CreateComponents() const { |
Tommi | 9b7232a | 2020-05-15 10:09:27 +0200 | [diff] [blame] | 50 | RTC_DCHECK(IsValidTestDependencyFactoryThread()); |
Patrik Höglund | d8f3c17 | 2018-09-26 14:39:17 +0200 | [diff] [blame] | 51 | return nullptr; |
| 52 | } |
| 53 | |
| 54 | } // namespace webrtc |