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" |
| 16 | #include "rtc_base/thread_checker.h" |
| 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | // This checks everything in this file gets called on the same thread. It's |
| 21 | // static because it needs to look at the static methods too. |
| 22 | rtc::ThreadChecker* GetThreadChecker() { |
| 23 | static rtc::ThreadChecker checker; |
| 24 | return &checker; |
| 25 | } |
| 26 | |
| 27 | std::unique_ptr<TestDependencyFactory> TestDependencyFactory::instance_ = |
| 28 | nullptr; |
| 29 | |
| 30 | const TestDependencyFactory& TestDependencyFactory::GetInstance() { |
| 31 | RTC_DCHECK(GetThreadChecker()->CalledOnValidThread()); |
| 32 | if (instance_ == nullptr) { |
| 33 | instance_ = absl::make_unique<TestDependencyFactory>(); |
| 34 | } |
| 35 | return *instance_; |
| 36 | } |
| 37 | |
| 38 | void TestDependencyFactory::SetInstance( |
| 39 | std::unique_ptr<TestDependencyFactory> instance) { |
| 40 | RTC_DCHECK(GetThreadChecker()->CalledOnValidThread()); |
| 41 | RTC_CHECK(instance_ == nullptr); |
| 42 | instance_ = std::move(instance); |
| 43 | } |
| 44 | |
| 45 | std::unique_ptr<VideoQualityTestFixtureInterface::InjectionComponents> |
| 46 | TestDependencyFactory::CreateComponents() const { |
| 47 | RTC_DCHECK(GetThreadChecker()->CalledOnValidThread()); |
| 48 | return nullptr; |
| 49 | } |
| 50 | |
| 51 | } // namespace webrtc |