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 "api/test/test_dependency_factory.h"
12 
13 #include <memory>
14 #include <utility>
15 
16 #include "rtc_base/checks.h"
17 #include "rtc_base/platform_thread_types.h"
18 
19 namespace webrtc {
20 
21 namespace {
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.
IsValidTestDependencyFactoryThread()24 bool IsValidTestDependencyFactoryThread() {
25   const rtc::PlatformThreadRef main_thread = rtc::CurrentThreadRef();
26   return rtc::IsThreadRefEqual(main_thread, rtc::CurrentThreadRef());
27 }
28 }  // namespace
29 
30 std::unique_ptr<TestDependencyFactory> TestDependencyFactory::instance_ =
31     nullptr;
32 
GetInstance()33 const TestDependencyFactory& TestDependencyFactory::GetInstance() {
34   RTC_DCHECK(IsValidTestDependencyFactoryThread());
35   if (instance_ == nullptr) {
36     instance_ = std::make_unique<TestDependencyFactory>();
37   }
38   return *instance_;
39 }
40 
SetInstance(std::unique_ptr<TestDependencyFactory> instance)41 void TestDependencyFactory::SetInstance(
42     std::unique_ptr<TestDependencyFactory> instance) {
43   RTC_DCHECK(IsValidTestDependencyFactoryThread());
44   RTC_CHECK(instance_ == nullptr);
45   instance_ = std::move(instance);
46 }
47 
48 std::unique_ptr<VideoQualityTestFixtureInterface::InjectionComponents>
CreateComponents() const49 TestDependencyFactory::CreateComponents() const {
50   RTC_DCHECK(IsValidTestDependencyFactoryThread());
51   return nullptr;
52 }
53 
54 }  // namespace webrtc
55