OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 var fileSystemNatives = requireNative('file_system_natives'); | |
6 | |
5 var nameToIds = {}; | 7 var nameToIds = {}; |
6 var idsToEntries = {}; | 8 var idsToEntries = {}; |
7 | 9 |
8 function computeName(entry) { | 10 function computeName(entry) { |
9 return entry.filesystem.name + ':' + entry.fullPath; | 11 return entry.filesystem.name + ':' + entry.fullPath; |
10 } | 12 } |
11 | 13 |
14 function computeId(entry) { | |
15 var fileSystemId = fileSystemNatives.CrackIsolatedFileSystemName( | |
16 entry.filesystem.name); | |
17 if (!fileSystemId) | |
18 return null; | |
19 return fileSystemId + ':' + entry.fullPath.slice(1); | |
20 } | |
21 | |
12 function registerEntry(id, entry) { | 22 function registerEntry(id, entry) { |
13 var name = computeName(entry); | 23 var name = computeName(entry); |
14 nameToIds[name] = id; | 24 nameToIds[name] = id; |
15 idsToEntries[id] = entry; | 25 idsToEntries[id] = entry; |
16 }; | 26 } |
17 | 27 |
18 function getEntryId(entry) { | 28 function getEntryId(entry) { |
19 var name = null; | 29 var name = null; |
20 try { | 30 try { |
21 name = computeName(entry); | 31 name = computeName(entry); |
22 } catch(e) { | 32 } catch(e) { |
23 return null; | 33 return null; |
24 } | 34 } |
25 return nameToIds[name]; | 35 var id = nameToIds[name]; |
Matt Giuca
2013/05/22 08:26:14
Maybe explain what this is doing.
Sam McNally
2013/05/23 03:47:28
Done.
| |
36 if (id != null) | |
37 return id; | |
38 | |
39 id = computeId(entry); | |
40 registerEntry(id, entry); | |
41 return id; | |
26 } | 42 } |
27 | 43 |
28 function getEntryById(id) { | 44 function getEntryById(id) { |
29 return idsToEntries[id]; | 45 return idsToEntries[id]; |
30 } | 46 } |
31 | 47 |
32 exports.registerEntry = registerEntry; | 48 exports.registerEntry = registerEntry; |
33 exports.getEntryId = getEntryId; | 49 exports.getEntryId = getEntryId; |
34 exports.getEntryById = getEntryById; | 50 exports.getEntryById = getEntryById; |
OLD | NEW |