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 * VolumeManager is responsible for tracking list of mounted volumes. | 6 * VolumeManager is responsible for tracking list of mounted volumes. |
7 * | 7 * |
8 * @constructor | 8 * @constructor |
9 * @extends {cr.EventTarget} | 9 * @extends {cr.EventTarget} |
10 */ | 10 */ |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 }; | 108 }; |
109 | 109 |
110 /** | 110 /** |
111 * Initialized mount points. | 111 * Initialized mount points. |
112 * @private | 112 * @private |
113 */ | 113 */ |
114 VolumeManager.prototype.initMountPoints_ = function() { | 114 VolumeManager.prototype.initMountPoints_ = function() { |
115 var mountedVolumes = []; | 115 var mountedVolumes = []; |
116 var self = this; | 116 var self = this; |
117 var index = 0; | 117 var index = 0; |
| 118 this.deferredQueue_ = []; |
118 function step(mountPoints) { | 119 function step(mountPoints) { |
119 if (index < mountPoints.length) { | 120 if (index < mountPoints.length) { |
120 var info = mountPoints[index]; | 121 var info = mountPoints[index]; |
121 if (info.mountType == 'gdata') | 122 if (info.mountType == 'gdata') |
122 console.error('GData is not expected initially mounted'); | 123 console.error('GData is not expected initially mounted'); |
123 var error = info.mountCondition ? 'error_' + info.mountCondition : ''; | 124 var error = info.mountCondition ? 'error_' + info.mountCondition : ''; |
124 function onVolumeInfo(volume) { | 125 function onVolumeInfo(volume) { |
125 mountedVolumes.push(volume); | 126 mountedVolumes.push(volume); |
126 index++; | 127 index++; |
127 step(mountPoints); | 128 step(mountPoints); |
128 } | 129 } |
129 self.makeVolumeInfo_('/' + info.mountPath, error, onVolumeInfo); | 130 self.makeVolumeInfo_('/' + info.mountPath, error, onVolumeInfo); |
130 } else { | 131 } else { |
131 for (var i = 0; i < mountedVolumes.length; i++) { | 132 for (var i = 0; i < mountedVolumes.length; i++) { |
132 var volume = mountedVolumes[i]; | 133 var volume = mountedVolumes[i]; |
133 self.mountedVolumes_[volume.mountPath] = volume; | 134 self.mountedVolumes_[volume.mountPath] = volume; |
134 } | 135 } |
135 | 136 |
136 // Subscribe to the mount completed event when mount points initialized. | 137 // Subscribe to the mount completed event when mount points initialized. |
137 chrome.fileBrowserPrivate.onMountCompleted.addListener( | 138 chrome.fileBrowserPrivate.onMountCompleted.addListener( |
138 self.onMountCompleted_.bind(self)); | 139 self.onMountCompleted_.bind(self)); |
139 | 140 |
| 141 var deferredQueue = self.deferredQueue_; |
| 142 self.deferredQueue_ = null; |
| 143 for (var i = 0; i < deferredQueue.length; i++) { |
| 144 deferredQueue[i](); |
| 145 } |
| 146 |
140 if (mountedVolumes.length > 0) | 147 if (mountedVolumes.length > 0) |
141 cr.dispatchSimpleEvent(self, 'change'); | 148 cr.dispatchSimpleEvent(self, 'change'); |
142 } | 149 } |
143 } | 150 } |
144 | 151 |
145 chrome.fileBrowserPrivate.getMountPoints(step); | 152 chrome.fileBrowserPrivate.getMountPoints(step); |
146 }; | 153 }; |
147 | 154 |
148 /** | 155 /** |
149 * Event handler called when some volume was mounted or unmouted. | 156 * Event handler called when some volume was mounted or unmouted. |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 /** | 302 /** |
296 * Unmounts volume. | 303 * Unmounts volume. |
297 * @param {string} mountPath Volume mounted path. | 304 * @param {string} mountPath Volume mounted path. |
298 * @param {Function} successCallback Success callback. | 305 * @param {Function} successCallback Success callback. |
299 * @param {Function} errorCallback Error callback. | 306 * @param {Function} errorCallback Error callback. |
300 */ | 307 */ |
301 VolumeManager.prototype.unmount = function(mountPath, | 308 VolumeManager.prototype.unmount = function(mountPath, |
302 successCallback, | 309 successCallback, |
303 errorCallback) { | 310 errorCallback) { |
304 this.validateMountPath_(mountPath); | 311 this.validateMountPath_(mountPath); |
| 312 if (this.deferredQueue_) { |
| 313 this.deferredQueue_.push(this.unmount.bind(this, |
| 314 mountPath, successCallback, errorCallback)); |
| 315 return; |
| 316 } |
| 317 |
305 var volumeInfo = this.mountedVolumes_[mountPath]; | 318 var volumeInfo = this.mountedVolumes_[mountPath]; |
306 if (!volumeInfo) { | 319 if (!volumeInfo) { |
307 errorCallback(VolumeManager.Error.NOT_MOUNTED); | 320 errorCallback(VolumeManager.Error.NOT_MOUNTED); |
308 return; | 321 return; |
309 } | 322 } |
310 | 323 |
311 chrome.fileBrowserPrivate.removeMount(util.makeFilesystemUrl(mountPath)); | 324 chrome.fileBrowserPrivate.removeMount(util.makeFilesystemUrl(mountPath)); |
312 var requestKey = this.makeRequestKey_('unmount', '', volumeInfo.mountPath); | 325 var requestKey = this.makeRequestKey_('unmount', '', volumeInfo.mountPath); |
313 this.startRequest_(requestKey, successCallback, errorCallback); | 326 this.startRequest_(requestKey, successCallback, errorCallback); |
314 }; | 327 }; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 /** | 376 /** |
364 * @param {string} url URL for for |fileBrowserPrivate.addMount|. | 377 * @param {string} url URL for for |fileBrowserPrivate.addMount|. |
365 * @param {'gdata'|'file'} mountType Mount type for | 378 * @param {'gdata'|'file'} mountType Mount type for |
366 * |fileBrowserPrivate.addMount|. | 379 * |fileBrowserPrivate.addMount|. |
367 * @param {Function} successCallback Success callback. | 380 * @param {Function} successCallback Success callback. |
368 * @param {Function} errorCallback Error callback. | 381 * @param {Function} errorCallback Error callback. |
369 * @private | 382 * @private |
370 */ | 383 */ |
371 VolumeManager.prototype.mount_ = function(url, mountType, | 384 VolumeManager.prototype.mount_ = function(url, mountType, |
372 successCallback, errorCallback) { | 385 successCallback, errorCallback) { |
| 386 if (this.deferredQueue_) { |
| 387 this.deferredQueue_.push(this.mount_.bind(this, |
| 388 url, mountType, successCallback, errorCallback)); |
| 389 return; |
| 390 } |
| 391 |
373 chrome.fileBrowserPrivate.addMount(url, mountType, {}, | 392 chrome.fileBrowserPrivate.addMount(url, mountType, {}, |
374 function(sourcePath) { | 393 function(sourcePath) { |
375 console.log('Mount request: url=' + url + '; mountType=' + mountType + | 394 console.log('Mount request: url=' + url + '; mountType=' + mountType + |
376 '; sourceUrl=' + sourcePath); | 395 '; sourceUrl=' + sourcePath); |
377 var requestKey = this.makeRequestKey_('mount', mountType, sourcePath); | 396 var requestKey = this.makeRequestKey_('mount', mountType, sourcePath); |
378 this.startRequest_(requestKey, successCallback, errorCallback); | 397 this.startRequest_(requestKey, successCallback, errorCallback); |
379 }.bind(this)); | 398 }.bind(this)); |
380 }; | 399 }; |
381 | 400 |
382 /** | 401 /** |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 }; | 484 }; |
466 | 485 |
467 /** | 486 /** |
468 * @param {string} mountPath Mount path. | 487 * @param {string} mountPath Mount path. |
469 * @private | 488 * @private |
470 */ | 489 */ |
471 VolumeManager.prototype.validateMountPath_ = function(mountPath) { | 490 VolumeManager.prototype.validateMountPath_ = function(mountPath) { |
472 if (!/^\/(((archive|removable)\/[^\/]+)|drive|Downloads)$/.test(mountPath)) | 491 if (!/^\/(((archive|removable)\/[^\/]+)|drive|Downloads)$/.test(mountPath)) |
473 throw new Error('Invalid mount path: ', mountPath); | 492 throw new Error('Invalid mount path: ', mountPath); |
474 }; | 493 }; |
OLD | NEW |