Files
brave-core/test/base/testing_brave_browser_process.cc
Alex 429c51348f [VPN 2.0] Add GN buildflags for VPN Architectures 1.0 and 2.0 (#36787)
To add a new BraveVpnService implementation based on Architecture 2.0,
which must co-exist with Architecture 1.0 for quite a while, we need
to split service's interface and implementation. All the external
components will keep accessing VPN service via the BraveVpnService
interface, but the implementation mostly goes into BraveVpnServiceImpl.

This change revisits the approach how Brave VPN is enabled in GN.
New flags are introduced: enable_brave_vpn_v1 and enable_brave_vpn_v2.
Currently, only V1 architecture is implemented, hence, the GN flag
enable_brave_vpn_v1 is enabled by default, and enable_brave_vpn_v2
is disabled by default. enable_brave_vpn becomes a dependent flag:
it is enabled when either enable_brave_vpn_v1, or enable_brave_vpn_v2,
or both are enabled.

Implements part of https://github.com/brave/brave-browser/issues/54597
2026-05-28 21:56:45 +01:00

187 lines
5.6 KiB
C++

/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */
#include "brave/test/base/testing_brave_browser_process.h"
#include <utility>
#include "base/check.h"
#include "base/files/file_path.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/scoped_refptr.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "brave/components/brave_origin/brave_origin_policy_manager.h"
#include "brave/components/brave_shields/content/browser/ad_block_service.h"
#include "brave/components/brave_vpn/common/buildflags/buildflags.h"
#include "brave/components/tor/buildflags/buildflags.h"
#if BUILDFLAG(ENABLE_BRAVE_VPN_V1)
#include "brave/components/brave_vpn/browser/connection/brave_vpn_connection_manager.h"
#endif
namespace tor {
class BraveTorClientUpdater;
}
// static
TestingBraveBrowserProcess* TestingBraveBrowserProcess::GetGlobal() {
return static_cast<TestingBraveBrowserProcess*>(g_brave_browser_process);
}
// static
void TestingBraveBrowserProcess::CreateInstance() {
DCHECK(!g_brave_browser_process);
TestingBraveBrowserProcess* process = new TestingBraveBrowserProcess;
g_brave_browser_process = process;
}
// static
void TestingBraveBrowserProcess::DeleteInstance() {
BraveBrowserProcess* browser_process = g_brave_browser_process;
g_brave_browser_process = nullptr;
delete browser_process;
}
// static
void TestingBraveBrowserProcess::StartTearDown() {
// Reset BraveOriginPolicyManager to prevent dangling pointer to local_state_.
brave_origin::BraveOriginPolicyManager::GetInstance()->Shutdown();
}
// static
void TestingBraveBrowserProcess::TearDownAndDeleteInstance() {
TestingBraveBrowserProcess::StartTearDown();
TestingBraveBrowserProcess::DeleteInstance();
}
TestingBraveBrowserProcess::TestingBraveBrowserProcess() = default;
TestingBraveBrowserProcess::~TestingBraveBrowserProcess() = default;
void TestingBraveBrowserProcess::StartBraveServices() {}
brave_shields::AdBlockService* TestingBraveBrowserProcess::ad_block_service() {
if (!ad_block_service_) {
scoped_refptr<base::SequencedTaskRunner> task_runner(
base::ThreadPool::CreateSequencedTaskRunner(
{base::MayBlock(), base::TaskPriority::USER_BLOCKING,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}));
ad_block_service_ = std::make_unique<brave_shields::AdBlockService>(
/*local_state*/ nullptr, /*locale*/ "en", /*component_updater*/ nullptr,
task_runner,
/*subscription_download_manager_getter*/ base::DoNothing(),
/*profile_dir*/ base::FilePath(FILE_PATH_LITERAL("")));
}
return ad_block_service_.get();
}
debounce::DebounceComponentInstaller*
TestingBraveBrowserProcess::debounce_component_installer() {
return nullptr;
}
#if BUILDFLAG(ENABLE_REQUEST_OTR)
request_otr::RequestOTRComponentInstallerPolicy*
TestingBraveBrowserProcess::request_otr_component_installer() {
return nullptr;
}
#endif
brave::URLSanitizerComponentInstaller*
TestingBraveBrowserProcess::URLSanitizerComponentInstaller() {
return nullptr;
}
https_upgrade_exceptions::HttpsUpgradeExceptionsService*
TestingBraveBrowserProcess::https_upgrade_exceptions_service() {
return nullptr;
}
brave_component_updater::LocalDataFilesService*
TestingBraveBrowserProcess::local_data_files_service() {
return nullptr;
}
#if BUILDFLAG(ENABLE_TOR)
tor::BraveTorClientUpdater* TestingBraveBrowserProcess::tor_client_updater() {
return nullptr;
}
tor::BraveTorPluggableTransportUpdater*
TestingBraveBrowserProcess::tor_pluggable_transport_updater() {
return nullptr;
}
#endif
p3a::P3AService* TestingBraveBrowserProcess::p3a_service() {
return nullptr;
}
brave::BraveReferralsService*
TestingBraveBrowserProcess::brave_referrals_service() {
return nullptr;
}
#if BUILDFLAG(ENABLE_BRAVE_STATS_UPDATER)
brave_stats::BraveStatsUpdater*
TestingBraveBrowserProcess::brave_stats_updater() {
return nullptr;
}
#endif // BUILDFLAG(ENABLE_BRAVE_STATS_UPDATER)
#if BUILDFLAG(ENABLE_BRAVE_ADS)
brave_ads::BraveStatsHelper*
TestingBraveBrowserProcess::ads_brave_stats_helper() {
return nullptr;
}
brave_ads::ResourceComponent* TestingBraveBrowserProcess::resource_component() {
return nullptr;
}
#endif // BUILDFLAG(ENABLE_BRAVE_ADS)
ntp_background_images::NTPBackgroundImagesService*
TestingBraveBrowserProcess::ntp_background_images_service() {
return nullptr;
}
#if BUILDFLAG(ENABLE_SPEEDREADER)
speedreader::SpeedreaderRewriterService*
TestingBraveBrowserProcess::speedreader_rewriter_service() {
return nullptr;
}
#endif
#if BUILDFLAG(ENABLE_BRAVE_VPN_V1)
brave_vpn::BraveVPNConnectionManager*
TestingBraveBrowserProcess::brave_vpn_connection_manager() {
return brave_vpn_connection_manager_.get();
}
void TestingBraveBrowserProcess::SetBraveVPNConnectionManagerForTesting(
std::unique_ptr<brave_vpn::BraveVPNConnectionManager> manager) {
brave_vpn_connection_manager_ = std::move(manager);
}
#endif
misc_metrics::ProcessMiscMetrics*
TestingBraveBrowserProcess::process_misc_metrics() {
return nullptr;
}
void TestingBraveBrowserProcess::SetAdBlockService(
std::unique_ptr<brave_shields::AdBlockService> service) {
ad_block_service_ = std::move(service);
}
///////////////////////////////////////////////////////////////////////////////
TestingBraveBrowserProcessInitializer::TestingBraveBrowserProcessInitializer() {
TestingBraveBrowserProcess::CreateInstance();
}
TestingBraveBrowserProcessInitializer::
~TestingBraveBrowserProcessInitializer() {
TestingBraveBrowserProcess::DeleteInstance();
}