| Index: chrome/browser/extensions/api/system_storage/system_storage_api.cc
|
| diff --git a/chrome/browser/extensions/api/system_storage/system_storage_api.cc b/chrome/browser/extensions/api/system_storage/system_storage_api.cc
|
| index 2157badefd4dcd5c1c1a93a9be66d3294ae18c47..e374f6328893f4f1b24d84a32d667b0368e999da 100644
|
| --- a/chrome/browser/extensions/api/system_storage/system_storage_api.cc
|
| +++ b/chrome/browser/extensions/api/system_storage/system_storage_api.cc
|
| @@ -8,6 +8,7 @@ namespace extensions {
|
|
|
| using api::system_storage::StorageUnitInfo;
|
| namespace EjectDevice = api::system_storage::EjectDevice;
|
| +namespace GetAvailableCapacity = api::system_storage::GetAvailableCapacity;
|
|
|
| SystemStorageGetInfoFunction::SystemStorageGetInfoFunction() {
|
| }
|
| @@ -92,4 +93,53 @@ void SystemStorageEjectDeviceFunction::HandleResponse(
|
| SendResponse(true);
|
| }
|
|
|
| +SystemStorageGetAvailableCapacityFunction::
|
| + SystemStorageGetAvailableCapacityFunction() {
|
| +}
|
| +
|
| +SystemStorageGetAvailableCapacityFunction::
|
| + ~SystemStorageGetAvailableCapacityFunction() {
|
| +}
|
| +
|
| +bool SystemStorageGetAvailableCapacityFunction::RunImpl() {
|
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
|
| +
|
| + scoped_ptr<GetAvailableCapacity::Params> params(
|
| + GetAvailableCapacity::Params::Create(*args_));
|
| + EXTENSION_FUNCTION_VALIDATE(params.get());
|
| +
|
| + StorageMonitor::GetInstance()->EnsureInitialized(base::Bind(
|
| + &SystemStorageGetAvailableCapacityFunction::OnStorageMonitorInit,
|
| + this,
|
| + params->id));
|
| + return true;
|
| +}
|
| +
|
| +void SystemStorageGetAvailableCapacityFunction::OnStorageMonitorInit(
|
| + const std::string& transient_id) {
|
| + content::BrowserThread::PostTaskAndReplyWithResult(
|
| + content::BrowserThread::FILE,
|
| + FROM_HERE,
|
| + base::Bind(
|
| + &StorageInfoProvider::GetStorageFreeSpaceFromTransientIdOnFileThread,
|
| + StorageInfoProvider::Get(), transient_id),
|
| + base::Bind(
|
| + &SystemStorageGetAvailableCapacityFunction::OnQueryCompleted,
|
| + this, transient_id));
|
| +}
|
| +
|
| +void SystemStorageGetAvailableCapacityFunction::OnQueryCompleted(
|
| + const std::string& transient_id, double available_capacity) {
|
| + bool success = available_capacity >= 0;
|
| + if (success) {
|
| + api::system_storage::StorageAvailableCapacityInfo result;
|
| + result.id = transient_id;
|
| + result.available_capacity = available_capacity;
|
| + SetResult(result.ToValue().release());
|
| + } else {
|
| + SetError("Error occurred when querying available capacity.");
|
| + }
|
| + SendResponse(success);
|
| +}
|
| +
|
| } // namespace extensions
|
|
|