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

Side by Side Diff: chrome/browser/resources/file_manager/js/volume_manager.js

Issue 11414152: Drive: Rename GData to Drive in extension JS API (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: review fix (comment #7) Created 8 years 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
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 * 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 this.deferredQueue_ = [];
119 function step(mountPoints) { 119 function step(mountPoints) {
120 if (index < mountPoints.length) { 120 if (index < mountPoints.length) {
121 var info = mountPoints[index]; 121 var info = mountPoints[index];
122 if (info.mountType == 'gdata') 122 if (info.mountType == 'drive')
123 console.error('GData is not expected initially mounted'); 123 console.error('GData is not expected initially mounted');
124 var error = info.mountCondition ? 'error_' + info.mountCondition : ''; 124 var error = info.mountCondition ? 'error_' + info.mountCondition : '';
125 function onVolumeInfo(volume) { 125 function onVolumeInfo(volume) {
126 mountedVolumes.push(volume); 126 mountedVolumes.push(volume);
127 index++; 127 index++;
128 step(mountPoints); 128 step(mountPoints);
129 } 129 }
130 self.makeVolumeInfo_('/' + info.mountPath, error, onVolumeInfo); 130 self.makeVolumeInfo_('/' + info.mountPath, error, onVolumeInfo);
131 } else { 131 } else {
132 for (var i = 0; i < mountedVolumes.length; i++) { 132 for (var i = 0; i < mountedVolumes.length; i++) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 this.dispatchEvent(e); 190 this.dispatchEvent(e);
191 } 191 }
192 this.finishRequest_(requestKey, status); 192 this.finishRequest_(requestKey, status);
193 193
194 if (event.status == 'success') { 194 if (event.status == 'success') {
195 delete this.mountedVolumes_[mountPath]; 195 delete this.mountedVolumes_[mountPath];
196 cr.dispatchSimpleEvent(this, 'change'); 196 cr.dispatchSimpleEvent(this, 'change');
197 } 197 }
198 } 198 }
199 199
200 if (event.mountType == 'gdata') { 200 if (event.mountType == 'drive') {
201 if (event.status == 'success') { 201 if (event.status == 'success') {
202 if (event.eventType == 'mount') { 202 if (event.eventType == 'mount') {
203 // If the mount is not requested, the mount status will not be changed 203 // If the mount is not requested, the mount status will not be changed
204 // at mountGData(). Sets it here in such a case. 204 // at mountGData(). Sets it here in such a case.
205 var self = this; 205 var self = this;
206 var timeout = setTimeout(function() { 206 var timeout = setTimeout(function() {
207 if (self.getGDataStatus() == VolumeManager.GDataStatus.UNMOUNTED) 207 if (self.getGDataStatus() == VolumeManager.GDataStatus.UNMOUNTED)
208 self.setGDataStatus_(VolumeManager.GDataStatus.MOUNTING); 208 self.setGDataStatus_(VolumeManager.GDataStatus.MOUNTING);
209 timeout = null; 209 timeout = null;
210 }, VolumeManager.MOUNTING_DELAY); 210 }, VolumeManager.MOUNTING_DELAY);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 readonly: !!metadata && metadata.isReadOnly 261 readonly: !!metadata && metadata.isReadOnly
262 }); 262 });
263 } 263 }
264 chrome.fileBrowserPrivate.getVolumeMetadata( 264 chrome.fileBrowserPrivate.getVolumeMetadata(
265 util.makeFilesystemUrl(mountPath), onVolumeMetadata); 265 util.makeFilesystemUrl(mountPath), onVolumeMetadata);
266 }; 266 };
267 267
268 /** 268 /**
269 * Creates string to match mount events with requests. 269 * Creates string to match mount events with requests.
270 * @param {string} requestType 'mount' | 'unmount'. 270 * @param {string} requestType 'mount' | 'unmount'.
271 * @param {string} mountType 'device' | 'file' | 'network' | 'gdata'. 271 * @param {string} mountType 'device' | 'file' | 'network' | 'drive'.
272 * @param {string} mountOrSourcePath Source path provided by API after 272 * @param {string} mountOrSourcePath Source path provided by API after
273 * resolving mount request or mountPath for unmount request. 273 * resolving mount request or mountPath for unmount request.
274 * @return {string} Key for |this.requests_|. 274 * @return {string} Key for |this.requests_|.
275 * @private 275 * @private
276 */ 276 */
277 VolumeManager.prototype.makeRequestKey_ = function(requestType, 277 VolumeManager.prototype.makeRequestKey_ = function(requestType,
278 mountType, 278 mountType,
279 mountOrSourcePath) { 279 mountOrSourcePath) {
280 return requestType + ':' + mountType + ':' + mountOrSourcePath; 280 return requestType + ':' + mountType + ':' + mountOrSourcePath;
281 }; 281 };
282 282
283 283
284 /** 284 /**
285 * @param {Function} successCallback Success callback. 285 * @param {Function} successCallback Success callback.
286 * @param {Function} errorCallback Error callback. 286 * @param {Function} errorCallback Error callback.
287 */ 287 */
288 VolumeManager.prototype.mountGData = function(successCallback, errorCallback) { 288 VolumeManager.prototype.mountGData = function(successCallback, errorCallback) {
289 if (this.getGDataStatus() == VolumeManager.GDataStatus.ERROR) { 289 if (this.getGDataStatus() == VolumeManager.GDataStatus.ERROR) {
290 this.setGDataStatus_(VolumeManager.GDataStatus.UNMOUNTED); 290 this.setGDataStatus_(VolumeManager.GDataStatus.UNMOUNTED);
291 } 291 }
292 var self = this; 292 var self = this;
293 this.mount_('', 'gdata', function(mountPath) { 293 this.mount_('', 'drive', function(mountPath) {
294 this.waitGDataLoaded_(mountPath, function(success, error) { 294 this.waitGDataLoaded_(mountPath, function(success, error) {
295 if (success) { 295 if (success) {
296 successCallback(mountPath); 296 successCallback(mountPath);
297 } else { 297 } else {
298 errorCallback(error); 298 errorCallback(error);
299 } 299 }
300 }); 300 });
301 }, function(error) { 301 }, function(error) {
302 if (self.getGDataStatus() != VolumeManager.GDataStatus.MOUNTED) 302 if (self.getGDataStatus() != VolumeManager.GDataStatus.MOUNTED)
303 self.setGDataStatus_(VolumeManager.GDataStatus.ERROR); 303 self.setGDataStatus_(VolumeManager.GDataStatus.ERROR);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 * @return {Object} Structure created in |startRequest_|. 384 * @return {Object} Structure created in |startRequest_|.
385 * @private 385 * @private
386 */ 386 */
387 VolumeManager.prototype.getVolumeInfo_ = function(mountPath) { 387 VolumeManager.prototype.getVolumeInfo_ = function(mountPath) {
388 this.validateMountPath_(mountPath); 388 this.validateMountPath_(mountPath);
389 return this.mountedVolumes_[mountPath] || {}; 389 return this.mountedVolumes_[mountPath] || {};
390 }; 390 };
391 391
392 /** 392 /**
393 * @param {string} url URL for for |fileBrowserPrivate.addMount|. 393 * @param {string} url URL for for |fileBrowserPrivate.addMount|.
394 * @param {'gdata'|'file'} mountType Mount type for 394 * @param {'drive'|'file'} mountType Mount type for
395 * |fileBrowserPrivate.addMount|. 395 * |fileBrowserPrivate.addMount|.
396 * @param {Function} successCallback Success callback. 396 * @param {Function} successCallback Success callback.
397 * @param {Function} errorCallback Error callback. 397 * @param {Function} errorCallback Error callback.
398 * @private 398 * @private
399 */ 399 */
400 VolumeManager.prototype.mount_ = function(url, mountType, 400 VolumeManager.prototype.mount_ = function(url, mountType,
401 successCallback, errorCallback) { 401 successCallback, errorCallback) {
402 if (this.deferredQueue_) { 402 if (this.deferredQueue_) {
403 this.deferredQueue_.push(this.mount_.bind(this, 403 this.deferredQueue_.push(this.mount_.bind(this,
404 url, mountType, successCallback, errorCallback)); 404 url, mountType, successCallback, errorCallback));
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 }; 500 };
501 501
502 /** 502 /**
503 * @param {string} mountPath Mount path. 503 * @param {string} mountPath Mount path.
504 * @private 504 * @private
505 */ 505 */
506 VolumeManager.prototype.validateMountPath_ = function(mountPath) { 506 VolumeManager.prototype.validateMountPath_ = function(mountPath) {
507 if (!/^\/(((archive|removable)\/[^\/]+)|drive|Downloads)$/.test(mountPath)) 507 if (!/^\/(((archive|removable)\/[^\/]+)|drive|Downloads)$/.test(mountPath))
508 throw new Error('Invalid mount path: ', mountPath); 508 throw new Error('Invalid mount path: ', mountPath);
509 }; 509 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/file_manager/js/mock_chrome.js ('k') | chrome/common/extensions/api/file_browser_private.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698