Skip to content

Commit

Permalink
Merge pull request #16854 from brave/brave_vpn_entry_name
Browse files Browse the repository at this point in the history
Set channel specific vpn entry name
  • Loading branch information
simonhong authored Jan 26, 2023
2 parents e6eaf9a + 5a013f0 commit 885d512
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 27 deletions.
3 changes: 2 additions & 1 deletion browser/brave_browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/obsolete_system/obsolete_system.h"
#include "chrome/common/buildflags.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
#include "components/component_updater/component_updater_service.h"
Expand Down Expand Up @@ -431,7 +432,7 @@ BraveBrowserProcessImpl::brave_vpn_os_connection_api() {
return brave_vpn_os_connection_api_.get();

brave_vpn_os_connection_api_ = brave_vpn::CreateBraveVPNOSConnectionAPI(
shared_url_loader_factory(), local_state());
shared_url_loader_factory(), local_state(), chrome::GetChannel());
return brave_vpn_os_connection_api_.get();
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions components/brave_vpn/browser/brave_vpn_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ BraveVpnService::BraveVpnService(
connection_api_ = connection_api;
observed_.Observe(GetBraveVPNConnectionAPI());

GetBraveVPNConnectionAPI()->SetTargetVpnEntryName(kBraveVPNEntryName);

pref_change_registrar_.Init(local_prefs_);
pref_change_registrar_.Add(
prefs::kBraveVPNSelectedRegion,
Expand Down
1 change: 1 addition & 0 deletions components/brave_vpn/browser/connection/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ source_set("sim") {
":common",
"//base",
"//brave/components/brave_vpn/common",
"//components/version_info:channel",
"//third_party/icu",
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ namespace brave_vpn {
// android.
std::unique_ptr<BraveVPNOSConnectionAPI> CreateBraveVPNOSConnectionAPI(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
PrefService* local_prefs) {
PrefService* local_prefs,
version_info::Channel channel) {
return nullptr;
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ namespace network {
class SharedURLLoaderFactory;
} // namespace network

namespace version_info {
enum class Channel;
} // namespace version_info

class PrefService;

namespace brave_vpn {
Expand All @@ -33,7 +37,6 @@ class BraveVPNOSConnectionAPI {
~Observer() override = default;
};

virtual void SetTargetVpnEntryName(const std::string& name) = 0;
virtual mojom::ConnectionState GetConnectionState() const = 0;
virtual void RemoveVPNConnection() = 0;
virtual void Connect() = 0;
Expand All @@ -58,7 +61,8 @@ class BraveVPNOSConnectionAPI {
// Only BraveBrowserProcess need to use this method.
std::unique_ptr<BraveVPNOSConnectionAPI> CreateBraveVPNOSConnectionAPI(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
PrefService* local_prefs);
PrefService* local_prefs,
version_info::Channel channel);

} // namespace brave_vpn

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ using ConnectionState = mojom::ConnectionState;

BraveVPNOSConnectionAPIBase::BraveVPNOSConnectionAPIBase(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
PrefService* local_prefs)
: local_prefs_(local_prefs), url_loader_factory_(url_loader_factory) {
PrefService* local_prefs,
version_info::Channel channel)
: target_vpn_entry_name_(GetBraveVPNEntryName(channel)),
local_prefs_(local_prefs),
url_loader_factory_(url_loader_factory) {
DCHECK(url_loader_factory && local_prefs);
net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
}
Expand Down Expand Up @@ -444,11 +447,6 @@ void BraveVPNOSConnectionAPIBase::OnGetProfileCredentials(
UpdateAndNotifyConnectionStateChange(ConnectionState::CONNECT_FAILED);
}

void BraveVPNOSConnectionAPIBase::SetTargetVpnEntryName(
const std::string& name) {
target_vpn_entry_name_ = name;
}

const BraveVPNConnectionInfo& BraveVPNOSConnectionAPIBase::connection_info()
const {
return connection_info_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class BraveVPNOSConnectionAPIBase
bool IsInProgress() const;

// BraveVPNOSConnectionAPI
void SetTargetVpnEntryName(const std::string& name) override;
mojom::ConnectionState GetConnectionState() const override;
void Connect() override;
void Disconnect() override;
Expand All @@ -58,7 +57,8 @@ class BraveVPNOSConnectionAPIBase
protected:
BraveVPNOSConnectionAPIBase(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
PrefService* local_prefs);
PrefService* local_prefs,
version_info::Channel channel);
~BraveVPNOSConnectionAPIBase() override;

// Subclass should add platform dependent impls.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "brave/components/brave_vpn/browser/connection/brave_vpn_os_connection_api.h"
#include "components/version_info/channel.h"

namespace brave_vpn {

BraveVPNOSConnectionAPISim::BraveVPNOSConnectionAPISim(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
PrefService* local_prefs)
: BraveVPNOSConnectionAPIBase(url_loader_factory, local_prefs) {}
: BraveVPNOSConnectionAPIBase(url_loader_factory,
local_prefs,
version_info::Channel::DEFAULT) {}

BraveVPNOSConnectionAPISim::~BraveVPNOSConnectionAPISim() = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class BraveVPNOSConnectionAPIMac : public BraveVPNOSConnectionAPIBase {
public:
BraveVPNOSConnectionAPIMac(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
PrefService* local_prefs);
PrefService* local_prefs,
version_info::Channel channel);
BraveVPNOSConnectionAPIMac(const BraveVPNOSConnectionAPIMac&) = delete;
BraveVPNOSConnectionAPIMac& operator=(const BraveVPNOSConnectionAPIMac&) =
delete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,17 @@ OSStatus StorePassword(const NSString* password, std::string* error_str) {

std::unique_ptr<BraveVPNOSConnectionAPI> CreateBraveVPNOSConnectionAPI(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
PrefService* local_prefs) {
PrefService* local_prefs,
version_info::Channel channel) {
return std::make_unique<BraveVPNOSConnectionAPIMac>(url_loader_factory,
local_prefs);
local_prefs, channel);
}

BraveVPNOSConnectionAPIMac::BraveVPNOSConnectionAPIMac(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
PrefService* local_prefs)
: BraveVPNOSConnectionAPIBase(url_loader_factory, local_prefs) {
PrefService* local_prefs,
version_info::Channel channel)
: BraveVPNOSConnectionAPIBase(url_loader_factory, local_prefs, channel) {
ObserveVPNConnectionChange();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ RasOperationResult DisconnectEntry(const std::wstring& name) {

std::unique_ptr<BraveVPNOSConnectionAPI> CreateBraveVPNOSConnectionAPI(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
PrefService* local_prefs) {
PrefService* local_prefs,
version_info::Channel channel) {
return std::make_unique<BraveVPNOSConnectionAPIWin>(url_loader_factory,
local_prefs);
local_prefs, channel);
}

BraveVPNOSConnectionAPIWin::BraveVPNOSConnectionAPIWin(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
PrefService* local_prefs)
: BraveVPNOSConnectionAPIBase(url_loader_factory, local_prefs) {
PrefService* local_prefs,
version_info::Channel channel)
: BraveVPNOSConnectionAPIBase(url_loader_factory, local_prefs, channel) {
StartVPNConnectionChangeMonitoring();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class BraveVPNOSConnectionAPIWin : public BraveVPNOSConnectionAPIBase,
public:
BraveVPNOSConnectionAPIWin(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
PrefService* local_prefs);
PrefService* local_prefs,
version_info::Channel channel);
BraveVPNOSConnectionAPIWin(const BraveVPNOSConnectionAPIWin&) = delete;
BraveVPNOSConnectionAPIWin& operator=(const BraveVPNOSConnectionAPIWin&) =
delete;
Expand Down
1 change: 1 addition & 0 deletions components/brave_vpn/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ source_set("common") {
"//build:buildflag_header_h",
"//components/pref_registry",
"//components/prefs",
"//components/version_info",
"//net",
]
}
Expand Down
1 change: 0 additions & 1 deletion components/brave_vpn/common/brave_vpn_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ constexpr char kManageUrlDev[] = "https://account.brave.software/account/";
constexpr char kFeedbackUrl[] = "https://support.brave.com/";
constexpr char kAboutUrl[] = "https://brave.com/firewall-vpn/";

constexpr char kBraveVPNEntryName[] = "BraveVPN";
constexpr char kRegionContinentKey[] = "continent";
constexpr char kRegionNameKey[] = "name";
constexpr char kRegionNamePrettyKey[] = "name-pretty";
Expand Down
19 changes: 19 additions & 0 deletions components/brave_vpn/common/brave_vpn_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/version_info/channel.h"

namespace brave_vpn {

Expand Down Expand Up @@ -84,6 +85,24 @@ bool IsBraveVPNEnabled() {
base::FeatureList::IsEnabled(skus::features::kSkusFeature);
}

std::string GetBraveVPNEntryName(version_info::Channel channel) {
constexpr char kBraveVPNEntryName[] = "BraveVPN";

const std::string entry_name(kBraveVPNEntryName);
switch (channel) {
case version_info::Channel::CANARY:
return entry_name + "-Nightly";
case version_info::Channel::DEV:
return entry_name + "-Dev";
case version_info::Channel::BETA:
return entry_name + "-Beta";
case version_info::Channel::STABLE:
return entry_name;
default:
return entry_name;
}
}

std::string GetManageUrl(const std::string& env) {
if (env == skus::kEnvProduction)
return brave_vpn::kManageUrlProd;
Expand Down
5 changes: 5 additions & 0 deletions components/brave_vpn/common/brave_vpn_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ namespace user_prefs {
class PrefRegistrySyncable;
} // namespace user_prefs

namespace version_info {
enum class Channel;
} // namespace version_info

namespace brave_vpn {

std::string GetBraveVPNEntryName(version_info::Channel channel);
bool IsBraveVPNEnabled();
std::string GetBraveVPNPaymentsEnv(const std::string& env);
std::string GetManageUrl(const std::string& env);
Expand Down

0 comments on commit 885d512

Please sign in to comment.