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; | |
1513 callback(); | 1515 callback(); |
1514 }, | 1516 }, |
1515 function() { | 1517 function() { |
hirono
2014/01/06 10:20:11
We can pass the callback directly.
mtomasz
2014/01/07 00:52:10
Done.
| |
1516 error = new Error('Failed to setup an initial directory: ' + | |
1517 nextCurrentDirPath); | |
1518 callback(); | 1518 callback(); |
1519 }); | 1519 }); |
1520 }.bind(this)); | 1520 }.bind(this)); |
1521 | |
1522 queue.run(function(callback) { | |
1523 // If the directory is not set at this stage, fallback to the default | |
1524 // mount point. | |
1525 if (nextCurrentDirEntry) { | |
1526 callback(); | |
1527 return; | |
1528 } | |
1529 this.volumeManager_.resolveAbsolutePath( | |
1530 PathUtil.DEFAULT_MOUNT_POINT, | |
1531 function(fallbackEntry) { | |
1532 nextCurrentDirEntry = fallbackEntry; | |
1533 callback(); | |
1534 }, | |
1535 function() { | |
1536 // Fallback directory not available? Throw an error. | |
1537 error = new Error('Unable to resolve the fallback directory: ' + | |
1538 PathUtil.DEFAULT_MOUNT_POINT); | |
1539 callback(); | |
1540 }); | |
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 } |
1528 // Check directory change. | 1549 // Check directory change. |
1529 tracker.stop(); | 1550 tracker.stop(); |
1530 if (tracker.hasChanged) { | 1551 if (tracker.hasChanged) { |
(...skipping 2099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3630 callback(this.preferences_); | 3651 callback(this.preferences_); |
3631 return; | 3652 return; |
3632 } | 3653 } |
3633 | 3654 |
3634 chrome.fileBrowserPrivate.getPreferences(function(prefs) { | 3655 chrome.fileBrowserPrivate.getPreferences(function(prefs) { |
3635 this.preferences_ = prefs; | 3656 this.preferences_ = prefs; |
3636 callback(prefs); | 3657 callback(prefs); |
3637 }.bind(this)); | 3658 }.bind(this)); |
3638 }; | 3659 }; |
3639 })(); | 3660 })(); |
OLD | NEW |