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 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h" |
6 | 6 |
7 #include <sys/stat.h> | 7 #include <sys/stat.h> |
8 #include <sys/statvfs.h> | 8 #include <sys/statvfs.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #include <utime.h> | 10 #include <utime.h> |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 if (statvfs(mount_path.c_str(), &stat) == 0) { | 302 if (statvfs(mount_path.c_str(), &stat) == 0) { |
303 total_size_in_bytes = | 303 total_size_in_bytes = |
304 static_cast<uint64_t>(stat.f_blocks) * stat.f_frsize; | 304 static_cast<uint64_t>(stat.f_blocks) * stat.f_frsize; |
305 remaining_size_in_bytes = | 305 remaining_size_in_bytes = |
306 static_cast<uint64_t>(stat.f_bfree) * stat.f_frsize; | 306 static_cast<uint64_t>(stat.f_bfree) * stat.f_frsize; |
307 } | 307 } |
308 *total_size_kb = static_cast<size_t>(total_size_in_bytes / 1024); | 308 *total_size_kb = static_cast<size_t>(total_size_in_bytes / 1024); |
309 *remaining_size_kb = static_cast<size_t>(remaining_size_in_bytes / 1024); | 309 *remaining_size_kb = static_cast<size_t>(remaining_size_in_bytes / 1024); |
310 } | 310 } |
311 | 311 |
312 // Given a |url| and a file system type |desired_type|, return the virtual | 312 // Given a |url|, return the virtual FilePath associated with it. If the file |
313 // FilePath associated with it. If the file isn't of the |desired_type| or can't | 313 // isn't of the type CrosMountPointProvider handles, return an empty FilePath. |
314 // be parsed, then return an empty FilePath. | 314 // |
| 315 // Virtual paths will look like "Downloads/foo/bar.txt" or "drive/foo/bar.txt". |
315 FilePath GetVirtualPathFromURL(const GURL& url) { | 316 FilePath GetVirtualPathFromURL(const GURL& url) { |
316 fileapi::FileSystemURL filesystem_url(url); | 317 fileapi::FileSystemURL filesystem_url(url); |
317 if (!filesystem_url.is_valid() || | 318 if (!chromeos::CrosMountPointProvider::CanHandleURL(filesystem_url)) |
318 (filesystem_url.type() != fileapi::kFileSystemTypeDrive && | |
319 filesystem_url.type() != fileapi::kFileSystemTypeNativeMedia && | |
320 filesystem_url.type() != fileapi::kFileSystemTypeNativeLocal)) { | |
321 return FilePath(); | 319 return FilePath(); |
322 } | |
323 return filesystem_url.virtual_path(); | 320 return filesystem_url.virtual_path(); |
324 } | 321 } |
325 | 322 |
| 323 // Given a |url|, return the local FilePath associated with it. If the file |
| 324 // isn't of the type CrosMountPointProvider handles, return an empty FilePath. |
| 325 // |
| 326 // Local paths will look like "/home/chronos/user/Downloads/foo/bar.txt" or |
| 327 // "/special/drive/foo/bar.txt". |
| 328 FilePath GetLocalPathFromURL(const GURL& url) { |
| 329 fileapi::FileSystemURL filesystem_url(url); |
| 330 if (!chromeos::CrosMountPointProvider::CanHandleURL(filesystem_url)) |
| 331 return FilePath(); |
| 332 return filesystem_url.path(); |
| 333 } |
| 334 |
326 // Make a set of unique filename suffixes out of the list of file URLs. | 335 // Make a set of unique filename suffixes out of the list of file URLs. |
327 std::set<std::string> GetUniqueSuffixes(base::ListValue* file_url_list) { | 336 std::set<std::string> GetUniqueSuffixes(base::ListValue* file_url_list) { |
328 std::set<std::string> suffixes; | 337 std::set<std::string> suffixes; |
329 for (size_t i = 0; i < file_url_list->GetSize(); ++i) { | 338 for (size_t i = 0; i < file_url_list->GetSize(); ++i) { |
330 std::string url; | 339 std::string url; |
331 if (!file_url_list->GetString(i, &url)) | 340 if (!file_url_list->GetString(i, &url)) |
332 return std::set<std::string>(); | 341 return std::set<std::string>(); |
333 FilePath path = GetVirtualPathFromURL(GURL(url)); | 342 FilePath path = GetVirtualPathFromURL(GURL(url)); |
334 if (path.empty()) | 343 if (path.empty()) |
335 return std::set<std::string>(); | 344 return std::set<std::string>(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 } else { | 390 } else { |
382 suffixes_str += ", " + *iter; | 391 suffixes_str += ", " + *iter; |
383 } | 392 } |
384 } | 393 } |
385 VLOG(1) << "Associating task " << task_id | 394 VLOG(1) << "Associating task " << task_id |
386 << " with the following suffixes: "; | 395 << " with the following suffixes: "; |
387 VLOG(1) << " " << suffixes_str; | 396 VLOG(1) << " " << suffixes_str; |
388 } | 397 } |
389 } | 398 } |
390 | 399 |
391 bool GetLocalFilePath( | |
392 const GURL& file_url, FilePath* local_path, FilePath* virtual_path) { | |
393 fileapi::FileSystemURL url(file_url); | |
394 if (!chromeos::CrosMountPointProvider::CanHandleURL(url)) | |
395 return false; | |
396 *local_path = url.path(); | |
397 *virtual_path = url.virtual_path(); | |
398 return true; | |
399 } | |
400 | |
401 } // namespace | 400 } // namespace |
402 | 401 |
403 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { | 402 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher { |
404 public: | 403 public: |
405 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( | 404 static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback( |
406 RequestLocalFileSystemFunction* function, | 405 RequestLocalFileSystemFunction* function, |
407 scoped_refptr<fileapi::FileSystemContext> file_system_context, | 406 scoped_refptr<fileapi::FileSystemContext> file_system_context, |
408 int child_id, | 407 int child_id, |
409 scoped_refptr<const Extension> extension) { | 408 scoped_refptr<const Extension> extension) { |
410 return base::Bind( | 409 return base::Bind( |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 bool FileWatchBrowserFunctionBase::RunImpl() { | 564 bool FileWatchBrowserFunctionBase::RunImpl() { |
566 if (!render_view_host() || !render_view_host()->GetProcess()) | 565 if (!render_view_host() || !render_view_host()->GetProcess()) |
567 return false; | 566 return false; |
568 | 567 |
569 // First param is url of a file to watch. | 568 // First param is url of a file to watch. |
570 std::string url; | 569 std::string url; |
571 if (!args_->GetString(0, &url) || url.empty()) | 570 if (!args_->GetString(0, &url) || url.empty()) |
572 return false; | 571 return false; |
573 | 572 |
574 GURL file_watch_url(url); | 573 GURL file_watch_url(url); |
575 scoped_refptr<fileapi::FileSystemContext> file_system_context = | |
576 BrowserContext::GetDefaultStoragePartition(profile_)-> | |
577 GetFileSystemContext(); | |
578 BrowserThread::PostTask( | 574 BrowserThread::PostTask( |
579 BrowserThread::FILE, FROM_HERE, | 575 BrowserThread::FILE, FROM_HERE, |
580 base::Bind( | 576 base::Bind( |
581 &FileWatchBrowserFunctionBase::RunFileWatchOperationOnFileThread, | 577 &FileWatchBrowserFunctionBase::RunFileWatchOperationOnFileThread, |
582 this, | 578 this, |
583 file_system_context, | |
584 FileBrowserEventRouterFactory::GetForProfile(profile_), | 579 FileBrowserEventRouterFactory::GetForProfile(profile_), |
585 file_watch_url, | 580 file_watch_url, |
586 extension_id())); | 581 extension_id())); |
587 | 582 |
588 return true; | 583 return true; |
589 } | 584 } |
590 | 585 |
591 void FileWatchBrowserFunctionBase::RunFileWatchOperationOnFileThread( | 586 void FileWatchBrowserFunctionBase::RunFileWatchOperationOnFileThread( |
592 scoped_refptr<fileapi::FileSystemContext> file_system_context, | |
593 scoped_refptr<FileBrowserEventRouter> event_router, | 587 scoped_refptr<FileBrowserEventRouter> event_router, |
594 const GURL& file_url, const std::string& extension_id) { | 588 const GURL& file_url, const std::string& extension_id) { |
595 FilePath local_path; | 589 FilePath local_path = GetLocalPathFromURL(file_url); |
596 FilePath virtual_path; | 590 FilePath virtual_path = GetVirtualPathFromURL(file_url); |
597 if (!GetLocalFilePath(file_url, &local_path, &virtual_path) || | 591 bool result = !local_path.empty() && PerformFileWatchOperation( |
598 local_path == FilePath()) { | 592 event_router, local_path, virtual_path, extension_id); |
599 BrowserThread::PostTask( | 593 |
600 BrowserThread::UI, FROM_HERE, | |
601 base::Bind( | |
602 &FileWatchBrowserFunctionBase::RespondOnUIThread, | |
603 this, | |
604 false)); | |
605 } | |
606 if (!PerformFileWatchOperation(event_router, | |
607 local_path, | |
608 virtual_path, | |
609 extension_id)) { | |
610 BrowserThread::PostTask( | |
611 BrowserThread::UI, FROM_HERE, | |
612 base::Bind( | |
613 &FileWatchBrowserFunctionBase::RespondOnUIThread, | |
614 this, | |
615 false)); | |
616 } | |
617 BrowserThread::PostTask( | 594 BrowserThread::PostTask( |
618 BrowserThread::UI, FROM_HERE, | 595 BrowserThread::UI, FROM_HERE, |
619 base::Bind( | 596 base::Bind( |
620 &FileWatchBrowserFunctionBase::RespondOnUIThread, | 597 &FileWatchBrowserFunctionBase::RespondOnUIThread, this, result)); |
621 this, | |
622 true)); | |
623 } | 598 } |
624 | 599 |
625 bool AddFileWatchBrowserFunction::PerformFileWatchOperation( | 600 bool AddFileWatchBrowserFunction::PerformFileWatchOperation( |
626 scoped_refptr<FileBrowserEventRouter> event_router, | 601 scoped_refptr<FileBrowserEventRouter> event_router, |
627 const FilePath& local_path, const FilePath& virtual_path, | 602 const FilePath& local_path, const FilePath& virtual_path, |
628 const std::string& extension_id) { | 603 const std::string& extension_id) { |
629 return event_router->AddFileWatch(local_path, virtual_path, extension_id); | 604 return event_router->AddFileWatch(local_path, virtual_path, extension_id); |
630 } | 605 } |
631 | 606 |
632 bool RemoveFileWatchBrowserFunction::PerformFileWatchOperation( | 607 bool RemoveFileWatchBrowserFunction::PerformFileWatchOperation( |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1306 return false; | 1281 return false; |
1307 } | 1282 } |
1308 | 1283 |
1309 ListValue* path_list = NULL; | 1284 ListValue* path_list = NULL; |
1310 args_->GetList(0, &path_list); | 1285 args_->GetList(0, &path_list); |
1311 DCHECK(path_list); | 1286 DCHECK(path_list); |
1312 | 1287 |
1313 std::string internal_task_id; | 1288 std::string internal_task_id; |
1314 args_->GetString(1, &internal_task_id); | 1289 args_->GetString(1, &internal_task_id); |
1315 | 1290 |
1316 std::string virtual_path; | 1291 std::vector<FilePath> files; |
1317 size_t len = path_list->GetSize(); | 1292 for (size_t i = 0; i < path_list->GetSize(); ++i) { |
1318 UrlList file_urls; | 1293 std::string url_as_string; |
1319 file_urls.reserve(len); | 1294 path_list->GetString(i, &url_as_string); |
1320 for (size_t i = 0; i < len; ++i) { | 1295 FilePath path = GetLocalPathFromURL(GURL(url_as_string)); |
1321 path_list->GetString(i, &virtual_path); | 1296 if (path.empty()) |
1322 file_urls.push_back(GURL(virtual_path)); | 1297 return false; |
| 1298 files.push_back(path); |
1323 } | 1299 } |
1324 | 1300 |
1325 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread( | |
1326 file_urls, | |
1327 base::Bind(&ViewFilesFunction::GetLocalPathsResponseOnUIThread, | |
1328 this, | |
1329 internal_task_id)); | |
1330 return true; | |
1331 } | |
1332 | |
1333 void ViewFilesFunction::GetLocalPathsResponseOnUIThread( | |
1334 const std::string& internal_task_id, | |
1335 const SelectedFileInfoList& files) { | |
1336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
1337 bool success = true; | 1301 bool success = true; |
1338 for (SelectedFileInfoList::const_iterator iter = files.begin(); | 1302 for (size_t i = 0; i < files.size(); ++i) { |
1339 iter != files.end(); | |
1340 ++iter) { | |
1341 bool handled = file_manager_util::ExecuteBuiltinHandler( | 1303 bool handled = file_manager_util::ExecuteBuiltinHandler( |
1342 GetCurrentBrowser(), iter->file_path, internal_task_id); | 1304 GetCurrentBrowser(), files[i], internal_task_id); |
1343 if (!handled && files.size() == 1) | 1305 if (!handled && files.size() == 1) |
1344 success = false; | 1306 success = false; |
1345 } | 1307 } |
1346 SetResult(Value::CreateBooleanValue(success)); | 1308 SetResult(Value::CreateBooleanValue(success)); |
1347 SendResponse(true); | 1309 SendResponse(true); |
| 1310 return true; |
1348 } | 1311 } |
1349 | 1312 |
1350 SelectFilesFunction::SelectFilesFunction() { | 1313 SelectFilesFunction::SelectFilesFunction() { |
1351 } | 1314 } |
1352 | 1315 |
1353 SelectFilesFunction::~SelectFilesFunction() { | 1316 SelectFilesFunction::~SelectFilesFunction() { |
1354 } | 1317 } |
1355 | 1318 |
1356 bool SelectFilesFunction::RunImpl() { | 1319 bool SelectFilesFunction::RunImpl() { |
1357 if (args_->GetSize() != 1) { | 1320 if (args_->GetSize() != 1) { |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1588 &SetLastModifiedFunction::RunOperationOnFileThread, | 1551 &SetLastModifiedFunction::RunOperationOnFileThread, |
1589 this, | 1552 this, |
1590 file_url, | 1553 file_url, |
1591 strtoul(timestamp.c_str(), NULL, 0))); | 1554 strtoul(timestamp.c_str(), NULL, 0))); |
1592 | 1555 |
1593 return true; | 1556 return true; |
1594 } | 1557 } |
1595 | 1558 |
1596 void SetLastModifiedFunction::RunOperationOnFileThread(std::string file_url, | 1559 void SetLastModifiedFunction::RunOperationOnFileThread(std::string file_url, |
1597 time_t timestamp) { | 1560 time_t timestamp) { |
1598 FilePath local_path, virtual_path; | |
1599 bool succeeded = false; | 1561 bool succeeded = false; |
1600 if (GetLocalFilePath(GURL(file_url), &local_path, &virtual_path) && | 1562 |
1601 local_path != FilePath()) { | 1563 FilePath local_path = GetLocalPathFromURL(GURL(file_url)); |
| 1564 if (!local_path.empty()) { |
1602 struct stat sb; | 1565 struct stat sb; |
1603 if (stat(local_path.value().c_str(), &sb) == 0) { | 1566 if (stat(local_path.value().c_str(), &sb) == 0) { |
1604 struct utimbuf times; | 1567 struct utimbuf times; |
1605 times.actime = sb.st_atime; | 1568 times.actime = sb.st_atime; |
1606 times.modtime = timestamp; | 1569 times.modtime = timestamp; |
1607 | 1570 |
1608 if (utime(local_path.value().c_str(), ×) == 0) | 1571 if (utime(local_path.value().c_str(), ×) == 0) |
1609 succeeded = true; | 1572 succeeded = true; |
1610 } | 1573 } |
1611 } | 1574 } |
(...skipping 14 matching lines...) Expand all Loading... |
1626 | 1589 |
1627 bool GetSizeStatsFunction::RunImpl() { | 1590 bool GetSizeStatsFunction::RunImpl() { |
1628 if (args_->GetSize() != 1) { | 1591 if (args_->GetSize() != 1) { |
1629 return false; | 1592 return false; |
1630 } | 1593 } |
1631 | 1594 |
1632 std::string mount_url; | 1595 std::string mount_url; |
1633 if (!args_->GetString(0, &mount_url)) | 1596 if (!args_->GetString(0, &mount_url)) |
1634 return false; | 1597 return false; |
1635 | 1598 |
1636 UrlList mount_paths; | 1599 FilePath file_path = GetLocalPathFromURL(GURL(mount_url)); |
1637 mount_paths.push_back(GURL(mount_url)); | 1600 if (file_path.empty()) |
| 1601 return false; |
1638 | 1602 |
1639 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread( | 1603 if (file_path == drive::util::GetDriveMountPointPath()) { |
1640 mount_paths, | |
1641 base::Bind(&GetSizeStatsFunction::GetLocalPathsResponseOnUIThread, this)); | |
1642 return true; | |
1643 } | |
1644 | |
1645 void GetSizeStatsFunction::GetLocalPathsResponseOnUIThread( | |
1646 const SelectedFileInfoList& files) { | |
1647 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
1648 | |
1649 if (files.size() != 1) { | |
1650 SendResponse(false); | |
1651 return; | |
1652 } | |
1653 | |
1654 if (files[0].file_path == drive::util::GetDriveMountPointPath()) { | |
1655 drive::DriveSystemService* system_service = | 1604 drive::DriveSystemService* system_service = |
1656 drive::DriveSystemServiceFactory::GetForProfile(profile_); | 1605 drive::DriveSystemServiceFactory::GetForProfile(profile_); |
1657 // |system_service| is NULL if Drive is disabled. | 1606 // |system_service| is NULL if Drive is disabled. |
1658 if (!system_service) { | 1607 if (!system_service) { |
1659 // If stats couldn't be gotten for drive, result should be left | 1608 // If stats couldn't be gotten for drive, result should be left |
1660 // undefined. See comments in GetDriveAvailableSpaceCallback(). | 1609 // undefined. See comments in GetDriveAvailableSpaceCallback(). |
1661 SendResponse(true); | 1610 SendResponse(true); |
1662 return; | 1611 return true; |
1663 } | 1612 } |
1664 | 1613 |
1665 drive::DriveFileSystemInterface* file_system = | 1614 drive::DriveFileSystemInterface* file_system = |
1666 system_service->file_system(); | 1615 system_service->file_system(); |
1667 | 1616 |
1668 file_system->GetAvailableSpace( | 1617 file_system->GetAvailableSpace( |
1669 base::Bind(&GetSizeStatsFunction::GetDriveAvailableSpaceCallback, | 1618 base::Bind(&GetSizeStatsFunction::GetDriveAvailableSpaceCallback, |
1670 this)); | 1619 this)); |
1671 | 1620 |
1672 } else { | 1621 } else { |
1673 BrowserThread::PostTask( | 1622 BrowserThread::PostTask( |
1674 BrowserThread::FILE, FROM_HERE, | 1623 BrowserThread::FILE, FROM_HERE, |
1675 base::Bind( | 1624 base::Bind( |
1676 &GetSizeStatsFunction::CallGetSizeStatsOnFileThread, | 1625 &GetSizeStatsFunction::CallGetSizeStatsOnFileThread, |
1677 this, | 1626 this, |
1678 files[0].file_path.value())); | 1627 file_path.value())); |
1679 } | 1628 } |
| 1629 return true; |
1680 } | 1630 } |
1681 | 1631 |
1682 void GetSizeStatsFunction::GetDriveAvailableSpaceCallback( | 1632 void GetSizeStatsFunction::GetDriveAvailableSpaceCallback( |
1683 drive::DriveFileError error, | 1633 drive::DriveFileError error, |
1684 int64 bytes_total, | 1634 int64 bytes_total, |
1685 int64 bytes_used) { | 1635 int64 bytes_used) { |
1686 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1636 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1687 | 1637 |
1688 if (error == drive::DRIVE_FILE_OK) { | 1638 if (error == drive::DRIVE_FILE_OK) { |
1689 int64 bytes_remaining = bytes_total - bytes_used; | 1639 int64 bytes_remaining = bytes_total - bytes_used; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1735 if (args_->GetSize() != 1) { | 1685 if (args_->GetSize() != 1) { |
1736 return false; | 1686 return false; |
1737 } | 1687 } |
1738 | 1688 |
1739 std::string volume_file_url; | 1689 std::string volume_file_url; |
1740 if (!args_->GetString(0, &volume_file_url)) { | 1690 if (!args_->GetString(0, &volume_file_url)) { |
1741 NOTREACHED(); | 1691 NOTREACHED(); |
1742 return false; | 1692 return false; |
1743 } | 1693 } |
1744 | 1694 |
1745 UrlList file_paths; | 1695 FilePath file_path = GetLocalPathFromURL(GURL(volume_file_url)); |
1746 file_paths.push_back(GURL(volume_file_url)); | 1696 if (file_path.empty()) |
| 1697 return false; |
1747 | 1698 |
1748 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread( | 1699 DiskMountManager::GetInstance()->FormatMountedDevice(file_path.value()); |
1749 file_paths, | 1700 SendResponse(true); |
1750 base::Bind(&FormatDeviceFunction::GetLocalPathsResponseOnUIThread, this)); | |
1751 return true; | 1701 return true; |
1752 } | 1702 } |
1753 | 1703 |
1754 void FormatDeviceFunction::GetLocalPathsResponseOnUIThread( | |
1755 const SelectedFileInfoList& files) { | |
1756 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
1757 | |
1758 if (files.size() != 1) { | |
1759 SendResponse(false); | |
1760 return; | |
1761 } | |
1762 | |
1763 DiskMountManager::GetInstance()->FormatMountedDevice( | |
1764 files[0].file_path.value()); | |
1765 SendResponse(true); | |
1766 } | |
1767 | |
1768 GetVolumeMetadataFunction::GetVolumeMetadataFunction() { | 1704 GetVolumeMetadataFunction::GetVolumeMetadataFunction() { |
1769 } | 1705 } |
1770 | 1706 |
1771 GetVolumeMetadataFunction::~GetVolumeMetadataFunction() { | 1707 GetVolumeMetadataFunction::~GetVolumeMetadataFunction() { |
1772 } | 1708 } |
1773 | 1709 |
1774 bool GetVolumeMetadataFunction::RunImpl() { | 1710 bool GetVolumeMetadataFunction::RunImpl() { |
1775 if (args_->GetSize() != 1) { | 1711 if (args_->GetSize() != 1) { |
1776 error_ = "Invalid argument count"; | 1712 error_ = "Invalid argument count"; |
1777 return false; | 1713 return false; |
1778 } | 1714 } |
1779 | 1715 |
1780 std::string volume_mount_url; | 1716 std::string volume_mount_url; |
1781 if (!args_->GetString(0, &volume_mount_url)) { | 1717 if (!args_->GetString(0, &volume_mount_url)) { |
1782 NOTREACHED(); | 1718 NOTREACHED(); |
| 1719 return false; |
1783 } | 1720 } |
1784 | 1721 |
1785 UrlList file_paths; | 1722 FilePath file_path = GetLocalPathFromURL(GURL(volume_mount_url)); |
1786 file_paths.push_back(GURL(volume_mount_url)); | 1723 if (file_path.empty()) { |
1787 | |
1788 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread( | |
1789 file_paths, | |
1790 base::Bind(&GetVolumeMetadataFunction::GetLocalPathsResponseOnUIThread, | |
1791 this)); | |
1792 | |
1793 return true; | |
1794 } | |
1795 | |
1796 void GetVolumeMetadataFunction::GetLocalPathsResponseOnUIThread( | |
1797 const SelectedFileInfoList& files) { | |
1798 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
1799 | |
1800 // Should contain volume's mount path. | |
1801 if (files.size() != 1) { | |
1802 error_ = "Invalid mount path."; | 1724 error_ = "Invalid mount path."; |
1803 SendResponse(false); | 1725 return false; |
1804 return; | |
1805 } | 1726 } |
1806 | 1727 |
1807 results_.reset(); | 1728 results_.reset(); |
1808 | 1729 |
1809 const DiskMountManager::Disk* volume = GetVolumeAsDisk( | 1730 const DiskMountManager::Disk* volume = GetVolumeAsDisk(file_path.value()); |
1810 files[0].file_path.value()); | |
1811 if (volume) { | 1731 if (volume) { |
1812 DictionaryValue* volume_info = | 1732 DictionaryValue* volume_info = |
1813 CreateValueFromDisk(profile_, volume); | 1733 CreateValueFromDisk(profile_, volume); |
1814 SetResult(volume_info); | 1734 SetResult(volume_info); |
1815 } | 1735 } |
1816 | 1736 |
1817 SendResponse(true); | 1737 SendResponse(true); |
| 1738 return true; |
1818 } | 1739 } |
1819 | 1740 |
1820 bool ToggleFullscreenFunction::RunImpl() { | 1741 bool ToggleFullscreenFunction::RunImpl() { |
1821 Browser* browser = GetCurrentBrowser(); | 1742 Browser* browser = GetCurrentBrowser(); |
1822 if (browser) { | 1743 if (browser) { |
1823 browser->ToggleFullscreenModeWithExtension( | 1744 browser->ToggleFullscreenModeWithExtension( |
1824 file_manager_util::GetFileBrowserExtensionUrl()); | 1745 file_manager_util::GetFileBrowserExtensionUrl()); |
1825 } | 1746 } |
1826 return true; | 1747 return true; |
1827 } | 1748 } |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2473 | 2394 |
2474 GetFileLocationsFunction::~GetFileLocationsFunction() { | 2395 GetFileLocationsFunction::~GetFileLocationsFunction() { |
2475 } | 2396 } |
2476 | 2397 |
2477 bool GetFileLocationsFunction::RunImpl() { | 2398 bool GetFileLocationsFunction::RunImpl() { |
2478 ListValue* file_urls_as_strings = NULL; | 2399 ListValue* file_urls_as_strings = NULL; |
2479 if (!args_->GetList(0, &file_urls_as_strings)) | 2400 if (!args_->GetList(0, &file_urls_as_strings)) |
2480 return false; | 2401 return false; |
2481 | 2402 |
2482 // Convert the list of strings to a list of GURLs. | 2403 // Convert the list of strings to a list of GURLs. |
2483 UrlList file_urls; | 2404 scoped_ptr<ListValue> locations(new ListValue); |
2484 for (size_t i = 0; i < file_urls_as_strings->GetSize(); ++i) { | 2405 for (size_t i = 0; i < file_urls_as_strings->GetSize(); ++i) { |
2485 std::string file_url_as_string; | 2406 std::string file_url_as_string; |
2486 if (!file_urls_as_strings->GetString(i, &file_url_as_string)) | 2407 if (!file_urls_as_strings->GetString(i, &file_url_as_string)) |
2487 return false; | 2408 return false; |
2488 file_urls.push_back(GURL(file_url_as_string)); | 2409 |
| 2410 fileapi::FileSystemURL url((GURL(file_url_as_string))); |
| 2411 if (url.type() == fileapi::kFileSystemTypeDrive) |
| 2412 locations->Append(new base::StringValue("drive")); |
| 2413 else |
| 2414 locations->Append(new base::StringValue("local")); |
2489 } | 2415 } |
2490 | 2416 |
2491 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread( | 2417 SetResult(locations.release()); |
2492 file_urls, | 2418 SendResponse(true); |
2493 base::Bind(&GetFileLocationsFunction::GetLocalPathsResponseOnUIThread, | |
2494 this)); | |
2495 return true; | 2419 return true; |
2496 } | 2420 } |
2497 | 2421 |
2498 void GetFileLocationsFunction::GetLocalPathsResponseOnUIThread( | |
2499 const SelectedFileInfoList& files) { | |
2500 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
2501 | |
2502 ListValue* locations = new ListValue; | |
2503 for (size_t i = 0; i < files.size(); ++i) { | |
2504 if (drive::util::IsUnderDriveMountPoint(files[i].file_path)) { | |
2505 locations->Append(new base::StringValue("drive")); | |
2506 } else { | |
2507 locations->Append(new base::StringValue("local")); | |
2508 } | |
2509 } | |
2510 | |
2511 SetResult(locations); | |
2512 SendResponse(true); | |
2513 } | |
2514 | |
2515 GetDriveFilesFunction::GetDriveFilesFunction() | 2422 GetDriveFilesFunction::GetDriveFilesFunction() |
2516 : local_paths_(NULL) { | 2423 : local_paths_(NULL) { |
2517 } | 2424 } |
2518 | 2425 |
2519 GetDriveFilesFunction::~GetDriveFilesFunction() { | 2426 GetDriveFilesFunction::~GetDriveFilesFunction() { |
2520 } | 2427 } |
2521 | 2428 |
2522 bool GetDriveFilesFunction::RunImpl() { | 2429 bool GetDriveFilesFunction::RunImpl() { |
2523 ListValue* file_urls_as_strings = NULL; | 2430 ListValue* file_urls_as_strings = NULL; |
2524 if (!args_->GetList(0, &file_urls_as_strings)) | 2431 if (!args_->GetList(0, &file_urls_as_strings)) |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2640 return true; | 2547 return true; |
2641 } | 2548 } |
2642 | 2549 |
2643 | 2550 |
2644 CancelFileTransfersFunction::CancelFileTransfersFunction() {} | 2551 CancelFileTransfersFunction::CancelFileTransfersFunction() {} |
2645 | 2552 |
2646 CancelFileTransfersFunction::~CancelFileTransfersFunction() {} | 2553 CancelFileTransfersFunction::~CancelFileTransfersFunction() {} |
2647 | 2554 |
2648 bool CancelFileTransfersFunction::RunImpl() { | 2555 bool CancelFileTransfersFunction::RunImpl() { |
2649 ListValue* url_list = NULL; | 2556 ListValue* url_list = NULL; |
2650 if (!args_->GetList(0, &url_list)) { | 2557 if (!args_->GetList(0, &url_list)) |
2651 SendResponse(false); | |
2652 return false; | 2558 return false; |
2653 } | |
2654 | 2559 |
2655 std::string virtual_path; | |
2656 size_t len = url_list->GetSize(); | |
2657 UrlList file_urls; | |
2658 file_urls.reserve(len); | |
2659 for (size_t i = 0; i < len; ++i) { | |
2660 url_list->GetString(i, &virtual_path); | |
2661 file_urls.push_back(GURL(virtual_path)); | |
2662 } | |
2663 | |
2664 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread( | |
2665 file_urls, | |
2666 base::Bind(&CancelFileTransfersFunction::GetLocalPathsResponseOnUIThread, | |
2667 this)); | |
2668 return true; | |
2669 } | |
2670 | |
2671 void CancelFileTransfersFunction::GetLocalPathsResponseOnUIThread( | |
2672 const SelectedFileInfoList& files) { | |
2673 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
2674 drive::DriveSystemService* system_service = | 2560 drive::DriveSystemService* system_service = |
2675 drive::DriveSystemServiceFactory::GetForProfile(profile_); | 2561 drive::DriveSystemServiceFactory::GetForProfile(profile_); |
2676 // |system_service| is NULL if Drive is disabled. | 2562 // |system_service| is NULL if Drive is disabled. |
2677 if (!system_service) { | 2563 if (!system_service) |
2678 SendResponse(false); | 2564 return false; |
2679 return; | |
2680 } | |
2681 | 2565 |
2682 scoped_ptr<ListValue> responses(new ListValue()); | 2566 scoped_ptr<ListValue> responses(new ListValue()); |
2683 for (size_t i = 0; i < files.size(); ++i) { | 2567 for (size_t i = 0; i < url_list->GetSize(); ++i) { |
2684 DCHECK(drive::util::IsUnderDriveMountPoint(files[i].file_path)); | 2568 std::string url_as_string; |
2685 FilePath file_path = drive::util::ExtractDrivePath(files[i].file_path); | 2569 url_list->GetString(i, &url_as_string); |
| 2570 |
| 2571 FilePath file_path = GetLocalPathFromURL(GURL(url_as_string)); |
| 2572 if (file_path.empty()) |
| 2573 continue; |
| 2574 |
| 2575 DCHECK(drive::util::IsUnderDriveMountPoint(file_path)); |
| 2576 file_path = drive::util::ExtractDrivePath(file_path); |
2686 scoped_ptr<DictionaryValue> result(new DictionaryValue()); | 2577 scoped_ptr<DictionaryValue> result(new DictionaryValue()); |
2687 result->SetBoolean( | 2578 result->SetBoolean( |
2688 "canceled", | 2579 "canceled", |
2689 system_service->drive_service()->CancelForFilePath(file_path)); | 2580 system_service->drive_service()->CancelForFilePath(file_path)); |
2690 GURL file_url; | 2581 GURL file_url; |
2691 if (file_manager_util::ConvertFileToFileSystemUrl(profile_, | 2582 if (file_manager_util::ConvertFileToFileSystemUrl(profile_, |
2692 drive::util::GetSpecialRemoteRootPath().Append(file_path), | 2583 drive::util::GetSpecialRemoteRootPath().Append(file_path), |
2693 source_url_.GetOrigin(), | 2584 source_url_.GetOrigin(), |
2694 &file_url)) { | 2585 &file_url)) { |
2695 result->SetString("fileUrl", file_url.spec()); | 2586 result->SetString("fileUrl", file_url.spec()); |
2696 } | 2587 } |
2697 | |
2698 responses->Append(result.release()); | 2588 responses->Append(result.release()); |
2699 } | 2589 } |
2700 SetResult(responses.release()); | 2590 SetResult(responses.release()); |
2701 SendResponse(true); | 2591 SendResponse(true); |
| 2592 return true; |
2702 } | 2593 } |
2703 | 2594 |
2704 TransferFileFunction::TransferFileFunction() {} | 2595 TransferFileFunction::TransferFileFunction() {} |
2705 | 2596 |
2706 TransferFileFunction::~TransferFileFunction() {} | 2597 TransferFileFunction::~TransferFileFunction() {} |
2707 | 2598 |
2708 bool TransferFileFunction::RunImpl() { | 2599 bool TransferFileFunction::RunImpl() { |
2709 std::string local_file_url; | 2600 std::string source_file_url; |
2710 std::string remote_file_url; | 2601 std::string destination_file_url; |
2711 if (!args_->GetString(0, &local_file_url) || | 2602 if (!args_->GetString(0, &source_file_url) || |
2712 !args_->GetString(1, &remote_file_url)) { | 2603 !args_->GetString(1, &destination_file_url)) { |
2713 return false; | 2604 return false; |
2714 } | 2605 } |
2715 | 2606 |
2716 UrlList file_urls; | |
2717 file_urls.push_back(GURL(local_file_url)); | |
2718 file_urls.push_back(GURL(remote_file_url)); | |
2719 | |
2720 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread( | |
2721 file_urls, | |
2722 base::Bind(&TransferFileFunction::GetLocalPathsResponseOnUIThread, | |
2723 this)); | |
2724 return true; | |
2725 } | |
2726 | |
2727 void TransferFileFunction::GetLocalPathsResponseOnUIThread( | |
2728 const SelectedFileInfoList& files) { | |
2729 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
2730 if (files.size() != 2U) { | |
2731 SendResponse(false); | |
2732 return; | |
2733 } | |
2734 | |
2735 drive::DriveSystemService* system_service = | 2607 drive::DriveSystemService* system_service = |
2736 drive::DriveSystemServiceFactory::GetForProfile(profile_); | 2608 drive::DriveSystemServiceFactory::GetForProfile(profile_); |
2737 // |system_service| is NULL if Drive is disabled. | 2609 // |system_service| is NULL if Drive is disabled. |
2738 if (!system_service) { | 2610 if (!system_service) |
2739 SendResponse(false); | 2611 return false; |
2740 return; | |
2741 } | |
2742 | 2612 |
2743 FilePath source_file = files[0].file_path; | 2613 FilePath source_file = GetLocalPathFromURL(GURL(source_file_url)); |
2744 FilePath destination_file = files[1].file_path; | 2614 FilePath destination_file = GetLocalPathFromURL(GURL(destination_file_url)); |
| 2615 if (source_file.empty() || destination_file.empty()) |
| 2616 return false; |
2745 | 2617 |
2746 bool source_file_under_drive = | 2618 bool source_file_under_drive = |
2747 drive::util::IsUnderDriveMountPoint(source_file); | 2619 drive::util::IsUnderDriveMountPoint(source_file); |
2748 bool destination_file_under_drive = | 2620 bool destination_file_under_drive = |
2749 drive::util::IsUnderDriveMountPoint(destination_file); | 2621 drive::util::IsUnderDriveMountPoint(destination_file); |
2750 | 2622 |
2751 if (source_file_under_drive && !destination_file_under_drive) { | 2623 if (source_file_under_drive && !destination_file_under_drive) { |
2752 // Transfer a file from gdata to local file system. | 2624 // Transfer a file from gdata to local file system. |
2753 source_file = drive::util::ExtractDrivePath(source_file); | 2625 source_file = drive::util::ExtractDrivePath(source_file); |
2754 system_service->file_system()->TransferFileFromRemoteToLocal( | 2626 system_service->file_system()->TransferFileFromRemoteToLocal( |
2755 source_file, | 2627 source_file, |
2756 destination_file, | 2628 destination_file, |
2757 base::Bind(&TransferFileFunction::OnTransferCompleted, this)); | 2629 base::Bind(&TransferFileFunction::OnTransferCompleted, this)); |
2758 } else if (!source_file_under_drive && destination_file_under_drive) { | 2630 } else if (!source_file_under_drive && destination_file_under_drive) { |
2759 // Transfer a file from local to Drive file system | 2631 // Transfer a file from local to Drive file system |
2760 destination_file = drive::util::ExtractDrivePath(destination_file); | 2632 destination_file = drive::util::ExtractDrivePath(destination_file); |
2761 system_service->file_system()->TransferFileFromLocalToRemote( | 2633 system_service->file_system()->TransferFileFromLocalToRemote( |
2762 source_file, | 2634 source_file, |
2763 destination_file, | 2635 destination_file, |
2764 base::Bind(&TransferFileFunction::OnTransferCompleted, this)); | 2636 base::Bind(&TransferFileFunction::OnTransferCompleted, this)); |
2765 } else { | 2637 } else { |
2766 // Local-to-local or Drive-to-Drive file transfers should be done via | 2638 // Local-to-local or Drive-to-Drive file transfers should be done via |
2767 // FileEntry.copyTo in the File API and are thus not supported here. | 2639 // FileEntry.copyTo in the File API and are thus not supported here. |
2768 NOTREACHED(); | 2640 NOTREACHED(); |
2769 SendResponse(false); | 2641 SendResponse(false); |
2770 } | 2642 } |
| 2643 return true; |
2771 } | 2644 } |
2772 | 2645 |
2773 void TransferFileFunction::OnTransferCompleted(drive::DriveFileError error) { | 2646 void TransferFileFunction::OnTransferCompleted(drive::DriveFileError error) { |
2774 if (error == drive::DRIVE_FILE_OK) { | 2647 if (error == drive::DRIVE_FILE_OK) { |
2775 SendResponse(true); | 2648 SendResponse(true); |
2776 } else { | 2649 } else { |
2777 error_ = base::StringPrintf("%d", static_cast<int>( | 2650 error_ = base::StringPrintf("%d", static_cast<int>( |
2778 fileapi::PlatformFileErrorToWebFileError( | 2651 fileapi::PlatformFileErrorToWebFileError( |
2779 drive::DriveFileErrorToPlatformError(error)))); | 2652 drive::DriveFileErrorToPlatformError(error)))); |
2780 SendResponse(false); | 2653 SendResponse(false); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2982 bool ZipSelectionFunction::RunImpl() { | 2855 bool ZipSelectionFunction::RunImpl() { |
2983 if (args_->GetSize() < 3) { | 2856 if (args_->GetSize() < 3) { |
2984 return false; | 2857 return false; |
2985 } | 2858 } |
2986 | 2859 |
2987 // First param is the source directory URL. | 2860 // First param is the source directory URL. |
2988 std::string dir_url; | 2861 std::string dir_url; |
2989 if (!args_->GetString(0, &dir_url) || dir_url.empty()) | 2862 if (!args_->GetString(0, &dir_url) || dir_url.empty()) |
2990 return false; | 2863 return false; |
2991 | 2864 |
| 2865 FilePath src_dir = GetLocalPathFromURL(GURL(dir_url)); |
| 2866 if (src_dir.empty()) |
| 2867 return false; |
| 2868 |
2992 // Second param is the list of selected file URLs. | 2869 // Second param is the list of selected file URLs. |
2993 ListValue* selection_urls = NULL; | 2870 ListValue* selection_urls = NULL; |
2994 args_->GetList(1, &selection_urls); | 2871 args_->GetList(1, &selection_urls); |
2995 if (!selection_urls || !selection_urls->GetSize()) | 2872 if (!selection_urls || !selection_urls->GetSize()) |
2996 return false; | 2873 return false; |
2997 | 2874 |
| 2875 std::vector<FilePath> files; |
| 2876 for (size_t i = 0; i < selection_urls->GetSize(); ++i) { |
| 2877 std::string file_url; |
| 2878 selection_urls->GetString(i, &file_url); |
| 2879 FilePath path = GetLocalPathFromURL(GURL(file_url)); |
| 2880 if (path.empty()) |
| 2881 return false; |
| 2882 files.push_back(path); |
| 2883 } |
| 2884 |
2998 // Third param is the name of the output zip file. | 2885 // Third param is the name of the output zip file. |
2999 std::string dest_name; | 2886 std::string dest_name; |
3000 if (!args_->GetString(2, &dest_name) || dest_name.empty()) | 2887 if (!args_->GetString(2, &dest_name) || dest_name.empty()) |
3001 return false; | 2888 return false; |
3002 | 2889 |
3003 UrlList file_urls; | |
3004 size_t len = selection_urls->GetSize(); | |
3005 file_urls.reserve(len + 1); | |
3006 file_urls.push_back(GURL(dir_url)); | |
3007 for (size_t i = 0; i < len; ++i) { | |
3008 std::string file_url; | |
3009 selection_urls->GetString(i, &file_url); | |
3010 file_urls.push_back(GURL(file_url)); | |
3011 } | |
3012 | |
3013 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread( | |
3014 file_urls, | |
3015 base::Bind(&ZipSelectionFunction::GetLocalPathsResponseOnUIThread, | |
3016 this, | |
3017 dest_name)); | |
3018 return true; | |
3019 } | |
3020 | |
3021 void ZipSelectionFunction::GetLocalPathsResponseOnUIThread( | |
3022 const std::string dest_name, | |
3023 const SelectedFileInfoList& files) { | |
3024 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
3025 if (files.size() <= 1) { | |
3026 NOTREACHED(); | |
3027 SendResponse(false); | |
3028 return; | |
3029 } | |
3030 | |
3031 SelectedFileInfoList::const_iterator iter = files.begin(); | |
3032 FilePath src_dir = iter->file_path; | |
3033 | |
3034 // Check if the dir path is under Drive cache directory. | 2890 // Check if the dir path is under Drive cache directory. |
3035 // TODO(hshi): support create zip file on Drive (crbug.com/158690). | 2891 // TODO(hshi): support create zip file on Drive (crbug.com/158690). |
3036 drive::DriveSystemService* system_service = | 2892 drive::DriveSystemService* system_service = |
3037 drive::DriveSystemServiceFactory::GetForProfile(profile_); | 2893 drive::DriveSystemServiceFactory::GetForProfile(profile_); |
3038 drive::DriveCache* cache = system_service ? system_service->cache() : NULL; | 2894 drive::DriveCache* cache = system_service ? system_service->cache() : NULL; |
3039 if (cache && cache->IsUnderDriveCacheDirectory(src_dir)) { | 2895 if (cache && cache->IsUnderDriveCacheDirectory(src_dir)) |
3040 SendResponse(false); | 2896 return false; |
3041 return; | |
3042 } | |
3043 | 2897 |
3044 FilePath dest_file = src_dir.Append(dest_name); | 2898 FilePath dest_file = src_dir.Append(dest_name); |
3045 std::vector<FilePath> src_relative_paths; | 2899 std::vector<FilePath> src_relative_paths; |
3046 for (++iter; iter != files.end(); ++iter) { | 2900 for (size_t i = 0; i != files.size(); ++i) { |
3047 const FilePath& file_path = iter->file_path; | 2901 const FilePath& file_path = files[i]; |
3048 | 2902 |
3049 // Obtain the relative path of |file_path| under |src_dir|. | 2903 // Obtain the relative path of |file_path| under |src_dir|. |
3050 FilePath relative_path; | 2904 FilePath relative_path; |
3051 if (!src_dir.AppendRelativePath(file_path, &relative_path)) { | 2905 if (!src_dir.AppendRelativePath(file_path, &relative_path)) |
3052 // All files must be under |src_dir| or there is a bug in extension code. | 2906 return false; |
3053 SendResponse(false); | |
3054 return; | |
3055 } | |
3056 src_relative_paths.push_back(relative_path); | 2907 src_relative_paths.push_back(relative_path); |
3057 } | 2908 } |
3058 | 2909 |
3059 zip_file_creator_ = new ZipFileCreator(this, src_dir, src_relative_paths, | 2910 zip_file_creator_ = new ZipFileCreator(this, src_dir, src_relative_paths, |
3060 dest_file); | 2911 dest_file); |
3061 zip_file_creator_->Start(); | 2912 zip_file_creator_->Start(); |
3062 | 2913 |
3063 // Keep the refcount until the zipping is complete on utility process. | 2914 // Keep the refcount until the zipping is complete on utility process. |
3064 AddRef(); | 2915 AddRef(); |
| 2916 return true; |
3065 } | 2917 } |
3066 | 2918 |
3067 void ZipSelectionFunction::OnZipDone(bool success) { | 2919 void ZipSelectionFunction::OnZipDone(bool success) { |
3068 SetResult(new base::FundamentalValue(success)); | 2920 SetResult(new base::FundamentalValue(success)); |
3069 SendResponse(true); | 2921 SendResponse(true); |
3070 Release(); | 2922 Release(); |
3071 } | 2923 } |
OLD | NEW |