Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "extensions/browser/api/system_storage/system_storage_api.h" | 5 #include "extensions/browser/api/system_storage/system_storage_api.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 | 8 |
| 9 using storage_monitor::StorageMonitor; | 9 using storage_monitor::StorageMonitor; |
| 10 | 10 |
| 11 namespace extensions { | 11 namespace extensions { |
| 12 | 12 |
| 13 using api::system_storage::StorageUnitInfo; | 13 using api::system_storage::StorageUnitInfo; |
| 14 namespace EjectDevice = api::system_storage::EjectDevice; | 14 namespace EjectDevice = api::system_storage::EjectDevice; |
| 15 namespace GetAvailableCapacity = api::system_storage::GetAvailableCapacity; | 15 namespace GetAvailableCapacity = api::system_storage::GetAvailableCapacity; |
| 16 | 16 |
| 17 SystemStorageGetInfoFunction::SystemStorageGetInfoFunction() { | 17 SystemStorageGetInfoFunction::SystemStorageGetInfoFunction() { |
| 18 } | 18 } |
| 19 | 19 |
| 20 SystemStorageGetInfoFunction::~SystemStorageGetInfoFunction() { | 20 SystemStorageGetInfoFunction::~SystemStorageGetInfoFunction() { |
| 21 } | 21 } |
| 22 | 22 |
| 23 bool SystemStorageGetInfoFunction::RunAsync() { | 23 ExtensionFunction::ResponseAction SystemStorageGetInfoFunction::Run() { |
| 24 StorageInfoProvider::Get()->StartQueryInfo(base::Bind( | 24 StorageInfoProvider::Get()->StartQueryInfo(base::Bind( |
| 25 &SystemStorageGetInfoFunction::OnGetStorageInfoCompleted, this)); | 25 &SystemStorageGetInfoFunction::OnGetStorageInfoCompleted, this)); |
| 26 return true; | 26 return RespondLater(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void SystemStorageGetInfoFunction::OnGetStorageInfoCompleted(bool success) { | 29 void SystemStorageGetInfoFunction::OnGetStorageInfoCompleted(bool success) { |
| 30 if (success) { | 30 if (success) { |
| 31 results_ = api::system_storage::GetInfo::Results::Create( | 31 Respond(ArgumentList(api::system_storage::GetInfo::Results::Create( |
| 32 StorageInfoProvider::Get()->storage_unit_info_list()); | 32 StorageInfoProvider::Get()->storage_unit_info_list()))); |
| 33 } else { | 33 } else { |
| 34 SetError("Error occurred when querying storage information."); | 34 Respond(Error("Error occurred when querying storage information.")); |
| 35 } | 35 } |
| 36 | |
| 37 SendResponse(success); | |
| 38 } | 36 } |
| 39 | 37 |
| 40 SystemStorageEjectDeviceFunction::~SystemStorageEjectDeviceFunction() { | 38 SystemStorageEjectDeviceFunction::~SystemStorageEjectDeviceFunction() { |
| 41 } | 39 } |
| 42 | 40 |
| 43 bool SystemStorageEjectDeviceFunction::RunAsync() { | 41 ExtensionFunction::ResponseAction SystemStorageEjectDeviceFunction::Run() { |
| 44 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 42 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 45 | 43 |
| 46 std::unique_ptr<EjectDevice::Params> params( | 44 std::unique_ptr<EjectDevice::Params> params( |
| 47 EjectDevice::Params::Create(*args_)); | 45 EjectDevice::Params::Create(*args_)); |
| 48 EXTENSION_FUNCTION_VALIDATE(params.get()); | 46 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 49 | 47 |
| 50 StorageMonitor::GetInstance()->EnsureInitialized( | 48 StorageMonitor::GetInstance()->EnsureInitialized( |
| 51 base::Bind(&SystemStorageEjectDeviceFunction::OnStorageMonitorInit, | 49 base::Bind(&SystemStorageEjectDeviceFunction::OnStorageMonitorInit, |
|
Devlin
2017/01/06 15:51:06
can return sync
lazyboy
2017/01/19 03:47:59
Added comment and fixed the issue.
| |
| 52 this, | 50 this, |
| 53 params->id)); | 51 params->id)); |
| 54 return true; | 52 return RespondLater(); |
| 55 } | 53 } |
| 56 | 54 |
| 57 void SystemStorageEjectDeviceFunction::OnStorageMonitorInit( | 55 void SystemStorageEjectDeviceFunction::OnStorageMonitorInit( |
| 58 const std::string& transient_device_id) { | 56 const std::string& transient_device_id) { |
| 59 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); | 57 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); |
| 60 StorageMonitor* monitor = StorageMonitor::GetInstance(); | 58 StorageMonitor* monitor = StorageMonitor::GetInstance(); |
| 61 std::string device_id_str = | 59 std::string device_id_str = |
| 62 StorageMonitor::GetInstance()->GetDeviceIdForTransientId( | 60 StorageMonitor::GetInstance()->GetDeviceIdForTransientId( |
| 63 transient_device_id); | 61 transient_device_id); |
| 64 | 62 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 83 case StorageMonitor::EJECT_IN_USE: | 81 case StorageMonitor::EJECT_IN_USE: |
| 84 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_IN_USE; | 82 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_IN_USE; |
| 85 break; | 83 break; |
| 86 case StorageMonitor::EJECT_NO_SUCH_DEVICE: | 84 case StorageMonitor::EJECT_NO_SUCH_DEVICE: |
| 87 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_NO_SUCH_DEVICE; | 85 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_NO_SUCH_DEVICE; |
| 88 break; | 86 break; |
| 89 case StorageMonitor::EJECT_FAILURE: | 87 case StorageMonitor::EJECT_FAILURE: |
| 90 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_FAILURE; | 88 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_FAILURE; |
| 91 } | 89 } |
| 92 | 90 |
| 93 SetResult(base::MakeUnique<base::StringValue>( | 91 Respond(OneArgument(base::MakeUnique<base::StringValue>( |
| 94 api::system_storage::ToString(result))); | 92 api::system_storage::ToString(result)))); |
| 95 SendResponse(true); | |
| 96 } | 93 } |
| 97 | 94 |
| 98 SystemStorageGetAvailableCapacityFunction:: | 95 SystemStorageGetAvailableCapacityFunction:: |
| 99 SystemStorageGetAvailableCapacityFunction() { | 96 SystemStorageGetAvailableCapacityFunction() { |
| 100 } | 97 } |
| 101 | 98 |
| 102 SystemStorageGetAvailableCapacityFunction:: | 99 SystemStorageGetAvailableCapacityFunction:: |
| 103 ~SystemStorageGetAvailableCapacityFunction() { | 100 ~SystemStorageGetAvailableCapacityFunction() { |
| 104 } | 101 } |
| 105 | 102 |
| 106 bool SystemStorageGetAvailableCapacityFunction::RunAsync() { | 103 ExtensionFunction::ResponseAction |
| 104 SystemStorageGetAvailableCapacityFunction::Run() { | |
| 107 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 105 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 108 | 106 |
| 109 std::unique_ptr<GetAvailableCapacity::Params> params( | 107 std::unique_ptr<GetAvailableCapacity::Params> params( |
| 110 GetAvailableCapacity::Params::Create(*args_)); | 108 GetAvailableCapacity::Params::Create(*args_)); |
| 111 EXTENSION_FUNCTION_VALIDATE(params.get()); | 109 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 112 | 110 |
| 113 StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( | 111 StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( |
| 114 &SystemStorageGetAvailableCapacityFunction::OnStorageMonitorInit, | 112 &SystemStorageGetAvailableCapacityFunction::OnStorageMonitorInit, |
| 115 this, | 113 this, |
| 116 params->id)); | 114 params->id)); |
| 117 return true; | 115 return RespondLater(); |
| 118 } | 116 } |
| 119 | 117 |
| 120 void SystemStorageGetAvailableCapacityFunction::OnStorageMonitorInit( | 118 void SystemStorageGetAvailableCapacityFunction::OnStorageMonitorInit( |
| 121 const std::string& transient_id) { | 119 const std::string& transient_id) { |
| 122 content::BrowserThread::PostTaskAndReplyWithResult( | 120 content::BrowserThread::PostTaskAndReplyWithResult( |
| 123 content::BrowserThread::FILE, | 121 content::BrowserThread::FILE, |
| 124 FROM_HERE, | 122 FROM_HERE, |
| 125 base::Bind( | 123 base::Bind( |
| 126 &StorageInfoProvider::GetStorageFreeSpaceFromTransientIdOnFileThread, | 124 &StorageInfoProvider::GetStorageFreeSpaceFromTransientIdOnFileThread, |
| 127 StorageInfoProvider::Get(), | 125 StorageInfoProvider::Get(), |
| 128 transient_id), | 126 transient_id), |
| 129 base::Bind(&SystemStorageGetAvailableCapacityFunction::OnQueryCompleted, | 127 base::Bind(&SystemStorageGetAvailableCapacityFunction::OnQueryCompleted, |
| 130 this, | 128 this, |
| 131 transient_id)); | 129 transient_id)); |
| 132 } | 130 } |
| 133 | 131 |
| 134 void SystemStorageGetAvailableCapacityFunction::OnQueryCompleted( | 132 void SystemStorageGetAvailableCapacityFunction::OnQueryCompleted( |
| 135 const std::string& transient_id, | 133 const std::string& transient_id, |
| 136 double available_capacity) { | 134 double available_capacity) { |
| 137 bool success = available_capacity >= 0; | 135 bool success = available_capacity >= 0; |
| 138 if (success) { | 136 if (success) { |
| 139 api::system_storage::StorageAvailableCapacityInfo result; | 137 api::system_storage::StorageAvailableCapacityInfo result; |
| 140 result.id = transient_id; | 138 result.id = transient_id; |
| 141 result.available_capacity = available_capacity; | 139 result.available_capacity = available_capacity; |
| 142 SetResult(result.ToValue()); | 140 Respond(OneArgument(result.ToValue())); |
| 143 } else { | 141 } else { |
| 144 SetError("Error occurred when querying available capacity."); | 142 Respond(Error("Error occurred when querying available capacity.")); |
| 145 } | 143 } |
| 146 SendResponse(success); | |
| 147 } | 144 } |
| 148 | 145 |
| 149 } // namespace extensions | 146 } // namespace extensions |
| OLD | NEW |