Skip to content

Commit

Permalink
Unified BraveVpnServiceDesktop into BraveVpnService
Browse files Browse the repository at this point in the history
No functional changes.
It's preparation for sharing the purchased state managing logic
on Desktop and Android.
  • Loading branch information
simonhong authored and bsclifton committed Feb 15, 2022
1 parent 27a3811 commit 641de45
Show file tree
Hide file tree
Showing 22 changed files with 1,227 additions and 1,282 deletions.
26 changes: 1 addition & 25 deletions browser/brave_vpn/brave_vpn_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,7 @@
#include "content/public/browser/browser_context.h"
#include "content/public/browser/storage_partition.h"

// TODO(bsclifton) or TODO(shong):
// We should be able to consolidate this integration into one implementation
// which we can share between Android and Desktop.
//
// As seen below, Desktop returns BraveVpnServiceDesktop and Android
// returns BraveVpnService.
//
// See https://github.com/brave/brave-browser/issues/20374 for more info.
#if defined(OS_WIN) || defined(OS_MAC)
#include "brave/components/brave_vpn/brave_vpn_service_desktop.h"
#include "brave/components/brave_vpn/brave_vpn_utils.h"
#endif

Expand All @@ -35,24 +26,11 @@ BraveVpnServiceFactory* BraveVpnServiceFactory::GetInstance() {
}

// static
#if defined(OS_WIN) || defined(OS_MAC)
BraveVpnServiceDesktop* BraveVpnServiceFactory::GetForProfile(
Profile* profile) {
return static_cast<BraveVpnServiceDesktop*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
#elif defined(OS_ANDROID)
BraveVpnService* BraveVpnServiceFactory::GetForProfile(Profile* profile) {
return static_cast<BraveVpnService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
#endif

// TODO(bsclifton) or TODO(shong):
// BraveVpnServiceDesktop is currently only used on Desktop,
// which is why there are only OS guards for Windows and macOS.
// Consolidating the Android/Desktop behaviors is captured with:
// https://github.com/brave/brave-browser/issues/20374
BraveVpnServiceFactory::BraveVpnServiceFactory()
: BrowserContextKeyedServiceFactory(
"BraveVpnService",
Expand All @@ -75,15 +53,13 @@ KeyedService* BraveVpnServiceFactory::BuildServiceInstanceFor(
auto shared_url_loader_factory =
default_storage_partition->GetURLLoaderFactoryForBrowserProcess();

// TODO(bsclifton) or TODO(shong):
// see same notes above
#if defined(OS_WIN) || defined(OS_MAC)
auto callback = base::BindRepeating(
[](content::BrowserContext* context) {
return skus::SkusServiceFactory::GetForContext(context);
},
context);
return new BraveVpnServiceDesktop(
return new BraveVpnService(
shared_url_loader_factory, user_prefs::UserPrefs::Get(context), callback);
#elif defined(OS_ANDROID)
return new BraveVpnService(shared_url_loader_factory);
Expand Down
15 changes: 1 addition & 14 deletions browser/brave_vpn/brave_vpn_service_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,12 @@
#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"

class Profile;

#if defined(OS_WIN) || defined(OS_MAC)
class BraveVpnServiceDesktop;
#endif

#if defined(OS_ANDROID)
class BraveVpnService;
#endif
class Profile;

class BraveVpnServiceFactory : public BrowserContextKeyedServiceFactory {
public:
#if defined(OS_WIN) || defined(OS_MAC)
static BraveVpnServiceDesktop* GetForProfile(Profile* profile);
#endif

#if defined(OS_ANDROID)
static BraveVpnService* GetForProfile(Profile* profile);
#endif
static BraveVpnServiceFactory* GetInstance();

BraveVpnServiceFactory(const BraveVpnServiceFactory&) = delete;
Expand Down
2 changes: 1 addition & 1 deletion browser/ui/brave_browser_command_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#if BUILDFLAG(ENABLE_BRAVE_VPN)
#include "brave/browser/brave_vpn/brave_vpn_service_factory.h"
#include "brave/components/brave_vpn/brave_vpn_service_desktop.h"
#include "brave/components/brave_vpn/brave_vpn_service.h"
#include "brave/components/brave_vpn/brave_vpn_utils.h"
#endif

Expand Down
2 changes: 1 addition & 1 deletion browser/ui/brave_browser_command_controller_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#if BUILDFLAG(ENABLE_BRAVE_VPN)
#include "brave/browser/brave_vpn/brave_vpn_service_factory.h"
#include "brave/components/brave_vpn/brave_vpn_service_desktop.h"
#include "brave/components/brave_vpn/brave_vpn_service.h"
#include "brave/components/brave_vpn/features.h"
#endif

Expand Down
2 changes: 1 addition & 1 deletion browser/ui/toolbar/brave_app_menu_model_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#if BUILDFLAG(ENABLE_BRAVE_VPN)
#include "brave/browser/brave_vpn/brave_vpn_service_factory.h"
#include "brave/components/brave_vpn/brave_vpn_service_desktop.h"
#include "brave/components/brave_vpn/brave_vpn_service.h"
#include "brave/components/brave_vpn/features.h"
#endif

Expand Down
2 changes: 1 addition & 1 deletion browser/ui/views/toolbar/brave_vpn_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "brave/app/vector_icons/vector_icons.h"
#include "brave/browser/brave_vpn/brave_vpn_service_factory.h"
#include "brave/browser/themes/theme_properties.h"
#include "brave/components/brave_vpn/brave_vpn_service_desktop.h"
#include "brave/components/brave_vpn/brave_vpn_service.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/browser.h"
Expand Down
4 changes: 2 additions & 2 deletions browser/ui/views/toolbar/brave_vpn_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "chrome/browser/ui/views/toolbar/toolbar_button.h"
#include "ui/base/metadata/metadata_header_macros.h"

class BraveVpnServiceDesktop;
class BraveVpnService;
class Browser;

class BraveVPNButton : public ToolbarButton, public BraveVPNServiceObserver {
Expand All @@ -37,7 +37,7 @@ class BraveVPNButton : public ToolbarButton, public BraveVPNServiceObserver {
void OnButtonPressed(const ui::Event& event);

Browser* browser_ = nullptr;
BraveVpnServiceDesktop* service_ = nullptr;
BraveVpnService* service_ = nullptr;
};

#endif // BRAVE_BROWSER_UI_VIEWS_TOOLBAR_BRAVE_VPN_BUTTON_H_
2 changes: 1 addition & 1 deletion browser/ui/views/toolbar/brave_vpn_status_label.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "brave/browser/brave_vpn/brave_vpn_service_factory.h"
#include "brave/browser/themes/theme_properties.h"
#include "brave/components/brave_vpn/brave_vpn_service_desktop.h"
#include "brave/components/brave_vpn/brave_vpn_service.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
Expand Down
4 changes: 2 additions & 2 deletions browser/ui/views/toolbar/brave_vpn_status_label.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "brave/components/brave_vpn/brave_vpn_service_observer.h"
#include "ui/views/controls/label.h"

class BraveVpnServiceDesktop;
class BraveVpnService;
class Browser;

class BraveVPNStatusLabel : public views::Label,
Expand All @@ -29,7 +29,7 @@ class BraveVPNStatusLabel : public views::Label,
void UpdateState();

Browser* browser_ = nullptr;
BraveVpnServiceDesktop* service_ = nullptr;
BraveVpnService* service_ = nullptr;
};

#endif // BRAVE_BROWSER_UI_VIEWS_TOOLBAR_BRAVE_VPN_STATUS_LABEL_H_
2 changes: 1 addition & 1 deletion browser/ui/views/toolbar/brave_vpn_toggle_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "base/bind.h"
#include "brave/browser/brave_vpn/brave_vpn_service_factory.h"
#include "brave/browser/themes/theme_properties.h"
#include "brave/components/brave_vpn/brave_vpn_service_desktop.h"
#include "brave/components/brave_vpn/brave_vpn_service.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
Expand Down
4 changes: 2 additions & 2 deletions browser/ui/views/toolbar/brave_vpn_toggle_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "brave/components/brave_vpn/brave_vpn_service_observer.h"
#include "ui/views/controls/button/toggle_button.h"

class BraveVpnServiceDesktop;
class BraveVpnService;
class Browser;

class BraveVPNToggleButton : public views::ToggleButton,
Expand All @@ -30,7 +30,7 @@ class BraveVPNToggleButton : public views::ToggleButton,
void UpdateState();

Browser* browser_ = nullptr;
BraveVpnServiceDesktop* service_ = nullptr;
BraveVpnService* service_ = nullptr;
};

#endif // BRAVE_BROWSER_UI_VIEWS_TOOLBAR_BRAVE_VPN_TOGGLE_BUTTON_H_
2 changes: 0 additions & 2 deletions browser/ui/webui/brave_vpn/vpn_panel_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ namespace content {
class WebUI;
} // namespace content

class BraveVpnServiceDesktop;

class VPNPanelHandler : public brave_vpn::mojom::PanelHandler {
public:
using GetWebContentsForTabCallback =
Expand Down
2 changes: 1 addition & 1 deletion browser/ui/webui/brave_vpn/vpn_panel_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void VPNPanelUI::CreatePanelHandler(
panel_handler_ =
std::make_unique<VPNPanelHandler>(std::move(panel_receiver), this);

BraveVpnServiceDesktop* vpn_service_desktop =
BraveVpnService* vpn_service_desktop =
BraveVpnServiceFactory::GetForProfile(profile);
if (vpn_service_desktop) {
vpn_service_desktop->BindInterface(std::move(vpn_service_receiver));
Expand Down
2 changes: 1 addition & 1 deletion browser/ui/webui/brave_vpn/vpn_panel_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "brave/browser/ui/webui/brave_vpn/vpn_panel_handler.h"
#include "brave/components/brave_vpn/brave_vpn.mojom.h"
#include "brave/components/brave_vpn/brave_vpn_service_desktop.h"
#include "brave/components/brave_vpn/brave_vpn_service.h"
#include "content/public/browser/web_ui_message_handler.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
Expand Down
2 changes: 0 additions & 2 deletions components/brave_vpn/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ static_library("brave_vpn") {
"brave_vpn_os_connection_api.h",
"brave_vpn_os_connection_api_sim.cc",
"brave_vpn_os_connection_api_sim.h",
"brave_vpn_service_desktop.cc",
"brave_vpn_service_desktop.h",
"brave_vpn_service_observer.cc",
"brave_vpn_service_observer.h",
"brave_vpn_utils.cc",
Expand Down
Loading

0 comments on commit 641de45

Please sign in to comment.