Commit 67f1533a authored by Rainhard Findling's avatar Rainhard Findling Committed by Commit Bot

Safety check: move parent status to backend (part 2)

* This is done as preparation for a subsequent refactoring of the
  safety check WebUi code. It moves the source of truth for the
  safety check parent status from the JS side to the C++ side. This
  removes some of the interdependencies of parent to children (and
  vice versa), and allows for a subsequent splitting of parent and
  children into individual parts on the WebUi side.
* This CL is part 2 of the change and updates the WebUi to use the
  parent state received from the backend, instead of holding and
  computing its own.

Bug: 1015841
Change-Id: I3a6f1c1bb195c6c050e14b31564316d4a9e2323d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2150429
Commit-Queue: Rainhard Findling <rainhard@chromium.org>
Reviewed-by: default avatarEsmael Elmoslimany <aee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759973}
parent b27eaeba
...@@ -201,19 +201,6 @@ Polymer({ ...@@ -201,19 +201,6 @@ Polymer({
settings.SafetyCheckInteractions.SAFETY_CHECK_START); settings.SafetyCheckInteractions.SAFETY_CHECK_START);
this.metricsBrowserProxy_.recordAction('Settings.SafetyCheck.Start'); this.metricsBrowserProxy_.recordAction('Settings.SafetyCheck.Start');
// Update UI.
this.parentDisplayString_ = this.i18n('safetyCheckRunning');
this.parentStatus_ = settings.SafetyCheckParentStatus.CHECKING;
// Reset all children states.
this.updatesStatus_ = settings.SafetyCheckUpdatesStatus.CHECKING;
this.passwordsStatus_ = settings.SafetyCheckPasswordsStatus.CHECKING;
this.safeBrowsingStatus_ = settings.SafetyCheckSafeBrowsingStatus.CHECKING;
this.extensionsStatus_ = settings.SafetyCheckExtensionsStatus.CHECKING;
// Display running-status for safety check elements.
this.updatesDisplayString_ = '';
this.passwordsDisplayString_ = '';
this.safeBrowsingDisplayString_ = '';
this.extensionsDisplayString_ = '';
// Trigger safety check. // Trigger safety check.
this.safetyCheckBrowserProxy_.runSafetyCheck(); this.safetyCheckBrowserProxy_.runSafetyCheck();
// Readout new safety check status via accessibility. // Readout new safety check status via accessibility.
...@@ -222,17 +209,14 @@ Polymer({ ...@@ -222,17 +209,14 @@ Polymer({
}); });
}, },
/** @private */ /**
updateParentFromChildren_: function() { * @param {!ParentChangedEvent} event
// If all children elements received updates: update parent element. * @private
if (this.updatesStatus_ != settings.SafetyCheckUpdatesStatus.CHECKING && */
this.passwordsStatus_ != settings.SafetyCheckPasswordsStatus.CHECKING && onSafetyCheckParentChanged_: function(event) {
this.safeBrowsingStatus_ != this.parentStatus_ = event.newState;
settings.SafetyCheckSafeBrowsingStatus.CHECKING && this.parentDisplayString_ = event.displayString;
this.extensionsStatus_ != if (this.parentStatus_ === settings.SafetyCheckParentStatus.AFTER) {
settings.SafetyCheckExtensionsStatus.CHECKING) {
// Update UI.
this.parentStatus_ = settings.SafetyCheckParentStatus.AFTER;
// Start periodic safety check parent ran string updates. // Start periodic safety check parent ran string updates.
const timestamp = Date.now(); const timestamp = Date.now();
const update = async () => { const update = async () => {
...@@ -251,15 +235,6 @@ Polymer({ ...@@ -251,15 +235,6 @@ Polymer({
} }
}, },
/**
* @param {!ParentChangedEvent} event
* @private
*/
onSafetyCheckParentChanged_: function(event) {
// TODO(crbug.com/1015841): Use parent state from backend instead of
// computing and storing parent state in WebUI.
},
/** /**
* @param {!UpdatesChangedEvent} event * @param {!UpdatesChangedEvent} event
* @private * @private
...@@ -267,7 +242,6 @@ Polymer({ ...@@ -267,7 +242,6 @@ Polymer({
onSafetyCheckUpdatesChanged_: function(event) { onSafetyCheckUpdatesChanged_: function(event) {
this.updatesStatus_ = event.newState; this.updatesStatus_ = event.newState;
this.updatesDisplayString_ = event.displayString; this.updatesDisplayString_ = event.displayString;
this.updateParentFromChildren_();
}, },
/** /**
...@@ -277,7 +251,6 @@ Polymer({ ...@@ -277,7 +251,6 @@ Polymer({
onSafetyCheckPasswordsChanged_: function(event) { onSafetyCheckPasswordsChanged_: function(event) {
this.passwordsDisplayString_ = event.displayString; this.passwordsDisplayString_ = event.displayString;
this.passwordsStatus_ = event.newState; this.passwordsStatus_ = event.newState;
this.updateParentFromChildren_();
}, },
/** /**
...@@ -287,7 +260,6 @@ Polymer({ ...@@ -287,7 +260,6 @@ Polymer({
onSafetyCheckSafeBrowsingChanged_: function(event) { onSafetyCheckSafeBrowsingChanged_: function(event) {
this.safeBrowsingStatus_ = event.newState; this.safeBrowsingStatus_ = event.newState;
this.safeBrowsingDisplayString_ = event.displayString; this.safeBrowsingDisplayString_ = event.displayString;
this.updateParentFromChildren_();
}, },
/** /**
...@@ -297,7 +269,6 @@ Polymer({ ...@@ -297,7 +269,6 @@ Polymer({
onSafetyCheckExtensionsChanged_: function(event) { onSafetyCheckExtensionsChanged_: function(event) {
this.extensionsDisplayString_ = event.displayString; this.extensionsDisplayString_ = event.displayString;
this.extensionsStatus_ = event.newState; this.extensionsStatus_ = event.newState;
this.updateParentFromChildren_();
}, },
/** /**
...@@ -321,6 +292,10 @@ Polymer({ ...@@ -321,6 +292,10 @@ Polymer({
settings.HatsBrowserProxyImpl.getInstance().tryShowSurvey(); settings.HatsBrowserProxyImpl.getInstance().tryShowSurvey();
this.runSafetyCheck_(); this.runSafetyCheck_();
// Update parent element so that re-run button is visible and can be
// focused.
this.parentStatus_ = settings.SafetyCheckParentStatus.CHECKING;
Polymer.dom.flush(); Polymer.dom.flush();
this.focusParent_(); this.focusParent_();
}, },
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
// clang-format off // clang-format off
// #import {HatsBrowserProxyImpl, LifetimeBrowserProxyImpl, MetricsBrowserProxyImpl, OpenWindowProxyImpl, PasswordManagerImpl, PasswordManagerProxy, Router, routes, SafetyCheckBrowserProxy, SafetyCheckBrowserProxyImpl, SafetyCheckCallbackConstants, SafetyCheckInteractions, SafetyCheckExtensionsStatus, SafetyCheckPasswordsStatus, SafetyCheckSafeBrowsingStatus, SafetyCheckUpdatesStatus} from 'chrome://settings/settings.js'; // #import {HatsBrowserProxyImpl, LifetimeBrowserProxyImpl, MetricsBrowserProxyImpl, OpenWindowProxyImpl, PasswordManagerImpl, PasswordManagerProxy, Router, routes, SafetyCheckBrowserProxy, SafetyCheckBrowserProxyImpl, SafetyCheckCallbackConstants, SafetyCheckInteractions, SafetyCheckExtensionsStatus, SafetyCheckParentStatus, SafetyCheckPasswordsStatus, SafetyCheckSafeBrowsingStatus, SafetyCheckUpdatesStatus} from 'chrome://settings/settings.js';
// #import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; // #import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
// #import {TestBrowserProxy} from 'chrome://test/test_browser_proxy.m.js'; // #import {TestBrowserProxy} from 'chrome://test/test_browser_proxy.m.js';
// #import {TestHatsBrowserProxy} from 'chrome://test/settings/test_hats_browser_proxy.m.js'; // #import {TestHatsBrowserProxy} from 'chrome://test/settings/test_hats_browser_proxy.m.js';
...@@ -48,6 +48,14 @@ suite('SafetyCheckUiTests', function() { ...@@ -48,6 +48,14 @@ suite('SafetyCheckUiTests', function() {
page.remove(); page.remove();
}); });
function fireSafetyCheckParentEvent(state) {
const event = {};
event.newState = state;
event.displayString = null;
cr.webUIListenerCallback(
settings.SafetyCheckCallbackConstants.PARENT_CHANGED, event);
}
function fireSafetyCheckUpdatesEvent(state) { function fireSafetyCheckUpdatesEvent(state) {
const event = {}; const event = {};
event.newState = state; event.newState = state;
...@@ -159,6 +167,7 @@ suite('SafetyCheckUiTests', function() { ...@@ -159,6 +167,7 @@ suite('SafetyCheckUiTests', function() {
settings.SafetyCheckSafeBrowsingStatus.ENABLED_STANDARD); settings.SafetyCheckSafeBrowsingStatus.ENABLED_STANDARD);
fireSafetyCheckExtensionsEvent( fireSafetyCheckExtensionsEvent(
settings.SafetyCheckExtensionsStatus.NO_BLOCKLISTED_EXTENSIONS); settings.SafetyCheckExtensionsStatus.NO_BLOCKLISTED_EXTENSIONS);
fireSafetyCheckParentEvent(settings.SafetyCheckParentStatus.AFTER);
Polymer.dom.flush(); Polymer.dom.flush();
// Only the icon button is present. // Only the icon button is present.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment