Index: chrome/browser/resources/file_manager/js/directory_model.js |
diff --git a/chrome/browser/resources/file_manager/js/directory_model.js b/chrome/browser/resources/file_manager/js/directory_model.js |
index 49f4af43a5a24e5dfe0541c5ece6872170dfda3b..2155fd481fe2526c4bc31b951ca04972042c1e91 100644 |
--- a/chrome/browser/resources/file_manager/js/directory_model.js |
+++ b/chrome/browser/resources/file_manager/js/directory_model.js |
@@ -53,9 +53,8 @@ function DirectoryModel(root, singleSelection, showGData, metadataCache) { |
this.filters_ = {}; |
this.setFilterHidden(true); |
- // Readonly status. |
- this.readonly_ = false; |
- this.currentVolumeMetadata_ = {rootPath: '/'}; |
+ /** @type {Hash.<srting, boolead>} */ |
Vladislav Kaznacheev
2012/04/25 08:43:11
2 typos
SeRya
2012/04/25 10:15:16
Done.
|
+ this.volumeReadOnlyStatus_ = {}; |
this.offline_ = false; |
} |
@@ -139,7 +138,26 @@ DirectoryModel.prototype.getRootName = function() { |
* @return {boolean} True if current directory is read only. |
*/ |
DirectoryModel.prototype.isReadOnly = function() { |
- return this.readonly_; |
+ return this.isPathReadOnly(this.getCurrentRootPath()); |
+}; |
+ |
+/** |
+ * @param {strin} path Path to check. |
+ * @return {boolean} True if the |path| is read only. |
+ */ |
+DirectoryModel.prototype.isPathReadOnly = function(path) { |
+ switch (DirectoryModel.getRootType(path)) { |
+ case DirectoryModel.RootType.REMOVABLE: |
+ return !!this.volumeReadOnlyStatus_[DirectoryModel.getRootPath(path)]; |
+ case DirectoryModel.RootType.ARCHIVE: |
+ return true; |
+ case DirectoryModel.RootType.DOWNLOADS: |
+ return false; |
+ case DirectoryModel.RootType.GDATA: |
+ return this.offline_; |
Vladislav Kaznacheev
2012/04/25 08:43:11
Lets use !navigator.onLine directly and remove the
SeRya
2012/04/25 10:15:16
Done.
|
+ default: |
+ return true; |
+ } |
}; |
/** |
@@ -155,7 +173,6 @@ DirectoryModel.prototype.isOffline = function() { |
DirectoryModel.prototype.setOffline = function(value) { |
if (this.offline_ != value) { |
this.offline_ = !!value; |
- this.updateReadonlyStatus_(); |
} |
}; |
@@ -708,8 +725,6 @@ DirectoryModel.prototype.changeDirectoryEntry_ = function(dirEntry, action, |
// is loaded at this point. |
chrome.test.sendMessage('directory-change-complete'); |
} |
- this.updateReadonlyStatus_(); |
- this.updateVolumeMetadata_(); |
this.updateRootsListSelection_(); |
this.scan_(onRescanComplete); |
this.currentDirByRoot_[this.getCurrentRootPath()] = dirEntry.fullPath; |
@@ -915,6 +930,7 @@ DirectoryModel.prototype.resolveRoots_ = function(callback, resolveGData) { |
removables: null, |
gdata: null |
}; |
+ var self = this; |
metrics.startInterval('Load.Roots'); |
function done() { |
@@ -922,6 +938,7 @@ DirectoryModel.prototype.resolveRoots_ = function(callback, resolveGData) { |
if (!groups[i]) |
return; |
+ self.updateVolumeReadOnlyStatus_(groups.removables); |
callback(groups.downloads. |
concat(groups.gdata). |
concat(groups.archives). |
@@ -944,8 +961,6 @@ DirectoryModel.prototype.resolveRoots_ = function(callback, resolveGData) { |
done(); |
} |
- var self = this; |
- |
function onGData(entry) { |
console.log('GData found:', entry); |
self.unmountedGDataEntry_ = null; |
@@ -1044,48 +1059,17 @@ DirectoryModel.prototype.updateRootsListSelection_ = function() { |
}; |
/** |
+ * @param {Array.<DirectoryEntry>} roots Removable volumes entries. |
* @private |
*/ |
-DirectoryModel.prototype.updateReadonlyStatus_ = function() { |
- switch (this.getRootType()) { |
- case DirectoryModel.RootType.REMOVABLE: |
- this.readonly_ = !!this.currentVolumeMetadata_.isReadOnly; |
- break; |
- case DirectoryModel.RootType.ARCHIVE: |
- this.readonly_ = true; |
- break; |
- case DirectoryModel.RootType.DOWNLOADS: |
- this.readonly_ = false; |
- break; |
- case DirectoryModel.RootType.GDATA: |
- this.readonly_ = this.offline_; |
- break; |
- default: |
- this.readonly_ = true; |
- break; |
- } |
-}; |
- |
-/** |
- * @private |
- */ |
-DirectoryModel.prototype.updateVolumeMetadata_ = function() { |
- var rootPath = this.getCurrentRootPath(); |
- if (this.currentVolumeMetadata_.rootPath != rootPath) { |
- var metadata = this.currentVolumeMetadata_ = {rootPath: rootPath}; |
- if (DirectoryModel.getRootType(rootPath) == |
- DirectoryModel.RootType.REMOVABLE) { |
- var self = this; |
- this.root_.getDirectory(rootPath, {}, function(entry) { |
- chrome.fileBrowserPrivate.getVolumeMetadata(entry.toURL(), |
- function(systemMetadata) { |
- if (systemMetadata) { |
- metadata.isReadOnly = systemMetadata.isReadOnly; |
- self.updateReadonlyStatus_(); |
- } |
- }); |
- }); |
- } |
+DirectoryModel.prototype.updateVolumeReadOnlyStatus_ = function(roots) { |
+ var status = this.volumeReadOnlyStatus_ = {}; |
+ for (var i = 0; i < roots.length; i++) { |
+ status[roots[i].fullPath] = false; |
+ chrome.fileBrowserPrivate.getVolumeMetadata(roots[i].toURL(), |
Vladislav Kaznacheev
2012/04/25 08:43:11
It looks like you are making this call for all roo
SeRya
2012/04/25 10:15:16
No, it's for removable only (I mentioned in JsDoc)
|
+ function(systemMetadata, path) { |
+ status[path] = !!(systemMetadata && systemMetadata.isReadOnly); |
+ }.bind(null, roots[i].fullPath)); |
} |
}; |