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