Skip to content

Commit

Permalink
Moved request otr settings under metrics reporting option
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhong committed Sep 14, 2023
1 parent 087492f commit 5d1e25c
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ RegisterPolymerTemplateModifications({
<settings-brave-personalization-options prefs="{{prefs}}">
</settings-brave-personalization-options>
`)
// Removed because we need to locate metrics reportng option between ours at our settings-brave-personalization-options
metricsReportingControl.remove()
}

// searchSugestToggle is moved to search engines section.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@
sub-label="$i18n{statsUsagePingEnabledDesc}"
on-settings-boolean-control-change="onStatsUsagePingEnabledChange_">
</settings-toggle-button>
<settings-toggle-button id="metricsReportingControl"
class="hr"
pref="[[metricsReportingPref_]]"
label="$i18n{enablePersonalizationLogging}"
sub-label="$i18n{enablePersonalizationLoggingDesc}" no-set-pref
on-settings-boolean-control-change="onMetricsReportingChange_">
<template is="dom-if" if="[[showRestartForMetricsReporting_]]" restamp>
<cr-button on-click="restartBrowser_" id="restart"
slot="more-actions">
$i18n{restart}
</cr-button>
</template>
</settings-toggle-button>
<div hidden="[[!isRequestOTRFeatureEnabled_]]" class="settings-box">
<div class="start" id="labelWrapper">
<div class="label">$i18n{requestOTRLabel}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// You can obtain one at https://mozilla.org/MPL/2.0/.

import {SettingsToggleButtonElement} from '/shared/settings/controls/settings_toggle_button.js';
import {MetricsReporting} from '/shared/settings/privacy_page/privacy_page_browser_proxy.js';
import {WebUiListenerMixin, WebUiListenerMixinInterface} from 'chrome://resources/cr_elements/web_ui_listener_mixin.js';
import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';

Expand All @@ -22,6 +23,7 @@ export interface SettingsBravePersonalizationOptions {
$: {
p3aEnabled: SettingsToggleButtonElement,
statsUsagePingEnabled: SettingsToggleButtonElement,
metricsReportingControl: SettingsToggleButtonElement,
}
}

Expand Down Expand Up @@ -65,6 +67,15 @@ export class SettingsBravePersonalizationOptions extends SettingsBravePersonaliz
return {};
},
},
metricsReportingPref_: {
type: Object,
value() {
// TODO(dbeam): this is basically only to appease PrefControlMixin.
// Maybe add a no-validate attribute instead? This makes little sense.
return {};
},
},
showRestartForMetricsReporting_: Boolean,
isRequestOTRFeatureEnabled_: {
readOnly: true,
type: Boolean,
Expand All @@ -91,6 +102,8 @@ export class SettingsBravePersonalizationOptions extends SettingsBravePersonaliz
private webRTCPolicy_: String;
private p3aEnabledPref_: Object;
private statsUsagePingEnabledPref_: Object;
private metricsReportingPref_: chrome.settingsPrivate.PrefObject<boolean>;
private showRestartForMetricsReporting_: boolean;
private requestOTRActions_: Object[];
private requestOTRAction_: String;

Expand All @@ -107,6 +120,11 @@ export class SettingsBravePersonalizationOptions extends SettingsBravePersonaliz
this.browserProxy_.getP3AEnabled().then(
(enabled: boolean) => setP3AEnabledPref(enabled));

const setMetricsReportingPref = (metricsReporting: MetricsReporting) =>
this.setMetricsReportingPref_(metricsReporting);
this.addWebUiListener('metrics-reporting-change', setMetricsReportingPref);
this.browserProxy_.getMetricsReporting().then(setMetricsReportingPref);

const setStatsUsagePingEnabledPref = (enabled: boolean) => this.setStatsUsagePingEnabledPref_(enabled);
this.addWebUiListener(
'stats-usage-ping-enabled-changed', setStatsUsagePingEnabledPref);
Expand Down Expand Up @@ -140,6 +158,38 @@ export class SettingsBravePersonalizationOptions extends SettingsBravePersonaliz
this.browserProxy_.setStatsUsagePingEnabled(this.$.statsUsagePingEnabled.checked);
}

// Metrics related code is copied from
// chrome/browser/resources/settings/privacy_page/personalization_options.ts as
// we hide that upstream option and put it in our this page.
onMetricsReportingChange_() {
const enabled = this.$.metricsReportingControl.checked;
this.browserProxy_.setMetricsReportingEnabled(enabled);
}

setMetricsReportingPref_(metricsReporting: MetricsReporting) {
const hadPreviousPref = this.metricsReportingPref_.value !== undefined;
const pref: chrome.settingsPrivate.PrefObject<boolean> = {
key: '',
type: chrome.settingsPrivate.PrefType.BOOLEAN,
value: metricsReporting.enabled,
};
if (metricsReporting.managed) {
pref.enforcement = chrome.settingsPrivate.Enforcement.ENFORCED;
pref.controlledBy = chrome.settingsPrivate.ControlledBy.USER_POLICY;
}

// Ignore the next change because it will happen when we set the pref.
this.metricsReportingPref_ = pref;

// TODO(dbeam): remember whether metrics reporting was enabled when Chrome
// started.
if (metricsReporting.managed) {
this.showRestartForMetricsReporting_ = false;
} else if (hadPreviousPref) {
this.showRestartForMetricsReporting_ = true;
}
}

shouldShowRestart_(enabled: boolean) {
return enabled != this.browserProxy_.wasPushMessagingEnabledAtStartup();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// 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/.

import {MetricsReporting} from '/shared/settings/privacy_page/privacy_page_browser_proxy.js';
import {sendWithPromise} from 'chrome://resources/js/cr.js';
import {loadTimeData} from '../i18n_setup.js';

Expand All @@ -12,6 +13,8 @@ export interface BravePrivacyBrowserProxy {
getStatsUsagePingEnabled(): Promise<boolean>
setStatsUsagePingEnabled(value: boolean): void
wasPushMessagingEnabledAtStartup(): boolean
setMetricsReportingEnabled(enabled: boolean): void
getMetricsReporting(): Promise<MetricsReporting>;
}

export class BravePrivacyBrowserProxyImpl implements BravePrivacyBrowserProxy {
Expand All @@ -35,6 +38,14 @@ export class BravePrivacyBrowserProxyImpl implements BravePrivacyBrowserProxy {
return loadTimeData.getBoolean('pushMessagingEnabledAtStartup');
}

setMetricsReportingEnabled(enabled: boolean) {
chrome.send('setMetricsReportingEnabled', [enabled]);
}

getMetricsReporting() {
return sendWithPromise('getMetricsReporting');
}

static getInstance(): BravePrivacyBrowserProxyImpl {
return instance || (instance = new BravePrivacyBrowserProxyImpl())
}
Expand Down

0 comments on commit 5d1e25c

Please sign in to comment.