Add ability for NetLogLogger to gather data from more than just NetLog
[chromium-blink-merge.git] / ui / file_manager / gallery / js / gallery_util.js
blob3275151fde8d14c533dc096e1e07a5caa575555f
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 var GalleryUtil = {};
7 /**
8 * Obtains the entry set from the entries passed from onLaunched events.
9 * If an single entry is specified, the function returns all entries in the same
10 * directory. Otherwise the function returns the passed entries.
12 * The function also filters non-image items and hidden items.
14 * @param {!Array.<!FileEntry>} originalEntries Entries passed from onLaunched
15 * events.
16 * @return {!Promise} Promise to be fulfilled with entry array.
18 GalleryUtil.createEntrySet = function(originalEntries) {
19 var entriesPromise;
20 if (originalEntries.length === 1) {
21 var parentPromise =
22 new Promise(originalEntries[0].getParent.bind(originalEntries[0]));
23 entriesPromise = parentPromise.then(function(parent) {
24 var reader = parent.createReader();
25 var readEntries = function() {
26 return new Promise(reader.readEntries.bind(reader)).then(
27 function(entries) {
28 if (entries.length === 0)
29 return [];
30 return readEntries().then(function(nextEntries) {
31 return entries.concat(nextEntries);
32 });
33 });
35 return readEntries();
36 }).then(function(entries) {
37 return entries.filter(function(entry) {
38 return originalEntries[0].toURL() === entry.toURL() ||
39 entry.name[0] !== '.';
40 });
41 });
42 } else {
43 entriesPromise = Promise.resolve(originalEntries);
46 return entriesPromise.then(function(entries) {
47 return entries.filter(FileType.isImage).sort(function(a, b) {
48 return a.name.localeCompare(b.name);
49 });
50 });