OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/extensions/api/system_info_storage/system_info_storage_
api.h" | 4 |
| 5 #include "chrome/browser/extensions/api/system_storage/system_storage_api.h" |
5 | 6 |
6 namespace extensions { | 7 namespace extensions { |
7 | 8 |
8 using api::experimental_system_info_storage::StorageUnitInfo; | 9 using api::system_storage::StorageUnitInfo; |
9 namespace EjectDevice = api::experimental_system_info_storage::EjectDevice; | 10 namespace EjectDevice = api::system_storage::EjectDevice; |
10 | 11 |
11 SystemInfoStorageGetFunction::SystemInfoStorageGetFunction() { | 12 SystemStorageGetInfoFunction::SystemStorageGetInfoFunction() { |
12 } | 13 } |
13 | 14 |
14 SystemInfoStorageGetFunction::~SystemInfoStorageGetFunction() { | 15 SystemStorageGetInfoFunction::~SystemStorageGetInfoFunction() { |
15 } | 16 } |
16 | 17 |
17 bool SystemInfoStorageGetFunction::RunImpl() { | 18 bool SystemStorageGetInfoFunction::RunImpl() { |
18 StorageInfoProvider::Get()->StartQueryInfo( | 19 StorageInfoProvider::Get()->StartQueryInfo( |
19 base::Bind(&SystemInfoStorageGetFunction::OnGetStorageInfoCompleted, | 20 base::Bind(&SystemStorageGetInfoFunction::OnGetStorageInfoCompleted, |
20 this)); | 21 this)); |
21 return true; | 22 return true; |
22 } | 23 } |
23 | 24 |
24 void SystemInfoStorageGetFunction::OnGetStorageInfoCompleted(bool success) { | 25 void SystemStorageGetInfoFunction::OnGetStorageInfoCompleted(bool success) { |
25 if (success) { | 26 if (success) { |
26 results_ = | 27 results_ = api::system_storage::GetInfo::Results::Create( |
27 api::experimental_system_info_storage::Get::Results::Create( | 28 StorageInfoProvider::Get()->storage_unit_info_list()); |
28 StorageInfoProvider::Get()->storage_unit_info_list()); | |
29 } else { | 29 } else { |
30 SetError("Error occurred when querying storage information."); | 30 SetError("Error occurred when querying storage information."); |
31 } | 31 } |
32 | 32 |
33 SendResponse(success); | 33 SendResponse(success); |
34 } | 34 } |
35 | 35 |
36 SystemInfoStorageEjectDeviceFunction::~SystemInfoStorageEjectDeviceFunction() { | 36 SystemStorageEjectDeviceFunction::~SystemStorageEjectDeviceFunction() { |
37 } | 37 } |
38 | 38 |
39 bool SystemInfoStorageEjectDeviceFunction::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 chrome::StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( |
46 &SystemInfoStorageEjectDeviceFunction::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 SystemInfoStorageEjectDeviceFunction::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(chrome::StorageMonitor::GetInstance()->IsInitialized()); |
55 chrome::StorageMonitor* monitor = chrome::StorageMonitor::GetInstance(); | 55 chrome::StorageMonitor* monitor = chrome::StorageMonitor::GetInstance(); |
56 std::string device_id_str = | 56 std::string device_id_str = |
57 StorageInfoProvider::Get()->GetDeviceIdForTransientId( | 57 StorageInfoProvider::Get()->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(chrome::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(&SystemInfoStorageEjectDeviceFunction::HandleResponse, | 67 base::Bind(&SystemStorageEjectDeviceFunction::HandleResponse, |
68 this)); | 68 this)); |
69 } | 69 } |
70 | 70 |
71 void SystemInfoStorageEjectDeviceFunction::HandleResponse( | 71 void SystemStorageEjectDeviceFunction::HandleResponse( |
72 chrome::StorageMonitor::EjectStatus status) { | 72 chrome::StorageMonitor::EjectStatus status) { |
73 api::experimental_system_info_storage:: EjectDeviceResultCode result = | 73 api::system_storage:: EjectDeviceResultCode result = |
74 api::experimental_system_info_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 chrome::StorageMonitor::EJECT_OK: |
77 result = api::experimental_system_info_storage:: | 77 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_SUCCESS; |
78 EJECT_DEVICE_RESULT_CODE_SUCCESS; | |
79 break; | 78 break; |
80 case chrome::StorageMonitor::EJECT_IN_USE: | 79 case chrome::StorageMonitor::EJECT_IN_USE: |
81 result = api::experimental_system_info_storage:: | 80 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_IN_USE; |
82 EJECT_DEVICE_RESULT_CODE_IN_USE; | |
83 break; | 81 break; |
84 case chrome::StorageMonitor::EJECT_NO_SUCH_DEVICE: | 82 case chrome::StorageMonitor::EJECT_NO_SUCH_DEVICE: |
85 result = api::experimental_system_info_storage:: | 83 result = api::system_storage:: |
86 EJECT_DEVICE_RESULT_CODE_NO_SUCH_DEVICE; | 84 EJECT_DEVICE_RESULT_CODE_NO_SUCH_DEVICE; |
87 break; | 85 break; |
88 case chrome::StorageMonitor::EJECT_FAILURE: | 86 case chrome::StorageMonitor::EJECT_FAILURE: |
89 result = api::experimental_system_info_storage:: | 87 result = api::system_storage::EJECT_DEVICE_RESULT_CODE_FAILURE; |
90 EJECT_DEVICE_RESULT_CODE_FAILURE; | |
91 } | 88 } |
92 | 89 |
93 SetResult(base::StringValue::CreateStringValue( | 90 SetResult(base::StringValue::CreateStringValue( |
94 api::experimental_system_info_storage::ToString(result))); | 91 api::system_storage::ToString(result))); |
95 SendResponse(true); | 92 SendResponse(true); |
96 } | 93 } |
97 | 94 |
98 SystemInfoStorageAddWatchFunction::SystemInfoStorageAddWatchFunction() { | 95 SystemStorageAddAvailableCapacityWatchFunction:: |
| 96 SystemStorageAddAvailableCapacityWatchFunction() { |
99 } | 97 } |
100 | 98 |
101 SystemInfoStorageAddWatchFunction::~SystemInfoStorageAddWatchFunction() { | 99 SystemStorageAddAvailableCapacityWatchFunction:: |
| 100 ~SystemStorageAddAvailableCapacityWatchFunction() { |
102 } | 101 } |
103 | 102 |
104 bool SystemInfoStorageAddWatchFunction::RunImpl() { | 103 bool SystemStorageAddAvailableCapacityWatchFunction::RunImpl() { |
105 // TODO(Haojian): Implement the addWatch api. | 104 // TODO(Haojian): Implement the addAvailableCapacityWatch API. |
106 return false; | 105 return false; |
107 } | 106 } |
108 | 107 |
109 SystemInfoStorageRemoveWatchFunction::SystemInfoStorageRemoveWatchFunction() { | 108 SystemStorageRemoveAvailableCapacityWatchFunction:: |
| 109 SystemStorageRemoveAvailableCapacityWatchFunction() { |
110 } | 110 } |
111 | 111 |
112 SystemInfoStorageRemoveWatchFunction::~SystemInfoStorageRemoveWatchFunction() { | 112 SystemStorageRemoveAvailableCapacityWatchFunction:: |
| 113 ~SystemStorageRemoveAvailableCapacityWatchFunction() { |
113 } | 114 } |
114 | 115 |
115 bool SystemInfoStorageRemoveWatchFunction::RunImpl() { | 116 bool SystemStorageRemoveAvailableCapacityWatchFunction::RunImpl() { |
116 // TODO(Haojian): Implement the removeWatch api. | 117 // TODO(Haojian): Implement the removeAvailableCapacityWatch API. |
117 return false; | 118 return false; |
118 } | 119 } |
119 | 120 |
120 SystemInfoStorageGetAllWatchFunction::SystemInfoStorageGetAllWatchFunction() { | 121 SystemStorageGetAllAvailableCapacityWatchesFunction |
| 122 ::SystemStorageGetAllAvailableCapacityWatchesFunction() { |
121 } | 123 } |
122 | 124 |
123 SystemInfoStorageGetAllWatchFunction::~SystemInfoStorageGetAllWatchFunction() { | 125 SystemStorageGetAllAvailableCapacityWatchesFunction |
| 126 ::~SystemStorageGetAllAvailableCapacityWatchesFunction() { |
124 } | 127 } |
125 | 128 |
126 bool SystemInfoStorageGetAllWatchFunction::RunImpl() { | 129 bool SystemStorageGetAllAvailableCapacityWatchesFunction::RunImpl() { |
127 // TODO(Haojian): Implement the getAllWatch api. | 130 // TODO(Haojian): Implement the getAllAvailableCapacityWatches API. |
128 return false; | 131 return false; |
129 } | 132 } |
130 | 133 |
131 SystemInfoStorageRemoveAllWatchFunction:: | 134 SystemStorageRemoveAllAvailableCapacityWatchesFunction:: |
132 SystemInfoStorageRemoveAllWatchFunction() { | 135 SystemStorageRemoveAllAvailableCapacityWatchesFunction() { |
133 } | 136 } |
134 | 137 |
135 SystemInfoStorageRemoveAllWatchFunction:: | 138 SystemStorageRemoveAllAvailableCapacityWatchesFunction:: |
136 ~SystemInfoStorageRemoveAllWatchFunction() { | 139 ~SystemStorageRemoveAllAvailableCapacityWatchesFunction() { |
137 } | 140 } |
138 | 141 |
139 bool SystemInfoStorageRemoveAllWatchFunction::RunImpl() { | 142 bool SystemStorageRemoveAllAvailableCapacityWatchesFunction::RunImpl() { |
140 // TODO(Haojian): Implement the removeAllWatch api. | 143 // TODO(Haojian): Implement the removeAllAvailableCapacityWatches api. |
141 return false; | 144 return false; |
142 } | 145 } |
143 | 146 |
144 } // namespace extensions | 147 } // namespace extensions |
OLD | NEW |