Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b0d1b0f7d72ca6fcbf5a88f7d7fe083f8af4f6f8 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/system_storage/system_storage_api.cc |
| @@ -0,0 +1,146 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
|
not at google - send to devlin
2013/07/18 17:06:18
ditto
Haojian Wu
2013/07/19 08:47:12
Done.
|
| +// found in the LICENSE file. |
| +#include "chrome/browser/extensions/api/system_storage/system_storage_api.h" |
| + |
| +namespace extensions { |
| + |
| +using api::system_storage::StorageUnitInfo; |
| +namespace EjectDevice = api::system_storage::EjectDevice; |
| + |
| +SystemStorageGetFunction::SystemStorageGetFunction() { |
| +} |
| + |
| +SystemStorageGetFunction::~SystemStorageGetFunction() { |
| +} |
| + |
| +bool SystemStorageGetFunction::RunImpl() { |
| + StorageInfoProvider::Get()->StartQueryInfo( |
| + base::Bind(&SystemStorageGetFunction::OnGetStorageInfoCompleted, |
| + this)); |
| + return true; |
| +} |
| + |
| +void SystemStorageGetFunction::OnGetStorageInfoCompleted(bool success) { |
| + if (success) { |
| + results_ = api::system_storage::Get::Results::Create( |
| + StorageInfoProvider::Get()->storage_unit_info_list()); |
| + } else { |
| + SetError("Error occurred when querying storage information."); |
| + } |
| + |
| + SendResponse(success); |
| +} |
| + |
| +SystemStorageEjectDeviceFunction::~SystemStorageEjectDeviceFunction() { |
| +} |
| + |
| +bool SystemStorageEjectDeviceFunction::RunImpl() { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + |
| + scoped_ptr<EjectDevice::Params> params(EjectDevice::Params::Create(*args_)); |
| + EXTENSION_FUNCTION_VALIDATE(params.get()); |
| + |
| + chrome::StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( |
| + &SystemStorageEjectDeviceFunction::OnStorageMonitorInit, |
| + this, |
| + params->id)); |
| + return true; |
| +} |
| + |
| +void SystemStorageEjectDeviceFunction::OnStorageMonitorInit( |
| + const std::string& transient_device_id) { |
| + DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); |
| + chrome::StorageMonitor* monitor = chrome::StorageMonitor::GetInstance(); |
| + std::string device_id_str = |
| + StorageInfoProvider::Get()->GetDeviceIdForTransientId( |
| + transient_device_id); |
| + |
| + if (device_id_str == "") { |
| + HandleResponse(chrome::StorageMonitor::EJECT_NO_SUCH_DEVICE); |
| + return; |
| + } |
| + |
| + monitor->EjectDevice( |
| + device_id_str, |
| + base::Bind(&SystemStorageEjectDeviceFunction::HandleResponse, |
| + this)); |
| +} |
| + |
| +void SystemStorageEjectDeviceFunction::HandleResponse( |
| + chrome::StorageMonitor::EjectStatus status) { |
| + api::system_storage:: EjectDeviceResultCode result = |
| + api::system_storage::EJECT_DEVICE_RESULT_CODE_FAILURE; |
| + switch (status) { |
| + case chrome::StorageMonitor::EJECT_OK: |
| + result = api::system_storage::EJECT_DEVICE_RESULT_CODE_SUCCESS; |
| + break; |
| + case chrome::StorageMonitor::EJECT_IN_USE: |
| + result = api::system_storage::EJECT_DEVICE_RESULT_CODE_IN_USE; |
| + break; |
| + case chrome::StorageMonitor::EJECT_NO_SUCH_DEVICE: |
| + result = api::system_storage:: |
| + EJECT_DEVICE_RESULT_CODE_NO_SUCH_DEVICE; |
| + break; |
| + case chrome::StorageMonitor::EJECT_FAILURE: |
| + result = api::system_storage::EJECT_DEVICE_RESULT_CODE_FAILURE; |
| + } |
| + |
| + SetResult(base::StringValue::CreateStringValue( |
| + api::system_storage::ToString(result))); |
| + SendResponse(true); |
| +} |
| + |
| +SystemStorageAddAvailableCapacityWatchFunction:: |
| + SystemStorageAddAvailableCapacityWatchFunction() { |
| +} |
| + |
| +SystemStorageAddAvailableCapacityWatchFunction:: |
| + ~SystemStorageAddAvailableCapacityWatchFunction() { |
| +} |
| + |
| +bool SystemStorageAddAvailableCapacityWatchFunction::RunImpl() { |
| + // TODO(Haojian): Implement the addAvailableCapacityWatch API. |
| + return false; |
| +} |
| + |
| +SystemStorageRemoveAvailableCapacityWatchFunction:: |
| + SystemStorageRemoveAvailableCapacityWatchFunction() { |
| +} |
| + |
| +SystemStorageRemoveAvailableCapacityWatchFunction:: |
| + ~SystemStorageRemoveAvailableCapacityWatchFunction() { |
| +} |
| + |
| +bool SystemStorageRemoveAvailableCapacityWatchFunction::RunImpl() { |
| + // TODO(Haojian): Implement the removeAvailableCapacityWatch API. |
| + return false; |
| +} |
| + |
| +SystemStorageGetAllAvailableCapacityWatchesFunction |
| + ::SystemStorageGetAllAvailableCapacityWatchesFunction() { |
| +} |
| + |
| +SystemStorageGetAllAvailableCapacityWatchesFunction |
| + ::~SystemStorageGetAllAvailableCapacityWatchesFunction() { |
| +} |
| + |
| +bool SystemStorageGetAllAvailableCapacityWatchesFunction::RunImpl() { |
| + // TODO(Haojian): Implement the getAllAvailableCapacityWatches API. |
| + return false; |
| +} |
| + |
| +SystemStorageRemoveAllAvailableCapacityWatchesFunction:: |
| + SystemStorageRemoveAllAvailableCapacityWatchesFunction() { |
| +} |
| + |
| +SystemStorageRemoveAllAvailableCapacityWatchesFunction:: |
| + ~SystemStorageRemoveAllAvailableCapacityWatchesFunction() { |
| +} |
| + |
| +bool SystemStorageRemoveAllAvailableCapacityWatchesFunction::RunImpl() { |
| + // TODO(Haojian): Implement the removeAllAvailableCapacityWatches api. |
| + return false; |
| +} |
| + |
| +} // namespace extensions |