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

Side by Side Diff: extensions/browser/api/system_storage/system_storage_api.cc

Issue 389633002: Move system.* family of APIs to extensions/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 6 years, 3 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 "extensions/browser/api/system_storage/system_storage_api.h"
6 6
7 using storage_monitor::StorageMonitor; 7 using storage_monitor::StorageMonitor;
8 8
9 namespace extensions { 9 namespace extensions {
10 10
11 using api::system_storage::StorageUnitInfo; 11 using core_api::system_storage::StorageUnitInfo;
12 namespace EjectDevice = api::system_storage::EjectDevice; 12 namespace EjectDevice = core_api::system_storage::EjectDevice;
13 namespace GetAvailableCapacity = api::system_storage::GetAvailableCapacity; 13 namespace GetAvailableCapacity = core_api::system_storage::GetAvailableCapacity;
14 14
15 SystemStorageGetInfoFunction::SystemStorageGetInfoFunction() { 15 SystemStorageGetInfoFunction::SystemStorageGetInfoFunction() {
16 } 16 }
17 17
18 SystemStorageGetInfoFunction::~SystemStorageGetInfoFunction() { 18 SystemStorageGetInfoFunction::~SystemStorageGetInfoFunction() {
19 } 19 }
20 20
21 bool SystemStorageGetInfoFunction::RunAsync() { 21 bool SystemStorageGetInfoFunction::RunAsync() {
22 StorageInfoProvider::Get()->StartQueryInfo( 22 StorageInfoProvider::Get()->StartQueryInfo(base::Bind(
23 base::Bind(&SystemStorageGetInfoFunction::OnGetStorageInfoCompleted, 23 &SystemStorageGetInfoFunction::OnGetStorageInfoCompleted, this));
24 this));
25 return true; 24 return true;
26 } 25 }
27 26
28 void SystemStorageGetInfoFunction::OnGetStorageInfoCompleted(bool success) { 27 void SystemStorageGetInfoFunction::OnGetStorageInfoCompleted(bool success) {
29 if (success) { 28 if (success) {
30 results_ = api::system_storage::GetInfo::Results::Create( 29 results_ = core_api::system_storage::GetInfo::Results::Create(
31 StorageInfoProvider::Get()->storage_unit_info_list()); 30 StorageInfoProvider::Get()->storage_unit_info_list());
32 } else { 31 } else {
33 SetError("Error occurred when querying storage information."); 32 SetError("Error occurred when querying storage information.");
34 } 33 }
35 34
36 SendResponse(success); 35 SendResponse(success);
37 } 36 }
38 37
39 SystemStorageEjectDeviceFunction::~SystemStorageEjectDeviceFunction() { 38 SystemStorageEjectDeviceFunction::~SystemStorageEjectDeviceFunction() {
40 } 39 }
41 40
42 bool SystemStorageEjectDeviceFunction::RunAsync() { 41 bool SystemStorageEjectDeviceFunction::RunAsync() {
43 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 42 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
44 43
45 scoped_ptr<EjectDevice::Params> params(EjectDevice::Params::Create(*args_)); 44 scoped_ptr<EjectDevice::Params> params(EjectDevice::Params::Create(*args_));
46 EXTENSION_FUNCTION_VALIDATE(params.get()); 45 EXTENSION_FUNCTION_VALIDATE(params.get());
47 46
48 StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( 47 StorageMonitor::GetInstance()->EnsureInitialized(
49 &SystemStorageEjectDeviceFunction::OnStorageMonitorInit, 48 base::Bind(&SystemStorageEjectDeviceFunction::OnStorageMonitorInit,
50 this, 49 this,
51 params->id)); 50 params->id));
52 return true; 51 return true;
53 } 52 }
54 53
55 void SystemStorageEjectDeviceFunction::OnStorageMonitorInit( 54 void SystemStorageEjectDeviceFunction::OnStorageMonitorInit(
56 const std::string& transient_device_id) { 55 const std::string& transient_device_id) {
57 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); 56 DCHECK(StorageMonitor::GetInstance()->IsInitialized());
58 StorageMonitor* monitor = StorageMonitor::GetInstance(); 57 StorageMonitor* monitor = StorageMonitor::GetInstance();
59 std::string device_id_str = 58 std::string device_id_str =
60 StorageMonitor::GetInstance()->GetDeviceIdForTransientId( 59 StorageMonitor::GetInstance()->GetDeviceIdForTransientId(
61 transient_device_id); 60 transient_device_id);
62 61
63 if (device_id_str == "") { 62 if (device_id_str == "") {
64 HandleResponse(StorageMonitor::EJECT_NO_SUCH_DEVICE); 63 HandleResponse(StorageMonitor::EJECT_NO_SUCH_DEVICE);
65 return; 64 return;
66 } 65 }
67 66
68 monitor->EjectDevice( 67 monitor->EjectDevice(
69 device_id_str, 68 device_id_str,
70 base::Bind(&SystemStorageEjectDeviceFunction::HandleResponse, 69 base::Bind(&SystemStorageEjectDeviceFunction::HandleResponse, this));
71 this));
72 } 70 }
73 71
74 void SystemStorageEjectDeviceFunction::HandleResponse( 72 void SystemStorageEjectDeviceFunction::HandleResponse(
75 StorageMonitor::EjectStatus status) { 73 StorageMonitor::EjectStatus status) {
76 api::system_storage:: EjectDeviceResultCode result = 74 core_api::system_storage::EjectDeviceResultCode result =
77 api::system_storage::EJECT_DEVICE_RESULT_CODE_FAILURE; 75 core_api::system_storage::EJECT_DEVICE_RESULT_CODE_FAILURE;
78 switch (status) { 76 switch (status) {
79 case StorageMonitor::EJECT_OK: 77 case StorageMonitor::EJECT_OK:
80 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_SUCCESS; 78 result = core_api::system_storage::EJECT_DEVICE_RESULT_CODE_SUCCESS;
81 break; 79 break;
82 case StorageMonitor::EJECT_IN_USE: 80 case StorageMonitor::EJECT_IN_USE:
83 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_IN_USE; 81 result = core_api::system_storage::EJECT_DEVICE_RESULT_CODE_IN_USE;
84 break; 82 break;
85 case StorageMonitor::EJECT_NO_SUCH_DEVICE: 83 case StorageMonitor::EJECT_NO_SUCH_DEVICE:
86 result = api::system_storage:: 84 result =
87 EJECT_DEVICE_RESULT_CODE_NO_SUCH_DEVICE; 85 core_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 = core_api::system_storage::EJECT_DEVICE_RESULT_CODE_FAILURE;
91 } 89 }
92 90
93 SetResult(new base::StringValue( 91 SetResult(new base::StringValue(core_api::system_storage::ToString(result)));
94 api::system_storage::ToString(result)));
95 SendResponse(true); 92 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 }
(...skipping 12 matching lines...) Expand all
117 return true; 114 return true;
118 } 115 }
119 116
120 void SystemStorageGetAvailableCapacityFunction::OnStorageMonitorInit( 117 void SystemStorageGetAvailableCapacityFunction::OnStorageMonitorInit(
121 const std::string& transient_id) { 118 const std::string& transient_id) {
122 content::BrowserThread::PostTaskAndReplyWithResult( 119 content::BrowserThread::PostTaskAndReplyWithResult(
123 content::BrowserThread::FILE, 120 content::BrowserThread::FILE,
124 FROM_HERE, 121 FROM_HERE,
125 base::Bind( 122 base::Bind(
126 &StorageInfoProvider::GetStorageFreeSpaceFromTransientIdOnFileThread, 123 &StorageInfoProvider::GetStorageFreeSpaceFromTransientIdOnFileThread,
127 StorageInfoProvider::Get(), transient_id), 124 StorageInfoProvider::Get(),
128 base::Bind( 125 transient_id),
129 &SystemStorageGetAvailableCapacityFunction::OnQueryCompleted, 126 base::Bind(&SystemStorageGetAvailableCapacityFunction::OnQueryCompleted,
130 this, transient_id)); 127 this,
128 transient_id));
131 } 129 }
132 130
133 void SystemStorageGetAvailableCapacityFunction::OnQueryCompleted( 131 void SystemStorageGetAvailableCapacityFunction::OnQueryCompleted(
134 const std::string& transient_id, double available_capacity) { 132 const std::string& transient_id,
133 double available_capacity) {
135 bool success = available_capacity >= 0; 134 bool success = available_capacity >= 0;
136 if (success) { 135 if (success) {
137 api::system_storage::StorageAvailableCapacityInfo result; 136 core_api::system_storage::StorageAvailableCapacityInfo result;
138 result.id = transient_id; 137 result.id = transient_id;
139 result.available_capacity = available_capacity; 138 result.available_capacity = available_capacity;
140 SetResult(result.ToValue().release()); 139 SetResult(result.ToValue().release());
141 } else { 140 } else {
142 SetError("Error occurred when querying available capacity."); 141 SetError("Error occurred when querying available capacity.");
143 } 142 }
144 SendResponse(success); 143 SendResponse(success);
145 } 144 }
146 145
147 } // namespace extensions 146 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698