Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(510)

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc

Issue 2274003004: Make chrome.fileManagerPrivate.getSizeStat return actual available space for Downloads. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 uint64_t* total_size, 76 uint64_t* total_size,
77 uint64_t* remaining_size) { 77 uint64_t* remaining_size) {
78 int64_t size = base::SysInfo::AmountOfTotalDiskSpace(mount_path); 78 int64_t size = base::SysInfo::AmountOfTotalDiskSpace(mount_path);
79 if (size >= 0) 79 if (size >= 0)
80 *total_size = size; 80 *total_size = size;
81 size = base::SysInfo::AmountOfFreeDiskSpace(mount_path); 81 size = base::SysInfo::AmountOfFreeDiskSpace(mount_path);
82 if (size >= 0) 82 if (size >= 0)
83 *remaining_size = size; 83 *remaining_size = size;
84 } 84 }
85 85
86 // Used for OnCalculateEvictableCacheSize.
87 using GetSizeStatsCallback =
88 base::Callback<void(const uint64_t* total_size,
89 const uint64_t* remaining_space)>;
90
91 // Calculates the real remaining size of Download volume and pass it to
92 // GetSizeStatsCallback.
93 void OnCalculateEvictableCacheSize(const GetSizeStatsCallback& callback,
94 uint64_t total_size,
95 uint64_t remaining_size,
96 int64_t evictable_cache_size) {
97 // For calculating real remaining size of Download volume
98 // - Adds evictable cache size since the space is available if they are
99 // evicted.
100 // - Subtracts minimum free space of cryptohome since the space is not
101 // available for file manager.
102 const uint64_t real_remaining_size =
103 std::max(static_cast<int64_t>(remaining_size + evictable_cache_size) -
104 cryptohome::kMinFreeSpaceInBytes,
105 int64_t(0));
106 callback.Run(&total_size, &real_remaining_size);
107 }
108
109 // Retrieves the maximum file name length of the file system of |path|. 86 // Retrieves the maximum file name length of the file system of |path|.
110 // Returns 0 if it could not be queried. 87 // Returns 0 if it could not be queried.
111 size_t GetFileNameMaxLengthOnBlockingPool(const std::string& path) { 88 size_t GetFileNameMaxLengthOnBlockingPool(const std::string& path) {
112 struct statvfs stat = {}; 89 struct statvfs stat = {};
113 if (HANDLE_EINTR(statvfs(path.c_str(), &stat)) != 0) { 90 if (HANDLE_EINTR(statvfs(path.c_str(), &stat)) != 0) {
114 // The filesystem seems not supporting statvfs(). Assume it to be a commonly 91 // The filesystem seems not supporting statvfs(). Assume it to be a commonly
115 // used bound 255, and log the failure. 92 // used bound 255, and log the failure.
116 LOG(ERROR) << "Cannot statvfs() the name length limit for: " << path; 93 LOG(ERROR) << "Cannot statvfs() the name length limit for: " << path;
117 return 255; 94 return 255;
118 } 95 }
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 storage_name, 442 storage_name,
466 base::Bind( 443 base::Bind(
467 &FileManagerPrivateGetSizeStatsFunction::OnGetMtpAvailableSpace, 444 &FileManagerPrivateGetSizeStatsFunction::OnGetMtpAvailableSpace,
468 this)); 445 this));
469 } else { 446 } else {
470 uint64_t* total_size = new uint64_t(0); 447 uint64_t* total_size = new uint64_t(0);
471 uint64_t* remaining_size = new uint64_t(0); 448 uint64_t* remaining_size = new uint64_t(0);
472 BrowserThread::PostBlockingPoolTaskAndReply( 449 BrowserThread::PostBlockingPoolTaskAndReply(
473 FROM_HERE, base::Bind(&GetSizeStatsOnBlockingPool, volume->mount_path(), 450 FROM_HERE, base::Bind(&GetSizeStatsOnBlockingPool, volume->mount_path(),
474 total_size, remaining_size), 451 total_size, remaining_size),
475 base::Bind( 452 base::Bind(&FileManagerPrivateGetSizeStatsFunction::OnGetSizeStats,
476 &FileManagerPrivateGetSizeStatsFunction::OnGetLocalSpace, this, 453 this, base::Owned(total_size), base::Owned(remaining_size)));
477 base::Owned(total_size), base::Owned(remaining_size),
478 volume->type() == file_manager::VOLUME_TYPE_DOWNLOADS_DIRECTORY));
479 } 454 }
480 return true; 455 return true;
481 } 456 }
482 457
483 void FileManagerPrivateGetSizeStatsFunction::OnGetLocalSpace(
484 uint64_t* total_size,
485 uint64_t* remaining_size,
486 bool is_download) {
487 drive::FileSystemInterface* const file_system =
488 drive::util::GetFileSystemByProfile(GetProfile());
489
490 if (!is_download || !file_system) {
491 OnGetSizeStats(total_size, remaining_size);
492 return;
493 }
494
495 // We need to add evictable cache size to the remaining size of Downloads
496 // volume if drive is available.
497 file_system->CalculateEvictableCacheSize(base::Bind(
498 &OnCalculateEvictableCacheSize,
499 base::Bind(&FileManagerPrivateGetSizeStatsFunction::OnGetSizeStats, this),
500 *total_size, *remaining_size));
501 }
502
503 void FileManagerPrivateGetSizeStatsFunction::OnGetDriveAvailableSpace( 458 void FileManagerPrivateGetSizeStatsFunction::OnGetDriveAvailableSpace(
504 drive::FileError error, 459 drive::FileError error,
505 int64_t bytes_total, 460 int64_t bytes_total,
506 int64_t bytes_used) { 461 int64_t bytes_used) {
507 if (error == drive::FILE_ERROR_OK) { 462 if (error == drive::FILE_ERROR_OK) {
508 const uint64_t bytes_total_unsigned = bytes_total; 463 const uint64_t bytes_total_unsigned = bytes_total;
509 // bytes_used can be larger than bytes_total (over quota). 464 // bytes_used can be larger than bytes_total (over quota).
510 const uint64_t bytes_remaining_unsigned = 465 const uint64_t bytes_remaining_unsigned =
511 std::max(bytes_total - bytes_used, int64_t(0)); 466 std::max(bytes_total - bytes_used, int64_t(0));
512 OnGetSizeStats(&bytes_total_unsigned, &bytes_remaining_unsigned); 467 OnGetSizeStats(&bytes_total_unsigned, &bytes_remaining_unsigned);
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 return RespondLater(); 949 return RespondLater();
995 } 950 }
996 951
997 void FileManagerPrivateInternalSetEntryTagFunction::OnSetEntryPropertyCompleted( 952 void FileManagerPrivateInternalSetEntryTagFunction::OnSetEntryPropertyCompleted(
998 drive::FileError result) { 953 drive::FileError result) {
999 Respond(result == drive::FILE_ERROR_OK ? NoArguments() 954 Respond(result == drive::FILE_ERROR_OK ? NoArguments()
1000 : Error("Failed to set a tag.")); 955 : Error("Failed to set a tag."));
1001 } 956 }
1002 957
1003 } // namespace extensions 958 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698