blob: 41ad70cc3f725623182ee589ce4ec2a379971f8d [file] [log] [blame]
Patrik Höglundd8f3c172018-09-26 14:39:17 +02001/*
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 Olssona4d87372019-07-05 19:08:33 +020011#include "api/test/test_dependency_factory.h"
12
Patrik Höglundd8f3c172018-09-26 14:39:17 +020013#include <memory>
14#include <utility>
15
Yves Gerey3e707812018-11-28 16:47:49 +010016#include "rtc_base/checks.h"
Tommi9b7232a2020-05-15 10:09:27 +020017#include "rtc_base/platform_thread_types.h"
Patrik Höglundd8f3c172018-09-26 14:39:17 +020018
19namespace webrtc {
20
Tommi9b7232a2020-05-15 10:09:27 +020021namespace {
Patrik Höglundd8f3c172018-09-26 14:39:17 +020022// 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.
Tommi9b7232a2020-05-15 10:09:27 +020024bool IsValidTestDependencyFactoryThread() {
25 const rtc::PlatformThreadRef main_thread = rtc::CurrentThreadRef();
26 return rtc::IsThreadRefEqual(main_thread, rtc::CurrentThreadRef());
Patrik Höglundd8f3c172018-09-26 14:39:17 +020027}
Tommi9b7232a2020-05-15 10:09:27 +020028} // namespace
Patrik Höglundd8f3c172018-09-26 14:39:17 +020029
30std::unique_ptr<TestDependencyFactory> TestDependencyFactory::instance_ =
31 nullptr;
32
33const TestDependencyFactory& TestDependencyFactory::GetInstance() {
Tommi9b7232a2020-05-15 10:09:27 +020034 RTC_DCHECK(IsValidTestDependencyFactoryThread());
Patrik Höglundd8f3c172018-09-26 14:39:17 +020035 if (instance_ == nullptr) {
Mirko Bonadei317a1f02019-09-17 17:06:18 +020036 instance_ = std::make_unique<TestDependencyFactory>();
Patrik Höglundd8f3c172018-09-26 14:39:17 +020037 }
38 return *instance_;
39}
40
41void TestDependencyFactory::SetInstance(
42 std::unique_ptr<TestDependencyFactory> instance) {
Tommi9b7232a2020-05-15 10:09:27 +020043 RTC_DCHECK(IsValidTestDependencyFactoryThread());
Patrik Höglundd8f3c172018-09-26 14:39:17 +020044 RTC_CHECK(instance_ == nullptr);
45 instance_ = std::move(instance);
46}
47
48std::unique_ptr<VideoQualityTestFixtureInterface::InjectionComponents>
49TestDependencyFactory::CreateComponents() const {
Tommi9b7232a2020-05-15 10:09:27 +020050 RTC_DCHECK(IsValidTestDependencyFactoryThread());
Patrik Höglundd8f3c172018-09-26 14:39:17 +020051 return nullptr;
52}
53
54} // namespace webrtc