Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1309)

Side by Side Diff: chrome/browser/resources/options/chromeos/storage_manager.js

Issue 2137463002: Storage manager: Update storage usage periodically. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * Enumeration for device state about remaining space. 6 * Enumeration for device state about remaining space.
7 * These values must be kept in sync with 7 * These values must be kept in sync with
8 * StorageManagerHandler::StorageSpaceState in C++ code. 8 * StorageManagerHandler::StorageSpaceState in C++ code.
9 * @enum {number} 9 * @enum {number}
10 * @const 10 * @const
(...skipping 23 matching lines...) Expand all
34 Page.call(this, 'storage', 34 Page.call(this, 'storage',
35 loadTimeData.getString('storageManagerPageTabTitle'), 35 loadTimeData.getString('storageManagerPageTabTitle'),
36 'storageManagerPage'); 36 'storageManagerPage');
37 } 37 }
38 38
39 cr.addSingletonGetter(StorageManager); 39 cr.addSingletonGetter(StorageManager);
40 40
41 StorageManager.prototype = { 41 StorageManager.prototype = {
42 __proto__: Page.prototype, 42 __proto__: Page.prototype,
43 43
44 /**
45 * Timer ID for periodical update.
46 * @type {number}
47 * @private
Dan Beam 2016/07/09 00:18:26 nit: @private {number}
fukino 2016/07/11 03:33:24 Done.
48 */
49 updateTimerId_: -1,
50
44 /** @override */ 51 /** @override */
45 initializePage: function() { 52 initializePage: function() {
46 Page.prototype.initializePage.call(this); 53 Page.prototype.initializePage.call(this);
47 54
48 $('storage-manager-label-downloads').onclick = function() { 55 $('storage-manager-label-downloads').onclick = function() {
49 chrome.send('openDownloads'); 56 chrome.send('openDownloads');
50 }; 57 };
51 $('storage-manager-label-drive-cache').onclick = function() { 58 $('storage-manager-label-drive-cache').onclick = function() {
52 PageManager.showPageByName('storageClearDriveCache'); 59 PageManager.showPageByName('storageClearDriveCache');
53 }; 60 };
54 $('storage-manager-label-browsing-data').onclick = function() { 61 $('storage-manager-label-browsing-data').onclick = function() {
55 PageManager.showPageByName('clearBrowserData'); 62 PageManager.showPageByName('clearBrowserData');
56 }; 63 };
57 $('storage-manager-label-arc').onclick = function() { 64 $('storage-manager-label-arc').onclick = function() {
58 chrome.send('openArcStorage'); 65 chrome.send('openArcStorage');
59 }; 66 };
60 67
61 $('storage-confirm').onclick = function() { 68 $('storage-confirm').onclick = function() {
62 PageManager.closeOverlay(); 69 PageManager.closeOverlay();
63 }; 70 };
64 }, 71 },
65 72
66 /** @override */ 73 /** @override */
67 didShowPage: function() { 74 didShowPage: function() {
68 // Updating storage information can be expensive (e.g. computing directory 75 // Updating storage information can be expensive (e.g. computing directory
69 // sizes recursively), so we delay this operation until the page is shown. 76 // sizes recursively), so we delay this operation until the page is shown.
70 chrome.send('updateStorageInfo'); 77 chrome.send('updateStorageInfo');
78 // We periodically update the storage usage while the overlay is visible.
79 this.startPeriodicalUpdate_();
80 },
81
82 /** @override */
83 didClosePage: function() {
84 this.stopPeriodicalUpdate_();
71 }, 85 },
72 86
73 /** 87 /**
74 * Updates the size information (total/used/available) of the internal 88 * Updates the size information (total/used/available) of the internal
75 * storage. 89 * storage.
76 * @param {!options.StorageSizeStat} sizeStat 90 * @param {!options.StorageSizeStat} sizeStat
77 * @private 91 * @private
78 */ 92 */
79 setSizeStat_: function(sizeStat) { 93 setSizeStat_: function(sizeStat) {
80 $('storage-manager-size-capacity').textContent = sizeStat.totalSize; 94 $('storage-manager-size-capacity').textContent = sizeStat.totalSize;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 $('storage-manager-size-arc').textContent = size; 151 $('storage-manager-size-arc').textContent = size;
138 }, 152 },
139 153
140 /** 154 /**
141 * Shows the item "Android apps and cache" on the overlay UI. 155 * Shows the item "Android apps and cache" on the overlay UI.
142 * @private 156 * @private
143 */ 157 */
144 showArcItem_: function() { 158 showArcItem_: function() {
145 $('storage-manager-item-arc').hidden = false; 159 $('storage-manager-item-arc').hidden = false;
146 }, 160 },
161
162 /**
163 * Starts periodical update for storage usage.
164 * @private
165 */
166 startPeriodicalUpdate_: function() {
167 // We update the storage usage every 5 seconds.
168 if (this.updateTimerId_ === -1) {
Dan Beam 2016/07/09 00:18:26 nit: arguably, you should use == unless there's a
fukino 2016/07/11 03:33:24 Done for all '===' and '!=='.
169 this.updateTimerId_ = window.setInterval(function() {
170 chrome.send('updateStorageInfo');
171 }, 5000);
172 }
173 },
174
175 /**
176 * Stops periodical update for storage usage.
177 * @private
178 */
179 stopPeriodicalUpdate_: function() {
180 if (this.updateTimerId_ !== -1) {
181 window.clearInterval(this.updateTimerId_);
182 this.updateTimerId_ = -1;
183 }
184 },
147 }; 185 };
148 186
149 // Forward public APIs to private implementations. 187 // Forward public APIs to private implementations.
150 cr.makePublic(StorageManager, [ 188 cr.makePublic(StorageManager, [
151 'setArcSize', 189 'setArcSize',
152 'setBrowsingDataSize', 190 'setBrowsingDataSize',
153 'setDownloadsSize', 191 'setDownloadsSize',
154 'setDriveCacheSize', 192 'setDriveCacheSize',
155 'setOtherUsersSize', 193 'setOtherUsersSize',
156 'setSizeStat', 194 'setSizeStat',
157 'showArcItem', 195 'showArcItem',
158 ]); 196 ]);
159 197
160 return { 198 return {
161 StorageManager: StorageManager 199 StorageManager: StorageManager
162 }; 200 };
163 }); 201 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698