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

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

Issue 2348913002: Port storage manager to MD settings. (Closed)
Patch Set: Address review comments. 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 = {
17 NORMAL: 0,
18 LOW: 1,
19 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 */
40 driveEnabled_: {
41 type: Boolean,
42 value: false,
43 },
44
45 /** @private */
46 androidEnabled_: {
47 type: Boolean,
48 value: false,
49 },
50
51 /** @private {StorageSizeStat} */
52 sizeStat_: Object,
53 },
54
55 /**
56 * Timer ID for periodic update.
57 * @private {number}
58 */
59 updateTimerId_: -1,
60
61 /** @override */
62 ready: function() {
63 cr.addWebUIListener(
64 'storage-size-stat-changed',
65 this.handleSizeStatChanged_.bind(this));
66 cr.addWebUIListener(
67 'storage-downloads-size-changed',
68 this.handleDownloadsSizeChanged_.bind(this));
69 cr.addWebUIListener(
70 'storage-drive-cache-size-changed',
71 this.handleDriveCacheSizeChanged_.bind(this));
72 cr.addWebUIListener(
73 'storage-browsing-data-size-changed',
74 this.handleBrowsingDataSizeChanged_.bind(this));
75 cr.addWebUIListener(
76 'storage-android-size-changed',
77 this.handleAndroidSizeChanged_.bind(this));
78 cr.addWebUIListener(
79 'storage-other-users-size-changed',
80 this.handleOtherUsersSizeChanged_.bind(this));
81 cr.addWebUIListener(
82 'storage-drive-enabled-changed',
83 this.handleDriveEnabledChanged_.bind(this));
84 cr.addWebUIListener(
85 'storage-android-enabled-changed',
86 this.handleAndroidEnabledChanged_.bind(this));
87 },
88
89 /**
90 * Overridden from settings.RouteObserverBehavior.
91 * @protected
92 */
93 currentRouteChanged: function() {
94 if (settings.getCurrentRoute() == settings.Route.STORAGE)
95 this.onPageShown_();
96 },
97
98 /** @private */
99 onPageShown_: function() {
100 // Updating storage information can be expensive (e.g. computing directory
101 // sizes recursively), so we delay this operation until the page is shown.
102 chrome.send('updateStorageInfo');
103 // We update the storage usage periodically when the overlay is visible.
104 this.startPeriodicUpdate_();
105 },
106
107 /**
108 * Handler for tapping the "Downloads" item.
109 * @private
110 */
111 onDownloadsTap_: function() {
112 chrome.send('openDownloads');
113 },
114
115 /**
116 * Handler for tapping the "Offline files" item.
117 * @private
118 */
119 onDriveCacheTap_: function() {
120 this.$.storageDriveCache.open();
121 },
122
123 /**
124 * Handler for tapping the "Browsing data" item.
125 * @private
126 */
127 onBrowsingDataTap_: function() {
128 settings.navigateTo(settings.Route.CLEAR_BROWSER_DATA);
129 },
130
131 /**
132 * Handler for tapping the "Android storage" item.
133 * @private
134 */
135 onAndroidTap_: function() {
136 chrome.send('openArcStorage');
137 },
138
139 /**
140 * Handler for tapping the "Other users" item.
141 * @private
142 */
143 onOtherUsersTap_: function() {
144 settings.navigateTo(settings.Route.ACCOUNTS);
145 },
146
147 /**
148 * @param {!StorageSizeStat} sizeStat
149 * @private
150 */
151 handleSizeStatChanged_: function(sizeStat) {
152 this.sizeStat_ = sizeStat;
153 this.$.inUseLabelArea.style.width = (sizeStat.usedRatio * 100) + '%';
154 this.$.availableLabelArea.style.width =
155 ((1 - sizeStat.usedRatio) * 100) + '%';
156 },
157
158 /**
159 * @param {string} size Formatted string representing the size of Downloads.
160 * @private
161 */
162 handleDownloadsSizeChanged_: function(size) {
163 this.$.downloadsSize.textContent = size;
164 },
165
166 /**
167 * @param {string} size Formatted string representing the size of Offline
168 * files.
169 * @private
170 */
171 handleDriveCacheSizeChanged_: function(size) {
172 this.$.driveCacheSize.textContent = size;
173 },
174
175 /**
176 * @param {string} size Formatted string representing the size of Browsing
177 * data.
178 * @private
179 */
180 handleBrowsingDataSizeChanged_: function(size) {
181 this.$.browsingDataSize.textContent = size;
182 },
183
184 /**
185 * @param {string} size Formatted string representing the size of Android
186 * storage.
187 * @private
188 */
189 handleAndroidSizeChanged_: function(size) {
190 this.$.androidSize.textContent = size;
191 },
192
193 /**
194 * @param {string} size Formatted string representing the size of Other users.
195 * @private
196 */
197 handleOtherUsersSizeChanged_: function(size) {
198 this.$.otherUsersSize.textContent = size;
199 },
200
201 /**
202 * @param {boolean} enabled True if Google Drive is enabled.
203 * @private
204 */
205 handleDriveEnabledChanged_: function(enabled) {
206 this.driveEnabled_ = enabled;
207 },
208
209 /**
210 * @param {boolean} enabled True if Android Play Store is enabled.
211 * @private
212 */
213 handleAndroidEnabledChanged_: function(enabled) {
214 this.androidEnabled_ = enabled;
215 },
216
217 /**
218 * Starts periodic update for storage usage.
219 * @private
220 */
221 startPeriodicUpdate_: function() {
222 // We update the storage usage every 5 seconds.
223 if (this.updateTimerId_ == -1) {
224 this.updateTimerId_ = window.setInterval(function() {
225 if (settings.getCurrentRoute() != settings.Route.STORAGE) {
226 this.stopPeriodicUpdate_();
227 return;
228 }
229 chrome.send('updateStorageInfo');
230 }.bind(this), 5000);
231 }
232 },
233
234 /**
235 * Stops periodic update for storage usage.
236 * @private
237 */
238 stopPeriodicUpdate_: function() {
239 if (this.updateTimerId_ != -1) {
240 window.clearInterval(this.updateTimerId_);
241 this.updateTimerId_ = -1;
242 }
243 },
244
245 /**
246 * Returns true if the remaining space is low, but not critically low.
247 * @param {!StorageSpaceState} spaceState Status about the remaining space.
248 * @private
249 */
250 isSpaceLow_: function(spaceState) {
251 return spaceState == StorageSpaceState.LOW;
252 },
253
254 /**
255 * Returns true if the remaining space is critically low.
256 * @param {!StorageSpaceState} spaceState Status about the remaining space.
257 * @private
258 */
259 isSpaceCriticallyLow_: function(spaceState) {
260 return spaceState == StorageSpaceState.CRITICALLY_LOW;
261 },
262
263 /**
264 * Computes class name of the bar based on the remaining space size.
265 * @param {!StorageSpaceState} spaceState Status about the remaining space.
266 * @private
267 */
268 getBarClass_: function(spaceState) {
269 switch (spaceState) {
270 case StorageSpaceState.LOW:
271 return 'space-low';
272 case StorageSpaceState.CRITICALLY_LOW:
273 return 'space-critically-low';
274 default:
275 return '';
276 }
277 },
278 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698