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 // If directory files changes too often, don't rescan directory more than once | 5 // If directory files changes too often, don't rescan directory more than once |
6 // per specified interval | 6 // per specified interval |
7 var SIMULTANEOUS_RESCAN_INTERVAL = 1000; | 7 var SIMULTANEOUS_RESCAN_INTERVAL = 1000; |
8 // Used for operations that require almost instant rescan. | 8 // Used for operations that require almost instant rescan. |
9 var SHORT_RESCAN_INTERVAL = 100; | 9 var SHORT_RESCAN_INTERVAL = 100; |
10 | 10 |
11 /** | 11 /** |
12 * Data model of the file manager. | 12 * Data model of the file manager. |
13 * | 13 * |
14 * @constructor | 14 * @constructor |
15 * @param {DirectoryEntry} root File system root. | 15 * @param {DirectoryEntry} root File system root. |
16 * @param {boolean} singleSelection True if only one file could be selected | 16 * @param {boolean} singleSelection True if only one file could be selected |
17 * at the time. | 17 * at the time. |
18 * @param {boolean} showGData Defines whether GData root should be should | |
19 * (regardless of its mounts status). | |
20 * @param {MetadataCache} metadataCache The metadata cache service. | 18 * @param {MetadataCache} metadataCache The metadata cache service. |
21 */ | 19 */ |
22 function DirectoryModel(root, singleSelection, showGData, metadataCache) { | 20 function DirectoryModel(root, singleSelection, metadataCache) { |
23 this.root_ = root; | 21 this.root_ = root; |
24 this.metadataCache_ = metadataCache; | 22 this.metadataCache_ = metadataCache; |
25 this.fileList_ = new cr.ui.ArrayDataModel([]); | 23 this.fileList_ = new cr.ui.ArrayDataModel([]); |
26 this.fileListSelection_ = singleSelection ? | 24 this.fileListSelection_ = singleSelection ? |
27 new cr.ui.ListSingleSelectionModel() : new cr.ui.ListSelectionModel(); | 25 new cr.ui.ListSingleSelectionModel() : new cr.ui.ListSelectionModel(); |
28 | 26 |
29 this.showGData_ = showGData; | |
30 | |
31 this.runningScan_ = null; | 27 this.runningScan_ = null; |
32 this.pendingScan_ = null; | 28 this.pendingScan_ = null; |
33 this.rescanTimeout_ = undefined; | 29 this.rescanTimeout_ = undefined; |
34 this.scanFailures_ = 0; | 30 this.scanFailures_ = 0; |
35 | 31 |
36 // DirectoryEntry representing the current directory of the dialog. | 32 // DirectoryEntry representing the current directory of the dialog. |
37 this.currentDirEntry_ = root; | 33 this.currentDirEntry_ = root; |
38 | 34 |
39 this.fileList_.prepareSort = this.prepareSort_.bind(this); | 35 this.fileList_.prepareSort = this.prepareSort_.bind(this); |
40 | 36 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 * The name of the downloads directory. | 84 * The name of the downloads directory. |
89 */ | 85 */ |
90 DirectoryModel.DOWNLOADS_DIRECTORY = 'Downloads'; | 86 DirectoryModel.DOWNLOADS_DIRECTORY = 'Downloads'; |
91 | 87 |
92 /** | 88 /** |
93 * The name of the gdata provider directory. | 89 * The name of the gdata provider directory. |
94 */ | 90 */ |
95 DirectoryModel.GDATA_DIRECTORY = 'drive'; | 91 DirectoryModel.GDATA_DIRECTORY = 'drive'; |
96 | 92 |
97 /** | 93 /** |
| 94 * GData access mode: disabled (no GData root displayed in the list). |
| 95 */ |
| 96 DirectoryModel.GDATA_ACCESS_DISABLED = 0; |
| 97 |
| 98 /** |
| 99 * GData access mode: lazy (GData root displayed, no content is fetched yet). |
| 100 */ |
| 101 DirectoryModel.GDATA_ACCESS_LAZY = 1; |
| 102 |
| 103 /** |
| 104 * GData access mode: full (GData root displayed, content is available). |
| 105 */ |
| 106 DirectoryModel.GDATA_ACCESS_FULL = 2; |
| 107 |
| 108 /** |
98 * DirectoryModel extends cr.EventTarget. | 109 * DirectoryModel extends cr.EventTarget. |
99 */ | 110 */ |
100 DirectoryModel.prototype.__proto__ = cr.EventTarget.prototype; | 111 DirectoryModel.prototype.__proto__ = cr.EventTarget.prototype; |
101 | 112 |
102 /** | 113 /** |
103 * @return {cr.ui.ArrayDataModel} Files in the current directory. | 114 * @return {cr.ui.ArrayDataModel} Files in the current directory. |
104 */ | 115 */ |
105 DirectoryModel.prototype.getFileList = function() { | 116 DirectoryModel.prototype.getFileList = function() { |
106 return this.fileList_; | 117 return this.fileList_; |
107 }; | 118 }; |
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 callback) { | 962 callback) { |
952 this.metadataCache_.get(entries, 'filesystem', function(properties) { | 963 this.metadataCache_.get(entries, 'filesystem', function(properties) { |
953 callback(); | 964 callback(); |
954 }); | 965 }); |
955 }; | 966 }; |
956 | 967 |
957 /** | 968 /** |
958 * Get root entries asynchronously. | 969 * Get root entries asynchronously. |
959 * @private | 970 * @private |
960 * @param {function(Array.<Entry>)} callback Called when roots are resolved. | 971 * @param {function(Array.<Entry>)} callback Called when roots are resolved. |
961 * @param {boolean} resolveGData See comment for updateRoots. | 972 * @param {number} gdataAccess One of GDATA_ACCESS_* constants. |
962 */ | 973 */ |
963 DirectoryModel.prototype.resolveRoots_ = function(callback, resolveGData) { | 974 DirectoryModel.prototype.resolveRoots_ = function(callback, gdataAccess) { |
964 var groups = { | 975 var groups = { |
965 downloads: null, | 976 downloads: null, |
966 archives: null, | 977 archives: null, |
967 removables: null, | 978 removables: null, |
968 gdata: null | 979 gdata: null |
969 }; | 980 }; |
970 var self = this; | 981 var self = this; |
971 | 982 |
972 metrics.startInterval('Load.Roots'); | 983 metrics.startInterval('Load.Roots'); |
973 function done() { | 984 function done() { |
(...skipping 17 matching lines...) Expand all Loading... |
991 function onDownloads(entry) { | 1002 function onDownloads(entry) { |
992 groups.downloads = [entry]; | 1003 groups.downloads = [entry]; |
993 done(); | 1004 done(); |
994 } | 1005 } |
995 | 1006 |
996 function onDownloadsError(error) { | 1007 function onDownloadsError(error) { |
997 groups.downloads = []; | 1008 groups.downloads = []; |
998 done(); | 1009 done(); |
999 } | 1010 } |
1000 | 1011 |
1001 function onGData(entry) { | 1012 function onGDataMounted(entry) { |
1002 console.log('GData found:', entry); | 1013 console.log('GData mounted:', entry); |
1003 self.unmountedGDataEntry_ = null; | 1014 self.unmountedGDataEntry_ = null; |
1004 groups.gdata = [entry]; | 1015 groups.gdata = [entry]; |
1005 done(); | 1016 done(); |
1006 } | 1017 } |
1007 | 1018 |
1008 function onGDataError(error) { | 1019 function onGDataNotMounted(error) { |
1009 console.log('GData error: ' + error); | 1020 console.log('GData not mounted: ' + (error || 'lazy')); |
1010 self.unmountedGDataEntry_ = { | 1021 self.unmountedGDataEntry_ = { |
1011 unmounted: true, // Clients use this field to distinguish a fake root. | 1022 unmounted: true, // Clients use this field to distinguish a fake root. |
| 1023 error: error, |
1012 toURL: function() { return '' }, | 1024 toURL: function() { return '' }, |
1013 fullPath: '/' + DirectoryModel.GDATA_DIRECTORY | 1025 fullPath: '/' + DirectoryModel.GDATA_DIRECTORY |
1014 }; | 1026 }; |
1015 groups.gdata = [self.unmountedGDataEntry_]; | 1027 groups.gdata = [self.unmountedGDataEntry_]; |
1016 done(); | 1028 done(); |
1017 } | 1029 } |
1018 | 1030 |
1019 var root = this.root_; | 1031 var root = this.root_; |
1020 root.getDirectory(DirectoryModel.DOWNLOADS_DIRECTORY, { create: false }, | 1032 root.getDirectory(DirectoryModel.DOWNLOADS_DIRECTORY, { create: false }, |
1021 onDownloads, onDownloadsError); | 1033 onDownloads, onDownloadsError); |
1022 util.readDirectory(root, DirectoryModel.ARCHIVE_DIRECTORY, | 1034 util.readDirectory(root, DirectoryModel.ARCHIVE_DIRECTORY, |
1023 append.bind(this, 'archives')); | 1035 append.bind(this, 'archives')); |
1024 util.readDirectory(root, DirectoryModel.REMOVABLE_DIRECTORY, | 1036 util.readDirectory(root, DirectoryModel.REMOVABLE_DIRECTORY, |
1025 append.bind(this, 'removables')); | 1037 append.bind(this, 'removables')); |
1026 if (this.showGData_) { | 1038 |
1027 if (resolveGData) { | 1039 if (gdataAccess == DirectoryModel.GDATA_ACCESS_FULL) { |
1028 root.getDirectory(DirectoryModel.GDATA_DIRECTORY, { create: false }, | 1040 root.getDirectory(DirectoryModel.GDATA_DIRECTORY, { create: false }, |
1029 onGData, onGDataError); | 1041 onGDataMounted, onGDataNotMounted); |
1030 } else { | 1042 } else if (gdataAccess == DirectoryModel.GDATA_ACCESS_LAZY) { |
1031 onGDataError('lazy mount'); | 1043 onGDataNotMounted(); |
1032 } | |
1033 } else { | 1044 } else { |
1034 groups.gdata = []; | 1045 groups.gdata = []; |
1035 } | 1046 } |
1036 }; | 1047 }; |
1037 | 1048 |
1038 /** | 1049 /** |
1039 * @param {function} opt_callback Called when all roots are resolved. | 1050 * @param {function} callback Called when all roots are resolved. |
1040 * @param {boolean} opt_resolveGData If true GData should be resolved for real, | 1051 * @param {number} gdataAccess One of GDATA_ACCESS_* constants. |
1041 * If false a stub entry should be created. | 1052 */ |
1042 */ | 1053 DirectoryModel.prototype.updateRoots = function(callback, gdataAccess) { |
1043 DirectoryModel.prototype.updateRoots = function(opt_callback, | |
1044 opt_resolveGData) { | |
1045 var self = this; | 1054 var self = this; |
1046 this.resolveRoots_(function(rootEntries) { | 1055 this.resolveRoots_(function(rootEntries) { |
1047 var dm = self.rootsList_; | 1056 var dm = self.rootsList_; |
1048 var args = [0, dm.length].concat(rootEntries); | 1057 var args = [0, dm.length].concat(rootEntries); |
1049 dm.splice.apply(dm, args); | 1058 dm.splice.apply(dm, args); |
1050 | 1059 |
1051 self.updateRootsListSelection_(); | 1060 self.updateRootsListSelection_(); |
1052 | 1061 |
1053 if (opt_callback) | 1062 callback(); |
1054 opt_callback(); | 1063 }, gdataAccess); |
1055 }, opt_resolveGData); | |
1056 }; | 1064 }; |
1057 | 1065 |
1058 /** | 1066 /** |
1059 * Find roots list item by root path. | 1067 * Find roots list item by root path. |
1060 * | 1068 * |
1061 * @param {string} path Root path. | 1069 * @param {string} path Root path. |
1062 * @return {number} Index of the item. | 1070 * @return {number} Index of the item. |
1063 * @private | 1071 * @private |
1064 */ | 1072 */ |
1065 DirectoryModel.prototype.findRootsListItem_ = function(path) { | 1073 DirectoryModel.prototype.findRootsListItem_ = function(path) { |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1275 /** | 1283 /** |
1276 * @private | 1284 * @private |
1277 */ | 1285 */ |
1278 DirectoryModel.Scanner.prototype.recordMetrics_ = function() { | 1286 DirectoryModel.Scanner.prototype.recordMetrics_ = function() { |
1279 metrics.recordInterval('DirectoryScan'); | 1287 metrics.recordInterval('DirectoryScan'); |
1280 if (this.dir_.fullPath == | 1288 if (this.dir_.fullPath == |
1281 '/' + DirectoryModel.DOWNLOADS_DIRECTORY) { | 1289 '/' + DirectoryModel.DOWNLOADS_DIRECTORY) { |
1282 metrics.recordMediumCount('DownloadsCount', this.list_.length); | 1290 metrics.recordMediumCount('DownloadsCount', this.list_.length); |
1283 } | 1291 } |
1284 }; | 1292 }; |
OLD | NEW |