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 |
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 | 873 |
874 function changeDirectoryEntry(directoryEntry, initial, opt_callback) { | 874 function changeDirectoryEntry(directoryEntry, initial, opt_callback) { |
875 tracker.stop(); | 875 tracker.stop(); |
876 if (!tracker.hasChanged) | 876 if (!tracker.hasChanged) |
877 self.changeDirectoryEntry_(initial, directoryEntry, opt_callback); | 877 self.changeDirectoryEntry_(initial, directoryEntry, opt_callback); |
878 } | 878 } |
879 | 879 |
880 var INITIAL = true; | 880 var INITIAL = true; |
881 var EXISTS = true; | 881 var EXISTS = true; |
882 | 882 |
883 function changeToDefault() { | 883 function changeToDefault(leafName) { |
884 var def = self.getDefaultDirectory(); | 884 var def = self.getDefaultDirectory(); |
885 self.resolveDirectory(def, function(directoryEntry) { | 885 self.resolveDirectory(def, function(directoryEntry) { |
886 resolveCallback(def, '', !EXISTS); | 886 resolveCallback(def, leafName, !EXISTS); |
887 changeDirectoryEntry(directoryEntry, INITIAL); | 887 changeDirectoryEntry(directoryEntry, INITIAL); |
888 }, function(error) { | 888 }, function(error) { |
889 console.error('Failed to resolve default directory: ' + def, error); | 889 console.error('Failed to resolve default directory: ' + def, error); |
890 resolveCallback('/', '', !EXISTS); | 890 resolveCallback('/', leafName, !EXISTS); |
891 }); | 891 }); |
892 } | 892 } |
893 | 893 |
894 function noParentDirectory(error) { | 894 function noParentDirectory(leafName, error) { |
895 console.log('Can\'t resolve parent directory: ' + path, error); | 895 console.log('Can\'t resolve parent directory: ' + path, error); |
896 changeToDefault(); | 896 changeToDefault(leafName); |
897 } | 897 } |
898 | 898 |
899 if (DirectoryModel.isSystemDirectory(path)) { | 899 if (DirectoryModel.isSystemDirectory(path)) { |
900 changeToDefault(); | 900 changeToDefault(''); |
901 return; | 901 return; |
902 } | 902 } |
903 | 903 |
904 this.resolveDirectory(path, function(directoryEntry) { | 904 this.resolveDirectory(path, function(directoryEntry) { |
905 resolveCallback(directoryEntry.fullPath, '', !EXISTS); | 905 resolveCallback(directoryEntry.fullPath, '', !EXISTS); |
906 changeDirectoryEntry(directoryEntry, INITIAL); | 906 changeDirectoryEntry(directoryEntry, INITIAL); |
907 }, function(error) { | 907 }, function(error) { |
908 // Usually, leaf does not exist, because it's just a suggested file name. | 908 // Usually, leaf does not exist, because it's just a suggested file name. |
909 var fileExists = error.code == FileError.TYPE_MISMATCH_ERR; | 909 var fileExists = error.code == FileError.TYPE_MISMATCH_ERR; |
| 910 var nameDelimiter = path.lastIndexOf('/'); |
| 911 var parentDirectoryPath = path.substr(0, nameDelimiter); |
| 912 var leafName = path.substr(nameDelimiter + 1); |
910 if (fileExists || error.code == FileError.NOT_FOUND_ERR) { | 913 if (fileExists || error.code == FileError.NOT_FOUND_ERR) { |
911 var nameDelimiter = path.lastIndexOf('/'); | |
912 var parentDirectoryPath = path.substr(0, nameDelimiter); | |
913 if (DirectoryModel.isSystemDirectory(parentDirectoryPath)) { | 914 if (DirectoryModel.isSystemDirectory(parentDirectoryPath)) { |
914 changeToDefault(); | 915 changeToDefault(leafName); |
915 return; | 916 return; |
916 } | 917 } |
917 self.resolveDirectory(parentDirectoryPath, | 918 self.resolveDirectory(parentDirectoryPath, |
918 function(parentDirectoryEntry) { | 919 function(parentDirectoryEntry) { |
919 var fileName = path.substr(nameDelimiter + 1); | 920 var fileName = path.substr(nameDelimiter + 1); |
920 resolveCallback(parentDirectoryEntry.fullPath, fileName, fileExists); | 921 resolveCallback(parentDirectoryEntry.fullPath, fileName, fileExists); |
921 changeDirectoryEntry(parentDirectoryEntry, | 922 changeDirectoryEntry(parentDirectoryEntry, |
922 !INITIAL /*HACK*/, | 923 !INITIAL /*HACK*/, |
923 function() { | 924 function() { |
924 self.selectEntry(fileName); | 925 self.selectEntry(fileName); |
925 }); | 926 }); |
926 // TODO(kaznacheev): Fix history.replaceState for the File Browser and | 927 // TODO(kaznacheev): Fix history.replaceState for the File Browser and |
927 // change !INITIAL to INITIAL. Passing |false| makes things | 928 // change !INITIAL to INITIAL. Passing |false| makes things |
928 // less ugly for now. | 929 // less ugly for now. |
929 }, noParentDirectory); | 930 }, noParentDirectory.bind(null, leafName)); |
930 } else { | 931 } else { |
931 // Unexpected errors. | 932 // Unexpected errors. |
932 console.error('Directory resolving error: ', error); | 933 console.error('Directory resolving error: ', error); |
933 changeToDefault(); | 934 changeToDefault(leafName); |
934 } | 935 } |
935 }); | 936 }); |
936 }; | 937 }; |
937 | 938 |
938 /** | 939 /** |
939 * Sets up the default path. | 940 * Sets up the default path. |
940 */ | 941 */ |
941 DirectoryModel.prototype.setupDefaultPath = function() { | 942 DirectoryModel.prototype.setupDefaultPath = function() { |
942 this.setupPath(this.getDefaultDirectory()); | 943 this.setupPath(this.getDefaultDirectory()); |
943 }; | 944 }; |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1385 }.bind(this)); | 1386 }.bind(this)); |
1386 } | 1387 } |
1387 }; | 1388 }; |
1388 | 1389 |
1389 /** | 1390 /** |
1390 * @return {DirectoryEntry} Current watched directory entry. | 1391 * @return {DirectoryEntry} Current watched directory entry. |
1391 */ | 1392 */ |
1392 FileWatcher.prototype.getWatchedDirectoryEntry = function() { | 1393 FileWatcher.prototype.getWatchedDirectoryEntry = function() { |
1393 return this.watchedDirectoryEntry_; | 1394 return this.watchedDirectoryEntry_; |
1394 }; | 1395 }; |
OLD | NEW |