Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // 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.
| |
| 3 // found in the LICENSE file. | |
| 4 #include "chrome/browser/extensions/api/system_storage/system_storage_api.h" | |
| 5 | |
| 6 namespace extensions { | |
| 7 | |
| 8 using api::system_storage::StorageUnitInfo; | |
| 9 namespace EjectDevice = api::system_storage::EjectDevice; | |
| 10 | |
| 11 SystemStorageGetFunction::SystemStorageGetFunction() { | |
| 12 } | |
| 13 | |
| 14 SystemStorageGetFunction::~SystemStorageGetFunction() { | |
| 15 } | |
| 16 | |
| 17 bool SystemStorageGetFunction::RunImpl() { | |
| 18 StorageInfoProvider::Get()->StartQueryInfo( | |
| 19 base::Bind(&SystemStorageGetFunction::OnGetStorageInfoCompleted, | |
| 20 this)); | |
| 21 return true; | |
| 22 } | |
| 23 | |
| 24 void SystemStorageGetFunction::OnGetStorageInfoCompleted(bool success) { | |
| 25 if (success) { | |
| 26 results_ = api::system_storage::Get::Results::Create( | |
| 27 StorageInfoProvider::Get()->storage_unit_info_list()); | |
| 28 } else { | |
| 29 SetError("Error occurred when querying storage information."); | |
| 30 } | |
| 31 | |
| 32 SendResponse(success); | |
| 33 } | |
| 34 | |
| 35 SystemStorageEjectDeviceFunction::~SystemStorageEjectDeviceFunction() { | |
| 36 } | |
| 37 | |
| 38 bool SystemStorageEjectDeviceFunction::RunImpl() { | |
| 39 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 40 | |
| 41 scoped_ptr<EjectDevice::Params> params(EjectDevice::Params::Create(*args_)); | |
| 42 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
| 43 | |
| 44 chrome::StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( | |
| 45 &SystemStorageEjectDeviceFunction::OnStorageMonitorInit, | |
| 46 this, | |
| 47 params->id)); | |
| 48 return true; | |
| 49 } | |
| 50 | |
| 51 void SystemStorageEjectDeviceFunction::OnStorageMonitorInit( | |
| 52 const std::string& transient_device_id) { | |
| 53 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); | |
| 54 chrome::StorageMonitor* monitor = chrome::StorageMonitor::GetInstance(); | |
| 55 std::string device_id_str = | |
| 56 StorageInfoProvider::Get()->GetDeviceIdForTransientId( | |
| 57 transient_device_id); | |
| 58 | |
| 59 if (device_id_str == "") { | |
| 60 HandleResponse(chrome::StorageMonitor::EJECT_NO_SUCH_DEVICE); | |
| 61 return; | |
| 62 } | |
| 63 | |
| 64 monitor->EjectDevice( | |
| 65 device_id_str, | |
| 66 base::Bind(&SystemStorageEjectDeviceFunction::HandleResponse, | |
| 67 this)); | |
| 68 } | |
| 69 | |
| 70 void SystemStorageEjectDeviceFunction::HandleResponse( | |
| 71 chrome::StorageMonitor::EjectStatus status) { | |
| 72 api::system_storage:: EjectDeviceResultCode result = | |
| 73 api::system_storage::EJECT_DEVICE_RESULT_CODE_FAILURE; | |
| 74 switch (status) { | |
| 75 case chrome::StorageMonitor::EJECT_OK: | |
| 76 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_SUCCESS; | |
| 77 break; | |
| 78 case chrome::StorageMonitor::EJECT_IN_USE: | |
| 79 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_IN_USE; | |
| 80 break; | |
| 81 case chrome::StorageMonitor::EJECT_NO_SUCH_DEVICE: | |
| 82 result = api::system_storage:: | |
| 83 EJECT_DEVICE_RESULT_CODE_NO_SUCH_DEVICE; | |
| 84 break; | |
| 85 case chrome::StorageMonitor::EJECT_FAILURE: | |
| 86 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_FAILURE; | |
| 87 } | |
| 88 | |
| 89 SetResult(base::StringValue::CreateStringValue( | |
| 90 api::system_storage::ToString(result))); | |
| 91 SendResponse(true); | |
| 92 } | |
| 93 | |
| 94 SystemStorageAddAvailableCapacityWatchFunction:: | |
| 95 SystemStorageAddAvailableCapacityWatchFunction() { | |
| 96 } | |
| 97 | |
| 98 SystemStorageAddAvailableCapacityWatchFunction:: | |
| 99 ~SystemStorageAddAvailableCapacityWatchFunction() { | |
| 100 } | |
| 101 | |
| 102 bool SystemStorageAddAvailableCapacityWatchFunction::RunImpl() { | |
| 103 // TODO(Haojian): Implement the addAvailableCapacityWatch API. | |
| 104 return false; | |
| 105 } | |
| 106 | |
| 107 SystemStorageRemoveAvailableCapacityWatchFunction:: | |
| 108 SystemStorageRemoveAvailableCapacityWatchFunction() { | |
| 109 } | |
| 110 | |
| 111 SystemStorageRemoveAvailableCapacityWatchFunction:: | |
| 112 ~SystemStorageRemoveAvailableCapacityWatchFunction() { | |
| 113 } | |
| 114 | |
| 115 bool SystemStorageRemoveAvailableCapacityWatchFunction::RunImpl() { | |
| 116 // TODO(Haojian): Implement the removeAvailableCapacityWatch API. | |
| 117 return false; | |
| 118 } | |
| 119 | |
| 120 SystemStorageGetAllAvailableCapacityWatchesFunction | |
| 121 ::SystemStorageGetAllAvailableCapacityWatchesFunction() { | |
| 122 } | |
| 123 | |
| 124 SystemStorageGetAllAvailableCapacityWatchesFunction | |
| 125 ::~SystemStorageGetAllAvailableCapacityWatchesFunction() { | |
| 126 } | |
| 127 | |
| 128 bool SystemStorageGetAllAvailableCapacityWatchesFunction::RunImpl() { | |
| 129 // TODO(Haojian): Implement the getAllAvailableCapacityWatches API. | |
| 130 return false; | |
| 131 } | |
| 132 | |
| 133 SystemStorageRemoveAllAvailableCapacityWatchesFunction:: | |
| 134 SystemStorageRemoveAllAvailableCapacityWatchesFunction() { | |
| 135 } | |
| 136 | |
| 137 SystemStorageRemoveAllAvailableCapacityWatchesFunction:: | |
| 138 ~SystemStorageRemoveAllAvailableCapacityWatchesFunction() { | |
| 139 } | |
| 140 | |
| 141 bool SystemStorageRemoveAllAvailableCapacityWatchesFunction::RunImpl() { | |
| 142 // TODO(Haojian): Implement the removeAllAvailableCapacityWatches api. | |
| 143 return false; | |
| 144 } | |
| 145 | |
| 146 } // namespace extensions | |
| OLD | NEW |