blob: d343beed0b767056360974e65424dd9e153de2aa [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
11#include <memory>
12#include <utility>
13
tzikf0e926f2018-10-15 13:52:10 +090014#include "absl/memory/memory.h"
Patrik Höglundd8f3c172018-09-26 14:39:17 +020015#include "api/test/test_dependency_factory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010016#include "rtc_base/checks.h"
Patrik Höglundd8f3c172018-09-26 14:39:17 +020017#include "rtc_base/thread_checker.h"
18
19namespace 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.
23rtc::ThreadChecker* GetThreadChecker() {
24 static rtc::ThreadChecker checker;
25 return &checker;
26}
27
28std::unique_ptr<TestDependencyFactory> TestDependencyFactory::instance_ =
29 nullptr;
30
31const TestDependencyFactory& TestDependencyFactory::GetInstance() {
Sebastian Janssonc01367d2019-04-08 15:20:44 +020032 RTC_DCHECK(GetThreadChecker()->IsCurrent());
Patrik Höglundd8f3c172018-09-26 14:39:17 +020033 if (instance_ == nullptr) {
34 instance_ = absl::make_unique<TestDependencyFactory>();
35 }
36 return *instance_;
37}
38
39void TestDependencyFactory::SetInstance(
40 std::unique_ptr<TestDependencyFactory> instance) {
Sebastian Janssonc01367d2019-04-08 15:20:44 +020041 RTC_DCHECK(GetThreadChecker()->IsCurrent());
Patrik Höglundd8f3c172018-09-26 14:39:17 +020042 RTC_CHECK(instance_ == nullptr);
43 instance_ = std::move(instance);
44}
45
46std::unique_ptr<VideoQualityTestFixtureInterface::InjectionComponents>
47TestDependencyFactory::CreateComponents() const {
Sebastian Janssonc01367d2019-04-08 15:20:44 +020048 RTC_DCHECK(GetThreadChecker()->IsCurrent());
Patrik Höglundd8f3c172018-09-26 14:39:17 +020049 return nullptr;
50}
51
52} // namespace webrtc