| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * FileManager constructor. | 8 * FileManager constructor. |
| 9 * | 9 * |
| 10 * FileManager objects encapsulate the functionality of the file selector | 10 * FileManager objects encapsulate the functionality of the file selector |
| (...skipping 1463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1474 var suggestedName = null; | 1474 var suggestedName = null; |
| 1475 var error = null; | 1475 var error = null; |
| 1476 queue.run(function(callback) { | 1476 queue.run(function(callback) { |
| 1477 // Cancel this sequence if the current directory has already changed. | 1477 // Cancel this sequence if the current directory has already changed. |
| 1478 if (tracker.hasChanged) { | 1478 if (tracker.hasChanged) { |
| 1479 callback(); | 1479 callback(); |
| 1480 return; | 1480 return; |
| 1481 } | 1481 } |
| 1482 | 1482 |
| 1483 if (candidateEntry) { | 1483 if (candidateEntry) { |
| 1484 // The entry is directry. Use it. | 1484 // The entry is directory. Use it. |
| 1485 if (candidateEntry.isDirectory) { | 1485 if (candidateEntry.isDirectory) { |
| 1486 nextCurrentDirEntry = candidateEntry; | 1486 nextCurrentDirEntry = candidateEntry; |
| 1487 callback(); | 1487 callback(); |
| 1488 return; | 1488 return; |
| 1489 } | 1489 } |
| 1490 // The entry exists, but it is not a directory. Therefore use a | 1490 // The entry exists, but it is not a directory. Therefore use a |
| 1491 // parent. | 1491 // parent. |
| 1492 candidateEntry.getParent(function(parentEntry) { | 1492 candidateEntry.getParent(function(parentEntry) { |
| 1493 nextCurrentDirEntry = parentEntry; | 1493 nextCurrentDirEntry = parentEntry; |
| 1494 selectionEntry = candidateEntry; | 1494 selectionEntry = candidateEntry; |
| 1495 callback(); | 1495 callback(); |
| 1496 }, function() { | 1496 }, function() { |
| 1497 error = new Error('Unable to resolve parent for: ' + | 1497 error = new Error('Unable to resolve parent for: ' + |
| 1498 candidateEntry.fullPath); | 1498 candidateEntry.fullPath); |
| 1499 callback(); | 1499 callback(); |
| 1500 }); | 1500 }); |
| 1501 return; | 1501 return; |
| 1502 } | 1502 } |
| 1503 | 1503 |
| 1504 // If the entry doesn't exist, most probably because the path contains a | 1504 // If the entry doesn't exist, most probably because the path contains a |
| 1505 // suggested name. Therefore try to open its parent. | 1505 // suggested name. Therefore try to open its parent. However, the parent |
| 1506 // may also not exist. In such situation, fallback. |
| 1506 var pathNodes = candidateFullPath.split('/'); | 1507 var pathNodes = candidateFullPath.split('/'); |
| 1507 suggestedName = pathNodes.pop(); | 1508 var baseName = pathNodes.pop(); |
| 1508 var parentPath = pathNodes.join('/'); | 1509 var parentPath = pathNodes.join('/'); |
| 1509 this.volumeManager_.resolveAbsolutePath( | 1510 this.volumeManager_.resolveAbsolutePath( |
| 1510 parentPath, | 1511 parentPath, |
| 1511 function(parentEntry) { | 1512 function(parentEntry) { |
| 1512 nextCurrentDirEntry = parentEntry; | 1513 nextCurrentDirEntry = parentEntry; |
| 1514 suggestedName = baseName; |
| 1515 callback(); |
| 1516 }, |
| 1517 callback); // In case of an error, continue. |
| 1518 }.bind(this)); |
| 1519 |
| 1520 // If the directory is not set at this stage, fallback to the default |
| 1521 // mount point. |
| 1522 queue.run(function(callback) { |
| 1523 // Cancel this sequence if the current directory has already changed, |
| 1524 // or the next current directory is already set. |
| 1525 if (tracker.hasChanged || nextCurrentDirEntry) { |
| 1526 callback(); |
| 1527 return; |
| 1528 } |
| 1529 this.volumeManager_.resolveAbsolutePath( |
| 1530 PathUtil.DEFAULT_MOUNT_POINT, |
| 1531 function(fallbackEntry) { |
| 1532 nextCurrentDirEntry = fallbackEntry; |
| 1513 callback(); | 1533 callback(); |
| 1514 }, | 1534 }, |
| 1515 function() { | 1535 function() { |
| 1516 error = new Error('Failed to setup an initial directory: ' + | 1536 // Fallback directory not available? Throw an error. |
| 1517 nextCurrentDirPath); | 1537 error = new Error('Unable to resolve the fallback directory: ' + |
| 1538 PathUtil.DEFAULT_MOUNT_POINT); |
| 1518 callback(); | 1539 callback(); |
| 1519 }); | 1540 }); |
| 1520 }.bind(this)); | 1541 }.bind(this)); |
| 1521 | 1542 |
| 1522 queue.run(function(callback) { | 1543 queue.run(function(callback) { |
| 1523 // Check error. | 1544 // Check error. |
| 1524 if (error) { | 1545 if (error) { |
| 1525 callback(); | 1546 callback(); |
| 1526 throw error; | 1547 throw error; |
| 1527 } | 1548 } |
| (...skipping 2101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3629 callback(this.preferences_); | 3650 callback(this.preferences_); |
| 3630 return; | 3651 return; |
| 3631 } | 3652 } |
| 3632 | 3653 |
| 3633 chrome.fileBrowserPrivate.getPreferences(function(prefs) { | 3654 chrome.fileBrowserPrivate.getPreferences(function(prefs) { |
| 3634 this.preferences_ = prefs; | 3655 this.preferences_ = prefs; |
| 3635 callback(prefs); | 3656 callback(prefs); |
| 3636 }.bind(this)); | 3657 }.bind(this)); |
| 3637 }; | 3658 }; |
| 3638 })(); | 3659 })(); |
| OLD | NEW |