OLD | NEW |
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 * @implements {VolumeInfo} |
10 * @struct | 11 * @struct |
11 * | 12 * |
12 * @param {VolumeManagerCommon.VolumeType} volumeType The type of the volume. | 13 * @param {VolumeManagerCommon.VolumeType} volumeType The type of the volume. |
13 * @param {string} volumeId ID of the volume. | 14 * @param {string} volumeId ID of the volume. |
14 * @param {FileSystem} fileSystem The file system object for this volume. | 15 * @param {FileSystem} fileSystem The file system object for this volume. |
15 * @param {(string|undefined)} error The error if an error is found. | 16 * @param {(string|undefined)} error The error if an error is found. |
16 * @param {(string|undefined)} deviceType The type of device | 17 * @param {(string|undefined)} deviceType The type of device |
17 * ('usb'|'sd'|'optical'|'mobile'|'unknown') (as defined in | 18 * ('usb'|'sd'|'optical'|'mobile'|'unknown') (as defined in |
18 * chromeos/disks/disk_mount_manager.cc). Can be undefined. | 19 * chromeos/disks/disk_mount_manager.cc). Can be undefined. |
19 * @param {(string|undefined)} devicePath Identifier of the device that the | 20 * @param {(string|undefined)} devicePath Identifier of the device that the |
20 * volume belongs to. Can be undefined. | 21 * volume belongs to. Can be undefined. |
21 * @param {boolean} isReadOnly True if the volume is read only. | 22 * @param {boolean} isReadOnly True if the volume is read only. |
22 * @param {!{displayName:string, isCurrentProfile:boolean}} profile Profile | 23 * @param {!{displayName:string, isCurrentProfile:boolean}} profile Profile |
23 * information. | 24 * information. |
24 * @param {string} label Label of the volume. | 25 * @param {string} label Label of the volume. |
25 * @param {(string|undefined)} extensionId Id of the extension providing this | 26 * @param {(string|undefined)} extensionId Id of the extension providing this |
26 * volume. Empty for native volumes. | 27 * volume. Empty for native volumes. |
27 * @param {boolean} hasMedia When true the volume has been identified | 28 * @param {boolean} hasMedia When true the volume has been identified |
28 * as containing media such as photos or videos. | 29 * as containing media such as photos or videos. |
29 * @param {boolean} configurable When true, then the volume can be configured. | 30 * @param {boolean} configurable When true, then the volume can be configured. |
30 * @param {VolumeManagerCommon.Source} source Source of the volume's data. | 31 * @param {VolumeManagerCommon.Source} source Source of the volume's data. |
31 */ | 32 */ |
32 function VolumeInfo( | 33 function VolumeInfoImpl( |
33 volumeType, | 34 volumeType, |
34 volumeId, | 35 volumeId, |
35 fileSystem, | 36 fileSystem, |
36 error, | 37 error, |
37 deviceType, | 38 deviceType, |
38 devicePath, | 39 devicePath, |
39 isReadOnly, | 40 isReadOnly, |
40 profile, | 41 profile, |
41 label, | 42 label, |
42 extensionId, | 43 extensionId, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 this.devicePath_ = devicePath; | 84 this.devicePath_ = devicePath; |
84 this.isReadOnly_ = isReadOnly; | 85 this.isReadOnly_ = isReadOnly; |
85 this.profile_ = Object.freeze(profile); | 86 this.profile_ = Object.freeze(profile); |
86 this.extensionId_ = extensionId; | 87 this.extensionId_ = extensionId; |
87 this.hasMedia_ = hasMedia; | 88 this.hasMedia_ = hasMedia; |
88 this.configurable_ = configurable; | 89 this.configurable_ = configurable; |
89 this.watchable_ = watchable; | 90 this.watchable_ = watchable; |
90 this.source_ = source; | 91 this.source_ = source; |
91 } | 92 } |
92 | 93 |
93 VolumeInfo.prototype = /** @struct */ { | 94 VolumeInfoImpl.prototype = /** @struct */ { |
94 /** | 95 /** |
95 * @return {VolumeManagerCommon.VolumeType} Volume type. | 96 * @return {VolumeManagerCommon.VolumeType} Volume type. |
96 */ | 97 */ |
97 get volumeType() { | 98 get volumeType() { |
98 return this.volumeType_; | 99 return this.volumeType_; |
99 }, | 100 }, |
100 /** | 101 /** |
101 * @return {string} Volume ID. | 102 * @return {string} Volume ID. |
102 */ | 103 */ |
103 get volumeId() { | 104 get volumeId() { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 }, | 185 }, |
185 /** | 186 /** |
186 * @return {VolumeManagerCommon.Source} Source of the volume's data. | 187 * @return {VolumeManagerCommon.Source} Source of the volume's data. |
187 */ | 188 */ |
188 get source() { | 189 get source() { |
189 return this.source_; | 190 return this.source_; |
190 } | 191 } |
191 }; | 192 }; |
192 | 193 |
193 /** | 194 /** |
194 * Starts resolving the display root and obtains it. It may take long time for | 195 * @override |
195 * Drive. Once resolved, it is cached. | |
196 * | |
197 * @param {function(!DirectoryEntry)=} opt_onSuccess Success callback with the | |
198 * display root directory as an argument. | |
199 * @param {function(*)=} opt_onFailure Failure callback. | |
200 * @return {!Promise.<!DirectoryEntry>} | |
201 */ | 196 */ |
202 VolumeInfo.prototype.resolveDisplayRoot = function(opt_onSuccess, | 197 VolumeInfoImpl.prototype.resolveDisplayRoot = function(opt_onSuccess, |
203 opt_onFailure) { | 198 opt_onFailure) { |
204 if (!this.displayRootPromise_) { | 199 if (!this.displayRootPromise_) { |
205 // TODO(mtomasz): Do not add VolumeInfo which failed to resolve root, and | 200 // TODO(mtomasz): Do not add VolumeInfo which failed to resolve root, and |
206 // remove this if logic. Call opt_onSuccess() always, instead. | 201 // remove this if logic. Call opt_onSuccess() always, instead. |
207 if (this.volumeType !== VolumeManagerCommon.VolumeType.DRIVE) { | 202 if (this.volumeType !== VolumeManagerCommon.VolumeType.DRIVE) { |
208 if (this.fileSystem_) | 203 if (this.fileSystem_) |
209 this.displayRootPromise_ = /** @type {Promise.<!DirectoryEntry>} */ ( | 204 this.displayRootPromise_ = /** @type {Promise.<!DirectoryEntry>} */ ( |
210 Promise.resolve(this.fileSystem_.root)); | 205 Promise.resolve(this.fileSystem_.root)); |
211 else | 206 else |
212 this.displayRootPromise_ = /** @type {Promise.<!DirectoryEntry>} */ ( | 207 this.displayRootPromise_ = /** @type {Promise.<!DirectoryEntry>} */ ( |
213 Promise.reject(this.error)); | 208 Promise.reject(this.error)); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 // it fails, accessing to some path later will just become | 334 // it fails, accessing to some path later will just become |
340 // a fast-fetch and it re-triggers full-feed fetch. | 335 // a fast-fetch and it re-triggers full-feed fetch. |
341 fileSystem.root.createReader().readEntries( | 336 fileSystem.root.createReader().readEntries( |
342 function() { /* do nothing */ }, | 337 function() { /* do nothing */ }, |
343 function(error) { | 338 function(error) { |
344 console.error( | 339 console.error( |
345 'Triggering full feed fetch is failed: ' + | 340 'Triggering full feed fetch is failed: ' + |
346 error.name); | 341 error.name); |
347 }); | 342 }); |
348 } | 343 } |
349 return new VolumeInfo( | 344 return new VolumeInfoImpl( |
350 /** @type {VolumeManagerCommon.VolumeType} */ | 345 /** @type {VolumeManagerCommon.VolumeType} */ |
351 (volumeMetadata.volumeType), | 346 (volumeMetadata.volumeType), |
352 volumeMetadata.volumeId, | 347 volumeMetadata.volumeId, |
353 fileSystem, | 348 fileSystem, |
354 volumeMetadata.mountCondition, | 349 volumeMetadata.mountCondition, |
355 volumeMetadata.deviceType, | 350 volumeMetadata.deviceType, |
356 volumeMetadata.devicePath, | 351 volumeMetadata.devicePath, |
357 volumeMetadata.isReadOnly, | 352 volumeMetadata.isReadOnly, |
358 volumeMetadata.profile, | 353 volumeMetadata.profile, |
359 localizedLabel, | 354 localizedLabel, |
360 volumeMetadata.extensionId, | 355 volumeMetadata.extensionId, |
361 volumeMetadata.hasMedia, | 356 volumeMetadata.hasMedia, |
362 volumeMetadata.configurable, | 357 volumeMetadata.configurable, |
363 volumeMetadata.watchable, | 358 volumeMetadata.watchable, |
364 /** @type {VolumeManagerCommon.Source} */ | 359 /** @type {VolumeManagerCommon.Source} */ |
365 (volumeMetadata.source)); | 360 (volumeMetadata.source)); |
366 }) | 361 }) |
367 .catch( | 362 .catch( |
368 /** | 363 /** |
369 * @param {*} error | 364 * @param {*} error |
370 */ | 365 */ |
371 function(error) { | 366 function(error) { |
372 console.error('Failed to mount a file system: ' + | 367 console.error('Failed to mount a file system: ' + |
373 volumeMetadata.volumeId + ' because of: ' + | 368 volumeMetadata.volumeId + ' because of: ' + |
374 (error.stack || error)); | 369 (error.stack || error)); |
375 volumeManagerUtil.reportMountError(volumeMetadata, error); | 370 volumeManagerUtil.reportMountError(volumeMetadata, error); |
376 | 371 |
377 return new VolumeInfo( | 372 return new VolumeInfoImpl( |
378 /** @type {VolumeManagerCommon.VolumeType} */ | 373 /** @type {VolumeManagerCommon.VolumeType} */ |
379 (volumeMetadata.volumeType), | 374 (volumeMetadata.volumeType), |
380 volumeMetadata.volumeId, | 375 volumeMetadata.volumeId, |
381 null, // File system is not found. | 376 null, // File system is not found. |
382 volumeMetadata.mountCondition, | 377 volumeMetadata.mountCondition, |
383 volumeMetadata.deviceType, | 378 volumeMetadata.deviceType, |
384 volumeMetadata.devicePath, | 379 volumeMetadata.devicePath, |
385 volumeMetadata.isReadOnly, | 380 volumeMetadata.isReadOnly, |
386 volumeMetadata.profile, | 381 volumeMetadata.profile, |
387 localizedLabel, | 382 localizedLabel, |
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1194 this.rootType === VolumeManagerCommon.RootType.DRIVE_OFFLINE; | 1189 this.rootType === VolumeManagerCommon.RootType.DRIVE_OFFLINE; |
1195 | 1190 |
1196 /** | 1191 /** |
1197 * Whether the entry is read only or not. | 1192 * Whether the entry is read only or not. |
1198 * @type {boolean} | 1193 * @type {boolean} |
1199 */ | 1194 */ |
1200 this.isReadOnly = isReadOnly; | 1195 this.isReadOnly = isReadOnly; |
1201 | 1196 |
1202 Object.freeze(this); | 1197 Object.freeze(this); |
1203 } | 1198 } |
OLD | NEW |