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

Side by Side Diff: ui/file_manager/file_manager/background/js/volume_manager.js

Issue 893913003: Files.app: Fix closure compiler error. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Created 5 years, 10 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 | ui/file_manager/file_manager/background/js/volume_manager_unittest.js » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 * Represents each volume, such as "drive", "download directory", each "USB 6 * Represents each volume, such as "drive", "download directory", each "USB
7 * flush storage", or "mounted zip archive" etc. 7 * flush storage", or "mounted zip archive" etc.
8 * 8 *
9 * @constructor 9 * @constructor
10 * @struct 10 * @struct
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 * Holds VolumeInfo instances. 348 * Holds VolumeInfo instances.
349 * @type {cr.ui.ArrayDataModel} 349 * @type {cr.ui.ArrayDataModel}
350 * @private 350 * @private
351 */ 351 */
352 this.model_ = new cr.ui.ArrayDataModel([]); 352 this.model_ = new cr.ui.ArrayDataModel([]);
353 this.model_.setCompareFunction(field, 353 this.model_.setCompareFunction(field,
354 /** @type {function(*, *): number} */ 354 /** @type {function(*, *): number} */
355 (volumeManagerUtil.compareVolumeInfo_)); 355 (volumeManagerUtil.compareVolumeInfo_));
356 this.model_.sort(field, 'asc'); 356 this.model_.sort(field, 'asc');
357 357
358 /** @private {!Object.<string, !importer.Resolver.<!VolumeInfo>>} */
359 this.volumeInfoResolvers_ = {};
360
361 Object.freeze(this); 358 Object.freeze(this);
362 } 359 }
363 360
364 VolumeInfoList.prototype = { 361 VolumeInfoList.prototype = {
365 get length() { return this.model_.length; } 362 get length() { return this.model_.length; }
366 }; 363 };
367 364
368 /** 365 /**
369 * Adds the event listener to listen the change of volume info. 366 * Adds the event listener to listen the change of volume info.
370 * @param {string} type The name of the event. 367 * @param {string} type The name of the event.
(...skipping 16 matching lines...) Expand all
387 * Adds the volumeInfo to the appropriate position. If there already exists, 384 * Adds the volumeInfo to the appropriate position. If there already exists,
388 * just replaces it. 385 * just replaces it.
389 * @param {VolumeInfo} volumeInfo The information of the new volume. 386 * @param {VolumeInfo} volumeInfo The information of the new volume.
390 */ 387 */
391 VolumeInfoList.prototype.add = function(volumeInfo) { 388 VolumeInfoList.prototype.add = function(volumeInfo) {
392 var index = this.findIndex(volumeInfo.volumeId); 389 var index = this.findIndex(volumeInfo.volumeId);
393 if (index !== -1) 390 if (index !== -1)
394 this.model_.splice(index, 1, volumeInfo); 391 this.model_.splice(index, 1, volumeInfo);
395 else 392 else
396 this.model_.push(volumeInfo); 393 this.model_.push(volumeInfo);
397
398 // Some folks might be expecting this volume to be initialized soon.
399 // In that case there'll be a resolver function (associated with a promise)
400 // waiting for us here.
401 var resolver = this.volumeInfoResolvers_[volumeInfo.volumeId];
402 if (resolver) {
403 resolver.resolve(volumeInfo);
404 }
405 }; 394 };
406 395
407 /** 396 /**
408 * Removes the VolumeInfo having the given ID. 397 * Removes the VolumeInfo having the given ID.
409 * @param {string} volumeId ID of the volume. 398 * @param {string} volumeId ID of the volume.
410 */ 399 */
411 VolumeInfoList.prototype.remove = function(volumeId) { 400 VolumeInfoList.prototype.remove = function(volumeId) {
412 var index = this.findIndex(volumeId); 401 var index = this.findIndex(volumeId);
413 if (index !== -1) 402 if (index !== -1)
414 this.model_.splice(index, 1); 403 this.model_.splice(index, 1);
415
416 // Remove any associated resolvers.
417 delete this.volumeInfoResolvers_[volumeId];
418 }; 404 };
419 405
420 /** 406 /**
421 * Obtains an index from the volume ID. 407 * Obtains an index from the volume ID.
422 * @param {string} volumeId Volume ID. 408 * @param {string} volumeId Volume ID.
423 * @return {number} Index of the volume. 409 * @return {number} Index of the volume.
424 */ 410 */
425 VolumeInfoList.prototype.findIndex = function(volumeId) { 411 VolumeInfoList.prototype.findIndex = function(volumeId) {
426 for (var i = 0; i < this.model_.length; i++) { 412 for (var i = 0; i < this.model_.length; i++) {
427 if (this.model_.item(i).volumeId === volumeId) 413 if (this.model_.item(i).volumeId === volumeId)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 470
485 /** 471 /**
486 * Returns a promise that will be resolved when volume info, identified 472 * Returns a promise that will be resolved when volume info, identified
487 * by {@code volumeId} is created. 473 * by {@code volumeId} is created.
488 * 474 *
489 * @param {string} volumeId 475 * @param {string} volumeId
490 * @return {!Promise.<!VolumeInfo>} The VolumeInfo. Will not resolve 476 * @return {!Promise.<!VolumeInfo>} The VolumeInfo. Will not resolve
491 * if the volume is never mounted. 477 * if the volume is never mounted.
492 */ 478 */
493 VolumeInfoList.prototype.whenVolumeInfoReady = function(volumeId) { 479 VolumeInfoList.prototype.whenVolumeInfoReady = function(volumeId) {
494 var info = this.findByVolumeId_(volumeId); 480 return new Promise(function(fulfill) {
495 if (!!info) { 481 var handler = function() {
496 return Promise.resolve(info); 482 var info = this.findByVolumeId_(volumeId);
497 } 483 if (info) {
498 484 fulfill(info);
499 var resolver = this.volumeInfoResolvers_[volumeId]; 485 this.model_.removeEventListener('splice', handler);
500 if (!resolver) { 486 }
501 resolver = new importer.Resolver(); 487 }.bind(this);
502 this.volumeInfoResolvers_[volumeId] = resolver; 488 this.model_.addEventListener('splice', handler);
503 } 489 handler();
504 490 }.bind(this));
505 return resolver.promise;
506 }; 491 };
507 492
508 /** 493 /**
509 * @param {number} index The index of the volume in the list. 494 * @param {number} index The index of the volume in the list.
510 * @return {!VolumeInfo} The VolumeInfo instance. 495 * @return {!VolumeInfo} The VolumeInfo instance.
511 */ 496 */
512 VolumeInfoList.prototype.item = function(index) { 497 VolumeInfoList.prototype.item = function(index) {
513 return /** @type {!VolumeInfo} */ (this.model_.item(index)); 498 return /** @type {!VolumeInfo} */ (this.model_.item(index));
514 }; 499 };
515 500
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 this.isDriveBased; 1028 this.isDriveBased;
1044 1029
1045 /** 1030 /**
1046 * Whether the entry is read only or not. 1031 * Whether the entry is read only or not.
1047 * @type {boolean} 1032 * @type {boolean}
1048 */ 1033 */
1049 this.isReadOnly = isReadOnly; 1034 this.isReadOnly = isReadOnly;
1050 1035
1051 Object.freeze(this); 1036 Object.freeze(this);
1052 } 1037 }
OLDNEW
« no previous file with comments | « no previous file | ui/file_manager/file_manager/background/js/volume_manager_unittest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698