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 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 using file_manager::util::FileDefinition; | 61 using file_manager::util::FileDefinition; |
62 using storage::FileSystemURL; | 62 using storage::FileSystemURL; |
63 | 63 |
64 namespace extensions { | 64 namespace extensions { |
65 namespace { | 65 namespace { |
66 | 66 |
67 const char kRootPath[] = "/"; | 67 const char kRootPath[] = "/"; |
68 | 68 |
69 // Retrieves total and remaining available size on |mount_path|. | 69 // Retrieves total and remaining available size on |mount_path|. |
70 void GetSizeStatsOnBlockingPool(const std::string& mount_path, | 70 void GetSizeStatsOnBlockingPool(const std::string& mount_path, |
71 uint64* total_size, | 71 uint64_t* total_size, |
72 uint64* remaining_size) { | 72 uint64_t* remaining_size) { |
73 struct statvfs stat = {}; // Zero-clear | 73 struct statvfs stat = {}; // Zero-clear |
74 if (HANDLE_EINTR(statvfs(mount_path.c_str(), &stat)) == 0) { | 74 if (HANDLE_EINTR(statvfs(mount_path.c_str(), &stat)) == 0) { |
75 *total_size = static_cast<uint64>(stat.f_blocks) * stat.f_frsize; | 75 *total_size = static_cast<uint64_t>(stat.f_blocks) * stat.f_frsize; |
76 *remaining_size = static_cast<uint64>(stat.f_bavail) * stat.f_frsize; | 76 *remaining_size = static_cast<uint64_t>(stat.f_bavail) * stat.f_frsize; |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 // Used for OnCalculateEvictableCacheSize. | 80 // Used for OnCalculateEvictableCacheSize. |
81 typedef base::Callback<void(const uint64_t* total_size, | 81 typedef base::Callback<void(const uint64_t* total_size, |
82 const uint64_t* remaining_space)> | 82 const uint64_t* remaining_space)> |
83 GetSizeStatsCallback; | 83 GetSizeStatsCallback; |
84 | 84 |
85 // Calculates the real remaining size of Download volume and pass it to | 85 // Calculates the real remaining size of Download volume and pass it to |
86 // GetSizeStatsCallback. | 86 // GetSizeStatsCallback. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 return file_manager::EventRouterFactory::GetForProfile(profile); | 126 return file_manager::EventRouterFactory::GetForProfile(profile); |
127 } | 127 } |
128 | 128 |
129 // Notifies the copy progress to extensions via event router. | 129 // Notifies the copy progress to extensions via event router. |
130 void NotifyCopyProgress( | 130 void NotifyCopyProgress( |
131 void* profile_id, | 131 void* profile_id, |
132 storage::FileSystemOperationRunner::OperationID operation_id, | 132 storage::FileSystemOperationRunner::OperationID operation_id, |
133 storage::FileSystemOperation::CopyProgressType type, | 133 storage::FileSystemOperation::CopyProgressType type, |
134 const FileSystemURL& source_url, | 134 const FileSystemURL& source_url, |
135 const FileSystemURL& destination_url, | 135 const FileSystemURL& destination_url, |
136 int64 size) { | 136 int64_t size) { |
137 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 137 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
138 | 138 |
139 file_manager::EventRouter* event_router = | 139 file_manager::EventRouter* event_router = |
140 GetEventRouterByProfileId(profile_id); | 140 GetEventRouterByProfileId(profile_id); |
141 if (event_router) { | 141 if (event_router) { |
142 event_router->OnCopyProgress( | 142 event_router->OnCopyProgress( |
143 operation_id, type, | 143 operation_id, type, |
144 source_url.ToGURL(), destination_url.ToGURL(), size); | 144 source_url.ToGURL(), destination_url.ToGURL(), size); |
145 } | 145 } |
146 } | 146 } |
147 | 147 |
148 // Callback invoked periodically on progress update of Copy(). | 148 // Callback invoked periodically on progress update of Copy(). |
149 void OnCopyProgress( | 149 void OnCopyProgress( |
150 void* profile_id, | 150 void* profile_id, |
151 storage::FileSystemOperationRunner::OperationID* operation_id, | 151 storage::FileSystemOperationRunner::OperationID* operation_id, |
152 storage::FileSystemOperation::CopyProgressType type, | 152 storage::FileSystemOperation::CopyProgressType type, |
153 const FileSystemURL& source_url, | 153 const FileSystemURL& source_url, |
154 const FileSystemURL& destination_url, | 154 const FileSystemURL& destination_url, |
155 int64 size) { | 155 int64_t size) { |
156 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 156 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
157 | 157 |
158 BrowserThread::PostTask( | 158 BrowserThread::PostTask( |
159 BrowserThread::UI, FROM_HERE, | 159 BrowserThread::UI, FROM_HERE, |
160 base::Bind(&NotifyCopyProgress, | 160 base::Bind(&NotifyCopyProgress, |
161 profile_id, *operation_id, type, | 161 profile_id, *operation_id, type, |
162 source_url, destination_url, size)); | 162 source_url, destination_url, size)); |
163 } | 163 } |
164 | 164 |
165 // Notifies the copy completion to extensions via event router. | 165 // Notifies the copy completion to extensions via event router. |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 // We need to add evictable cache size to the remaining size of Downloads | 490 // We need to add evictable cache size to the remaining size of Downloads |
491 // volume if drive is available. | 491 // volume if drive is available. |
492 file_system->CalculateEvictableCacheSize(base::Bind( | 492 file_system->CalculateEvictableCacheSize(base::Bind( |
493 &OnCalculateEvictableCacheSize, | 493 &OnCalculateEvictableCacheSize, |
494 base::Bind(&FileManagerPrivateGetSizeStatsFunction::OnGetSizeStats, this), | 494 base::Bind(&FileManagerPrivateGetSizeStatsFunction::OnGetSizeStats, this), |
495 *total_size, *remaining_size)); | 495 *total_size, *remaining_size)); |
496 } | 496 } |
497 | 497 |
498 void FileManagerPrivateGetSizeStatsFunction::OnGetDriveAvailableSpace( | 498 void FileManagerPrivateGetSizeStatsFunction::OnGetDriveAvailableSpace( |
499 drive::FileError error, | 499 drive::FileError error, |
500 int64 bytes_total, | 500 int64_t bytes_total, |
501 int64 bytes_used) { | 501 int64_t bytes_used) { |
502 if (error == drive::FILE_ERROR_OK) { | 502 if (error == drive::FILE_ERROR_OK) { |
503 const uint64 bytes_total_unsigned = bytes_total; | 503 const uint64_t bytes_total_unsigned = bytes_total; |
504 // bytes_used can be larger than bytes_total (over quota). | 504 // bytes_used can be larger than bytes_total (over quota). |
505 const uint64 bytes_remaining_unsigned = | 505 const uint64_t bytes_remaining_unsigned = |
506 std::max(bytes_total - bytes_used, int64(0)); | 506 std::max(bytes_total - bytes_used, int64_t(0)); |
507 OnGetSizeStats(&bytes_total_unsigned, &bytes_remaining_unsigned); | 507 OnGetSizeStats(&bytes_total_unsigned, &bytes_remaining_unsigned); |
508 } else { | 508 } else { |
509 // If stats couldn't be gotten for drive, result should be left undefined. | 509 // If stats couldn't be gotten for drive, result should be left undefined. |
510 SendResponse(true); | 510 SendResponse(true); |
511 } | 511 } |
512 } | 512 } |
513 | 513 |
514 void FileManagerPrivateGetSizeStatsFunction::OnGetMtpAvailableSpace( | 514 void FileManagerPrivateGetSizeStatsFunction::OnGetMtpAvailableSpace( |
515 const MtpStorageInfo& mtp_storage_info, | 515 const MtpStorageInfo& mtp_storage_info, |
516 const bool error) { | 516 const bool error) { |
517 if (error) { | 517 if (error) { |
518 // If stats couldn't be gotten from MTP volume, result should be left | 518 // If stats couldn't be gotten from MTP volume, result should be left |
519 // undefined same as we do for Drive. | 519 // undefined same as we do for Drive. |
520 SendResponse(true); | 520 SendResponse(true); |
521 return; | 521 return; |
522 } | 522 } |
523 | 523 |
524 const uint64 max_capacity = mtp_storage_info.max_capacity(); | 524 const uint64_t max_capacity = mtp_storage_info.max_capacity(); |
525 const uint64 free_space_in_bytes = mtp_storage_info.free_space_in_bytes(); | 525 const uint64_t free_space_in_bytes = mtp_storage_info.free_space_in_bytes(); |
526 OnGetSizeStats(&max_capacity, &free_space_in_bytes); | 526 OnGetSizeStats(&max_capacity, &free_space_in_bytes); |
527 } | 527 } |
528 | 528 |
529 void FileManagerPrivateGetSizeStatsFunction::OnGetSizeStats( | 529 void FileManagerPrivateGetSizeStatsFunction::OnGetSizeStats( |
530 const uint64* total_size, | 530 const uint64_t* total_size, |
531 const uint64* remaining_size) { | 531 const uint64_t* remaining_size) { |
532 base::DictionaryValue* sizes = new base::DictionaryValue(); | 532 base::DictionaryValue* sizes = new base::DictionaryValue(); |
533 SetResult(sizes); | 533 SetResult(sizes); |
534 | 534 |
535 sizes->SetDouble("totalSize", static_cast<double>(*total_size)); | 535 sizes->SetDouble("totalSize", static_cast<double>(*total_size)); |
536 sizes->SetDouble("remainingSize", static_cast<double>(*remaining_size)); | 536 sizes->SetDouble("remainingSize", static_cast<double>(*remaining_size)); |
537 | 537 |
538 SendResponse(true); | 538 SendResponse(true); |
539 } | 539 } |
540 | 540 |
541 bool FileManagerPrivateInternalValidatePathNameLengthFunction::RunAsync() { | 541 bool FileManagerPrivateInternalValidatePathNameLengthFunction::RunAsync() { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 scoped_refptr<storage::FileSystemContext> file_system_context, | 603 scoped_refptr<storage::FileSystemContext> file_system_context, |
604 const FileSystemURL& url, | 604 const FileSystemURL& url, |
605 int fields, | 605 int fields, |
606 const storage::FileSystemOperation::GetMetadataCallback& callback) { | 606 const storage::FileSystemOperation::GetMetadataCallback& callback) { |
607 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 607 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
608 file_system_context->operation_runner()->GetMetadata( | 608 file_system_context->operation_runner()->GetMetadata( |
609 url, fields, base::Bind(&GetFileMetadataRespondOnUIThread, callback)); | 609 url, fields, base::Bind(&GetFileMetadataRespondOnUIThread, callback)); |
610 } | 610 } |
611 | 611 |
612 // Checks if the available space of the |path| is enough for required |bytes|. | 612 // Checks if the available space of the |path| is enough for required |bytes|. |
613 bool CheckLocalDiskSpaceOnIOThread(const base::FilePath& path, int64 bytes) { | 613 bool CheckLocalDiskSpaceOnIOThread(const base::FilePath& path, int64_t bytes) { |
614 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 614 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
615 return bytes <= base::SysInfo::AmountOfFreeDiskSpace(path) - | 615 return bytes <= base::SysInfo::AmountOfFreeDiskSpace(path) - |
616 cryptohome::kMinFreeSpaceInBytes; | 616 cryptohome::kMinFreeSpaceInBytes; |
617 } | 617 } |
618 | 618 |
619 bool FileManagerPrivateInternalStartCopyFunction::RunAsync() { | 619 bool FileManagerPrivateInternalStartCopyFunction::RunAsync() { |
620 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 620 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
621 | 621 |
622 using extensions::api::file_manager_private_internal::StartCopy::Params; | 622 using extensions::api::file_manager_private_internal::StartCopy::Params; |
623 const scoped_ptr<Params> params(Params::Create(*args_)); | 623 const scoped_ptr<Params> params(Params::Create(*args_)); |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 return RespondLater(); | 989 return RespondLater(); |
990 } | 990 } |
991 | 991 |
992 void FileManagerPrivateInternalSetEntryTagFunction::OnSetEntryPropertyCompleted( | 992 void FileManagerPrivateInternalSetEntryTagFunction::OnSetEntryPropertyCompleted( |
993 drive::FileError result) { | 993 drive::FileError result) { |
994 Respond(result == drive::FILE_ERROR_OK ? NoArguments() | 994 Respond(result == drive::FILE_ERROR_OK ? NoArguments() |
995 : Error("Failed to set a tag.")); | 995 : Error("Failed to set a tag.")); |
996 } | 996 } |
997 | 997 |
998 } // namespace extensions | 998 } // namespace extensions |
OLD | NEW |