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

Unified Diff: chrome/browser/extensions/api/system_storage/system_storage_api.cc

Issue 22548009: [SystemInfo API] Implement storage.getAvailableCapacity API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@impl_get_available_capacity_api2
Patch Set: Rebase Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698