Skip to content

Commit 6b86b55

Browse files
committed
Moved class/apis that need channel info to chrome layer
1 parent ca8d00f commit 6b86b55

File tree

69 files changed

+619
-612
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+619
-612
lines changed

Diff for: browser/brave_browser_process_impl.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@
9595
#endif
9696

9797
#if BUILDFLAG(ENABLE_BRAVE_VPN)
98+
#include "brave/browser/brave_vpn/vpn_utils.h"
9899
#include "brave/components/brave_vpn/browser/connection/brave_vpn_os_connection_api.h"
100+
#include "brave/components/brave_vpn/common/brave_vpn_utils.h"
99101
#if BUILDFLAG(IS_WIN)
100102
#include "brave/browser/brave_vpn/win/vpn_utils_win.h"
101103
#endif
@@ -520,7 +522,8 @@ BraveBrowserProcessImpl::brave_vpn_os_connection_api() {
520522
brave_vpn_os_connection_api_ = brave_vpn::CreateBraveVPNConnectionAPI(
521523
shared_url_loader_factory(), local_state(), service_installer);
522524
if (brave_vpn_os_connection_api_) {
523-
brave_vpn_os_connection_api_->SetChannel(chrome::GetChannel());
525+
brave_vpn_os_connection_api_->set_target_vpn_entry_name(
526+
brave_vpn::GetBraveVPNEntryName(chrome::GetChannel()));
524527
}
525528
return brave_vpn_os_connection_api_.get();
526529
}

Diff for: browser/brave_vpn/BUILD.gn

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (c) 2023 The Brave Authors. All rights reserved.
2+
# This Source Code Form is subject to the terms of the Mozilla Public
3+
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
# You can obtain one at https://mozilla.org/MPL/2.0/.
5+
6+
import("//brave/components/brave_vpn/common/buildflags/buildflags.gni")
7+
8+
assert(enable_brave_vpn)
9+
10+
source_set("brave_vpn") {
11+
sources = [
12+
"vpn_utils.cc",
13+
"vpn_utils.h",
14+
]
15+
16+
deps = [
17+
"//brave/browser/profiles",
18+
"//brave/components/brave_vpn/browser/connection:api",
19+
"//brave/components/brave_vpn/common",
20+
"//brave/components/brave_vpn/common/buildflags",
21+
"//components/prefs",
22+
"//components/user_prefs",
23+
"//services/network/public/cpp",
24+
]
25+
}

Diff for: browser/brave_vpn/brave_vpn_service_factory.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "chrome/browser/browser_process.h"
2121
#include "chrome/browser/profiles/incognito_helpers.h"
2222
#include "chrome/browser/profiles/profile.h"
23-
#include "chrome/common/channel_info.h"
2423
#include "components/keyed_service/content/browser_context_dependency_manager.h"
2524
#include "components/user_prefs/user_prefs.h"
2625
#include "content/public/browser/browser_context.h"
@@ -29,6 +28,7 @@
2928
#if BUILDFLAG(IS_WIN)
3029
#include "brave/browser/brave_vpn/dns/brave_vpn_dns_observer_factory_win.h"
3130
#include "brave/browser/brave_vpn/dns/brave_vpn_dns_observer_service_win.h"
31+
#include "brave/browser/brave_vpn/win/brave_vpn_service_delegate_win.h"
3232
#include "brave/browser/brave_vpn/win/brave_vpn_wireguard_observer_factory_win.h"
3333
#include "brave/browser/brave_vpn/win/brave_vpn_wireguard_observer_service_win.h"
3434
#endif
@@ -66,7 +66,7 @@ std::unique_ptr<KeyedService> BuildVpnService(
6666
shared_url_loader_factory, local_state,
6767
user_prefs::UserPrefs::Get(context), callback);
6868
#if BUILDFLAG(IS_WIN)
69-
vpn_service->set_channel(chrome::GetChannel());
69+
vpn_service->set_delegate(std::make_unique<BraveVPNServiceDelegateWin>());
7070
if (brave_vpn::IsBraveVPNWireguardEnabled(g_browser_process->local_state())) {
7171
auto* observer_service =
7272
brave_vpn::BraveVpnWireguardObserverFactory::GetInstance()

Diff for: browser/brave_vpn/dns/BUILD.gn

-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@ source_set("unit_tests") {
1717
"//chrome/test:test_support",
1818
"//net",
1919
"//testing/gtest",
20-
"//third_party/abseil-cpp:absl",
2120
]
2221
}

Diff for: browser/brave_vpn/sources.gni

+6-8
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ if (enable_brave_vpn) {
1212
brave_browser_brave_vpn_sources += [
1313
"//brave/browser/brave_vpn/brave_vpn_service_factory.cc",
1414
"//brave/browser/brave_vpn/brave_vpn_service_factory.h",
15-
"//brave/browser/brave_vpn/vpn_utils.cc",
16-
"//brave/browser/brave_vpn/vpn_utils.h",
1715
]
16+
1817
if (is_win) {
1918
brave_browser_brave_vpn_sources += [
2019
"//brave/browser/brave_vpn/dns/brave_vpn_dns_observer_factory_win.cc",
@@ -25,25 +24,24 @@ if (enable_brave_vpn) {
2524
"//brave/browser/brave_vpn/win/brave_vpn_wireguard_observer_factory_win.h",
2625
"//brave/browser/brave_vpn/win/brave_vpn_wireguard_observer_service_win.cc",
2726
"//brave/browser/brave_vpn/win/brave_vpn_wireguard_observer_service_win.h",
28-
"//brave/browser/brave_vpn/win/vpn_utils_win.cc",
29-
"//brave/browser/brave_vpn/win/vpn_utils_win.h",
3027
]
28+
3129
brave_browser_brave_vpn_deps += [
3230
"//brave/app:brave_generated_resources_grit",
3331
"//brave/browser:browser_process",
32+
"//brave/browser/brave_vpn/win",
33+
"//brave/browser/brave_vpn/win:wireguard_utils",
3434
"//brave/browser/brave_vpn/win/brave_vpn_helper:common",
3535
"//brave/components/brave_vpn/common/win",
36-
"//brave/components/brave_vpn/common/wireguard/win",
3736
"//chrome/common:constants",
38-
"//chrome/elevation_service:public_headers",
39-
"//chrome/install_static:install_static_util",
4037
"//components/prefs",
4138
"//net",
42-
"//third_party/abseil-cpp:absl",
4339
]
4440
}
41+
4542
brave_browser_brave_vpn_deps += [
4643
"//base",
44+
"//brave/browser/brave_vpn",
4745
"//brave/components/brave_vpn/browser",
4846
"//chrome/browser/profiles:profile",
4947
"//components/keyed_service/content",

Diff for: browser/brave_vpn/vpn_utils.cc

+37
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,49 @@
66
#include "brave/browser/brave_vpn/vpn_utils.h"
77

88
#include "brave/browser/profiles/profile_util.h"
9+
#include "brave/components/brave_vpn/browser/connection/brave_vpn_os_connection_api.h"
910
#include "brave/components/brave_vpn/common/brave_vpn_utils.h"
11+
#include "brave/components/brave_vpn/common/buildflags/buildflags.h"
1012
#include "build/build_config.h"
13+
#include "components/prefs/pref_service.h"
1114
#include "components/user_prefs/user_prefs.h"
15+
#include "services/network/public/cpp/shared_url_loader_factory.h"
1216

1317
namespace brave_vpn {
1418

19+
// Defined in each platform's connection api.
20+
std::unique_ptr<BraveVPNOSConnectionAPI> CreateBraveVPNIKEv2ConnectionAPI(
21+
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
22+
PrefService* local_prefs,
23+
base::RepeatingCallback<bool()> service_installer);
24+
25+
#if BUILDFLAG(ENABLE_BRAVE_VPN_WIREGUARD)
26+
// Defined in each platform's connection api.
27+
std::unique_ptr<BraveVPNOSConnectionAPI> CreateBraveVPNWireguardConnectionAPI(
28+
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
29+
PrefService* local_prefs,
30+
base::RepeatingCallback<bool()> service_installer);
31+
#endif
32+
33+
std::unique_ptr<BraveVPNOSConnectionAPI> CreateBraveVPNConnectionAPI(
34+
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
35+
PrefService* local_prefs,
36+
base::RepeatingCallback<bool()> service_installer) {
37+
#if BUILDFLAG(ENABLE_BRAVE_VPN_WIREGUARD)
38+
if (IsBraveVPNWireguardEnabled(local_prefs)) {
39+
return CreateBraveVPNWireguardConnectionAPI(url_loader_factory, local_prefs,
40+
service_installer);
41+
}
42+
#endif
43+
#if BUILDFLAG(IS_ANDROID)
44+
// Android doesn't use connection api.
45+
return nullptr;
46+
#else
47+
return CreateBraveVPNIKEv2ConnectionAPI(url_loader_factory, local_prefs,
48+
service_installer);
49+
#endif
50+
}
51+
1552
bool IsAllowedForContext(content::BrowserContext* context) {
1653
return brave::IsRegularProfile(context) &&
1754
brave_vpn::IsBraveVPNFeatureEnabled();

Diff for: browser/brave_vpn/vpn_utils.h

+17
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,31 @@
66
#ifndef BRAVE_BROWSER_BRAVE_VPN_VPN_UTILS_H_
77
#define BRAVE_BROWSER_BRAVE_VPN_VPN_UTILS_H_
88

9+
#include <memory>
10+
11+
#include "base/functional/callback_forward.h"
12+
#include "base/memory/scoped_refptr.h"
13+
914
namespace content {
1015
class BrowserContext;
1116
} // namespace content
1217

18+
namespace network {
19+
class SharedURLLoaderFactory;
20+
} // namespace network
21+
22+
class PrefService;
23+
1324
namespace brave_vpn {
1425

26+
class BraveVPNOSConnectionAPI;
27+
1528
bool IsBraveVPNEnabled(content::BrowserContext* context);
1629
bool IsAllowedForContext(content::BrowserContext* context);
30+
std::unique_ptr<BraveVPNOSConnectionAPI> CreateBraveVPNConnectionAPI(
31+
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
32+
PrefService* local_prefs,
33+
base::RepeatingCallback<bool()> service_installer);
1734

1835
} // namespace brave_vpn
1936

Diff for: browser/brave_vpn/win/BUILD.gn

+55-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,63 @@ assert(enable_brave_vpn && is_win)
1010

1111
source_set("unit_tests") {
1212
testonly = true
13-
sources = [ "brave_vpn_wireguard_observer_service_win_unittest.cc" ]
13+
sources = [
14+
"brave_vpn_wireguard_observer_service_win_unittest.cc",
15+
"storage_utils_unittest.cc",
16+
]
17+
1418
deps = [
19+
":wireguard_utils",
20+
"//base",
1521
"//chrome/test:test_support",
22+
"//components/version_info:channel",
1623
"//testing/gtest",
17-
"//third_party/abseil-cpp:absl",
24+
]
25+
}
26+
27+
source_set("win") {
28+
sources = [
29+
"brave_vpn_service_delegate_win.cc",
30+
"brave_vpn_service_delegate_win.h",
31+
"brave_vpn_wireguard_connection_api_win.cc",
32+
"brave_vpn_wireguard_connection_api_win.h",
33+
"vpn_utils_win.cc",
34+
"vpn_utils_win.h",
35+
]
36+
37+
deps = [
38+
":wireguard_utils",
39+
"//base",
40+
"//brave/components/brave_vpn/browser",
41+
"//brave/components/brave_vpn/browser/connection/wireguard",
42+
"//brave/components/brave_vpn/browser/connection/wireguard/credentials",
43+
"//brave/components/brave_vpn/common/win",
44+
"//chrome/elevation_service:public_headers",
45+
"//chrome/install_static:install_static_util",
46+
"//components/keyed_service/core",
47+
]
48+
}
49+
50+
source_set("wireguard_utils") {
51+
sources = [
52+
"service_commands.cc",
53+
"service_commands.h",
54+
"service_constants.h",
55+
"service_details.cc",
56+
"service_details.h",
57+
"storage_utils.cc",
58+
"storage_utils.h",
59+
"wireguard_utils_win.cc",
60+
"wireguard_utils_win.h",
61+
]
62+
63+
deps = [
64+
"//base",
65+
"//brave/components/brave_vpn/common/buildflags",
66+
"//brave/components/brave_vpn/common/win",
67+
"//brave/components/brave_vpn/common/wireguard",
68+
"//brave/components/brave_vpn/common/wireguard/win:brave_wireguard_manager_idl",
69+
"//chrome/common:channel_info",
70+
"//components/version_info",
1871
]
1972
}

Diff for: browser/brave_vpn/win/brave_vpn_helper/BUILD.gn

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ source_set("common") {
2929
"//brave/components/brave_vpn/common",
3030
"//brave/components/brave_vpn/common/buildflags",
3131
"//brave/components/brave_vpn/common/win",
32-
"//brave/components/brave_vpn/common/wireguard/win:win",
3332
"//chrome/common:channel_info",
3433
"//chrome/install_static:install_static_util",
3534
"//chrome/installer/util:with_no_strings",
@@ -53,8 +52,8 @@ source_set("lib") {
5352
deps = [
5453
":common",
5554
"//base",
55+
"//brave/browser/brave_vpn/win:wireguard_utils",
5656
"//brave/components/brave_vpn/browser/connection/ikev2/win:ras_utils",
57-
"//brave/components/brave_vpn/common/wireguard/win",
5857
"//chrome/common:channel_info",
5958
"//components/version_info:channel",
6059
]

Diff for: browser/brave_vpn/win/brave_vpn_helper/brave_vpn_helper_utils.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ bool IsNetworkFiltersInstalled() {
8080

8181
std::wstring GetBraveVPNConnectionName() {
8282
return base::UTF8ToWide(
83-
brave_vpn::GetBraveVPNEntryName(install_static::GetChromeChannel()));
83+
brave_vpn::GetBraveVPNEntryName(chrome::GetChannel()));
8484
}
8585

8686
std::wstring GetBraveVpnHelperServiceDisplayName() {

Diff for: browser/brave_vpn/win/brave_vpn_helper/vpn_dns_handler.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
#include "base/strings/utf_string_conversions.h"
1212
#include "base/time/time.h"
1313
#include "brave/browser/brave_vpn/win/brave_vpn_helper/brave_vpn_dns_delegate.h"
14-
#include "brave/browser/brave_vpn/win/brave_vpn_helper/vpn_utils.h"
1514
#include "brave/browser/brave_vpn/win/brave_vpn_helper/brave_vpn_helper_constants.h"
1615
#include "brave/browser/brave_vpn/win/brave_vpn_helper/brave_vpn_helper_utils.h"
16+
#include "brave/browser/brave_vpn/win/brave_vpn_helper/vpn_utils.h"
17+
#include "brave/browser/brave_vpn/win/service_commands.h"
18+
#include "brave/browser/brave_vpn/win/service_constants.h"
1719
#include "brave/components/brave_vpn/browser/connection/ikev2/win/ras_utils.h"
18-
#include "brave/components/brave_vpn/common/wireguard/win/service_commands.h"
19-
#include "brave/components/brave_vpn/common/wireguard/win/service_constants.h"
2020

2121
namespace brave_vpn {
2222

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* Copyright (c) 2024 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at https://mozilla.org/MPL/2.0/. */
5+
6+
#include "brave/browser/brave_vpn/win/brave_vpn_service_delegate_win.h"
7+
8+
#include "brave/browser/brave_vpn/win/storage_utils.h"
9+
#include "brave/browser/brave_vpn/win/wireguard_utils_win.h"
10+
11+
namespace brave_vpn {
12+
13+
BraveVPNServiceDelegateWin::BraveVPNServiceDelegateWin() = default;
14+
15+
BraveVPNServiceDelegateWin::~BraveVPNServiceDelegateWin() = default;
16+
17+
void BraveVPNServiceDelegateWin::WriteConnectionState(
18+
mojom::ConnectionState state) {
19+
::brave_vpn::WriteConnectionState(static_cast<int>(state));
20+
}
21+
22+
void BraveVPNServiceDelegateWin::ShowBraveVpnStatusTrayIcon() {
23+
wireguard::ShowBraveVpnStatusTrayIcon();
24+
}
25+
26+
} // namespace brave_vpn
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* Copyright (c) 2024 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at https://mozilla.org/MPL/2.0/. */
5+
6+
#ifndef BRAVE_BROWSER_BRAVE_VPN_WIN_BRAVE_VPN_SERVICE_DELEGATE_WIN_H_
7+
#define BRAVE_BROWSER_BRAVE_VPN_WIN_BRAVE_VPN_SERVICE_DELEGATE_WIN_H_
8+
9+
#include "brave/components/brave_vpn/browser/brave_vpn_service_delegate.h"
10+
11+
namespace brave_vpn {
12+
13+
class BraveVPNServiceDelegateWin : public BraveVPNServiceDelegate {
14+
public:
15+
BraveVPNServiceDelegateWin();
16+
~BraveVPNServiceDelegateWin() override;
17+
18+
BraveVPNServiceDelegateWin(const BraveVPNServiceDelegateWin&) = delete;
19+
BraveVPNServiceDelegateWin& operator=(const BraveVPNServiceDelegateWin&) =
20+
delete;
21+
22+
void WriteConnectionState(mojom::ConnectionState state) override;
23+
void ShowBraveVpnStatusTrayIcon() override;
24+
};
25+
26+
} // namespace brave_vpn
27+
28+
#endif // BRAVE_BROWSER_BRAVE_VPN_WIN_BRAVE_VPN_SERVICE_DELEGATE_WIN_H_

0 commit comments

Comments
 (0)