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

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: Use == and != 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
« no previous file with comments | « no previous file | chrome/browser/ui/webui/options/chromeos/storage_manager_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 * @private {number}
47 */
48 updateTimerId_: -1,
49
44 /** @override */ 50 /** @override */
45 initializePage: function() { 51 initializePage: function() {
46 Page.prototype.initializePage.call(this); 52 Page.prototype.initializePage.call(this);
47 53
48 $('storage-manager-label-downloads').onclick = function() { 54 $('storage-manager-label-downloads').onclick = function() {
49 chrome.send('openDownloads'); 55 chrome.send('openDownloads');
50 }; 56 };
51 $('storage-manager-label-drive-cache').onclick = function() { 57 $('storage-manager-label-drive-cache').onclick = function() {
52 PageManager.showPageByName('storageClearDriveCache'); 58 PageManager.showPageByName('storageClearDriveCache');
53 }; 59 };
54 $('storage-manager-label-browsing-data').onclick = function() { 60 $('storage-manager-label-browsing-data').onclick = function() {
55 PageManager.showPageByName('clearBrowserData'); 61 PageManager.showPageByName('clearBrowserData');
56 }; 62 };
57 $('storage-manager-label-arc').onclick = function() { 63 $('storage-manager-label-arc').onclick = function() {
58 chrome.send('openArcStorage'); 64 chrome.send('openArcStorage');
59 }; 65 };
60 66
61 $('storage-confirm').onclick = function() { 67 $('storage-confirm').onclick = function() {
62 PageManager.closeOverlay(); 68 PageManager.closeOverlay();
63 }; 69 };
64 }, 70 },
65 71
66 /** @override */ 72 /** @override */
67 didShowPage: function() { 73 didShowPage: function() {
68 // Updating storage information can be expensive (e.g. computing directory 74 // Updating storage information can be expensive (e.g. computing directory
69 // sizes recursively), so we delay this operation until the page is shown. 75 // sizes recursively), so we delay this operation until the page is shown.
70 chrome.send('updateStorageInfo'); 76 chrome.send('updateStorageInfo');
77 // We periodically update the storage usage while the overlay is visible.
78 this.startPeriodicalUpdate_();
79 },
80
81 /** @override */
82 didClosePage: function() {
83 this.stopPeriodicalUpdate_();
71 }, 84 },
72 85
73 /** 86 /**
74 * Updates the size information (total/used/available) of the internal 87 * Updates the size information (total/used/available) of the internal
75 * storage. 88 * storage.
76 * @param {!options.StorageSizeStat} sizeStat 89 * @param {!options.StorageSizeStat} sizeStat
77 * @private 90 * @private
78 */ 91 */
79 setSizeStat_: function(sizeStat) { 92 setSizeStat_: function(sizeStat) {
80 $('storage-manager-size-capacity').textContent = sizeStat.totalSize; 93 $('storage-manager-size-capacity').textContent = sizeStat.totalSize;
81 $('storage-manager-size-in-use').textContent = sizeStat.usedSize; 94 $('storage-manager-size-in-use').textContent = sizeStat.usedSize;
82 $('storage-manager-size-available').textContent = sizeStat.availableSize; 95 $('storage-manager-size-available').textContent = sizeStat.availableSize;
83 $('storage-bar-progress').setAttribute('value', sizeStat.usedRatio); 96 $('storage-bar-progress').setAttribute('value', sizeStat.usedRatio);
84 $('storageManagerPage').classList.toggle('low-space', 97 $('storageManagerPage').classList.toggle('low-space',
85 sizeStat.spaceState === 98 sizeStat.spaceState ==
86 options.StorageSpaceState.STORAGE_SPACE_LOW); 99 options.StorageSpaceState.STORAGE_SPACE_LOW);
87 $('storageManagerPage').classList.toggle('critically-low-space', 100 $('storageManagerPage').classList.toggle('critically-low-space',
88 sizeStat.spaceState === 101 sizeStat.spaceState ==
89 options.StorageSpaceState.STORAGE_SPACE_CRITICALLY_LOW); 102 options.StorageSpaceState.STORAGE_SPACE_CRITICALLY_LOW);
90 }, 103 },
91 104
92 /** 105 /**
93 * Updates the size Downloads directory. 106 * Updates the size Downloads directory.
94 * @param {string} size Formatted string of the size of Downloads. 107 * @param {string} size Formatted string of the size of Downloads.
95 * @private 108 * @private
96 */ 109 */
97 setDownloadsSize_: function(size) { 110 setDownloadsSize_: function(size) {
98 $('storage-manager-size-downloads').textContent = size; 111 $('storage-manager-size-downloads').textContent = size;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 $('storage-manager-size-arc').textContent = size; 150 $('storage-manager-size-arc').textContent = size;
138 }, 151 },
139 152
140 /** 153 /**
141 * Shows the item "Android apps and cache" on the overlay UI. 154 * Shows the item "Android apps and cache" on the overlay UI.
142 * @private 155 * @private
143 */ 156 */
144 showArcItem_: function() { 157 showArcItem_: function() {
145 $('storage-manager-item-arc').hidden = false; 158 $('storage-manager-item-arc').hidden = false;
146 }, 159 },
160
161 /**
162 * Starts periodical update for storage usage.
163 * @private
164 */
165 startPeriodicalUpdate_: function() {
166 // We update the storage usage every 5 seconds.
167 if (this.updateTimerId_ == -1) {
168 this.updateTimerId_ = window.setInterval(function() {
169 chrome.send('updateStorageInfo');
170 }, 5000);
171 }
172 },
173
174 /**
175 * Stops periodical update for storage usage.
176 * @private
177 */
178 stopPeriodicalUpdate_: function() {
179 if (this.updateTimerId_ != -1) {
180 window.clearInterval(this.updateTimerId_);
181 this.updateTimerId_ = -1;
182 }
183 },
147 }; 184 };
148 185
149 // Forward public APIs to private implementations. 186 // Forward public APIs to private implementations.
150 cr.makePublic(StorageManager, [ 187 cr.makePublic(StorageManager, [
151 'setArcSize', 188 'setArcSize',
152 'setBrowsingDataSize', 189 'setBrowsingDataSize',
153 'setDownloadsSize', 190 'setDownloadsSize',
154 'setDriveCacheSize', 191 'setDriveCacheSize',
155 'setOtherUsersSize', 192 'setOtherUsersSize',
156 'setSizeStat', 193 'setSizeStat',
157 'showArcItem', 194 'showArcItem',
158 ]); 195 ]);
159 196
160 return { 197 return {
161 StorageManager: StorageManager 198 StorageManager: StorageManager
162 }; 199 };
163 }); 200 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/options/chromeos/storage_manager_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698