Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: ui/file_manager/file_manager/common/js/importer_common.js

Issue 1022423005: Move view change analytics tracking into DirectoryModel where implementation details can be hidden. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add FSP extension whitelist so we can report names to analytics rather than extension ids for provi… Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/file_manager/file_manager/common/js/importer_common_unittest.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // Shared cloud importer namespace 5 // Shared cloud importer namespace
6 var importer = importer || {}; 6 var importer = importer || {};
7 7
8 /** @enum {string} */ 8 /** @enum {string} */
9 importer.ScanEvent = { 9 importer.ScanEvent = {
10 FINALIZED: 'finalized', 10 FINALIZED: 'finalized',
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 // valid import root. 190 // valid import root.
191 if (splitPath[0] in importer.ValidImportRoots_ && splitPath.length === 1) { 191 if (splitPath[0] in importer.ValidImportRoots_ && splitPath.length === 1) {
192 console.assert(volumeInfoProvider !== null); 192 console.assert(volumeInfoProvider !== null);
193 var volumeInfo = volumeInfoProvider.getVolumeInfo(entry); 193 var volumeInfo = volumeInfoProvider.getVolumeInfo(entry);
194 return importer.isEligibleVolume(volumeInfo); 194 return importer.isEligibleVolume(volumeInfo);
195 } 195 }
196 return false; 196 return false;
197 }; 197 };
198 198
199 /** 199 /**
200 * @param {!DirectoryEntry} directory Presumably the root of a filesystem.
201 * @return {!Promise<boolean>} True if the directory contains a
202 * child media directory (like 'DCIM').
203 */
204 importer.hasMediaDirectory = function(directory) {
205 /**
206 * @param {boolean} answer
207 * @return {boolean}
208 */
209 var isTrue = function(answer) {
210 return answer;
211 };
212 var dirNames = Object.keys(importer.ValidImportRoots_);
213 return Promise.all(dirNames.map(importer.hasDirectory_.bind(null, directory)))
214 .then(
215 /**
216 * @param {!Array<boolean>} results
217 * @return {!Promise<boolean>}
218 */
219 function(results) {
220 if (results.some(isTrue)) {
221 return Promise.resolve(true);
222 } else {
223 // If standard (upper case) forms are not present,
224 // check for a lower-case "DCIM".
225 return importer.hasDirectory_(directory, 'dcim');
226 }
227 });
228 };
229
230 /**
231 * @param {!DirectoryEntry} parent
232 * @param {string} name
233 * @return {!Promise<boolean>} True if parent contains a directory
234 * with the specified name.
235 * @private
236 */
237 importer.hasDirectory_ = function(parent, name) {
238 return importer.getDirectory_(parent, name)
239 .then(
240 function() {
241 return true;
242 },
243 function() {
244 return false;
245 });
246 };
247
248 /**
249 * @param {!DirectoryEntry} parent
250 * @param {string} name
251 * @return {!Promise<!DirectoryEntry>}
252 * @private
253 */
254 importer.getDirectory_ = function(parent, name) {
255 return new Promise(
256 function(resolve, reject) {
257 parent.getDirectory(
258 name,
259 {
260 create: false,
261 exclusive: false
262 },
263 resolve,
264 reject);
265 });
266 };
267
268 /**
200 * @return {!Promise<boolean>} Resolves with true when Cloud Import feature 269 * @return {!Promise<boolean>} Resolves with true when Cloud Import feature
201 * is enabled. 270 * is enabled.
202 */ 271 */
203 importer.importEnabled = function() { 272 importer.importEnabled = function() {
204 return new Promise( 273 return new Promise(
205 function(resolve, reject) { 274 function(resolve, reject) {
206 chrome.commandLinePrivate.hasSwitch( 275 chrome.commandLinePrivate.hasSwitch(
207 'disable-cloud-import', 276 'disable-cloud-import',
208 /** @param {boolean} disabled */ 277 /** @param {boolean} disabled */
209 function(disabled) { 278 function(disabled) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 * @return {!Promise<!FileEntry>} all history files not having 391 * @return {!Promise<!FileEntry>} all history files not having
323 * a machine id matching {@code machineId}. 392 * a machine id matching {@code machineId}.
324 * @private 393 * @private
325 */ 394 */
326 importer.getUnownedHistoryFiles_ = function(machineId) { 395 importer.getUnownedHistoryFiles_ = function(machineId) {
327 var historyFiles = []; 396 var historyFiles = [];
328 return importer.ChromeSyncFilesystem.getRoot() 397 return importer.ChromeSyncFilesystem.getRoot()
329 .then( 398 .then(
330 /** @param {!DirectoryEntry} root */ 399 /** @param {!DirectoryEntry} root */
331 function(root) { 400 function(root) {
332 return fileOperationUtil.listEntries( 401 return importer.listEntries_(
333 root, 402 root,
334 /** @param {Entry} entry */ 403 /** @param {Entry} entry */
335 function(entry) { 404 function(entry) {
336 if (entry.isFile && 405 if (entry.isFile &&
337 entry.name.indexOf(machineId.toString()) === -1 && 406 entry.name.indexOf(machineId.toString()) === -1 &&
338 /^([0-9]{6}-import-history.log)$/.test(entry.name)) { 407 /^([0-9]{6}-import-history.log)$/.test(entry.name)) {
339 historyFiles.push(/** @type {!FileEntry} */ (entry)); 408 historyFiles.push(/** @type {!FileEntry} */ (entry));
340 } 409 }
341 }) 410 })
342 .then( 411 .then(
(...skipping 25 matching lines...) Expand all
368 ]).then( 437 ]).then(
369 /** @param {!Array<!FileEntry|!Array<!FileEntry>>} entries */ 438 /** @param {!Array<!FileEntry|!Array<!FileEntry>>} entries */
370 function(entries) { 439 function(entries) {
371 var historyFiles = entries[1]; 440 var historyFiles = entries[1];
372 historyFiles.unshift(entries[0]); 441 historyFiles.unshift(entries[0]);
373 return historyFiles; 442 return historyFiles;
374 }); 443 });
375 }; 444 };
376 445
377 /** 446 /**
447 * Calls {@code callback} for each child entry of {@code directory}.
448 *
449 * @param {!DirectoryEntry} directory
450 * @param {function(!Entry)} callback
451 * @return {!Promise} Resolves when listing is complete.
452 * @private
453 */
454 importer.listEntries_ = function(directory, callback) {
455 return new Promise(
456 function(resolve, reject) {
457 var reader = directory.createReader();
458
459 var readEntries = function() {
460 reader.readEntries (
461 /** @param {!Array<!Entry>} entries */
462 function(entries) {
463 if (entries.length === 0) {
464 resolve(undefined);
465 return;
466 }
467 entries.forEach(callback);
468 readEntries();
469 },
470 reject);
471 };
472
473 readEntries();
474 });
475 };
476
477 /**
378 * A Promise wrapper that provides public access to resolve and reject methods. 478 * A Promise wrapper that provides public access to resolve and reject methods.
379 * 479 *
380 * @constructor 480 * @constructor
381 * @struct 481 * @struct
382 * @template T 482 * @template T
383 */ 483 */
384 importer.Resolver = function() { 484 importer.Resolver = function() {
385 /** @private {boolean} */ 485 /** @private {boolean} */
386 this.settled_ = false; 486 this.settled_ = false;
387 487
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 function(resolve, reject) { 758 function(resolve, reject) {
659 directory.getFile( 759 directory.getFile(
660 fileName, 760 fileName,
661 { 761 {
662 create: true, 762 create: true,
663 exclusive: false 763 exclusive: false
664 }, 764 },
665 resolve, 765 resolve,
666 reject); 766 reject);
667 }); 767 });
668
669 }); 768 });
670 }); 769 });
671 770
672 return /** @type {!Promise<!FileEntry>} */ (promise); 771 return /** @type {!Promise<!FileEntry>} */ (promise);
673 }; 772 };
674 773
675 /** 774 /**
676 * A basic logging mechanism. 775 * A basic logging mechanism.
677 * 776 *
678 * @interface 777 * @interface
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 }); 1091 });
993 }; 1092 };
994 1093
995 /** @private @const {!importer.ChromeLocalStorage} */ 1094 /** @private @const {!importer.ChromeLocalStorage} */
996 importer.ChromeLocalStorage.INSTANCE_ = new importer.ChromeLocalStorage(); 1095 importer.ChromeLocalStorage.INSTANCE_ = new importer.ChromeLocalStorage();
997 1096
998 /** @return {!importer.ChromeLocalStorage} */ 1097 /** @return {!importer.ChromeLocalStorage} */
999 importer.ChromeLocalStorage.getInstance = function() { 1098 importer.ChromeLocalStorage.getInstance = function() {
1000 return importer.ChromeLocalStorage.INSTANCE_; 1099 return importer.ChromeLocalStorage.INSTANCE_;
1001 }; 1100 };
OLDNEW
« no previous file with comments | « no previous file | ui/file_manager/file_manager/common/js/importer_common_unittest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698