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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/i18n/time_formatting.h" | 8 #include "base/i18n/time_formatting.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 #include "policy/policy_constants.h" | 42 #include "policy/policy_constants.h" |
43 #include "views/widget/widget.h" | 43 #include "views/widget/widget.h" |
44 | 44 |
45 using chromeos::CrosLibrary; | 45 using chromeos::CrosLibrary; |
46 using chromeos::NetworkLibrary; | 46 using chromeos::NetworkLibrary; |
47 using chromeos::UpdateLibrary; | 47 using chromeos::UpdateLibrary; |
48 using chromeos::UserManager; | 48 using chromeos::UserManager; |
49 | 49 |
50 namespace { | 50 namespace { |
51 | 51 |
52 // Last reported power status. | |
53 chromeos::PowerSupplyStatus power_status; | |
54 | |
52 bool EnsureCrosLibraryLoaded(AutomationProvider* provider, | 55 bool EnsureCrosLibraryLoaded(AutomationProvider* provider, |
53 IPC::Message* reply_message) { | 56 IPC::Message* reply_message) { |
54 if (!CrosLibrary::Get()->EnsureLoaded()) { | 57 if (!CrosLibrary::Get()->EnsureLoaded()) { |
55 AutomationJSONReply(provider, reply_message).SendError( | 58 AutomationJSONReply(provider, reply_message).SendError( |
56 "Could not load cros library."); | 59 "Could not load cros library."); |
57 return false; | 60 return false; |
58 } | 61 } |
59 return true; | 62 return true; |
60 } | 63 } |
61 | 64 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 for (i = policy_map->begin(); i != policy_map->end(); i++) | 206 for (i = policy_map->begin(); i != policy_map->end(); i++) |
204 dict->Set(policy::GetPolicyName(i->first), | 207 dict->Set(policy::GetPolicyName(i->first), |
205 i->second->DeepCopy()); | 208 i->second->DeepCopy()); |
206 } | 209 } |
207 } | 210 } |
208 return dict; | 211 return dict; |
209 } | 212 } |
210 | 213 |
211 } // namespace | 214 } // namespace |
212 | 215 |
216 void TestingAutomationProvider::PowerChanged( | |
217 const chromeos::PowerSupplyStatus& status) { | |
218 power_status = status; | |
219 } | |
stevenjb
2011/10/25 02:33:20
Since this observer is only changing a local varia
| |
220 | |
213 void TestingAutomationProvider::GetLoginInfo(DictionaryValue* args, | 221 void TestingAutomationProvider::GetLoginInfo(DictionaryValue* args, |
214 IPC::Message* reply_message) { | 222 IPC::Message* reply_message) { |
215 AutomationJSONReply reply(this, reply_message); | 223 AutomationJSONReply reply(this, reply_message); |
216 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 224 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
217 | 225 |
218 const UserManager* user_manager = UserManager::Get(); | 226 const UserManager* user_manager = UserManager::Get(); |
219 if (!user_manager) | 227 if (!user_manager) |
220 reply.SendError("No user manager!"); | 228 reply.SendError("No user manager!"); |
221 const chromeos::ScreenLocker* screen_locker = | 229 const chromeos::ScreenLocker* screen_locker = |
222 chromeos::ScreenLocker::default_screen_locker(); | 230 chromeos::ScreenLocker::default_screen_locker(); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 // session manager then we'll die when the session is stopped. | 343 // session manager then we'll die when the session is stopped. |
336 reply.SendSuccess(NULL); | 344 reply.SendSuccess(NULL); |
337 screen_locker->Signout(); | 345 screen_locker->Signout(); |
338 } | 346 } |
339 | 347 |
340 void TestingAutomationProvider::GetBatteryInfo(DictionaryValue* args, | 348 void TestingAutomationProvider::GetBatteryInfo(DictionaryValue* args, |
341 IPC::Message* reply_message) { | 349 IPC::Message* reply_message) { |
342 if (!EnsureCrosLibraryLoaded(this, reply_message)) | 350 if (!EnsureCrosLibraryLoaded(this, reply_message)) |
343 return; | 351 return; |
344 | 352 |
345 chromeos::PowerLibrary* power_library = CrosLibrary::Get()->GetPowerLibrary(); | |
346 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 353 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
347 | 354 |
348 return_value->SetBoolean("battery_is_present", | 355 return_value->SetBoolean("battery_is_present", |
349 power_library->IsBatteryPresent()); | 356 power_status.battery_is_present); |
350 return_value->SetBoolean("line_power_on", power_library->IsLinePowerOn()); | 357 return_value->SetBoolean("line_power_on", power_status.line_power_on); |
351 if (power_library->IsBatteryPresent()) { | 358 if (power_status.battery_is_present) { |
352 return_value->SetBoolean("battery_fully_charged", | 359 return_value->SetBoolean("battery_fully_charged", |
353 power_library->IsBatteryFullyCharged()); | 360 power_status.battery_is_full); |
354 return_value->SetDouble("battery_percentage", | 361 return_value->SetDouble("battery_percentage", |
355 power_library->GetBatteryPercentage()); | 362 power_status.battery_percentage); |
356 if (power_library->IsLinePowerOn()) { | 363 if (power_status.line_power_on) { |
357 int time = power_library->GetBatteryTimeToFull().InSeconds(); | 364 int64 time = power_status.battery_seconds_to_full; |
358 if (time > 0 || power_library->IsBatteryFullyCharged()) | 365 if (time > 0 || power_status.battery_is_full) |
359 return_value->SetInteger("battery_time_to_full", time); | 366 return_value->SetInteger("battery_seconds_to_full", time); |
360 } else { | 367 } else { |
361 int time = power_library->GetBatteryTimeToEmpty().InSeconds(); | 368 int64 time = power_status.battery_seconds_to_empty; |
362 if (time > 0) | 369 if (time > 0) |
363 return_value->SetInteger("battery_time_to_empty", time); | 370 return_value->SetInteger("battery_seconds_to_empty", time); |
364 } | 371 } |
365 } | 372 } |
366 | 373 |
367 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); | 374 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
368 } | 375 } |
369 | 376 |
370 void TestingAutomationProvider::GetNetworkInfo(DictionaryValue* args, | 377 void TestingAutomationProvider::GetNetworkInfo(DictionaryValue* args, |
371 IPC::Message* reply_message) { | 378 IPC::Message* reply_message) { |
372 if (!EnsureCrosLibraryLoaded(this, reply_message)) | 379 if (!EnsureCrosLibraryLoaded(this, reply_message)) |
373 return; | 380 return; |
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1194 | 1201 |
1195 // Set up an observer (it will delete itself). | 1202 // Set up an observer (it will delete itself). |
1196 take_photo_dialog->AddObserver(new PhotoCaptureObserver( | 1203 take_photo_dialog->AddObserver(new PhotoCaptureObserver( |
1197 this, reply_message)); | 1204 this, reply_message)); |
1198 | 1205 |
1199 views::Widget* window = browser::CreateViewsWindow( | 1206 views::Widget* window = browser::CreateViewsWindow( |
1200 browser->window()->GetNativeHandle(), take_photo_dialog); | 1207 browser->window()->GetNativeHandle(), take_photo_dialog); |
1201 window->SetAlwaysOnTop(true); | 1208 window->SetAlwaysOnTop(true); |
1202 window->Show(); | 1209 window->Show(); |
1203 } | 1210 } |
OLD | NEW |