Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1331)

Unified Diff: chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc

Issue 1274403003: Full Implementation of Audio for the Chrome Os Device Emulator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Initial Patch Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 4bc2fc183c5c0f28ae146e22075e91d519e1b75c..f4defd520f793bd6d3c90eebcf0cbfadf8365de7 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,13 @@ 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 kUpdateAudioNodes[] =
+ "device_emulator.audioSettings.updateAudioNodes";
xiyuan 2015/08/07 20:17:12 nit: Move this with other JS callback names around
mozartalouis 2015/08/07 22:44:07 Done.
+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.
@@ -72,18 +82,42 @@ 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::DeviceRemoved(
const dbus::ObjectPath& object_path) {
- owner_->web_ui()->CallJavascriptFunction(kRemoveBluetoothDeviceJSCallback,
- base::StringValue(object_path.value()));
+ 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);
}
class DeviceEmulatorMessageHandler::PowerObserver
@@ -98,13 +132,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(
@@ -120,7 +153,7 @@ void DeviceEmulatorMessageHandler::PowerObserver::PowerChanged(
proto.battery_time_to_full_sec());
owner_->web_ui()->CallJavascriptFunction(kUpdatePowerPropertiesJSCallback,
- power_properties);
+ power_properties);
}
DeviceEmulatorMessageHandler::DeviceEmulatorMessageHandler()
@@ -128,6 +161,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())) {}
@@ -137,6 +173,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));
}
@@ -183,6 +220,55 @@ void DeviceEmulatorMessageHandler::HandleRequestBluetoothPair(
props->address.value());
}
+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("is_input", node.is_input);
+ audio_node->SetString("id", base::Uint64ToString(node.id));
+ audio_node->SetString("device_name", 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(device_dict->GetBoolean("isInput", &audio_node.is_input));
+ CHECK(device_dict->GetString("deviceName", &audio_node.device_name));
+ CHECK(device_dict->GetString("type", &audio_node.type));
+ 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;
@@ -279,6 +365,18 @@ void DeviceEmulatorMessageHandler::RegisterMessages() {
kRequestBluetoothInfo,
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,
+ base::Unretained(this)));
}
std::string DeviceEmulatorMessageHandler::CreateBluetoothDeviceFromListValue(

Powered by Google App Engine
This is Rietveld 408576698