OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_EMULATOR_DEVICE_EMULATOR_MESSAGE_HANDLE
R_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_EMULATOR_DEVICE_EMULATOR_MESSAGE_HANDLE
R_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_EMULATOR_DEVICE_EMULATOR_MESSAGE_HANDLE
R_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_EMULATOR_DEVICE_EMULATOR_MESSAGE_HANDLE
R_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" | 9 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" |
10 #include "content/public/browser/web_ui_message_handler.h" | 10 #include "content/public/browser/web_ui_message_handler.h" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 class ListValue; | 13 class ListValue; |
14 } // namespace base | 14 } // namespace base |
15 | 15 |
16 namespace dbus { | 16 namespace dbus { |
17 class ObjectPath; | 17 class ObjectPath; |
18 } // namespace dbus | 18 } // namespace dbus |
19 | 19 |
20 namespace chromeos { | 20 namespace chromeos { |
21 | 21 |
22 class FakeBluetoothDeviceClient; | 22 class FakeBluetoothDeviceClient; |
| 23 class FakeCrasAudioClient; |
23 class FakePowerManagerClient; | 24 class FakePowerManagerClient; |
24 | 25 |
25 // Handler class for the Device Emulator page operations. | 26 // Handler class for the Device Emulator page operations. |
26 class DeviceEmulatorMessageHandler | 27 class DeviceEmulatorMessageHandler |
27 : public content::WebUIMessageHandler { | 28 : public content::WebUIMessageHandler { |
28 public: | 29 public: |
29 DeviceEmulatorMessageHandler(); | 30 DeviceEmulatorMessageHandler(); |
30 ~DeviceEmulatorMessageHandler() override; | 31 ~DeviceEmulatorMessageHandler() override; |
31 | 32 |
32 // Adds |this| as an observer to all necessary objects. | 33 // Adds |this| as an observer to all necessary objects. |
33 void Init(); | 34 void Init(); |
34 | 35 |
35 // Callback for the "requestBluetoothDiscover" message. This asynchronously | 36 // Callback for the "requestBluetoothDiscover" message. This asynchronously |
36 // requests for the system to discover a certain device. The device's data | 37 // requests for the system to discover a certain device. The device's data |
37 // should be passed into |args| as a dictionary. If the device does not | 38 // should be passed into |args| as a dictionary. If the device does not |
38 // already exist, then it will be created and attached to the main adapter. | 39 // already exist, then it will be created and attached to the main adapter. |
39 void HandleRequestBluetoothDiscover(const base::ListValue* args); | 40 void HandleRequestBluetoothDiscover(const base::ListValue* args); |
40 | 41 |
41 // Callback for the "requestBluetoothInfo" message. This asynchronously | 42 // Callback for the "requestBluetoothInfo" message. This asynchronously |
42 // requests for the devices which are already paired with the device. | 43 // requests for the devices which are already paired with the device. |
43 void HandleRequestBluetoothInfo(const base::ListValue* args); | 44 void HandleRequestBluetoothInfo(const base::ListValue* args); |
44 | 45 |
45 // Callback for the "requestBluetoothPair" message. This asynchronously | 46 // Callback for the "requestBluetoothPair" message. This asynchronously |
46 // requests for the system to pair a certain device. The device's data should | 47 // requests for the system to pair a certain device. The device's data should |
47 // be passed into |args| as a dictionary. If the device does not already | 48 // be passed into |args| as a dictionary. If the device does not already |
48 // exist, then it will be created and attached to the main adapter. | 49 // exist, then it will be created and attached to the main adapter. |
49 void HandleRequestBluetoothPair(const base::ListValue* args); | 50 void HandleRequestBluetoothPair(const base::ListValue* args); |
50 | 51 |
| 52 // Callback for the "requestAudioNodes" message. This asynchronously |
| 53 // requests the audio node that is current set to active. It is possible |
| 54 // that there can be multiple current active nodes. |
| 55 void HandleRequestAudioNodes(const base::ListValue* args); |
| 56 |
| 57 // Create a node and add the node to the current AudioNodeList in |
| 58 // |fake_cras_audio_client_|. |
| 59 void HandleInsertAudioNode(const base::ListValue* args); |
| 60 |
| 61 // Removes an AudioNode from the current list in |fake_cras_audio_client_|. |
| 62 // based on the node id. |
| 63 void HandleRemoveAudioNode(const base::ListValue* args); |
| 64 |
51 // Callbacks for JS update methods. All these methods work | 65 // Callbacks for JS update methods. All these methods work |
52 // asynchronously. | 66 // asynchronously. |
53 void UpdateBatteryPercent(const base::ListValue* args); | 67 void UpdateBatteryPercent(const base::ListValue* args); |
54 void UpdateBatteryState(const base::ListValue* args); | 68 void UpdateBatteryState(const base::ListValue* args); |
55 void UpdateExternalPower(const base::ListValue* args); | 69 void UpdateExternalPower(const base::ListValue* args); |
56 void UpdateTimeToEmpty(const base::ListValue* args); | 70 void UpdateTimeToEmpty(const base::ListValue* args); |
57 void UpdateTimeToFull(const base::ListValue* args); | 71 void UpdateTimeToFull(const base::ListValue* args); |
58 | 72 |
59 // content::WebUIMessageHandler: | 73 // content::WebUIMessageHandler: |
60 void RegisterMessages() override; | 74 void RegisterMessages() override; |
61 | 75 |
62 // Callback for the "requestPowerInfo" message. This asynchonously requests | 76 // Callback for the "requestPowerInfo" message. This asynchronously requests |
63 // for power settings such as battery percentage, external power, etc. to | 77 // for power settings such as battery percentage, external power, etc. to |
64 // update the view. | 78 // update the view. |
65 void RequestPowerInfo(const base::ListValue* args); | 79 void RequestPowerInfo(const base::ListValue* args); |
66 | 80 |
67 private: | 81 private: |
68 class BluetoothObserver; | 82 class BluetoothObserver; |
| 83 class CrasAudioObserver; |
69 class PowerObserver; | 84 class PowerObserver; |
70 | 85 |
71 // Creates a bluetooth device with the properties given in |args|. |args| | 86 // Creates a bluetooth device with the properties given in |args|. |args| |
72 // should contain a dictionary so that each dictionary value can be mapped | 87 // should contain a dictionary so that each dictionary value can be mapped |
73 // to its respective property upon creating the device. Returns the device | 88 // to its respective property upon creating the device. Returns the device |
74 // path. | 89 // path. |
75 std::string CreateBluetoothDeviceFromListValue(const base::ListValue* args); | 90 std::string CreateBluetoothDeviceFromListValue(const base::ListValue* args); |
76 | 91 |
77 // Builds a dictionary with each key representing a property of the device | 92 // Builds a dictionary with each key representing a property of the device |
78 // with path |object_path|. | 93 // with path |object_path|. |
79 scoped_ptr<base::DictionaryValue> GetDeviceInfo( | 94 scoped_ptr<base::DictionaryValue> GetDeviceInfo( |
80 const dbus::ObjectPath& object_path); | 95 const dbus::ObjectPath& object_path); |
81 | 96 |
| 97 FakeBluetoothDeviceClient* fake_bluetooth_device_client_; |
82 scoped_ptr<BluetoothObserver> bluetooth_observer_; | 98 scoped_ptr<BluetoothObserver> bluetooth_observer_; |
83 FakeBluetoothDeviceClient* fake_bluetooth_device_client_; | 99 |
| 100 FakeCrasAudioClient* fake_cras_audio_client_; |
| 101 scoped_ptr<CrasAudioObserver> cras_audio_observer_; |
| 102 |
84 FakePowerManagerClient* fake_power_manager_client_; | 103 FakePowerManagerClient* fake_power_manager_client_; |
85 scoped_ptr<PowerObserver> power_observer_; | 104 scoped_ptr<PowerObserver> power_observer_; |
86 | 105 |
87 DISALLOW_COPY_AND_ASSIGN(DeviceEmulatorMessageHandler); | 106 DISALLOW_COPY_AND_ASSIGN(DeviceEmulatorMessageHandler); |
88 }; | 107 }; |
89 | 108 |
90 } // namespace chromeos | 109 } // namespace chromeos |
91 | 110 |
92 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_EMULATOR_DEVICE_EMULATOR_MESSAGE_HAN
DLER_H_ | 111 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_EMULATOR_DEVICE_EMULATOR_MESSAGE_HAN
DLER_H_ |
OLD | NEW |