blob: daae0362663d0e0d9d8f0af61abcbc8c363af196 [file] [log] [blame]
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/global_features.h"
#include "base/check_is_test.h"
#include "base/memory/ptr_util.h"
#include "base/no_destructor.h"
namespace {
// This is the generic entry point for test code to stub out browser
// functionality. It is called by production code, but only used by tests.
GlobalFeatures::GlobalFeaturesFactory& GetFactory() {
static base::NoDestructor<GlobalFeatures::GlobalFeaturesFactory> factory;
return *factory;
}
} // namespace
// static
std::unique_ptr<GlobalFeatures> GlobalFeatures::CreateGlobalFeatures() {
if (GetFactory()) {
CHECK_IS_TEST();
return GetFactory().Run();
}
// Constructor is protected.
return base::WrapUnique(new GlobalFeatures());
}
GlobalFeatures::~GlobalFeatures() = default;
// static
void GlobalFeatures::ReplaceGlobalFeaturesForTesting(
GlobalFeaturesFactory factory) {
GlobalFeatures::GlobalFeaturesFactory& f = GetFactory();
f = std::move(factory);
}
void GlobalFeatures::Init() {}
GlobalFeatures::GlobalFeatures() = default;