Commit fae919ed authored by dpapad's avatar dpapad Committed by Commit Bot

CrOS Settings: Leverage browser proxy pattern in storage.js

The motivation behind this is to remove usages of
registerMessageCallback() test helper in order to eventually fully
remove it. The usage in device_page_tests.js is actually the last
usage of this helper.

Bug: 1148403
Change-Id: I734fe61bfd7bdd7c440658618ac5486c3c1d06a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2534152
Auto-Submit: dpapad <dpapad@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Commit-Queue: dpapad <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826977}
parent bdd5b811
......@@ -147,6 +147,7 @@ js_library("power") {
js_library("storage") {
deps = [
":device_page_browser_proxy",
"..:os_route",
"..:route_origin_behavior",
"../..:router",
......
......@@ -194,6 +194,9 @@ cr.define('settings', function() {
* @param {number} deltaY y-axis position change since the last update.
*/
dragDisplayDelta(id, deltaX, deltaY) {}
updateStorageInfo() {}
openMyFiles() {}
}
/**
......@@ -299,6 +302,16 @@ cr.define('settings', function() {
dragDisplayDelta(id, deltaX, deltaY) {
chrome.send('dragDisplayDelta', [id, deltaX, deltaY]);
}
/** @override */
updateStorageInfo() {
chrome.send('updateStorageInfo');
}
/** @override */
openMyFiles() {
chrome.send('openMyFiles');
}
}
cr.addSingletonGetter(DevicePageBrowserProxyImpl);
......
......@@ -8,6 +8,7 @@
<link rel="import" href="chrome://resources/html/cr/ui/focus_without_ink.html">
<link rel="import" href="chrome://resources/html/web_ui_listener_behavior.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-icon/iron-icon.html">
<link rel="import" href="device_page_browser_proxy.html">
<link rel="import" href="storage_external.html">
<link rel="import" href="../route_origin_behavior.html">
<link rel="import" href="../../prefs/prefs.html">
......
......@@ -74,6 +74,9 @@ cr.define('settings', function() {
*/
updateTimerId_: -1,
/** @private {?settings.DevicePageBrowserProxy} */
browserProxy_: null,
/** @override */
attached() {
this.addWebUIListener(
......@@ -105,6 +108,7 @@ cr.define('settings', function() {
this.addFocusConfig_(r.ACCOUNTS, '#otherUsersSize');
this.addFocusConfig_(
r.EXTERNAL_STORAGE_PREFERENCES, '#externalStoragePreferences');
this.browserProxy_ = settings.DevicePageBrowserProxyImpl.getInstance();
},
/**
......@@ -128,7 +132,7 @@ cr.define('settings', function() {
onPageShown_() {
// Updating storage information can be expensive (e.g. computing directory
// sizes recursively), so we delay this operation until the page is shown.
chrome.send('updateStorageInfo');
this.browserProxy_.updateStorageInfo();
// We update the storage usage periodically when the overlay is visible.
this.startPeriodicUpdate_();
},
......@@ -138,7 +142,7 @@ cr.define('settings', function() {
* @private
*/
onMyFilesTap_() {
chrome.send('openMyFiles');
this.browserProxy_.openMyFiles();
},
/**
......@@ -279,7 +283,7 @@ cr.define('settings', function() {
this.stopPeriodicUpdate_();
return;
}
chrome.send('updateStorageInfo');
this.browserProxy_.updateStorageInfo();
}, 5000);
}
},
......
......@@ -151,6 +151,9 @@ cr.define('device_page_tests', function() {
this.lastHighlightedDisplayId_ = id;
},
/** @override */
updateStorageInfo: function() {},
// Test interface:
/**
* Sets whether the app list contains Android apps.
......@@ -2433,12 +2436,6 @@ cr.define('device_page_tests', function() {
});
setup(function() {
// Avoid unwanted callbacks by disabling storage computations when the
// storage page is loaded.
registerMessageCallback(
'updateStorageInfo', null /* message handler */,
() => {} /* callback */);
return showAndGetDeviceSubpage('storage', settings.routes.STORAGE)
.then(function(page) {
storagePage = page;
......
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