Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_hand ler.h" | |
| 6 | |
| 7 #include <stdlib.h> | |
|
oshima
2015/06/26 16:22:07
you don't need this, do you?
rfrappier
2015/06/26 16:33:08
It worked without it, but comment #6 indicated tha
oshima
2015/06/26 17:19:49
oh, I missed rand() below. Yes, this should be her
rfrappier
2015/06/26 17:29:13
Done.
| |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/values.h" | |
| 11 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" | |
|
oshima
2015/06/26 16:22:07
and this?
rfrappier
2015/06/26 16:33:08
This will be used later for handling the power sup
oshima
2015/06/26 17:19:49
Please add when necessary. It can confuse reviewer
rfrappier
2015/06/26 17:29:13
Done.
rfrappier
2015/06/26 17:29:13
Okay, will remove for now.
| |
| 12 #include "content/public/browser/web_ui.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 // Define the name of the callback functions that will be used by JavaScript | |
|
oshima
2015/06/26 16:22:07
. at the end
rfrappier
2015/06/26 16:33:08
Done.
| |
| 17 const char kBatteryPercentFunction[] = "requestBatteryInfo"; | |
| 18 const char kUpdateBatteryPercentFunction[] = "updateBatteryInfo"; | |
| 19 const char kUpdatePowerModeFunction[] = "updatePowerSource"; | |
| 20 const char kBatteryPercentFunctionJSCallback[] = | |
| 21 "device_emulator.setBatteryInfo"; | |
| 22 | |
| 23 } // namespace | |
| 24 | |
| 25 DeviceEmulatorMessageHandler::DeviceEmulatorMessageHandler() { | |
| 26 } | |
| 27 | |
| 28 DeviceEmulatorMessageHandler::~DeviceEmulatorMessageHandler() { | |
| 29 } | |
| 30 | |
| 31 void DeviceEmulatorMessageHandler::RegisterMessages() { | |
| 32 web_ui()->RegisterMessageCallback( | |
| 33 kBatteryPercentFunction, | |
| 34 base::Bind(&DeviceEmulatorMessageHandler::HandleRequestBatteryInfo, | |
| 35 base::Unretained(this))); | |
| 36 web_ui()->RegisterMessageCallback( | |
| 37 kUpdateBatteryPercentFunction, | |
| 38 base::Bind(&DeviceEmulatorMessageHandler::HandleUpdateBatteryInfo, | |
| 39 base::Unretained(this))); | |
| 40 web_ui()->RegisterMessageCallback( | |
| 41 kUpdatePowerModeFunction, | |
| 42 base::Bind(&DeviceEmulatorMessageHandler::HandleUpdatePowerSource, | |
| 43 base::Unretained(this))); | |
| 44 } | |
| 45 | |
| 46 void DeviceEmulatorMessageHandler::HandleRequestBatteryInfo( | |
| 47 const base::ListValue* args) { | |
| 48 web_ui()->CallJavascriptFunction(kBatteryPercentFunctionJSCallback, | |
| 49 base::FundamentalValue(rand() % 101)); | |
| 50 } | |
| 51 | |
| 52 void DeviceEmulatorMessageHandler::HandleUpdateBatteryInfo( | |
| 53 const base::ListValue* args) { | |
| 54 int new_percent = -1; | |
| 55 args->GetInteger(0, &new_percent); | |
| 56 } | |
| 57 | |
| 58 void DeviceEmulatorMessageHandler::HandleUpdatePowerSource( | |
| 59 const base::ListValue* args) { | |
| 60 } | |
| OLD | NEW |