| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 /** | 5 /** |
| 6 * Global fileManager reference useful for poking at from the console. | 6 * Global fileManager reference useful for poking at from the console. |
| 7 */ | 7 */ |
| 8 var fileManager; | 8 var fileManager; |
| 9 | 9 |
| 10 /** | 10 /** |
| 11 * Kick off the file manager dialog. | 11 * Kick off the file manager dialog. |
| 12 * | 12 * |
| 13 * Called by main.html after the dom has been parsed. | 13 * Called by main.html after the dom has been parsed. |
| 14 */ | 14 */ |
| 15 function init() { | 15 function init() { |
| 16 var rootPaths = ['Downloads', 'removable', 'archive', 'tmp']; | 16 FileManager.initStrings(function () { |
| 17 | 17 metrics.startInterval('Construct'); |
| 18 function onEntriesFound(filesystem, entries) { | 18 fileManager = new FileManager(document.body); |
| 19 metrics.recordTime('EnumerateRoots'); | 19 metrics.recordTime('Construct'); |
| 20 FileManager.initStrings(function () { | 20 // We're ready to run. Tests can monitor for this state with |
| 21 metrics.startInterval('Construct'); | 21 // ExtensionTestMessageListener listener("ready"); |
| 22 fileManager = new FileManager(document.body, filesystem, entries); | 22 // ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| 23 metrics.recordTime('Construct'); | 23 chrome.test.sendMessage('ready'); |
| 24 metrics.recordTime('TotalLoad'); | 24 }); |
| 25 // We're ready to run. Tests can monitor for this state with | |
| 26 // ExtensionTestMessageListener listener("ready"); | |
| 27 // ASSERT_TRUE(listener.WaitUntilSatisfied()); | |
| 28 chrome.test.sendMessage('ready'); | |
| 29 }); | |
| 30 } | |
| 31 | |
| 32 function onFileSystemFound(filesystem) { | |
| 33 metrics.recordTime('RequestLocalFileSystem'); | |
| 34 console.log('Found filesystem: ' + filesystem.name, filesystem); | |
| 35 | |
| 36 var entries = []; | |
| 37 | |
| 38 function onPathError(path, err) { | |
| 39 console.error('Error locating root path: ' + path + ': ' + err); | |
| 40 } | |
| 41 | |
| 42 function onEntryFound(entry) { | |
| 43 if (entry) { | |
| 44 entries.push(entry); | |
| 45 } else { | |
| 46 onEntriesFound(filesystem, entries); | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 metrics.startInterval('EnumerateRoots'); | |
| 51 if (filesystem.name.match(/^chrome-extension_\S+:external/i)) { | |
| 52 // We've been handed the local filesystem, whose root directory | |
| 53 // cannot be enumerated. | |
| 54 util.getDirectories(filesystem.root, {create: false}, rootPaths, | |
| 55 onEntryFound, onPathError); | |
| 56 } else { | |
| 57 util.forEachDirEntry(filesystem.root, onEntryFound); | |
| 58 } | |
| 59 }; | |
| 60 | |
| 61 util.installFileErrorToString(); | |
| 62 | |
| 63 console.log('Requesting filesystem.'); | |
| 64 metrics.startInterval('RequestLocalFileSystem'); | |
| 65 chrome.fileBrowserPrivate.requestLocalFileSystem(onFileSystemFound); | |
| 66 } | 25 } |
| OLD | NEW |