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 | |
| 11 | #include <memory> |
| 12 | #include <utility> |
| 13 | |
tzik | f0e926f | 2018-10-15 13:52:10 +0900 | [diff] [blame] | 14 | #include "absl/memory/memory.h" |
Patrik Höglund | d8f3c17 | 2018-09-26 14:39:17 +0200 | [diff] [blame] | 15 | #include "api/test/test_dependency_factory.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 16 | #include "rtc_base/checks.h" |
Patrik Höglund | d8f3c17 | 2018-09-26 14:39:17 +0200 | [diff] [blame] | 17 | #include "rtc_base/thread_checker.h" |
| 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | // This checks everything in this file gets called on the same thread. It's |
| 22 | // static because it needs to look at the static methods too. |
| 23 | rtc::ThreadChecker* GetThreadChecker() { |
| 24 | static rtc::ThreadChecker checker; |
| 25 | return &checker; |
| 26 | } |
| 27 | |
| 28 | std::unique_ptr<TestDependencyFactory> TestDependencyFactory::instance_ = |
| 29 | nullptr; |
| 30 | |
| 31 | const TestDependencyFactory& TestDependencyFactory::GetInstance() { |
Sebastian Jansson | c01367d | 2019-04-08 15:20:44 +0200 | [diff] [blame^] | 32 | RTC_DCHECK(GetThreadChecker()->IsCurrent()); |
Patrik Höglund | d8f3c17 | 2018-09-26 14:39:17 +0200 | [diff] [blame] | 33 | if (instance_ == nullptr) { |
| 34 | instance_ = absl::make_unique<TestDependencyFactory>(); |
| 35 | } |
| 36 | return *instance_; |
| 37 | } |
| 38 | |
| 39 | void TestDependencyFactory::SetInstance( |
| 40 | std::unique_ptr<TestDependencyFactory> instance) { |
Sebastian Jansson | c01367d | 2019-04-08 15:20:44 +0200 | [diff] [blame^] | 41 | RTC_DCHECK(GetThreadChecker()->IsCurrent()); |
Patrik Höglund | d8f3c17 | 2018-09-26 14:39:17 +0200 | [diff] [blame] | 42 | RTC_CHECK(instance_ == nullptr); |
| 43 | instance_ = std::move(instance); |
| 44 | } |
| 45 | |
| 46 | std::unique_ptr<VideoQualityTestFixtureInterface::InjectionComponents> |
| 47 | TestDependencyFactory::CreateComponents() const { |
Sebastian Jansson | c01367d | 2019-04-08 15:20:44 +0200 | [diff] [blame^] | 48 | RTC_DCHECK(GetThreadChecker()->IsCurrent()); |
Patrik Höglund | d8f3c17 | 2018-09-26 14:39:17 +0200 | [diff] [blame] | 49 | return nullptr; |
| 50 | } |
| 51 | |
| 52 | } // namespace webrtc |