OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // require cr.js | 5 // require cr.js |
6 // require cr/event_target.js | 6 // require cr/event_target.js |
7 // require cr/ui.js | 7 // require cr/ui.js |
8 // require cr/ui/tabs.js | 8 // require cr/ui/tabs.js |
9 // require cr/ui/tree.js | 9 // require cr/ui/tree.js |
10 // require cr/util.js | 10 // require cr/util.js |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 * @param {?number} value Number of milliseconds since | 119 * @param {?number} value Number of milliseconds since |
120 * UNIX epoch time (0:00, Jan 1, 1970, UTC). | 120 * UNIX epoch time (0:00, Jan 1, 1970, UTC). |
121 * @return {string} Formatted text of date or 'N/A'. | 121 * @return {string} Formatted text of date or 'N/A'. |
122 * @private | 122 * @private |
123 */ | 123 */ |
124 function dateToText(value) { | 124 function dateToText(value) { |
125 var result = checkIfAvailable_(value); | 125 var result = checkIfAvailable_(value); |
126 if (result) | 126 if (result) |
127 return result; | 127 return result; |
128 | 128 |
129 var lastAccessTime = new Date(value); | 129 var time = new Date(value); |
130 var now = new Date(); | 130 var now = new Date(); |
131 var delta = Date.now() - value; | 131 var delta = Date.now() - value; |
132 | 132 |
133 var SECOND = 1000; | 133 var SECOND = 1000; |
134 var MINUTE = 60 * SECOND; | 134 var MINUTE = 60 * SECOND; |
135 var HOUR = 60 * MINUTE; | 135 var HOUR = 60 * MINUTE; |
136 var DAY = 23 * HOUR; | 136 var DAY = 23 * HOUR; |
137 var WEEK = 7 * DAY; | 137 var WEEK = 7 * DAY; |
138 | 138 |
139 var SHOW_SECOND = 5 * MINUTE; | 139 var SHOW_SECOND = 5 * MINUTE; |
140 var SHOW_MINUTE = 5 * HOUR; | 140 var SHOW_MINUTE = 5 * HOUR; |
141 var SHOW_HOUR = 3 * DAY; | 141 var SHOW_HOUR = 3 * DAY; |
142 var SHOW_DAY = 2 * WEEK; | 142 var SHOW_DAY = 2 * WEEK; |
143 var SHOW_WEEK = 3 * 30 * DAY; | 143 var SHOW_WEEK = 3 * 30 * DAY; |
144 | 144 |
145 if (delta < 0) { | 145 if (delta < 0) { |
146 result = 'access from future '; | 146 result = 'access from future '; |
147 } else if (delta < SHOW_SECOND) { | 147 } else if (delta < SHOW_SECOND) { |
148 result = Math.ceil(delta / SECOND) + ' sec ago '; | 148 result = Math.ceil(delta / SECOND) + ' sec ago '; |
149 } else if (delta < SHOW_MINUTE) { | 149 } else if (delta < SHOW_MINUTE) { |
150 result = Math.ceil(delta / MINUTE) + ' min ago '; | 150 result = Math.ceil(delta / MINUTE) + ' min ago '; |
151 } else if (delta < SHOW_HOUR) { | 151 } else if (delta < SHOW_HOUR) { |
152 result = Math.ceil(delta / HOUR) + ' hr ago '; | 152 result = Math.ceil(delta / HOUR) + ' hr ago '; |
153 } else if (delta < SHOW_WEEK) { | 153 } else if (delta < SHOW_WEEK) { |
154 result = Math.ceil(delta / DAY) + ' day ago '; | 154 result = Math.ceil(delta / DAY) + ' day ago '; |
155 } | 155 } |
156 | 156 |
157 result += '(' + lastAccessTime.toString() + ')'; | 157 result += '(' + time.toString() + ')'; |
158 return result; | 158 return result; |
159 } | 159 } |
160 | 160 |
161 /** | 161 /** |
162 * Available disk space. | 162 * Available disk space. |
163 * @type {number|undefined} | 163 * @type {number|undefined} |
164 */ | 164 */ |
165 var availableSpace = undefined; | 165 var availableSpace = undefined; |
166 | 166 |
167 /** | 167 /** |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 */ | 266 */ |
267 function handleAvailableSpace(event) { | 267 function handleAvailableSpace(event) { |
268 /** | 268 /** |
269 * @type {string} | 269 * @type {string} |
270 */ | 270 */ |
271 availableSpace = event.detail; | 271 availableSpace = event.detail; |
272 $('diskspace-entry').innerHTML = numBytesToText_(availableSpace); | 272 $('diskspace-entry').innerHTML = numBytesToText_(availableSpace); |
273 }; | 273 }; |
274 | 274 |
275 /** | 275 /** |
276 * Event Handler for |cr.quota.onGlobalDataUpdated|. | 276 * Event Handler for |cr.quota.onGlobalInfoUpdated|. |
277 * |event.detail| contains a record which has: | 277 * |event.detail| contains a record which has: |
278 * |type|: | 278 * |type|: |
279 * Storage type, that is either 'temporary' or 'persistent'. | 279 * Storage type, that is either 'temporary' or 'persistent'. |
280 * |usage|: | 280 * |usage|: |
281 * Total storage usage of all hosts. | 281 * Total storage usage of all hosts. |
282 * |unlimitedUsage|: | 282 * |unlimitedUsage|: |
283 * Total storage usage of unlimited-quota origins. | 283 * Total storage usage of unlimited-quota origins. |
284 * |quota|: | 284 * |quota|: |
285 * Total quota of the storage. | 285 * Total quota of the storage. |
286 * | 286 * |
287 * |usage|, |unlimitedUsage| and |quota| can be missing, | 287 * |usage|, |unlimitedUsage| and |quota| can be missing, |
288 * and some additional fields can be included. | 288 * and some additional fields can be included. |
289 * @param {CustomEvent} event GlobalDataUpdated event. | 289 * @param {CustomEvent} event GlobalInfoUpdated event. |
290 */ | 290 */ |
291 function handleGlobalData(event) { | 291 function handleGlobalInfo(event) { |
292 /** | 292 /** |
293 * @type {{ | 293 * @type {{ |
294 * type: {!string}, | 294 * type: {!string}, |
295 * usage: {?number}, | 295 * usage: {?number}, |
296 * unlimitedUsage: {?number} | 296 * unlimitedUsage: {?number} |
297 * quota: {?string} | 297 * quota: {?string} |
298 * }} | 298 * }} |
299 */ | 299 */ |
300 var data = event.detail; | 300 var data = event.detail; |
301 var storageObject = getStorageObject(data.type); | 301 var storageObject = getStorageObject(data.type); |
302 copyAttributes_(data, storageObject.detail.payload); | 302 copyAttributes_(data, storageObject.detail.payload); |
303 storageObject.reveal(); | 303 storageObject.reveal(); |
| 304 if (getTreeViewObject().selectedItem == storageObject) |
| 305 updateDescription(); |
| 306 |
304 }; | 307 }; |
305 | 308 |
306 /** | 309 /** |
307 * Event Handler for |cr.quota.onHostDataUpdated|. | 310 * Event Handler for |cr.quota.onPerHostInfoUpdated|. |
308 * |event.detail| contains records which have: | 311 * |event.detail| contains records which have: |
309 * |host|: | 312 * |host|: |
310 * Hostname of the entry. (e.g. 'example.com') | 313 * Hostname of the entry. (e.g. 'example.com') |
311 * |type|: | 314 * |type|: |
312 * Storage type. 'temporary' or 'persistent' | 315 * Storage type. 'temporary' or 'persistent' |
313 * |usage|: | 316 * |usage|: |
314 * Total storage usage of the host. | 317 * Total storage usage of the host. |
315 * |quota|: | 318 * |quota|: |
316 * Per-host quota. | 319 * Per-host quota. |
317 * | 320 * |
318 * |usage| and |quota| can be missing, | 321 * |usage| and |quota| can be missing, |
319 * and some additional fields can be included. | 322 * and some additional fields can be included. |
320 * @param {CustomEvent} event HostDataUpdated event. | 323 * @param {CustomEvent} event PerHostInfoUpdated event. |
321 */ | 324 */ |
322 function handleHostData(event) { | 325 function handlePerHostInfo(event) { |
323 /** | 326 /** |
324 * @type {Array<{ | 327 * @type {Array<{ |
325 * host: {!string}, | 328 * host: {!string}, |
326 * type: {!string}, | 329 * type: {!string}, |
327 * usage: {?number}, | 330 * usage: {?number}, |
328 * quota: {?number} | 331 * quota: {?number} |
329 * }} | 332 * }} |
330 */ | 333 */ |
331 var dataArray = event.detail; | 334 var dataArray = event.detail; |
332 | 335 |
333 for (var i = 0; i < dataArray.length; ++i) { | 336 for (var i = 0; i < dataArray.length; ++i) { |
334 var data = dataArray[i]; | 337 var data = dataArray[i]; |
335 var hostObject = getHostObject(data.type, data.host); | 338 var hostObject = getHostObject(data.type, data.host); |
336 copyAttributes_(data, hostObject.detail.payload); | 339 copyAttributes_(data, hostObject.detail.payload); |
337 hostObject.reveal(); | 340 hostObject.reveal(); |
| 341 if (getTreeViewObject().selectedItem == hostObject) |
| 342 updateDescription(); |
| 343 |
338 } | 344 } |
339 } | 345 } |
340 | 346 |
341 /** | 347 /** |
342 * Event Handler for |cr.quota.onOriginDataUpdated|. | 348 * Event Handler for |cr.quota.onPerOriginInfoUpdated|. |
343 * |event.detail| contains records which have: | 349 * |event.detail| contains records which have: |
344 * |origin|: | 350 * |origin|: |
345 * Origin URL of the entry. | 351 * Origin URL of the entry. |
346 * |type|: | 352 * |type|: |
347 * Storage type of the entry. 'temporary' or 'persistent'. | 353 * Storage type of the entry. 'temporary' or 'persistent'. |
348 * |host|: | 354 * |host|: |
349 * Hostname of the entry. | 355 * Hostname of the entry. |
350 * |inUse|: | 356 * |inUse|: |
351 * true if the origin is in use. | 357 * true if the origin is in use. |
352 * |usedCount|: | 358 * |usedCount|: |
353 * Used count of the storage from the origin. | 359 * Used count of the storage from the origin. |
354 * |lastAccessTime|: | 360 * |lastAccessTime|: |
355 * Last storage access time from the origin. | 361 * Last storage access time from the origin. |
356 * Number of milliseconds since UNIX epoch (Jan 1, 1970, 0:00:00 UTC). | 362 * Number of milliseconds since UNIX epoch (Jan 1, 1970, 0:00:00 UTC). |
| 363 * |lastModifiedTime|: |
| 364 * Last modified time of the storage from the origin. |
| 365 * Number of milliseconds since UNIX epoch. |
357 * | 366 * |
358 * |inUse|, |usedCount| and |lastAccessTime| can be missing, | 367 * |inUse|, |usedCount|, |lastAccessTime| and |lastModifiedTime| can be missing, |
359 * and some additional fields can be included. | 368 * and some additional fields can be included. |
360 * @param {CustomEvent} event OriginDataUpdated event. | 369 * @param {CustomEvent} event PerOriginInfoUpdated event. |
361 */ | 370 */ |
362 function handleOriginData(event) { | 371 function handlePerOriginInfo(event) { |
363 /** | 372 /** |
364 * @type {Array<{ | 373 * @type {Array<{ |
365 * origin: {!string}, | 374 * origin: {!string}, |
366 * type: {!string}, | 375 * type: {!string}, |
367 * host: {!string}, | 376 * host: {!string}, |
368 * inUse: {?boolean}, | 377 * inUse: {?boolean}, |
369 * usedCount: {?number}, | 378 * usedCount: {?number}, |
370 * lastAccessTime: {?number} | 379 * lastAccessTime: {?number} |
| 380 * lastModifiedTime: {?number} |
371 * }>} | 381 * }>} |
372 */ | 382 */ |
373 var dataArray = event.detail; | 383 var dataArray = event.detail; |
374 | 384 |
375 for (var i = 0; i < dataArray.length; ++i) { | 385 for (var i = 0; i < dataArray.length; ++i) { |
376 var data = dataArray[i]; | 386 var data = dataArray[i]; |
377 var originObject = getOriginObject(data.type, data.host, data.origin); | 387 var originObject = getOriginObject(data.type, data.host, data.origin); |
378 copyAttributes_(data, originObject.detail.payload); | 388 copyAttributes_(data, originObject.detail.payload); |
379 originObject.reveal(); | 389 originObject.reveal(); |
| 390 if (getTreeViewObject().selectedItem == originObject) |
| 391 updateDescription(); |
380 } | 392 } |
381 } | 393 } |
382 | 394 |
383 /** | 395 /** |
384 * Event Handler for |cr.quota.onStatisticsUpdated|. | 396 * Event Handler for |cr.quota.onStatisticsUpdated|. |
385 * |event.detail| contains misc statistics data as dictionary. | 397 * |event.detail| contains misc statistics data as dictionary. |
386 * @param {CustomEvent} event StatisticsUpdated event. | 398 * @param {CustomEvent} event StatisticsUpdated event. |
387 */ | 399 */ |
388 function handleStatistics(event) { | 400 function handleStatistics(event) { |
389 /** | 401 /** |
(...skipping 28 matching lines...) Expand all Loading... |
418 var keyAndLabel = [['type', 'Storage Type'], | 430 var keyAndLabel = [['type', 'Storage Type'], |
419 ['host', 'Host Name'], | 431 ['host', 'Host Name'], |
420 ['origin', 'Origin URL'], | 432 ['origin', 'Origin URL'], |
421 ['usage', 'Total Storage Usage', numBytesToText_], | 433 ['usage', 'Total Storage Usage', numBytesToText_], |
422 ['unlimitedUsage', 'Usage of Unlimited Origins', | 434 ['unlimitedUsage', 'Usage of Unlimited Origins', |
423 numBytesToText_], | 435 numBytesToText_], |
424 ['quota', 'Quota', numBytesToText_], | 436 ['quota', 'Quota', numBytesToText_], |
425 ['inUse', 'Origin is in use?'], | 437 ['inUse', 'Origin is in use?'], |
426 ['usedCount', 'Used count'], | 438 ['usedCount', 'Used count'], |
427 ['lastAccessTime', 'Last Access Time', | 439 ['lastAccessTime', 'Last Access Time', |
| 440 dateToText], |
| 441 ['lastModifiedTime', 'Last Modified Time', |
428 dateToText] | 442 dateToText] |
429 ]; | 443 ]; |
430 for (var i = 0; i < keyAndLabel.length; ++i) { | 444 for (var i = 0; i < keyAndLabel.length; ++i) { |
431 var key = keyAndLabel[i][0]; | 445 var key = keyAndLabel[i][0]; |
432 var label = keyAndLabel[i][1]; | 446 var label = keyAndLabel[i][1]; |
433 var entry = item.detail.payload[key]; | 447 var entry = item.detail.payload[key]; |
434 if (entry === undefined) | 448 if (entry === undefined) |
435 continue; | 449 continue; |
436 | 450 |
437 var normalize = keyAndLabel[i][2] || stringToText_; | 451 var normalize = keyAndLabel[i][2] || stringToText_; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 separator + | 515 separator + |
502 JSON.stringify(dumpStatisticsToObj(), null, 2); | 516 JSON.stringify(dumpStatisticsToObj(), null, 2); |
503 } | 517 } |
504 | 518 |
505 function onLoad() { | 519 function onLoad() { |
506 cr.ui.decorate('tabbox', cr.ui.TabBox); | 520 cr.ui.decorate('tabbox', cr.ui.TabBox); |
507 localize_(document); | 521 localize_(document); |
508 | 522 |
509 cr.quota.onAvailableSpaceUpdated.addEventListener('update', | 523 cr.quota.onAvailableSpaceUpdated.addEventListener('update', |
510 handleAvailableSpace); | 524 handleAvailableSpace); |
511 cr.quota.onGlobalDataUpdated.addEventListener('update', handleGlobalData); | 525 cr.quota.onGlobalInfoUpdated.addEventListener('update', handleGlobalInfo); |
512 cr.quota.onHostDataUpdated.addEventListener('update', handleHostData); | 526 cr.quota.onPerHostInfoUpdated.addEventListener('update', handlePerHostInfo); |
513 cr.quota.onOriginDataUpdated.addEventListener('update', handleOriginData); | 527 cr.quota.onPerOriginInfoUpdated.addEventListener('update', |
| 528 handlePerOriginInfo); |
514 cr.quota.onStatisticsUpdated.addEventListener('update', handleStatistics); | 529 cr.quota.onStatisticsUpdated.addEventListener('update', handleStatistics); |
515 cr.quota.requestData(); | 530 cr.quota.requestInfo(); |
516 | 531 |
517 $('refresh-button').addEventListener('click', cr.quota.requestData, false); | 532 $('refresh-button').addEventListener('click', cr.quota.requestInfo, false); |
518 $('dump-button').addEventListener('click', dump, false); | 533 $('dump-button').addEventListener('click', dump, false); |
519 } | 534 } |
520 | 535 |
521 cr.doc.addEventListener('DOMContentLoaded', onLoad, false); | 536 cr.doc.addEventListener('DOMContentLoaded', onLoad, false); |
522 })(); | 537 })(); |
OLD | NEW |