blob: c6ffda162563790265c37d256f2a7217e77cb24b [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview
* 'personalization-options' contains several toggles related to
* personalizations.
*/
(function() {
Polymer({
is: 'settings-personalization-options',
behaviors: [
WebUIListenerBehavior,
],
properties: {
prefs: {
type: Object,
notify: true,
},
/**
* Dictionary defining page visibility.
* @type {!PrivacyPageVisibility}
*/
pageVisibility: Object,
unifiedConsentEnabled: Boolean,
/** @type {settings.SyncStatus} */
syncStatus: Object,
// <if expr="_google_chrome and not chromeos">
// TODO(dbeam): make a virtual.* pref namespace and set/get this normally
// (but handled differently in C++).
/** @private {chrome.settingsPrivate.PrefObject} */
metricsReportingPref_: {
type: Object,
value: function() {
// TODO(dbeam): this is basically only to appease PrefControlBehavior.
// Maybe add a no-validate attribute instead? This makes little sense.
return /** @type {chrome.settingsPrivate.PrefObject} */ ({});
},
},
/** @private */
showRestart_: Boolean,
// </if>
},
/** @override */
ready: function() {
this.browserProxy_ = settings.PrivacyPageBrowserProxyImpl.getInstance();
// <if expr="_google_chrome and not chromeos">
const setMetricsReportingPref = this.setMetricsReportingPref_.bind(this);
this.addWebUIListener('metrics-reporting-change', setMetricsReportingPref);
this.browserProxy_.getMetricsReporting().then(setMetricsReportingPref);
// </if>
},
// <if expr="_google_chrome and not chromeos">
/** @private */
onMetricsReportingChange_: function() {
const enabled = this.$.metricsReportingControl.checked;
this.browserProxy_.setMetricsReportingEnabled(enabled);
},
/**
* @param {!MetricsReporting} metricsReporting
* @private
*/
setMetricsReportingPref_: function(metricsReporting) {
const hadPreviousPref = this.metricsReportingPref_.value !== undefined;
const pref = {
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.showRestart_ = false;
} else if (hadPreviousPref) {
this.showRestart_ = true;
}
},
/**
* @param {!Event} e
* @private
*/
onRestartTap_: function(e) {
e.stopPropagation();
settings.LifetimeBrowserProxyImpl.getInstance().restart();
},
// </if>
/**
* @return {boolean}
* @private
*/
showSpellCheckControl_: function() {
return !this.unifiedConsentEnabled ||
(!!this.prefs.spellcheck &&
/** @type {!Array<string>} */
(this.prefs.spellcheck.dictionaries.value).length > 0);
},
/**
* @return {boolean}
* @private
*/
shouldShowDriveSuggest_: function() {
return loadTimeData.getBoolean('driveSuggestAvailable') &&
!!this.unifiedConsentEnabled && !!this.syncStatus &&
!!this.syncStatus.signedIn &&
this.syncStatus.statusAction !== settings.StatusAction.REAUTHENTICATE;
},
});
})();