| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_manager/private_api_file_syste
m.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_file_syste
m.h" |
| 6 | 6 |
| 7 #include <sys/statvfs.h> | 7 #include <sys/statvfs.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/posix/eintr_wrapper.h" | 17 #include "base/posix/eintr_wrapper.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/sys_info.h" | 20 #include "base/sys_info.h" |
| 21 #include "base/task_runner_util.h" | 21 #include "base/task_runner_util.h" |
| 22 #include "base/task_scheduler/post_task.h" |
| 22 #include "base/threading/sequenced_worker_pool.h" | 23 #include "base/threading/sequenced_worker_pool.h" |
| 23 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 24 #include "chrome/browser/chromeos/drive/file_system_util.h" | 25 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 25 #include "chrome/browser/chromeos/extensions/file_manager/event_router.h" | 26 #include "chrome/browser/chromeos/extensions/file_manager/event_router.h" |
| 26 #include "chrome/browser/chromeos/extensions/file_manager/event_router_factory.h
" | 27 #include "chrome/browser/chromeos/extensions/file_manager/event_router_factory.h
" |
| 27 #include "chrome/browser/chromeos/extensions/file_manager/file_stream_md5_digest
er.h" | 28 #include "chrome/browser/chromeos/extensions/file_manager/file_stream_md5_digest
er.h" |
| 28 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" | 29 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" |
| 29 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" | 30 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
| 30 #include "chrome/browser/chromeos/file_manager/path_util.h" | 31 #include "chrome/browser/chromeos/file_manager/path_util.h" |
| 31 #include "chrome/browser/chromeos/file_manager/volume_manager.h" | 32 #include "chrome/browser/chromeos/file_manager/volume_manager.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 using file_manager::util::EntryDefinition; | 66 using file_manager::util::EntryDefinition; |
| 66 using file_manager::util::FileDefinition; | 67 using file_manager::util::FileDefinition; |
| 67 using storage::FileSystemURL; | 68 using storage::FileSystemURL; |
| 68 | 69 |
| 69 namespace extensions { | 70 namespace extensions { |
| 70 namespace { | 71 namespace { |
| 71 | 72 |
| 72 const char kRootPath[] = "/"; | 73 const char kRootPath[] = "/"; |
| 73 | 74 |
| 74 // Retrieves total and remaining available size on |mount_path|. | 75 // Retrieves total and remaining available size on |mount_path|. |
| 75 void GetSizeStatsOnBlockingPool(const base::FilePath& mount_path, | 76 void GetSizeStatsAsync(const base::FilePath& mount_path, |
| 76 uint64_t* total_size, | 77 uint64_t* total_size, |
| 77 uint64_t* remaining_size) { | 78 uint64_t* remaining_size) { |
| 78 int64_t size = base::SysInfo::AmountOfTotalDiskSpace(mount_path); | 79 int64_t size = base::SysInfo::AmountOfTotalDiskSpace(mount_path); |
| 79 if (size >= 0) | 80 if (size >= 0) |
| 80 *total_size = size; | 81 *total_size = size; |
| 81 size = base::SysInfo::AmountOfFreeDiskSpace(mount_path); | 82 size = base::SysInfo::AmountOfFreeDiskSpace(mount_path); |
| 82 if (size >= 0) | 83 if (size >= 0) |
| 83 *remaining_size = size; | 84 *remaining_size = size; |
| 84 } | 85 } |
| 85 | 86 |
| 86 // Retrieves the maximum file name length of the file system of |path|. | 87 // Retrieves the maximum file name length of the file system of |path|. |
| 87 // Returns 0 if it could not be queried. | 88 // Returns 0 if it could not be queried. |
| 88 size_t GetFileNameMaxLengthOnBlockingPool(const std::string& path) { | 89 size_t GetFileNameMaxLengthAsync(const std::string& path) { |
| 89 struct statvfs stat = {}; | 90 struct statvfs stat = {}; |
| 90 if (HANDLE_EINTR(statvfs(path.c_str(), &stat)) != 0) { | 91 if (HANDLE_EINTR(statvfs(path.c_str(), &stat)) != 0) { |
| 91 // The filesystem seems not supporting statvfs(). Assume it to be a commonly | 92 // The filesystem seems not supporting statvfs(). Assume it to be a commonly |
| 92 // used bound 255, and log the failure. | 93 // used bound 255, and log the failure. |
| 93 LOG(ERROR) << "Cannot statvfs() the name length limit for: " << path; | 94 LOG(ERROR) << "Cannot statvfs() the name length limit for: " << path; |
| 94 return 255; | 95 return 255; |
| 95 } | 96 } |
| 96 return stat.f_namemax; | 97 return stat.f_namemax; |
| 97 } | 98 } |
| 98 | 99 |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 device::MediaTransferProtocolManager* manager = | 440 device::MediaTransferProtocolManager* manager = |
| 440 storage_monitor->media_transfer_protocol_manager(); | 441 storage_monitor->media_transfer_protocol_manager(); |
| 441 manager->GetStorageInfoFromDevice( | 442 manager->GetStorageInfoFromDevice( |
| 442 storage_name, | 443 storage_name, |
| 443 base::Bind( | 444 base::Bind( |
| 444 &FileManagerPrivateGetSizeStatsFunction::OnGetMtpAvailableSpace, | 445 &FileManagerPrivateGetSizeStatsFunction::OnGetMtpAvailableSpace, |
| 445 this)); | 446 this)); |
| 446 } else { | 447 } else { |
| 447 uint64_t* total_size = new uint64_t(0); | 448 uint64_t* total_size = new uint64_t(0); |
| 448 uint64_t* remaining_size = new uint64_t(0); | 449 uint64_t* remaining_size = new uint64_t(0); |
| 449 BrowserThread::PostBlockingPoolTaskAndReply( | 450 base::PostTaskWithTraitsAndReply( |
| 450 FROM_HERE, base::Bind(&GetSizeStatsOnBlockingPool, volume->mount_path(), | 451 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( |
| 451 total_size, remaining_size), | 452 base::TaskPriority::USER_VISIBLE), |
| 453 base::Bind(&GetSizeStatsAsync, volume->mount_path(), total_size, |
| 454 remaining_size), |
| 452 base::Bind(&FileManagerPrivateGetSizeStatsFunction::OnGetSizeStats, | 455 base::Bind(&FileManagerPrivateGetSizeStatsFunction::OnGetSizeStats, |
| 453 this, base::Owned(total_size), base::Owned(remaining_size))); | 456 this, base::Owned(total_size), base::Owned(remaining_size))); |
| 454 } | 457 } |
| 455 return true; | 458 return true; |
| 456 } | 459 } |
| 457 | 460 |
| 458 void FileManagerPrivateGetSizeStatsFunction::OnGetDriveAvailableSpace( | 461 void FileManagerPrivateGetSizeStatsFunction::OnGetDriveAvailableSpace( |
| 459 drive::FileError error, | 462 drive::FileError error, |
| 460 int64_t bytes_total, | 463 int64_t bytes_total, |
| 461 int64_t bytes_used) { | 464 int64_t bytes_used) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 if (!chromeos::FileSystemBackend::CanHandleURL(file_system_url)) | 516 if (!chromeos::FileSystemBackend::CanHandleURL(file_system_url)) |
| 514 return false; | 517 return false; |
| 515 | 518 |
| 516 // No explicit limit on the length of Drive file names. | 519 // No explicit limit on the length of Drive file names. |
| 517 if (file_system_url.type() == storage::kFileSystemTypeDrive) { | 520 if (file_system_url.type() == storage::kFileSystemTypeDrive) { |
| 518 SetResult(base::MakeUnique<base::FundamentalValue>(true)); | 521 SetResult(base::MakeUnique<base::FundamentalValue>(true)); |
| 519 SendResponse(true); | 522 SendResponse(true); |
| 520 return true; | 523 return true; |
| 521 } | 524 } |
| 522 | 525 |
| 523 base::PostTaskAndReplyWithResult( | 526 base::PostTaskWithTraitsAndReplyWithResult( |
| 524 BrowserThread::GetBlockingPool(), FROM_HERE, | 527 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( |
| 525 base::Bind(&GetFileNameMaxLengthOnBlockingPool, | 528 base::TaskPriority::USER_BLOCKING), |
| 529 base::Bind(&GetFileNameMaxLengthAsync, |
| 526 file_system_url.path().AsUTF8Unsafe()), | 530 file_system_url.path().AsUTF8Unsafe()), |
| 527 base::Bind(&FileManagerPrivateInternalValidatePathNameLengthFunction:: | 531 base::Bind(&FileManagerPrivateInternalValidatePathNameLengthFunction:: |
| 528 OnFilePathLimitRetrieved, | 532 OnFilePathLimitRetrieved, |
| 529 this, params->name.size())); | 533 this, params->name.size())); |
| 530 return true; | 534 return true; |
| 531 } | 535 } |
| 532 | 536 |
| 533 void FileManagerPrivateInternalValidatePathNameLengthFunction:: | 537 void FileManagerPrivateInternalValidatePathNameLengthFunction:: |
| 534 OnFilePathLimitRetrieved(size_t current_length, size_t max_length) { | 538 OnFilePathLimitRetrieved(size_t current_length, size_t max_length) { |
| 535 SetResult( | 539 SetResult( |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 return false; | 984 return false; |
| 981 } | 985 } |
| 982 | 986 |
| 983 const base::FilePath root_path = file_manager::util::GetLocalPathFromURL( | 987 const base::FilePath root_path = file_manager::util::GetLocalPathFromURL( |
| 984 render_frame_host(), GetProfile(), GURL(params->url)); | 988 render_frame_host(), GetProfile(), GURL(params->url)); |
| 985 if (root_path.empty()) { | 989 if (root_path.empty()) { |
| 986 SetError("Failed to get a local path from the entry's url."); | 990 SetError("Failed to get a local path from the entry's url."); |
| 987 return false; | 991 return false; |
| 988 } | 992 } |
| 989 | 993 |
| 990 base::PostTaskAndReplyWithResult( | 994 base::PostTaskWithTraitsAndReplyWithResult( |
| 991 BrowserThread::GetBlockingPool(), FROM_HERE, | 995 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( |
| 996 base::TaskPriority::USER_VISIBLE), |
| 992 base::Bind(&base::ComputeDirectorySize, root_path), | 997 base::Bind(&base::ComputeDirectorySize, root_path), |
| 993 base::Bind(&FileManagerPrivateInternalGetDirectorySizeFunction:: | 998 base::Bind(&FileManagerPrivateInternalGetDirectorySizeFunction:: |
| 994 OnDirectorySizeRetrieved, | 999 OnDirectorySizeRetrieved, |
| 995 this)); | 1000 this)); |
| 996 return true; | 1001 return true; |
| 997 } | 1002 } |
| 998 | 1003 |
| 999 void FileManagerPrivateInternalGetDirectorySizeFunction:: | 1004 void FileManagerPrivateInternalGetDirectorySizeFunction:: |
| 1000 OnDirectorySizeRetrieved(int64_t size) { | 1005 OnDirectorySizeRetrieved(int64_t size) { |
| 1001 SetResult( | 1006 SetResult( |
| 1002 base::MakeUnique<base::FundamentalValue>(static_cast<double>(size))); | 1007 base::MakeUnique<base::FundamentalValue>(static_cast<double>(size))); |
| 1003 SendResponse(true); | 1008 SendResponse(true); |
| 1004 } | 1009 } |
| 1005 | 1010 |
| 1006 } // namespace extensions | 1011 } // namespace extensions |
| OLD | NEW |