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

Side by Side Diff: chrome/browser/resources/settings/device_page/storage.js

Issue 2348913002: Port storage manager to MD settings. (Closed)
Patch Set: histograms.xml Created 4 years, 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 /**
6 * @fileoverview
7 * 'settings-storage' is the settings subpage for storage settings.
8 */
9
10 /**
11 * Enumeration for device state about remaining space.
12 * These values must be kept in sync with
13 * StorageManagerHandler::StorageSpaceState in C++ code.
14 * @enum {number}
15 */
16 var StorageSpaceState = {
michaelpg 2016/10/01 01:41:05 namespace these in 'settings' via cr.define; see h
fukino 2016/10/03 18:40:41 As far as I tried, an enum defined in a namespace
michaelpg 2016/10/03 23:44:44 You're right, I forgot about that. I think it's a
fukino 2016/10/04 09:03:53 Thanks! I used cr.exportPath('settings') to keep t
17 STORAGE_SPACE_NORMAL: 0,
michaelpg 2016/10/01 01:41:05 why not just NORMAL, LOW, CRITICALLY_LOW?
fukino 2016/10/03 18:40:41 Done.
18 STORAGE_SPACE_LOW: 1,
19 STORAGE_SPACE_CRITICALLY_LOW: 2
20 };
21
22 /**
23 * @typedef {{
24 * totalSize: string,
25 * availableSize: string,
26 * usedSize: string,
27 * usedRatio: number,
28 * spaceState: StorageSpaceState,
29 * }}
30 */
31 var StorageSizeStat;
32
33 Polymer({
34 is: 'settings-storage',
35
36 behaviors: [settings.RouteObserverBehavior, WebUIListenerBehavior],
37
38 properties: {
39 /** @private {boolean} */
michaelpg 2016/10/01 01:41:05 the Polymer pass for closure infers type names for
fukino 2016/10/03 18:40:41 Done.
40 driveEnabled_: {
41 type: Boolean,
42 value: false,
43 },
44
45 /** @private {boolean} */
46 androidEnabled_: {
47 type: Boolean,
48 value: false,
49 },
50
51 /** @private {number} */
52 usedRatio_: {
53 type: Number,
54 value: 0,
55 },
56
57 /** @private {number} */
michaelpg 2016/10/01 01:41:05 here, though, you want to provide closure with *mo
fukino 2016/10/03 18:40:41 Done.
58 spaceState_: {
59 type: Number,
60 value: StorageSpaceState.STORAGE_SPACE_NORMAL,
61 },
62 },
63
64 /**
65 * Timer ID for periodical update.
michaelpg 2016/10/01 01:41:05 nit: "periodic" :-)
fukino 2016/10/03 18:40:41 Oops! Done.
66 * @private {number}
67 */
68 updateTimerId_: -1,
69
70 /**
71 * True if the current route is STORAGE.
72 * @private {boolean}
73 */
74 visible_: false,
michaelpg 2016/10/01 01:41:05 what is this used for?
fukino 2016/10/03 18:40:41 I couldn't find how to know the previous route, so
75
76 /** @override */
77 ready: function() {
78 cr.addWebUIListener(
79 'storage-size-stat-changed',
80 this.handleSizeStatChanged_.bind(this));
81 cr.addWebUIListener(
82 'storage-downloads-size-changed',
83 this.handleDownloadsSizeChanged_.bind(this));
84 cr.addWebUIListener(
85 'storage-drive-cache-size-changed',
86 this.handleDriveCacheSizeChanged_.bind(this));
87 cr.addWebUIListener(
88 'storage-browsing-data-size-changed',
89 this.handleBrowsingDataSizeChanged_.bind(this));
90 cr.addWebUIListener(
91 'storage-android-size-changed',
92 this.handleAndroidSizeChanged_.bind(this));
93 cr.addWebUIListener(
94 'storage-other-users-size-changed',
95 this.handleOtherUsersSizeChanged_.bind(this));
96 cr.addWebUIListener(
97 'storage-drive-enabled-changed',
98 this.handleDriveEnabledChanged_.bind(this));
99 cr.addWebUIListener(
100 'storage-android-enabled-changed',
101 this.handleAndroidEnabledChanged_.bind(this));
102 },
103
104 /**
105 * Overridden from settings.RouteObserverBehavior.
106 * @protected
107 */
108 currentRouteChanged: function() {
109 if (settings.getCurrentRoute() == settings.Route.STORAGE) {
110 if (!this.visible_) {
111 this.visible_ = true;
112 this.onPageShown_();
113 }
114 } else {
115 if (this.visible_) {
116 this.visible_ = false;
117 this.onPageHidden_();
118 }
119 }
120 },
121
122 /** @private */
123 onPageShown_: function() {
124 // Updating storage information can be expensive (e.g. computing directory
125 // sizes recursively), so we delay this operation until the page is shown.
126 chrome.send('updateStorageInfo');
127 // We periodically update the storage usage while the overlay is visible.
128 this.startPeriodicalUpdate_();
michaelpg 2016/10/01 01:41:05 same, "Periodic" (but "periodically" is correct. e
fukino 2016/10/03 18:40:41 Done.
129 },
130
131 /** @private */
132 onPageHidden_: function() {
133 this.stopPeriodicalUpdate_();
134 },
135
136 /**
137 * Handler for tapping the "Downloads" item.
138 * @private
139 */
140 onDownloadsTap_: function() {
141 chrome.send('openDownloads');
142 },
143
144 /**
145 * Handler for tapping the "Offlien files" item.
michaelpg 2016/10/01 01:41:05 Offline
fukino 2016/10/03 18:40:41 Done.
146 * @private
147 */
148 onDriveCacheTap_: function() {
149 // TODO(fukino): Show a dialog of Drive cache.
michaelpg 2016/10/01 01:41:05 should this TODO go in drive_cache_dialog?
fukino 2016/10/03 18:40:41 I removed the TODO comment. (The dialog was alread
150 this.$.storageDriveCache.open();
151 },
152
153 /**
154 * Handler for tapping the "Browsing data" item.
155 * @private
156 */
157 onBrowsingDataTap_: function() {
158 settings.navigateTo(settings.Route.CLEAR_BROWSER_DATA);
159 },
160
161 /**
162 * Handler for tapping the "Android storage" item.
163 * @private
164 */
165 onAndroidTap_: function() {
166 chrome.send('openArcStorage');
167 },
168
169 /**
170 * Handler for tapping the "Other users" item.
171 * @private
172 */
173 onOtherUsersTap_: function() {
174 settings.navigateTo(settings.Route.ACCOUNTS);
175 },
176
177 /**
178 * @param {!StorageSizeStat} sizeStat
179 * @private
180 */
181 handleSizeStatChanged_: function(sizeStat) {
182 this.usedRatio_ = sizeStat.usedRatio;
michaelpg 2016/10/01 01:41:05 So, why not just have a sizeStat_ property? You ca
fukino 2016/10/03 18:40:41 Wow nice cleanup! I totally forgot the binding to
183 this.spaceState_ = sizeStat.spaceState;
184 this.$.inUseSize.textContent = sizeStat.usedSize;
185 this.$.availableSize.textContent = sizeStat.availableSize;
186 this.$.inUseLabelArea.style.width = (sizeStat.usedRatio * 100) + '%';
187 this.$.availableLabelArea.style.width =
188 ((1 - sizeStat.usedRatio) * 100) + '%';
189 },
190
191 /**
192 * @param {string} size Formatted string representing the size of Downloads.
193 * @private
194 */
195 handleDownloadsSizeChanged_: function(size) {
196 this.$.downloadsSize.textContent = size;
197 },
198
199 /**
200 * @param {string} size Formatted string representing the size of Offline
201 * files.
202 * @private
203 */
204 handleDriveCacheSizeChanged_: function(size) {
205 this.$.driveCacheSize.textContent = size;
206 },
207
208 /**
209 * @param {string} size Formatted string representing the size of Browsing
210 * data.
211 * @private
212 */
213 handleBrowsingDataSizeChanged_: function(size) {
214 this.$.browsingDataSize.textContent = size;
215 },
216
217 /**
218 * @param {string} size Formatted string representing the size of Android
219 * storage.
220 * @private
221 */
222 handleAndroidSizeChanged_: function(size) {
223 this.$.androidSize.textContent = size;
224 },
225
226 /**
227 * @param {string} size Formatted string representing the size of Other users.
228 * @private
229 */
230 handleOtherUsersSizeChanged_: function(size) {
231 this.$.otherUsersSize.textContent = size;
232 },
233
234 /**
235 * @param {boolean} enabled True if Google Drive is enabled.
236 * @private
237 */
238 handleDriveEnabledChanged_: function(enabled) {
239 this.driveEnabled_ = enabled;
240 },
241
242 /**
243 * @param {boolean} enabled True if Android Play Store is enabled.
244 * @private
245 */
246 handleAndroidEnabledChanged_: function(enabled) {
247 this.androidEnabled_ = enabled;
248 },
249
250 /**
251 * Starts periodical update for storage usage.
252 * @private
253 */
254 startPeriodicalUpdate_: function() {
255 // We update the storage usage every 5 seconds.
256 if (this.updateTimerId_ == -1) {
257 this.updateTimerId_ = window.setInterval(function() {
258 chrome.send('updateStorageInfo');
michaelpg 2016/10/01 01:41:05 I would feel better if we checked the route here,
fukino 2016/10/03 18:40:41 Oh, I didn't understand that the dialog can be det
259 }, 5000);
260 }
261 },
262
263 /**
264 * Stops periodical update for storage usage.
265 * @private
266 */
267 stopPeriodicalUpdate_: function() {
268 if (this.updateTimerId_ != -1) {
269 window.clearInterval(this.updateTimerId_);
270 this.updateTimerId_ = -1;
271 }
272 },
273
274 /**
275 * Returns true if the remaining space is low, but not critically low.
276 * @param {!StorageSpaceState} spaceState Status about the remaining space.
277 * @private
278 */
279 isSpaceLow_: function(spaceState) {
280 return spaceState == StorageSpaceState.STORAGE_SPACE_LOW;
281 },
282
283 /**
284 * Returns true if the remaining space is critically low.
285 * @param {!StorageSpaceState} spaceState Status about the remaining space.
286 * @private
287 */
288 isSpaceCriticallyLow_: function(spaceState) {
289 return spaceState == StorageSpaceState.STORAGE_SPACE_CRITICALLY_LOW;
290 },
291
292 /**
293 * Computes class name of the bar based on the remaining space size.
294 * @param {!StorageSpaceState} spaceState Status about the remaining space.
295 * @private
296 */
297 getBarClass_: function(spaceState) {
298 switch (spaceState) {
299 case StorageSpaceState.STORAGE_SPACE_LOW:
300 return 'space-low';
301 case StorageSpaceState.STORAGE_SPACE_CRITICALLY_LOW:
302 return 'space-critically-low';
303 default:
304 return '';
305 }
306 },
307 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698