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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 * The name of the downloads directory. | 82 * The name of the downloads directory. |
87 */ | 83 */ |
88 DirectoryModel.DOWNLOADS_DIRECTORY = 'Downloads'; | 84 DirectoryModel.DOWNLOADS_DIRECTORY = 'Downloads'; |
89 | 85 |
90 /** | 86 /** |
91 * The name of the gdata provider directory. | 87 * The name of the gdata provider directory. |
92 */ | 88 */ |
93 DirectoryModel.GDATA_DIRECTORY = 'drive'; | 89 DirectoryModel.GDATA_DIRECTORY = 'drive'; |
94 | 90 |
95 /** | 91 /** |
92 * GData access mode: disabled (no GData root displayed in the list). | |
93 */ | |
94 DirectoryModel.GDATA_ACCESS_DISABLED = 0; | |
95 | |
96 /** | |
97 * GData access mode: lazy (GData root displayed, no content is fetched yet). | |
98 */ | |
99 DirectoryModel.GDATA_ACCESS_LAZY = 1; | |
100 | |
101 /** | |
102 * GData access mode: full (GData root displayed, content is available). | |
103 */ | |
104 DirectoryModel.GDATA_ACCESS_FULL = 2; | |
105 | |
106 /** | |
96 * DirectoryModel extends cr.EventTarget. | 107 * DirectoryModel extends cr.EventTarget. |
97 */ | 108 */ |
98 DirectoryModel.prototype.__proto__ = cr.EventTarget.prototype; | 109 DirectoryModel.prototype.__proto__ = cr.EventTarget.prototype; |
99 | 110 |
100 /** | 111 /** |
101 * @return {cr.ui.ArrayDataModel} Files in the current directory. | 112 * @return {cr.ui.ArrayDataModel} Files in the current directory. |
102 */ | 113 */ |
103 DirectoryModel.prototype.getFileList = function() { | 114 DirectoryModel.prototype.getFileList = function() { |
104 return this.fileList_; | 115 return this.fileList_; |
105 }; | 116 }; |
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
938 callback) { | 949 callback) { |
939 this.metadataCache_.get(entries, 'filesystem', function(properties) { | 950 this.metadataCache_.get(entries, 'filesystem', function(properties) { |
940 callback(); | 951 callback(); |
941 }); | 952 }); |
942 }; | 953 }; |
943 | 954 |
944 /** | 955 /** |
945 * Get root entries asynchronously. | 956 * Get root entries asynchronously. |
946 * @private | 957 * @private |
947 * @param {function(Array.<Entry>)} callback Called when roots are resolved. | 958 * @param {function(Array.<Entry>)} callback Called when roots are resolved. |
948 * @param {boolean} resolveGData See comment for updateRoots. | 959 * @param {number} gdataAccess One of GDATA_ACCESS_* constants. |
949 */ | 960 */ |
950 DirectoryModel.prototype.resolveRoots_ = function(callback, resolveGData) { | 961 DirectoryModel.prototype.resolveRoots_ = function(callback, gdataAccess) { |
951 var groups = { | 962 var groups = { |
952 downloads: null, | 963 downloads: null, |
953 archives: null, | 964 archives: null, |
954 removables: null, | 965 removables: null, |
955 gdata: null | 966 gdata: null |
956 }; | 967 }; |
957 var self = this; | 968 var self = this; |
958 | 969 |
959 metrics.startInterval('Load.Roots'); | 970 metrics.startInterval('Load.Roots'); |
960 function done() { | 971 function done() { |
(...skipping 17 matching lines...) Expand all Loading... | |
978 function onDownloads(entry) { | 989 function onDownloads(entry) { |
979 groups.downloads = [entry]; | 990 groups.downloads = [entry]; |
980 done(); | 991 done(); |
981 } | 992 } |
982 | 993 |
983 function onDownloadsError(error) { | 994 function onDownloadsError(error) { |
984 groups.downloads = []; | 995 groups.downloads = []; |
985 done(); | 996 done(); |
986 } | 997 } |
987 | 998 |
988 function onGData(entry) { | 999 function onGDataMounted(entry) { |
989 console.log('GData found:', entry); | 1000 console.log('GData mounted:', entry); |
990 self.unmountedGDataEntry_ = null; | 1001 self.unmountedGDataEntry_ = null; |
991 groups.gdata = [entry]; | 1002 groups.gdata = [entry]; |
992 done(); | 1003 done(); |
993 } | 1004 } |
994 | 1005 |
995 function onGDataError(error) { | 1006 function onGDataNotMounted(error) { |
996 console.log('GData error: ' + error); | 1007 console.log('GData not mounted: ' + (error || 'lazy')); |
997 self.unmountedGDataEntry_ = { | 1008 self.unmountedGDataEntry_ = { |
998 unmounted: true, // Clients use this field to distinguish a fake root. | 1009 unmounted: true, // Clients use this field to distinguish a fake root. |
1010 error: error, | |
999 toURL: function() { return '' }, | 1011 toURL: function() { return '' }, |
1000 fullPath: '/' + DirectoryModel.GDATA_DIRECTORY | 1012 fullPath: '/' + DirectoryModel.GDATA_DIRECTORY |
1001 }; | 1013 }; |
1002 groups.gdata = [self.unmountedGDataEntry_]; | 1014 groups.gdata = [self.unmountedGDataEntry_]; |
1003 done(); | 1015 done(); |
1004 } | 1016 } |
1005 | 1017 |
1006 var root = this.root_; | 1018 var root = this.root_; |
1007 root.getDirectory(DirectoryModel.DOWNLOADS_DIRECTORY, { create: false }, | 1019 root.getDirectory(DirectoryModel.DOWNLOADS_DIRECTORY, { create: false }, |
1008 onDownloads, onDownloadsError); | 1020 onDownloads, onDownloadsError); |
1009 util.readDirectory(root, DirectoryModel.ARCHIVE_DIRECTORY, | 1021 util.readDirectory(root, DirectoryModel.ARCHIVE_DIRECTORY, |
1010 append.bind(this, 'archives')); | 1022 append.bind(this, 'archives')); |
1011 util.readDirectory(root, DirectoryModel.REMOVABLE_DIRECTORY, | 1023 util.readDirectory(root, DirectoryModel.REMOVABLE_DIRECTORY, |
1012 append.bind(this, 'removables')); | 1024 append.bind(this, 'removables')); |
1013 if (this.showGData_) { | 1025 |
1014 if (resolveGData) { | 1026 if (gdataAccess == DirectoryModel.GDATA_ACCESS_FULL) { |
1015 root.getDirectory(DirectoryModel.GDATA_DIRECTORY, { create: false }, | 1027 root.getDirectory(DirectoryModel.GDATA_DIRECTORY, { create: false }, |
1016 onGData, onGDataError); | 1028 onGDataMounted, onGDataNotMounted); |
1017 } else { | 1029 } else if (gdataAccess == DirectoryModel.GDATA_ACCESS_LAZY) { |
1018 onGDataError('lazy mount'); | 1030 onGDataNotMounted(); |
1019 } | |
1020 } else { | 1031 } else { |
1021 groups.gdata = []; | 1032 groups.gdata = []; |
1022 } | 1033 } |
1023 }; | 1034 }; |
1024 | 1035 |
1025 /** | 1036 /** |
1026 * @param {function} opt_callback Called when all roots are resolved. | 1037 * @param {function} callback Called when all roots are resolved. |
1027 * @param {boolean} opt_resolveGData If true GData should be resolved for real, | 1038 * @param {number} gdataAccess One of GDATA_ACCESS_* constants. |
1028 * If false a stub entry should be created. | 1039 */ |
1029 */ | 1040 DirectoryModel.prototype.updateRoots = function(callback, gdataAccess) { |
1030 DirectoryModel.prototype.updateRoots = function(opt_callback, | |
1031 opt_resolveGData) { | |
1032 var self = this; | 1041 var self = this; |
1033 this.resolveRoots_(function(rootEntries) { | 1042 this.resolveRoots_(function(rootEntries) { |
1034 var dm = self.rootsList_; | 1043 var dm = self.rootsList_; |
1035 var args = [0, dm.length].concat(rootEntries); | 1044 var args = [0, dm.length].concat(rootEntries); |
1036 dm.splice.apply(dm, args); | 1045 dm.splice.apply(dm, args); |
1037 | 1046 |
1038 self.updateRootsListSelection_(); | 1047 self.updateRootsListSelection_(); |
1039 | 1048 |
1040 if (opt_callback) | 1049 callback(); |
dgozman
2012/05/14 08:52:54
I hope, you've checked that callback was never nul
Vladislav Kaznacheev
2012/05/14 09:45:42
Yes, of course. There are only 3 call sites, all w
| |
1041 opt_callback(); | 1050 }, gdataAccess); |
1042 }, opt_resolveGData); | |
1043 }; | 1051 }; |
1044 | 1052 |
1045 /** | 1053 /** |
1046 * Change root. In case user already opened the root, the last selected | 1054 * Change root. In case user already opened the root, the last selected |
1047 * directory will be selected. | 1055 * directory will be selected. |
1048 * @param {string} rootPath The path of the root. | 1056 * @param {string} rootPath The path of the root. |
1049 */ | 1057 */ |
1050 DirectoryModel.prototype.changeRoot = function(rootPath) { | 1058 DirectoryModel.prototype.changeRoot = function(rootPath) { |
1051 if (this.currentDirByRoot_[rootPath]) { | 1059 if (this.currentDirByRoot_[rootPath]) { |
1052 var onFail = this.changeDirectory.bind(this, rootPath); | 1060 var onFail = this.changeDirectory.bind(this, rootPath); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1276 /** | 1284 /** |
1277 * @private | 1285 * @private |
1278 */ | 1286 */ |
1279 DirectoryModel.Scanner.prototype.recordMetrics_ = function() { | 1287 DirectoryModel.Scanner.prototype.recordMetrics_ = function() { |
1280 metrics.recordInterval('DirectoryScan'); | 1288 metrics.recordInterval('DirectoryScan'); |
1281 if (this.dir_.fullPath == | 1289 if (this.dir_.fullPath == |
1282 '/' + DirectoryModel.DOWNLOADS_DIRECTORY) { | 1290 '/' + DirectoryModel.DOWNLOADS_DIRECTORY) { |
1283 metrics.recordMediumCount('DownloadsCount', this.list_.length); | 1291 metrics.recordMediumCount('DownloadsCount', this.list_.length); |
1284 } | 1292 } |
1285 }; | 1293 }; |
OLD | NEW |