Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 has a media directory | |
| 202 * (like DCIM) as a direct child. | |
| 203 */ | |
| 204 importer.hasMediaDirectory = function(directory) { | |
|
mtomasz
2015/03/24 01:34:58
nit: This may be slow. Are we fine with it? Instea
Steve McKay
2015/03/24 22:39:20
I agree about this possibly being slow. Fixed.
| |
| 205 var hasMediaDirectory = false; | |
| 206 return importer.listEntries_( | |
| 207 directory, | |
| 208 /** @param {!Entry} entry */ | |
| 209 function(entry) { | |
| 210 if (!hasMediaDirectory && | |
| 211 entry.name.toUpperCase() in importer.ValidImportRoots_) { | |
| 212 hasMediaDirectory = true; | |
| 213 } | |
| 214 }) | |
| 215 .then( | |
| 216 function() { | |
| 217 return hasMediaDirectory; | |
| 218 }); | |
| 219 }; | |
| 220 | |
| 221 /** | |
| 200 * @return {!Promise<boolean>} Resolves with true when Cloud Import feature | 222 * @return {!Promise<boolean>} Resolves with true when Cloud Import feature |
| 201 * is enabled. | 223 * is enabled. |
| 202 */ | 224 */ |
| 203 importer.importEnabled = function() { | 225 importer.importEnabled = function() { |
| 204 return new Promise( | 226 return new Promise( |
| 205 function(resolve, reject) { | 227 function(resolve, reject) { |
| 206 chrome.commandLinePrivate.hasSwitch( | 228 chrome.commandLinePrivate.hasSwitch( |
| 207 'disable-cloud-import', | 229 'disable-cloud-import', |
| 208 /** @param {boolean} disabled */ | 230 /** @param {boolean} disabled */ |
| 209 function(disabled) { | 231 function(disabled) { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 * @return {!Promise<!FileEntry>} all history files not having | 344 * @return {!Promise<!FileEntry>} all history files not having |
| 323 * a machine id matching {@code machineId}. | 345 * a machine id matching {@code machineId}. |
| 324 * @private | 346 * @private |
| 325 */ | 347 */ |
| 326 importer.getUnownedHistoryFiles_ = function(machineId) { | 348 importer.getUnownedHistoryFiles_ = function(machineId) { |
| 327 var historyFiles = []; | 349 var historyFiles = []; |
| 328 return importer.ChromeSyncFilesystem.getRoot() | 350 return importer.ChromeSyncFilesystem.getRoot() |
| 329 .then( | 351 .then( |
| 330 /** @param {!DirectoryEntry} root */ | 352 /** @param {!DirectoryEntry} root */ |
| 331 function(root) { | 353 function(root) { |
| 332 return fileOperationUtil.listEntries( | 354 return importer.listEntries_( |
| 333 root, | 355 root, |
| 334 /** @param {Entry} entry */ | 356 /** @param {Entry} entry */ |
| 335 function(entry) { | 357 function(entry) { |
| 336 if (entry.isFile && | 358 if (entry.isFile && |
| 337 entry.name.indexOf(machineId.toString()) === -1 && | 359 entry.name.indexOf(machineId.toString()) === -1 && |
| 338 /^([0-9]{6}-import-history.log)$/.test(entry.name)) { | 360 /^([0-9]{6}-import-history.log)$/.test(entry.name)) { |
| 339 historyFiles.push(/** @type {!FileEntry} */ (entry)); | 361 historyFiles.push(/** @type {!FileEntry} */ (entry)); |
| 340 } | 362 } |
| 341 }) | 363 }) |
| 342 .then( | 364 .then( |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 368 ]).then( | 390 ]).then( |
| 369 /** @param {!Array<!FileEntry|!Array<!FileEntry>>} entries */ | 391 /** @param {!Array<!FileEntry|!Array<!FileEntry>>} entries */ |
| 370 function(entries) { | 392 function(entries) { |
| 371 var historyFiles = entries[1]; | 393 var historyFiles = entries[1]; |
| 372 historyFiles.unshift(entries[0]); | 394 historyFiles.unshift(entries[0]); |
| 373 return historyFiles; | 395 return historyFiles; |
| 374 }); | 396 }); |
| 375 }; | 397 }; |
| 376 | 398 |
| 377 /** | 399 /** |
| 400 * Calls {@code callback} for each child entry of {@code directory}. | |
| 401 * | |
| 402 * @param {!DirectoryEntry} directory | |
| 403 * @param {function(!Entry)} callback | |
| 404 * @return {!Promise} Resolves when listing is complete. | |
| 405 * @private | |
| 406 */ | |
| 407 importer.listEntries_ = function(directory, callback) { | |
| 408 return new Promise( | |
| 409 function(resolve, reject) { | |
| 410 var reader = directory.createReader(); | |
| 411 | |
| 412 var readEntries = function() { | |
| 413 reader.readEntries ( | |
| 414 /** @param {!Array<!Entry>} entries */ | |
| 415 function(entries) { | |
| 416 if (entries.length === 0) { | |
| 417 resolve(undefined); | |
| 418 return; | |
| 419 } | |
| 420 entries.forEach(callback); | |
|
mtomasz
2015/03/24 01:34:58
nit: I think this should cause a js compile error,
Steve McKay
2015/03/24 22:39:20
Callback is required, all others are optional.
| |
| 421 readEntries(); | |
| 422 }, | |
| 423 reject); | |
| 424 }; | |
| 425 | |
| 426 readEntries(); | |
| 427 }); | |
| 428 }; | |
| 429 | |
| 430 /** | |
| 378 * A Promise wrapper that provides public access to resolve and reject methods. | 431 * A Promise wrapper that provides public access to resolve and reject methods. |
| 379 * | 432 * |
| 380 * @constructor | 433 * @constructor |
| 381 * @struct | 434 * @struct |
| 382 * @template T | 435 * @template T |
| 383 */ | 436 */ |
| 384 importer.Resolver = function() { | 437 importer.Resolver = function() { |
| 385 /** @private {boolean} */ | 438 /** @private {boolean} */ |
| 386 this.settled_ = false; | 439 this.settled_ = false; |
| 387 | 440 |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 994 }); | 1047 }); |
| 995 }; | 1048 }; |
| 996 | 1049 |
| 997 /** @private @const {!importer.ChromeLocalStorage} */ | 1050 /** @private @const {!importer.ChromeLocalStorage} */ |
| 998 importer.ChromeLocalStorage.INSTANCE_ = new importer.ChromeLocalStorage(); | 1051 importer.ChromeLocalStorage.INSTANCE_ = new importer.ChromeLocalStorage(); |
| 999 | 1052 |
| 1000 /** @return {!importer.ChromeLocalStorage} */ | 1053 /** @return {!importer.ChromeLocalStorage} */ |
| 1001 importer.ChromeLocalStorage.getInstance = function() { | 1054 importer.ChromeLocalStorage.getInstance = function() { |
| 1002 return importer.ChromeLocalStorage.INSTANCE_; | 1055 return importer.ChromeLocalStorage.INSTANCE_; |
| 1003 }; | 1056 }; |
| OLD | NEW |