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

Side by Side 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 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/extensions/api/system_storage/system_storage_api.h" 5 #include "chrome/browser/extensions/api/system_storage/system_storage_api.h"
6 6
7 namespace extensions { 7 namespace extensions {
8 8
9 using api::system_storage::StorageUnitInfo; 9 using api::system_storage::StorageUnitInfo;
10 namespace EjectDevice = api::system_storage::EjectDevice; 10 namespace EjectDevice = api::system_storage::EjectDevice;
11 namespace GetAvailableCapacity = api::system_storage::GetAvailableCapacity;
11 12
12 SystemStorageGetInfoFunction::SystemStorageGetInfoFunction() { 13 SystemStorageGetInfoFunction::SystemStorageGetInfoFunction() {
13 } 14 }
14 15
15 SystemStorageGetInfoFunction::~SystemStorageGetInfoFunction() { 16 SystemStorageGetInfoFunction::~SystemStorageGetInfoFunction() {
16 } 17 }
17 18
18 bool SystemStorageGetInfoFunction::RunImpl() { 19 bool SystemStorageGetInfoFunction::RunImpl() {
19 StorageInfoProvider::Get()->StartQueryInfo( 20 StorageInfoProvider::Get()->StartQueryInfo(
20 base::Bind(&SystemStorageGetInfoFunction::OnGetStorageInfoCompleted, 21 base::Bind(&SystemStorageGetInfoFunction::OnGetStorageInfoCompleted,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 break; 86 break;
86 case StorageMonitor::EJECT_FAILURE: 87 case StorageMonitor::EJECT_FAILURE:
87 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_FAILURE; 88 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_FAILURE;
88 } 89 }
89 90
90 SetResult(new base::StringValue( 91 SetResult(new base::StringValue(
91 api::system_storage::ToString(result))); 92 api::system_storage::ToString(result)));
92 SendResponse(true); 93 SendResponse(true);
93 } 94 }
94 95
96 SystemStorageGetAvailableCapacityFunction::
97 SystemStorageGetAvailableCapacityFunction() {
98 }
99
100 SystemStorageGetAvailableCapacityFunction::
101 ~SystemStorageGetAvailableCapacityFunction() {
102 }
103
104 bool SystemStorageGetAvailableCapacityFunction::RunImpl() {
105 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
106
107 scoped_ptr<GetAvailableCapacity::Params> params(
108 GetAvailableCapacity::Params::Create(*args_));
109 EXTENSION_FUNCTION_VALIDATE(params.get());
110
111 StorageMonitor::GetInstance()->EnsureInitialized(base::Bind(
112 &SystemStorageGetAvailableCapacityFunction::OnStorageMonitorInit,
113 this,
114 params->id));
115 return true;
116 }
117
118 void SystemStorageGetAvailableCapacityFunction::OnStorageMonitorInit(
119 const std::string& transient_id) {
120 content::BrowserThread::PostTaskAndReplyWithResult(
121 content::BrowserThread::FILE,
122 FROM_HERE,
123 base::Bind(
124 &StorageInfoProvider::GetStorageFreeSpaceFromTransientIdOnFileThread,
125 StorageInfoProvider::Get(), transient_id),
126 base::Bind(
127 &SystemStorageGetAvailableCapacityFunction::OnQueryCompleted,
128 this, transient_id));
129 }
130
131 void SystemStorageGetAvailableCapacityFunction::OnQueryCompleted(
132 const std::string& transient_id, double available_capacity) {
133 bool success = available_capacity >= 0;
134 if (success) {
135 api::system_storage::StorageAvailableCapacityInfo result;
136 result.id = transient_id;
137 result.available_capacity = available_capacity;
138 SetResult(result.ToValue().release());
139 } else {
140 SetError("Error occurred when querying available capacity.");
141 }
142 SendResponse(success);
143 }
144
95 } // namespace extensions 145 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698