diff options
author | kaznacheev@chromium.org <kaznacheev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-23 14:09:52 +0000 |
---|---|---|
committer | kaznacheev@chromium.org <kaznacheev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-23 14:09:52 +0000 |
commit | 6b978b960775755e665fa0c6d9139495362eba07 (patch) | |
tree | 98e5fc3c27a130f15352a9771c2c26c0686f460d | |
parent | 53caef1fa9b3767d3cefe72f5359255321b2fd60 (diff) | |
download | chromium_src-6b978b960775755e665fa0c6d9139495362eba07.zip chromium_src-6b978b960775755e665fa0c6d9139495362eba07.tar.gz chromium_src-6b978b960775755e665fa0c6d9139495362eba07.tar.bz2 |
Postpone fetching the gdata content until the user opens the gdata folder
BUG=chromium-os:28155
TEST=
Review URL: http://codereview.chromium.org/9834009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128479 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/resources/file_manager/js/directory_model.js | 51 | ||||
-rw-r--r-- | chrome/browser/resources/file_manager/js/file_manager.js | 81 |
2 files changed, 98 insertions, 34 deletions
diff --git a/chrome/browser/resources/file_manager/js/directory_model.js b/chrome/browser/resources/file_manager/js/directory_model.js index ca9f739..aa3bfec 100644 --- a/chrome/browser/resources/file_manager/js/directory_model.js +++ b/chrome/browser/resources/file_manager/js/directory_model.js @@ -10,15 +10,19 @@ const SIMULTANEOUS_RESCAN_INTERVAL = 1000; * Data model of the file manager. * * @param {DirectoryEntry} root File system root. - * @param {boolean} singleSelection True if only one file could be seletet + * @param {boolean} singleSelection True if only one file could be selected * at the time. + * @param {boolean} showGData Defines whether GData root should be should + * (regardless of its mounts status). */ -function DirectoryModel(root, singleSelection) { +function DirectoryModel(root, singleSelection, showGData) { this.root_ = root; this.fileList_ = new cr.ui.ArrayDataModel([]); this.fileListSelection_ = singleSelection ? new cr.ui.ListSingleSelectionModel() : new cr.ui.ListSelectionModel(); + this.showGData_ = showGData; + this.runningScan_ = null; this.pendingScan_ = null; this.rescanTimeout_ = undefined; @@ -352,8 +356,10 @@ DirectoryModel.prototype = { clearTimeout(this.rescanTimeout_); this.rescanTimeout_ = 0; } - if (this.runningScan_) + if (this.runningScan_) { this.runningScan_.cancel(); + this.runningScan_ = null; + } this.pendingScan_ = null; var onDone = function() { @@ -364,6 +370,10 @@ DirectoryModel.prototype = { // Clear the table first. this.fileList_.splice(0, this.fileList_.length); cr.dispatchSimpleEvent(this, 'scan-started'); + if (this.currentDirEntry_ == this.unmountedGDataEntry_) { + onDone(); + return; + } this.runningScan_ = this.createScanner_(this.fileList_, onDone); this.runningScan_.run(); }, @@ -481,7 +491,7 @@ DirectoryModel.prototype = { }, /** - * Canges directory. Causes 'directory-change' event. + * Changes directory. Causes 'directory-change' event. * * @param {string} path New current directory path. */ @@ -491,6 +501,19 @@ DirectoryModel.prototype = { this.changeDirectoryEntry_(dirEntry, autoSelect, false); }.bind(this); + if (this.unmountedGDataEntry_ && + DirectoryModel.getRootType(path) == DirectoryModel.RootType.GDATA) { + this.readonly_ = true; + // TODO(kaznacheeev): Currently if path points to some GData subdirectory + // and GData is not mounted we will change to the fake GData root and + // ignore the rest of the path. Consider remembering the path and + // changing to it once GDdata is mounted. This is only relevant for cases + // when we open the File Manager with an URL pointing to GData (e.g. via + // a bookmark). + onDirectoryResolved(this.unmountedGDataEntry_); + return; + } + this.readonly_ = false; if (path == '/') return onDirectoryResolved(this.root_); @@ -519,7 +542,7 @@ DirectoryModel.prototype = { * false if caused by an user action. */ changeDirectoryEntry_: function(dirEntry, action, initial) { - var current = this.currentEntry; + var previous = this.currentEntry; this.currentDirEntry_ = dirEntry; function onRescanComplete() { action(); @@ -531,7 +554,7 @@ DirectoryModel.prototype = { this.scan_(onRescanComplete); var e = new cr.Event('directory-changed'); - e.previousDirEntry = this.currentEntry; + e.previousDirEntry = previous; e.newDirEntry = dirEntry; e.initial = initial; this.dispatchEvent(e); @@ -770,9 +793,12 @@ DirectoryModel.prototype = { done(); } + var self = this; + function onGData(entry) { console.log('onGData'); console.log(entry); + self.unmountedGDataEntry_ = null; groups.gdata = [entry]; done(); } @@ -780,7 +806,10 @@ DirectoryModel.prototype = { function onGDataError(error) { console.log('onGDataError'); console.log(error); - groups.gdata = []; + self.unmountedGDataEntry_ = { + fullPath: '/' + DirectoryModel.GDATA_DIRECTORY + }; + groups.gdata = [self.unmountedGDataEntry_]; done(); } @@ -791,8 +820,12 @@ DirectoryModel.prototype = { append.bind(this, 'archives')); util.readDirectory(root, DirectoryModel.REMOVABLE_DIRECTORY, append.bind(this, 'removables')); - root.getDirectory(DirectoryModel.GDATA_DIRECTORY, { create: false }, - onGData, onGDataError); + if (this.showGData_) { + root.getDirectory(DirectoryModel.GDATA_DIRECTORY, { create: false }, + onGData, onGDataError); + } else { + groups.gdata = []; + } }, updateRoots: function(opt_callback) { diff --git a/chrome/browser/resources/file_manager/js/file_manager.js b/chrome/browser/resources/file_manager/js/file_manager.js index 1e8237f..46ea6a1 100644 --- a/chrome/browser/resources/file_manager/js/file_manager.js +++ b/chrome/browser/resources/file_manager/js/file_manager.js @@ -31,7 +31,7 @@ function FileManager(dialogDom) { this.butterTimer_ = null; this.currentButter_ = null; - this.subscribedOnDirectoryChanges_ = false; + this.watchedDirectoryUrl_ = null; this.commands_ = {}; @@ -511,6 +511,7 @@ FileManager.prototype = { var offlineHandler = this.onOnlineOffline_.bind(this); window.addEventListener('online', offlineHandler); window.addEventListener('offline', offlineHandler); + offlineHandler(); // Sync with the current state. this.directoryModel_.addEventListener('directory-changed', this.onDirectoryChanged_.bind(this)); @@ -539,10 +540,6 @@ FileManager.prototype = { chrome.fileBrowserPrivate.onFileChanged.addListener( this.onFileChanged_.bind(this)); - // We should initialize Gdata after we subscribed to onMountCompleted. - if (str('ENABLE_GDATA') == '1') - this.initGData_(); - // The list of callbacks to be invoked during the directory rescan after // all paste tasks are complete. this.pasteSuccessCallbacks_ = []; @@ -730,8 +727,10 @@ FileManager.prototype = { this.dialogType_ == FileManager.DialogType.SELECT_FOLDER || this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE; - this.directoryModel_ = new DirectoryModel(this.filesystem_.root, - sigleSelection); + this.directoryModel_ = new DirectoryModel( + this.filesystem_.root, + sigleSelection, + str('ENABLE_GDATA') == '1'); var dataModel = this.directoryModel_.fileList; var collator = this.collator_; @@ -797,8 +796,17 @@ FileManager.prototype = { FileManager.prototype.initGData_ = function() { metrics.startInterval('Load.GData'); - // TODO(zelidrag): We should do this first time user selects this provider. chrome.fileBrowserPrivate.addMount('', 'gdata', {}); + if (this.gdataMountTimer_) { + clearTimeout(this.gdataMountTimer_); + } + this.gdataMountTimer_ = setTimeout(function() { + this.gdataMountTimer_ = null; + if (this.isOnGData()) { + // TODO(kaznacheev): show the message in the file list space. + this.alert.show('Could not connect to GData'); + } + }.bind(this), 10 * 1000); }; /** @@ -2501,26 +2509,34 @@ FileManager.prototype = { FileManager.prototype.onMountCompleted_ = function(event) { var self = this; + var changeDirectoryTo = null; + if (event && event.mountType == 'gdata') { metrics.recordInterval('Load.GData'); + if (this.gdataMountTimer_) { + clearTimeout(this.gdataMountTimer_); + this.gdataMountTimer_ = null; + } if (event.status == 'success') { - self.gdataMounted_ = true; - self.gdataMountInfo_ = { + this.gdataMounted_ = true; + this.gdataMountInfo_ = { "mountPath": event.mountPath, "sourceUrl": event.sourceUrl, "mountType": event.mountType, "mountCondition": event.status }; + if (this.isOnGData()) { + // We are currently on an unmounted GData directory, force a rescan. + changeDirectoryTo = this.directoryModel_.rootPath; + } } else { - self.gdataMounted_ = false; - self.gdataMountInfo_ = null; + this.gdataMounted_ = false; + this.gdataMountInfo_ = null; } } chrome.fileBrowserPrivate.getMountPoints(function(mountPoints) { self.setMountPoints_(mountPoints); - var changeDirectoryTo = null; - if (event.eventType == 'mount') { // Mount request finished - remove it. var index = self.mountRequests_.indexOf(event.sourceUrl); @@ -3423,31 +3439,46 @@ FileManager.prototype = { var self = this; - if (this.subscribedOnDirectoryChanges_) { - chrome.fileBrowserPrivate.removeFileWatch(event.previousDirEntry.toURL(), + if (this.watchedDirectoryUrl_) { + if (this.watchedDirectoryUrl_ != event.previousDirEntry.toURL()) { + console.warn('event.previousDirEntry does not match File Manager state', + event, this.watchedDirectoryUrl_); + } + chrome.fileBrowserPrivate.removeFileWatch(this.watchedDirectoryUrl_, function(result) { if (!result) { console.log('Failed to remove file watch'); } }); + this.watchedDirectoryUrl_ = null; } - if (event.newDirEntry.fullPath != '/') { - this.subscribedOnDirectoryChanges_ = true; - chrome.fileBrowserPrivate.addFileWatch(event.newDirEntry.toURL(), + if (event.newDirEntry.fullPath != '/' && + DirectoryModel.getRootType(event.newDirEntry.fullPath) != + DirectoryModel.GDATA_DIRECTORY) { + // Currently file watchers do not work on GData. When they start working + // we should be careful not to watch GData before it is mounted. + this.watchedDirectoryUrl_ = event.newDirEntry.toURL(); + chrome.fileBrowserPrivate.addFileWatch(this.watchedDirectoryUrl_, function(result) { if (!result) { console.log('Failed to add file watch'); + this.watchedDirectoryUrl_ = null; } - }); + }.bind(this)); } this.updateVolumeMetadata_(); - if (this.isOnGData()) + if (this.isOnGData()) { this.dialogContainer_.setAttribute('gdata', true); - else + if (!this.requestedGDataMount_) { // Request GData mount only once. + this.requestedGDataMount_ = true; + this.initGData_(); + } + } else { this.dialogContainer_.removeAttribute('gdata'); + } }; FileManager.prototype.updateVolumeMetadata_ = function() { @@ -3506,15 +3537,15 @@ FileManager.prototype = { * return. */ FileManager.prototype.onUnload_ = function() { - if (this.subscribedOnDirectoryChanges_) { - this.subscribedOnDirectoryChanges_ = false; + if (this.watchedDirectoryUrl_) { chrome.fileBrowserPrivate.removeFileWatch( - this.getCurrentDirectoryURL(), + this.watchedDirectoryUrl_, function(result) { if (!result) { console.log('Failed to remove file watch'); } }); + this.watchedDirectoryUrl_ = null; } }; |