| 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 "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; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 SystemStorageEjectDeviceFunction::~SystemStorageEjectDeviceFunction() { | 36 SystemStorageEjectDeviceFunction::~SystemStorageEjectDeviceFunction() { |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool SystemStorageEjectDeviceFunction::RunImpl() { | 39 bool SystemStorageEjectDeviceFunction::RunImpl() { |
| 40 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 40 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 41 | 41 |
| 42 scoped_ptr<EjectDevice::Params> params(EjectDevice::Params::Create(*args_)); | 42 scoped_ptr<EjectDevice::Params> params(EjectDevice::Params::Create(*args_)); |
| 43 EXTENSION_FUNCTION_VALIDATE(params.get()); | 43 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 44 | 44 |
| 45 chrome::StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( | 45 StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( |
| 46 &SystemStorageEjectDeviceFunction::OnStorageMonitorInit, | 46 &SystemStorageEjectDeviceFunction::OnStorageMonitorInit, |
| 47 this, | 47 this, |
| 48 params->id)); | 48 params->id)); |
| 49 return true; | 49 return true; |
| 50 } | 50 } |
| 51 | 51 |
| 52 void SystemStorageEjectDeviceFunction::OnStorageMonitorInit( | 52 void SystemStorageEjectDeviceFunction::OnStorageMonitorInit( |
| 53 const std::string& transient_device_id) { | 53 const std::string& transient_device_id) { |
| 54 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); | 54 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); |
| 55 chrome::StorageMonitor* monitor = chrome::StorageMonitor::GetInstance(); | 55 StorageMonitor* monitor = StorageMonitor::GetInstance(); |
| 56 std::string device_id_str = | 56 std::string device_id_str = |
| 57 chrome::StorageMonitor::GetInstance()->GetDeviceIdForTransientId( | 57 StorageMonitor::GetInstance()->GetDeviceIdForTransientId( |
| 58 transient_device_id); | 58 transient_device_id); |
| 59 | 59 |
| 60 if (device_id_str == "") { | 60 if (device_id_str == "") { |
| 61 HandleResponse(chrome::StorageMonitor::EJECT_NO_SUCH_DEVICE); | 61 HandleResponse(StorageMonitor::EJECT_NO_SUCH_DEVICE); |
| 62 return; | 62 return; |
| 63 } | 63 } |
| 64 | 64 |
| 65 monitor->EjectDevice( | 65 monitor->EjectDevice( |
| 66 device_id_str, | 66 device_id_str, |
| 67 base::Bind(&SystemStorageEjectDeviceFunction::HandleResponse, | 67 base::Bind(&SystemStorageEjectDeviceFunction::HandleResponse, |
| 68 this)); | 68 this)); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void SystemStorageEjectDeviceFunction::HandleResponse( | 71 void SystemStorageEjectDeviceFunction::HandleResponse( |
| 72 chrome::StorageMonitor::EjectStatus status) { | 72 StorageMonitor::EjectStatus status) { |
| 73 api::system_storage:: EjectDeviceResultCode result = | 73 api::system_storage:: EjectDeviceResultCode result = |
| 74 api::system_storage::EJECT_DEVICE_RESULT_CODE_FAILURE; | 74 api::system_storage::EJECT_DEVICE_RESULT_CODE_FAILURE; |
| 75 switch (status) { | 75 switch (status) { |
| 76 case chrome::StorageMonitor::EJECT_OK: | 76 case StorageMonitor::EJECT_OK: |
| 77 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_SUCCESS; | 77 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_SUCCESS; |
| 78 break; | 78 break; |
| 79 case chrome::StorageMonitor::EJECT_IN_USE: | 79 case StorageMonitor::EJECT_IN_USE: |
| 80 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_IN_USE; | 80 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_IN_USE; |
| 81 break; | 81 break; |
| 82 case chrome::StorageMonitor::EJECT_NO_SUCH_DEVICE: | 82 case StorageMonitor::EJECT_NO_SUCH_DEVICE: |
| 83 result = api::system_storage:: | 83 result = api::system_storage:: |
| 84 EJECT_DEVICE_RESULT_CODE_NO_SUCH_DEVICE; | 84 EJECT_DEVICE_RESULT_CODE_NO_SUCH_DEVICE; |
| 85 break; | 85 break; |
| 86 case chrome::StorageMonitor::EJECT_FAILURE: | 86 case StorageMonitor::EJECT_FAILURE: |
| 87 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_FAILURE; | 87 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_FAILURE; |
| 88 } | 88 } |
| 89 | 89 |
| 90 SetResult(new base::StringValue( | 90 SetResult(new base::StringValue( |
| 91 api::system_storage::ToString(result))); | 91 api::system_storage::ToString(result))); |
| 92 SendResponse(true); | 92 SendResponse(true); |
| 93 } | 93 } |
| 94 | 94 |
| 95 } // namespace extensions | 95 } // namespace extensions |
| OLD | NEW |