OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/automation/testing_automation_provider.h" | 5 #include "chrome/browser/automation/testing_automation_provider.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/automation/automation_provider_json.h" | 8 #include "chrome/browser/automation/automation_provider_json.h" |
9 #include "chrome/browser/automation/automation_provider_observers.h" | 9 #include "chrome/browser/automation/automation_provider_observers.h" |
10 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
11 #include "chrome/browser/chromeos/cros/network_library.h" | 11 #include "chrome/browser/chromeos/cros/network_library.h" |
| 12 #include "chrome/browser/chromeos/cros/power_library.h" |
12 #include "chrome/browser/chromeos/cros/screen_lock_library.h" | 13 #include "chrome/browser/chromeos/cros/screen_lock_library.h" |
13 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 14 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
14 #include "chrome/browser/chromeos/login/screen_locker.h" | 15 #include "chrome/browser/chromeos/login/screen_locker.h" |
15 | 16 |
16 using chromeos::CrosLibrary; | 17 using chromeos::CrosLibrary; |
17 using chromeos::NetworkLibrary; | 18 using chromeos::NetworkLibrary; |
18 using chromeos::UserManager; | 19 using chromeos::UserManager; |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 "No default screen locker. Are you sure the screen is locked?"); | 117 "No default screen locker. Are you sure the screen is locked?"); |
117 return; | 118 return; |
118 } | 119 } |
119 | 120 |
120 // Send success before stopping session because if we're a child of | 121 // Send success before stopping session because if we're a child of |
121 // session manager then we'll die when the session is stopped. | 122 // session manager then we'll die when the session is stopped. |
122 reply.SendSuccess(NULL); | 123 reply.SendSuccess(NULL); |
123 screen_locker->Signout(); | 124 screen_locker->Signout(); |
124 } | 125 } |
125 | 126 |
| 127 void TestingAutomationProvider::GetBatteryInfo(DictionaryValue* args, |
| 128 IPC::Message* reply_message) { |
| 129 AutomationJSONReply reply(this, reply_message); |
| 130 |
| 131 if (!CrosLibrary::Get()->EnsureLoaded()) { |
| 132 reply.SendError("Could not load cros library."); |
| 133 return; |
| 134 } |
| 135 |
| 136 chromeos::PowerLibrary* power_library = CrosLibrary::Get()->GetPowerLibrary(); |
| 137 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 138 |
| 139 return_value->SetBoolean("battery_is_present", |
| 140 power_library->battery_is_present()); |
| 141 return_value->SetBoolean("line_power_on", power_library->line_power_on()); |
| 142 if (power_library->battery_is_present()) { |
| 143 return_value->SetBoolean("battery_fully_charged", |
| 144 power_library->battery_fully_charged()); |
| 145 return_value->SetDouble("battery_percentage", |
| 146 power_library->battery_percentage()); |
| 147 if (power_library->line_power_on()) { |
| 148 int time = power_library->battery_time_to_full().InSeconds(); |
| 149 if (time > 0 || power_library->battery_fully_charged()) |
| 150 return_value->SetInteger("battery_time_to_full", time); |
| 151 } else { |
| 152 int time = power_library->battery_time_to_empty().InSeconds(); |
| 153 if (time > 0) |
| 154 return_value->SetInteger("battery_time_to_empty", time); |
| 155 } |
| 156 } |
| 157 |
| 158 reply.SendSuccess(return_value.get()); |
| 159 } |
| 160 |
126 void TestingAutomationProvider::GetNetworkInfo(DictionaryValue* args, | 161 void TestingAutomationProvider::GetNetworkInfo(DictionaryValue* args, |
127 IPC::Message* reply_message) { | 162 IPC::Message* reply_message) { |
128 AutomationJSONReply reply(this, reply_message); | 163 AutomationJSONReply reply(this, reply_message); |
129 | 164 |
130 if (!CrosLibrary::Get()->EnsureLoaded()) { | 165 if (!CrosLibrary::Get()->EnsureLoaded()) { |
131 reply.SendError("Could not load cros library."); | 166 reply.SendError("Could not load cros library."); |
132 return; | 167 return; |
133 } | 168 } |
134 | 169 |
135 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); | 170 NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 chromeos::WifiNetwork* wifi = | 303 chromeos::WifiNetwork* wifi = |
269 network_library->FindWifiNetworkByPath(service_path); | 304 network_library->FindWifiNetworkByPath(service_path); |
270 if (!wifi) { | 305 if (!wifi) { |
271 reply.SendError("No network found with specified service path."); | 306 reply.SendError("No network found with specified service path."); |
272 return; | 307 return; |
273 } | 308 } |
274 | 309 |
275 network_library->DisconnectFromWirelessNetwork(wifi); | 310 network_library->DisconnectFromWirelessNetwork(wifi); |
276 reply.SendSuccess(NULL); | 311 reply.SendSuccess(NULL); |
277 } | 312 } |
OLD | NEW |