Skip to content

Commit 4d78df7

Browse files
committed
Part 2 - Update Callers
1 parent 2992757 commit 4d78df7

50 files changed

Lines changed: 509 additions & 745 deletions

Some content is hidden

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

src/addons/addon.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
#include "conditionwatchers/addonconditionwatchertranslationthreshold.h"
2525
#include "conditionwatchers/addonconditionwatchertriggertimesecs.h"
2626
#include "env.h"
27-
#include "feature/feature.h"
27+
#include "feature/featuremodel.h"
28+
#include "feature/features.h"
2829
#include "leakdetector.h"
2930
#include "localizer.h"
3031
#include "logger.h"
@@ -59,8 +60,7 @@ QList<ConditionCallback> s_conditionCallbacks{
5960
for (const QJsonValue& enabledFeature : enabledFeatures) {
6061
QString featureName = enabledFeature.toString();
6162

62-
const Feature* feature = Feature::getOrNull(featureName);
63-
if (!feature) {
63+
if (!FeatureModel::instance()->get(featureName)) {
6464
logger.info() << "Feature not found" << featureName;
6565
return false;
6666
}
@@ -369,7 +369,7 @@ Addon* Addon::create(QObject* parent, const QString& manifestFileName) {
369369
}
370370

371371
else if (type == "replacer") {
372-
if (!Feature::get(Feature::Feature_replacerAddon)->isSupported()) {
372+
if (!Feature::isEnabled(Feature::replacerAddon)) {
373373
// This addon type is blocked pending
374374
// https://mozilla-hub.atlassian.net/browse/VPN-4858
375375
logger.error() << "The replacer type addon is unsupported.";
@@ -461,7 +461,12 @@ Addon::Addon(QObject* parent, const QString& manifestFileName,
461461
}
462462
}
463463

464-
Addon::~Addon() { MZ_COUNT_DTOR(Addon); }
464+
Addon::~Addon() {
465+
MZ_COUNT_DTOR(Addon);
466+
if (!m_translators.isEmpty()) {
467+
unloadTranslators();
468+
}
469+
}
465470

466471
void Addon::updateAddonStatus(Status newStatus) {
467472
Q_ASSERT(newStatus != Unknown);

src/addons/addonreplacer.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ AddonReplacer::AddonReplacer(QObject* parent, const QString& manifestFileName,
114114
MZ_COUNT_CTOR(AddonReplacer);
115115
}
116116

117-
AddonReplacer::~AddonReplacer() { MZ_COUNT_DTOR(AddonReplacer); }
117+
AddonReplacer::~AddonReplacer() {
118+
MZ_COUNT_DTOR(AddonReplacer);
119+
if (enabled()) {
120+
AddonReplacer::disable();
121+
}
122+
}
118123

119124
void AddonReplacer::enable() {
120125
Addon::enable();

src/addons/conditionwatchers/addonconditionwatcherfeaturesenabled.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
#include "addonconditionwatcherfeaturesenabled.h"
66

7-
#include "feature/feature.h"
7+
#include "feature/featuremodel.h"
8+
#include "feature/featureproxy.h"
89
#include "leakdetector.h"
910

1011
// static
@@ -15,8 +16,7 @@ AddonConditionWatcher* AddonConditionWatcherFeaturesEnabled::maybeCreate(
1516
}
1617

1718
for (const QString& featureName : features) {
18-
const Feature* feature = Feature::getOrNull(featureName);
19-
if (!feature) {
19+
if (!FeatureModel::instance()->get(featureName)) {
2020
return nullptr;
2121
}
2222
}
@@ -32,10 +32,11 @@ AddonConditionWatcherFeaturesEnabled::AddonConditionWatcherFeaturesEnabled(
3232
m_currentStatus = conditionApplied();
3333

3434
for (const QString& featureName : m_features) {
35-
const Feature* feature = Feature::get(featureName);
36-
Q_ASSERT(feature);
35+
auto* proxy =
36+
qobject_cast<FeatureProxy*>(FeatureModel::instance()->get(featureName));
37+
Q_ASSERT(proxy);
3738

38-
connect(feature, &Feature::supportedChanged, this, [this]() {
39+
connect(proxy, &FeatureProxy::supportedChanged, this, [this]() {
3940
bool newStatus = conditionApplied();
4041
if (m_currentStatus != newStatus) {
4142
m_currentStatus = newStatus;
@@ -51,11 +52,7 @@ AddonConditionWatcherFeaturesEnabled::~AddonConditionWatcherFeaturesEnabled() {
5152

5253
bool AddonConditionWatcherFeaturesEnabled::conditionApplied() const {
5354
for (const QString& featureName : m_features) {
54-
// If the feature doesn't exist, we crash.
55-
const Feature* feature = Feature::get(featureName);
56-
Q_ASSERT(feature);
57-
58-
if (!feature->isSupported()) {
55+
if (!FeatureModel::instance()->isEnabledById(featureName)) {
5956
return false;
6057
}
6158
}

src/addons/manager/addonmanager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "addonindex.h"
2121
#include "addons/addonmessage.h"
2222
#include "constants.h"
23-
#include "feature/feature.h"
23+
#include "feature/features.h"
2424
#include "leakdetector.h"
2525
#include "logger.h"
2626
#include "qmlengineholder.h"
@@ -474,7 +474,7 @@ bool AddonManager::signatureVerificationNeeded() {
474474
return false;
475475
}
476476

477-
return Feature::get(Feature::Feature_addonSignature)->isSupported();
477+
return Feature::isEnabled(Feature::addonSignature);
478478
}
479479

480480
void AddonManager::loadCompleted() {

src/authenticationinapp/authenticationinappsession.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "authenticationinapp.h"
1414
#include "authenticationlistener.h"
1515
#include "constants.h"
16-
#include "feature/feature.h"
16+
#include "feature/features.h"
1717
#include "hawkauth.h"
1818
#include "hkdf.h"
1919
#include "leakdetector.h"
@@ -222,7 +222,7 @@ void AuthenticationInAppSession::accountChecked(bool exists, bool hasPassword,
222222
return;
223223
}
224224

225-
if (Feature::get(Feature::Feature_inAppAccountCreate)->isSupported()) {
225+
if (Feature::isEnabled(Feature::inAppAccountCreate)) {
226226
AuthenticationInApp::instance()->requestState(
227227
AuthenticationInApp::StateSignUp, this);
228228
return;

src/commands/commandexcludeip.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
#include "commandexcludeip.h"
66

7+
#include <QCoreApplication>
78
#include <QHostAddress>
89
#include <QTextStream>
910

1011
#include "commandlineparser.h"
1112
#include "constants.h"
1213
#include "ipaddress.h"
1314
#include "leakdetector.h"
15+
#include "loghandler.h"
1416
#include "mozillavpn.h"
1517
#include "settingsholder.h"
1618

src/controller.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "controller_p.h"
1313
#include "controllerimpl.h"
1414
#include "dnshelper.h"
15-
#include "feature/feature.h"
15+
#include "feature/features.h"
1616
#include "frontend/navigator.h"
1717
#include "ipaddress.h"
1818
#include "leakdetector.h"
@@ -408,16 +408,15 @@ void Controller::activateInternal(
408408
logger.debug() << "DNS Set" << exitConfig.m_dnsServer;
409409

410410
// Splittunnel-feature could have been disabled due to a driver conflict.
411-
if (Feature::get(Feature::Feature_splitTunnel)->isSupported()) {
411+
if (Feature::isEnabled(Feature::splitTunnel)) {
412412
exitConfig.m_vpnDisabledApps = settingsHolder->vpnDisabledApps();
413413
}
414-
if (Feature::get(Feature::Feature_alwaysPort53)->isSupported()) {
414+
if (Feature::isEnabled(Feature::alwaysPort53)) {
415415
dnsPort = ForceDNSPort;
416416
}
417417

418418
// For single-hop connections, exclude the entry server
419-
if (!Feature::get(Feature::Feature_multiHop)->isSupported() ||
420-
!m_serverData.multihop()) {
419+
if (!Feature::multiHop.supported || !m_serverData.multihop()) {
421420
logger.info() << "Activating single hop";
422421
exitConfig.m_hopType = InterfaceConfig::SingleHop;
423422

@@ -943,8 +942,7 @@ bool Controller::activate(const ServerData& serverData,
943942
return true;
944943
}
945944

946-
if (Feature::get(Feature::Feature_checkConnectivityOnActivation)
947-
->isSupported()) {
945+
if (Feature::isEnabled(Feature::checkConnectivityOnActivation)) {
948946
// Ensure that the device is connected to the Internet.
949947
if (MozillaVPN::instance()->networkWatcher()->getReachability() ==
950948
QNetworkInformation::Reachability::Disconnected) {

src/dnshelper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <QHostAddress>
88

9-
#include "feature/feature.h"
9+
#include "feature/features.h"
1010
#include "logger.h"
1111
#include "settingsholder.h"
1212

@@ -37,7 +37,7 @@ QString DNSHelper::getDNSType() {
3737

3838
// static
3939
dnsData DNSHelper::getDNSDetails(const QString& fallback) {
40-
if (!Feature::get(Feature::Feature_customDNS)->isSupported()) {
40+
if (!Feature::customDNS.supported) {
4141
return dnsData{fallback, "NoCustomDNSAvailable"};
4242
}
4343

src/feature/featuremodel.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ FeatureModel* FeatureModel::instance() {
3030
return s_instance;
3131
}
3232

33+
#ifdef UNIT_TEST
34+
void FeatureModel::testCleanup() {
35+
delete s_instance;
36+
s_instance = nullptr;
37+
}
38+
#endif
39+
3340
void FeatureModel::initialize() {
3441
if (m_initialized) return;
3542
m_initialized = true;
@@ -117,7 +124,7 @@ void FeatureModel::toggle(const QString& featureId) {
117124

118125
// static
119126
QHash<QString, bool> FeatureModel::parseFeatures(const QByteArray& data,
120-
bool acceptExperiments) {
127+
bool acceptExperiments) {
121128
QHash<QString, bool> overrides;
122129
QJsonObject json = QJsonDocument::fromJson(data).object();
123130

src/feature/featuremodel.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ inline const AnyFeature s_exposedFeatures[] = {
2222
ref(addonSignature),
2323
ref(alwaysPort53),
2424
ref(annualUpgrade),
25+
ref(appReview),
2526
ref(captivePortal),
2627
ref(checkConnectivityOnActivation),
2728
ref(customDNS),
@@ -67,14 +68,18 @@ class FeatureModel final : public QAbstractListModel {
6768

6869
bool isEnabledById(const QString& id) const;
6970

71+
#ifdef UNIT_TEST
72+
static void testCleanup();
73+
#endif
74+
7075
private:
7176
FeatureModel();
7277
void initialize();
7378

7479
FeatureProxy* proxyForId(const QString& id);
7580

7681
static QHash<QString, bool> parseFeatures(const QByteArray& data,
77-
bool acceptExperiments);
82+
bool acceptExperiments);
7883

7984
bool m_initialized = false;
8085
std::array<FeatureProxy, std::size(s_exposedFeatures)> m_proxies;

0 commit comments

Comments
 (0)