| Index: chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc
|
| diff --git a/chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc b/chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc
|
| index 123bcd40e9cfa329d4efdbd100bd54310135777a..5b4ad6cee92efb8031e06b72cd1532231f147f2e 100644
|
| --- a/chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc
|
| +++ b/chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc
|
| @@ -5,12 +5,15 @@
|
| #include "chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.h"
|
|
|
| #include "ash/shell.h"
|
| +#include "ash/system/audio/audio_observer.h"
|
| #include "ash/system/tray/system_tray_delegate.h"
|
| #include "base/bind.h"
|
| +#include "base/strings/string_number_conversions.h"
|
| #include "base/values.h"
|
| #include "chromeos/dbus/dbus_thread_manager.h"
|
| #include "chromeos/dbus/fake_bluetooth_adapter_client.h"
|
| #include "chromeos/dbus/fake_bluetooth_device_client.h"
|
| +#include "chromeos/dbus/fake_cras_audio_client.h"
|
| #include "chromeos/dbus/fake_power_manager_client.h"
|
| #include "content/public/browser/web_ui.h"
|
| #include "device/bluetooth/bluetooth_device_chromeos.h"
|
| @@ -22,6 +25,11 @@ const char kBluetoothDiscoverFunction[] = "requestBluetoothDiscover";
|
| const char kBluetoothPairFunction[] = "requestBluetoothPair";
|
| const char kRequestBluetoothInfo[] = "requestBluetoothInfo";
|
| const char kRequestPowerInfo[] = "requestPowerInfo";
|
| +const char kRequestAudioNodes[] = "requestAudioNodes";
|
| +
|
| +// Define update function that will update the state of the audio ui.
|
| +const char kInsertAudioNode[] = "insertAudioNode";
|
| +const char kRemoveAudioNode[] = "removeAudioNode";
|
|
|
| // Define update functions that will update the power properties to the
|
| // variables defined in the web UI.
|
| @@ -34,6 +42,8 @@ const char kUpdateTimeToFull[] = "updateTimeToFull";
|
|
|
| // Define callback functions that will update the JavaScript variable
|
| // and the web UI.
|
| +const char kUpdateAudioNodes[] =
|
| + "device_emulator.audioSettings.updateAudioNodes";
|
| const char kAddBluetoothDeviceJSCallback[] =
|
| "device_emulator.bluetoothSettings.addBluetoothDevice";
|
| const char kDevicePairedFromTrayJSCallback[] =
|
| @@ -83,12 +93,11 @@ class DeviceEmulatorMessageHandler::BluetoothObserver
|
|
|
| void DeviceEmulatorMessageHandler::BluetoothObserver::DeviceAdded(
|
| const dbus::ObjectPath& object_path) {
|
| - scoped_ptr<base::DictionaryValue> device = owner_->GetDeviceInfo(
|
| - object_path);
|
| + scoped_ptr<base::DictionaryValue> device = owner_->GetDeviceInfo(object_path);
|
|
|
| // Request to add the device to the view's list of devices.
|
| owner_->web_ui()->CallJavascriptFunction(kAddBluetoothDeviceJSCallback,
|
| - *device);
|
| + *device);
|
| }
|
|
|
| void DeviceEmulatorMessageHandler::BluetoothObserver::DevicePropertyChanged(
|
| @@ -103,6 +112,32 @@ void DeviceEmulatorMessageHandler::BluetoothObserver::DevicePropertyChanged(
|
| void DeviceEmulatorMessageHandler::BluetoothObserver::DeviceRemoved(
|
| const dbus::ObjectPath& object_path) {
|
| owner_->web_ui()->CallJavascriptFunction(
|
| + kRemoveBluetoothDeviceJSCallback, base::StringValue(object_path.value()));
|
| +}
|
| +
|
| +class DeviceEmulatorMessageHandler::CrasAudioObserver
|
| + : public CrasAudioClient::Observer {
|
| + public:
|
| + explicit CrasAudioObserver(DeviceEmulatorMessageHandler* owner)
|
| + : owner_(owner) {
|
| + owner_->fake_cras_audio_client_->AddObserver(this);
|
| + }
|
| +
|
| + ~CrasAudioObserver() override {
|
| + owner_->fake_cras_audio_client_->RemoveObserver(this);
|
| + }
|
| +
|
| + // chromeos::CrasAudioClient::Observer.
|
| + void NodesChanged() override;
|
| +
|
| + private:
|
| + DeviceEmulatorMessageHandler* owner_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(CrasAudioObserver);
|
| +};
|
| +
|
| +void DeviceEmulatorMessageHandler::CrasAudioObserver::NodesChanged() {
|
| + owner_->HandleRequestAudioNodes(nullptr);
|
| kDeviceRemovedFromMainAdapterJSCallback,
|
| base::StringValue(object_path.value()));
|
| }
|
| @@ -119,13 +154,12 @@ class DeviceEmulatorMessageHandler::PowerObserver
|
| owner_->fake_power_manager_client_->RemoveObserver(this);
|
| }
|
|
|
| - void PowerChanged(
|
| - const power_manager::PowerSupplyProperties& proto) override;
|
| + void PowerChanged(const power_manager::PowerSupplyProperties& proto) override;
|
|
|
| private:
|
| - DeviceEmulatorMessageHandler* owner_;
|
| + DeviceEmulatorMessageHandler* owner_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(PowerObserver);
|
| + DISALLOW_COPY_AND_ASSIGN(PowerObserver);
|
| };
|
|
|
| void DeviceEmulatorMessageHandler::PowerObserver::PowerChanged(
|
| @@ -141,7 +175,7 @@ void DeviceEmulatorMessageHandler::PowerObserver::PowerChanged(
|
| proto.battery_time_to_full_sec());
|
|
|
| owner_->web_ui()->CallJavascriptFunction(kUpdatePowerPropertiesJSCallback,
|
| - power_properties);
|
| + power_properties);
|
| }
|
|
|
| DeviceEmulatorMessageHandler::DeviceEmulatorMessageHandler()
|
| @@ -149,6 +183,9 @@ DeviceEmulatorMessageHandler::DeviceEmulatorMessageHandler()
|
| static_cast<chromeos::FakeBluetoothDeviceClient*>(
|
| chromeos::DBusThreadManager::Get()
|
| ->GetBluetoothDeviceClient())),
|
| + fake_cras_audio_client_(static_cast<chromeos::FakeCrasAudioClient*>(
|
| + chromeos::DBusThreadManager::Get()
|
| + ->GetCrasAudioClient())),
|
| fake_power_manager_client_(static_cast<chromeos::FakePowerManagerClient*>(
|
| chromeos::DBusThreadManager::Get()
|
| ->GetPowerManagerClient())) {}
|
| @@ -158,6 +195,7 @@ DeviceEmulatorMessageHandler::~DeviceEmulatorMessageHandler() {
|
|
|
| void DeviceEmulatorMessageHandler::Init() {
|
| bluetooth_observer_.reset(new BluetoothObserver(this));
|
| + cras_audio_observer_.reset(new CrasAudioObserver(this));
|
| power_observer_.reset(new PowerObserver(this));
|
| }
|
|
|
| @@ -239,6 +277,56 @@ void DeviceEmulatorMessageHandler::HandleRequestBluetoothPair(
|
| }
|
| }
|
|
|
| +void DeviceEmulatorMessageHandler::HandleRequestAudioNodes(
|
| + const base::ListValue* args) {
|
| + // Get every active audio node and create a dictionary to
|
| + // send it to JavaScript.
|
| + base::ListValue audio_nodes;
|
| + for (const AudioNode& node : fake_cras_audio_client_->node_list()) {
|
| + scoped_ptr<base::DictionaryValue> audio_node(new base::DictionaryValue());
|
| +
|
| + audio_node->SetBoolean("isInput", node.is_input);
|
| + audio_node->SetString("id", base::Uint64ToString(node.id));
|
| + audio_node->SetString("deviceName", node.device_name);
|
| + audio_node->SetString("type", node.type);
|
| + audio_node->SetString("name", node.name);
|
| + audio_node->SetBoolean("active", node.active);
|
| +
|
| + audio_nodes.Append(audio_node.Pass());
|
| + }
|
| + web_ui()->CallJavascriptFunction(kUpdateAudioNodes, audio_nodes);
|
| +}
|
| +
|
| +void DeviceEmulatorMessageHandler::HandleInsertAudioNode(
|
| + const base::ListValue* args) {
|
| + AudioNode audio_node;
|
| + const base::DictionaryValue* device_dict = nullptr;
|
| +
|
| + CHECK(args->GetDictionary(0, &device_dict));
|
| + CHECK(args->GetString(1, &audio_node.type));
|
| +
|
| + CHECK(device_dict->GetBoolean("isInput", &audio_node.is_input));
|
| + CHECK(device_dict->GetString("deviceName", &audio_node.device_name));
|
| + CHECK(device_dict->GetString("name", &audio_node.name));
|
| + CHECK(device_dict->GetBoolean("active", &audio_node.active));
|
| +
|
| + std::string tmp_id;
|
| + CHECK(device_dict->GetString("id", &tmp_id));
|
| + CHECK(base::StringToUint64(tmp_id, &audio_node.id));
|
| +
|
| + fake_cras_audio_client_->InsertAudioNodeToList(audio_node);
|
| +}
|
| +
|
| +void DeviceEmulatorMessageHandler::HandleRemoveAudioNode(
|
| + const base::ListValue* args) {
|
| + std::string tmp_id;
|
| + uint64 id;
|
| + CHECK(args->GetString(0, &tmp_id));
|
| + CHECK(base::StringToUint64(tmp_id, &id));
|
| +
|
| + fake_cras_audio_client_->RemoveAudioNodeFromList(id);
|
| +}
|
| +
|
| void DeviceEmulatorMessageHandler::UpdateBatteryPercent(
|
| const base::ListValue* args) {
|
| int new_percent;
|
| @@ -336,6 +424,16 @@ void DeviceEmulatorMessageHandler::RegisterMessages() {
|
| base::Bind(&DeviceEmulatorMessageHandler::HandleRequestBluetoothInfo,
|
| base::Unretained(this)));
|
| web_ui()->RegisterMessageCallback(
|
| + kRequestAudioNodes,
|
| + base::Bind(&DeviceEmulatorMessageHandler::HandleRequestAudioNodes,
|
| + base::Unretained(this)));
|
| + web_ui()->RegisterMessageCallback(
|
| + kInsertAudioNode,
|
| + base::Bind(&DeviceEmulatorMessageHandler::HandleInsertAudioNode,
|
| + base::Unretained(this)));
|
| + web_ui()->RegisterMessageCallback(
|
| + kRemoveAudioNode,
|
| + base::Bind(&DeviceEmulatorMessageHandler::HandleRemoveAudioNode,
|
| kRemoveBluetoothDevice,
|
| base::Bind(&DeviceEmulatorMessageHandler::HandleRemoveBluetoothDevice,
|
| base::Unretained(this)));
|
|
|