Commit e2322779 authored by fukino's avatar fukino Committed by Commit bot

Make chrome.fileManagerPrivate.getSizeStat return actual available space for Downloads.

getSizeStat() for Downloads used to return
|actual available space| + |evictable Drive cache| - 512MB.
To be consistent with Storage manager (chrome://settings/storage), getSizeStat()
should simplly return |actual available size|.

BUG=640504
TEST=manually compared the avaiable space in Files app and Storage manager.

Review-Url: https://codereview.chromium.org/2274003004
Cr-Commit-Position: refs/heads/master@{#414371}
parent 34260675
...@@ -1143,7 +1143,7 @@ Press any key to continue exploring. ...@@ -1143,7 +1143,7 @@ Press any key to continue exploring.
</message> </message>
<message name="IDS_FILE_BROWSER_SPACE_AVAILABLE" desc="Menu item showing space left for storage."> <message name="IDS_FILE_BROWSER_SPACE_AVAILABLE" desc="Menu item showing space left for storage.">
<ph name="SPACE_AVAILABLE">$1<ex>4.8 GB</ex></ph> left <ph name="SPACE_AVAILABLE">$1<ex>4.8 GB</ex></ph> available
</message> </message>
<message name="IDS_FILE_BROWSER_WAITING_FOR_SPACE_INFO" desc="Menu item, saying that FileBrowser is waiting for space information for storage. When actual data arrives, this item will be replaced with IDS_FILE_BROWSER_SPACE_AVAILABLE"> <message name="IDS_FILE_BROWSER_WAITING_FOR_SPACE_INFO" desc="Menu item, saying that FileBrowser is waiting for space information for storage. When actual data arrives, this item will be replaced with IDS_FILE_BROWSER_SPACE_AVAILABLE">
Waiting for space info... Waiting for space info...
......
...@@ -83,29 +83,6 @@ void GetSizeStatsOnBlockingPool(const base::FilePath& mount_path, ...@@ -83,29 +83,6 @@ void GetSizeStatsOnBlockingPool(const base::FilePath& mount_path,
*remaining_size = size; *remaining_size = size;
} }
// Used for OnCalculateEvictableCacheSize.
using GetSizeStatsCallback =
base::Callback<void(const uint64_t* total_size,
const uint64_t* remaining_space)>;
// Calculates the real remaining size of Download volume and pass it to
// GetSizeStatsCallback.
void OnCalculateEvictableCacheSize(const GetSizeStatsCallback& callback,
uint64_t total_size,
uint64_t remaining_size,
int64_t evictable_cache_size) {
// For calculating real remaining size of Download volume
// - Adds evictable cache size since the space is available if they are
// evicted.
// - Subtracts minimum free space of cryptohome since the space is not
// available for file manager.
const uint64_t real_remaining_size =
std::max(static_cast<int64_t>(remaining_size + evictable_cache_size) -
cryptohome::kMinFreeSpaceInBytes,
int64_t(0));
callback.Run(&total_size, &real_remaining_size);
}
// Retrieves the maximum file name length of the file system of |path|. // Retrieves the maximum file name length of the file system of |path|.
// Returns 0 if it could not be queried. // Returns 0 if it could not be queried.
size_t GetFileNameMaxLengthOnBlockingPool(const std::string& path) { size_t GetFileNameMaxLengthOnBlockingPool(const std::string& path) {
...@@ -472,34 +449,12 @@ bool FileManagerPrivateGetSizeStatsFunction::RunAsync() { ...@@ -472,34 +449,12 @@ bool FileManagerPrivateGetSizeStatsFunction::RunAsync() {
BrowserThread::PostBlockingPoolTaskAndReply( BrowserThread::PostBlockingPoolTaskAndReply(
FROM_HERE, base::Bind(&GetSizeStatsOnBlockingPool, volume->mount_path(), FROM_HERE, base::Bind(&GetSizeStatsOnBlockingPool, volume->mount_path(),
total_size, remaining_size), total_size, remaining_size),
base::Bind( base::Bind(&FileManagerPrivateGetSizeStatsFunction::OnGetSizeStats,
&FileManagerPrivateGetSizeStatsFunction::OnGetLocalSpace, this, this, base::Owned(total_size), base::Owned(remaining_size)));
base::Owned(total_size), base::Owned(remaining_size),
volume->type() == file_manager::VOLUME_TYPE_DOWNLOADS_DIRECTORY));
} }
return true; return true;
} }
void FileManagerPrivateGetSizeStatsFunction::OnGetLocalSpace(
uint64_t* total_size,
uint64_t* remaining_size,
bool is_download) {
drive::FileSystemInterface* const file_system =
drive::util::GetFileSystemByProfile(GetProfile());
if (!is_download || !file_system) {
OnGetSizeStats(total_size, remaining_size);
return;
}
// We need to add evictable cache size to the remaining size of Downloads
// volume if drive is available.
file_system->CalculateEvictableCacheSize(base::Bind(
&OnCalculateEvictableCacheSize,
base::Bind(&FileManagerPrivateGetSizeStatsFunction::OnGetSizeStats, this),
*total_size, *remaining_size));
}
void FileManagerPrivateGetSizeStatsFunction::OnGetDriveAvailableSpace( void FileManagerPrivateGetSizeStatsFunction::OnGetDriveAvailableSpace(
drive::FileError error, drive::FileError error,
int64_t bytes_total, int64_t bytes_total,
......
...@@ -155,10 +155,6 @@ class FileManagerPrivateGetSizeStatsFunction ...@@ -155,10 +155,6 @@ class FileManagerPrivateGetSizeStatsFunction
bool RunAsync() override; bool RunAsync() override;
private: private:
void OnGetLocalSpace(uint64_t* total_size,
uint64_t* remaining_size,
bool is_download);
void OnGetDriveAvailableSpace(drive::FileError error, void OnGetDriveAvailableSpace(drive::FileError error,
int64_t bytes_total, int64_t bytes_total,
int64_t bytes_used); int64_t bytes_used);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment