diff options
27 files changed, 374 insertions, 257 deletions
diff --git a/ash/system/audio/audio_observer.h b/ash/system/audio/audio_observer.h index 6023226..780bb5e 100644 --- a/ash/system/audio/audio_observer.h +++ b/ash/system/audio/audio_observer.h @@ -5,14 +5,18 @@ #ifndef ASH_SYSTEM_AUDIO_AUDIO_OBSERVER_H_ #define ASH_SYSTEM_AUDIO_AUDIO_OBSERVER_H_ +#include <stdint.h> + namespace ash { class AudioObserver { public: virtual ~AudioObserver() {} - // Called when output volume changed. - virtual void OnOutputVolumeChanged() = 0; + // Called when an active output device's volume changed. + // |node_id|: id of the active node. + // |volume|: volume as a percentage, 0.0 -- 100.0. + virtual void OnOutputNodeVolumeChanged(uint64_t node_id, double volume) = 0; // Called when output mute state changed. virtual void OnOutputMuteChanged() = 0; diff --git a/ash/system/audio/tray_audio.cc b/ash/system/audio/tray_audio.cc index e7260e8..6c2ae48 100644 --- a/ash/system/audio/tray_audio.cc +++ b/ash/system/audio/tray_audio.cc @@ -97,7 +97,8 @@ bool TrayAudio::ShouldShowShelf() const { return TrayAudio::ShowAudioDeviceMenu() && !pop_up_volume_view_; } -void TrayAudio::OnOutputVolumeChanged() { +void TrayAudio::OnOutputNodeVolumeChanged(uint64_t /* node_id */, + double /* volume */) { float percent = static_cast<float>(audio_delegate_->GetOutputVolumeLevel()) / 100.0f; if (tray_view()) diff --git a/ash/system/audio/tray_audio.h b/ash/system/audio/tray_audio.h index d9ddf83..65ac42e 100644 --- a/ash/system/audio/tray_audio.h +++ b/ash/system/audio/tray_audio.h @@ -53,7 +53,7 @@ class TrayAudio : public TrayImageItem, bool ShouldShowShelf() const override; // Overridden from AudioObserver. - void OnOutputVolumeChanged() override; + void OnOutputNodeVolumeChanged(uint64_t node_id, double volume) override; void OnOutputMuteChanged() override; void OnAudioNodesChanged() override; void OnActiveOutputNodeChanged() override; diff --git a/ash/system/tray/system_tray_notifier.cc b/ash/system/tray/system_tray_notifier.cc index 81ed05f..331fb95 100644 --- a/ash/system/tray/system_tray_notifier.cc +++ b/ash/system/tray/system_tray_notifier.cc @@ -195,11 +195,10 @@ void SystemTrayNotifier::NotifyAccessibilityModeChanged( OnAccessibilityModeChanged(notify)); } -void SystemTrayNotifier::NotifyAudioOutputVolumeChanged() { - FOR_EACH_OBSERVER( - AudioObserver, - audio_observers_, - OnOutputVolumeChanged()); +void SystemTrayNotifier::NotifyAudioOutputVolumeChanged(uint64_t node_id, + double volume) { + FOR_EACH_OBSERVER(AudioObserver, audio_observers_, + OnOutputNodeVolumeChanged(node_id, volume)); } void SystemTrayNotifier::NotifyAudioOutputMuteChanged() { diff --git a/ash/system/tray/system_tray_notifier.h b/ash/system/tray/system_tray_notifier.h index f095609..632d122 100644 --- a/ash/system/tray/system_tray_notifier.h +++ b/ash/system/tray/system_tray_notifier.h @@ -110,7 +110,7 @@ class ASH_EXPORT SystemTrayNotifier { void NotifyAccessibilityModeChanged( ui::AccessibilityNotificationVisibility notify); - void NotifyAudioOutputVolumeChanged(); + void NotifyAudioOutputVolumeChanged(uint64_t node_id, double volume); void NotifyAudioOutputMuteChanged(); void NotifyAudioNodesChanged(); void NotifyAudioActiveOutputNodeChanged(); diff --git a/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc b/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc index 8b33013..27ea957 100644 --- a/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc +++ b/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc @@ -1219,15 +1219,17 @@ void SystemTrayDelegateChromeOS::InputMethodMenuItemChanged( } // Overridden from CrasAudioHandler::AudioObserver. -void SystemTrayDelegateChromeOS::OnOutputVolumeChanged() { - GetSystemTrayNotifier()->NotifyAudioOutputVolumeChanged(); +void SystemTrayDelegateChromeOS::OnOutputNodeVolumeChanged(uint64_t node_id, + int volume) { + GetSystemTrayNotifier()->NotifyAudioOutputVolumeChanged(node_id, volume); } void SystemTrayDelegateChromeOS::OnOutputMuteChanged() { GetSystemTrayNotifier()->NotifyAudioOutputMuteChanged(); } -void SystemTrayDelegateChromeOS::OnInputGainChanged() { +void SystemTrayDelegateChromeOS::OnInputNodeGainChanged(uint64_t /* node_id */, + int /* gain */) { } void SystemTrayDelegateChromeOS::OnInputMuteChanged() { diff --git a/chrome/browser/ui/ash/system_tray_delegate_chromeos.h b/chrome/browser/ui/ash/system_tray_delegate_chromeos.h index 0e4f2cd..5aa5ddc 100644 --- a/chrome/browser/ui/ash/system_tray_delegate_chromeos.h +++ b/chrome/browser/ui/ash/system_tray_delegate_chromeos.h @@ -220,9 +220,9 @@ class SystemTrayDelegateChromeOS ui::ime::InputMethodMenuManager* manager) override; // Overridden from CrasAudioHandler::AudioObserver. - void OnOutputVolumeChanged() override; + void OnOutputNodeVolumeChanged(uint64_t node_id, int volume) override; void OnOutputMuteChanged() override; - void OnInputGainChanged() override; + void OnInputNodeGainChanged(uint64_t node_id, int gain) override; void OnInputMuteChanged() override; void OnAudioNodesChanged() override; void OnActiveOutputNodeChanged() override; diff --git a/chrome/browser/ui/ash/volume_controller_chromeos.cc b/chrome/browser/ui/ash/volume_controller_chromeos.cc index da8df85..36d9676 100644 --- a/chrome/browser/ui/ash/volume_controller_chromeos.cc +++ b/chrome/browser/ui/ash/volume_controller_chromeos.cc @@ -92,7 +92,7 @@ void VolumeController::HandleVolumeUp(const ui::Accelerator& accelerator) { PlayVolumeAdjustSound(); } -void VolumeController::OnOutputVolumeChanged() { +void VolumeController::OnOutputNodeVolumeChanged(uint64_t node_id, int volume) { CrasAudioHandler* audio_handler = CrasAudioHandler::Get(); extensions::DispatchVolumeChangedEvent( audio_handler->GetOutputVolumePercent(), diff --git a/chrome/browser/ui/ash/volume_controller_chromeos.h b/chrome/browser/ui/ash/volume_controller_chromeos.h index 3a29b89..3c36933 100644 --- a/chrome/browser/ui/ash/volume_controller_chromeos.h +++ b/chrome/browser/ui/ash/volume_controller_chromeos.h @@ -6,7 +6,6 @@ #define CHROME_BROWSER_UI_ASH_VOLUME_CONTROLLER_CHROMEOS_H_ #include "ash/volume_control_delegate.h" -#include "base/basictypes.h" #include "base/compiler_specific.h" #include "chromeos/audio/cras_audio_handler.h" @@ -24,7 +23,7 @@ class VolumeController : public ash::VolumeControlDelegate, void HandleVolumeUp(const ui::Accelerator& accelerator) override; // Overridden from chromeos::CrasAudioHandler::AudioObserver. - void OnOutputVolumeChanged() override; + void OnOutputNodeVolumeChanged(uint64_t node_id, int volume) override; void OnOutputMuteChanged() override; private: diff --git a/chromeos/audio/cras_audio_handler.cc b/chromeos/audio/cras_audio_handler.cc index c3e7c2d..5cf17ee 100644 --- a/chromeos/audio/cras_audio_handler.cc +++ b/chromeos/audio/cras_audio_handler.cc @@ -35,11 +35,12 @@ bool IsSameAudioDevice(const AudioDevice& a, const AudioDevice& b) { && a.device_name == b.device_name; } -bool IsInNodeList(uint64 node_id, const CrasAudioHandler::NodeIdList& id_list) { +bool IsInNodeList(uint64_t node_id, + const CrasAudioHandler::NodeIdList& id_list) { return std::find(id_list.begin(), id_list.end(), node_id) != id_list.end(); } -bool IsNodeInTheList(uint64 node_id, const AudioNodeList& node_list) { +bool IsNodeInTheList(uint64_t node_id, const AudioNodeList& node_list) { for (size_t i = 0; i < node_list.size(); ++i) { if (node_id == node_list[i].id) return true; @@ -55,10 +56,14 @@ CrasAudioHandler::AudioObserver::AudioObserver() { CrasAudioHandler::AudioObserver::~AudioObserver() { } -void CrasAudioHandler::AudioObserver::OnOutputVolumeChanged() { +void CrasAudioHandler::AudioObserver::OnOutputNodeVolumeChanged( + uint64_t /* node_id */, + int /* volume */) { } -void CrasAudioHandler::AudioObserver::OnInputGainChanged() { +void CrasAudioHandler::AudioObserver::OnInputNodeGainChanged( + uint64_t /* node_id */, + int /* gain */) { } void CrasAudioHandler::AudioObserver::OnOutputMuteChanged() { @@ -124,7 +129,7 @@ bool CrasAudioHandler::IsOutputMuted() { return output_mute_on_; } -bool CrasAudioHandler::IsOutputMutedForDevice(uint64 device_id) { +bool CrasAudioHandler::IsOutputMutedForDevice(uint64_t device_id) { const AudioDevice* device = GetDeviceFromId(device_id); if (!device) return false; @@ -140,7 +145,7 @@ bool CrasAudioHandler::IsInputMuted() { return input_mute_on_; } -bool CrasAudioHandler::IsInputMutedForDevice(uint64 device_id) { +bool CrasAudioHandler::IsInputMutedForDevice(uint64_t device_id) { const AudioDevice* device = GetDeviceFromId(device_id); if (!device) return false; @@ -160,7 +165,7 @@ int CrasAudioHandler::GetOutputVolumePercent() { return output_volume_; } -int CrasAudioHandler::GetOutputVolumePercentForDevice(uint64 device_id) { +int CrasAudioHandler::GetOutputVolumePercentForDevice(uint64_t device_id) { if (device_id == active_output_node_id_) { return output_volume_; } else { @@ -173,7 +178,7 @@ int CrasAudioHandler::GetInputGainPercent() { return input_gain_; } -int CrasAudioHandler::GetInputGainPercentForDevice(uint64 device_id) { +int CrasAudioHandler::GetInputGainPercentForDevice(uint64_t device_id) { if (device_id == active_input_node_id_) { return input_gain_; } else { @@ -182,11 +187,11 @@ int CrasAudioHandler::GetInputGainPercentForDevice(uint64 device_id) { } } -uint64 CrasAudioHandler::GetPrimaryActiveOutputNode() const { +uint64_t CrasAudioHandler::GetPrimaryActiveOutputNode() const { return active_output_node_id_; } -uint64 CrasAudioHandler::GetPrimaryActiveInputNode() const { +uint64_t CrasAudioHandler::GetPrimaryActiveInputNode() const { return active_input_node_id_; } @@ -218,7 +223,7 @@ void CrasAudioHandler::SetKeyboardMicActive(bool active) { RemoveActiveNodeInternal(keyboard_mic->id, true); } -void CrasAudioHandler::AddActiveNode(uint64 node_id, bool notify) { +void CrasAudioHandler::AddActiveNode(uint64_t node_id, bool notify) { const AudioDevice* device = GetDeviceFromId(node_id); if (!device) { VLOG(1) << "AddActiveInputNode: Cannot find device id=" @@ -378,21 +383,21 @@ void CrasAudioHandler::SetInputMute(bool mute_on) { FOR_EACH_OBSERVER(AudioObserver, observers_, OnInputMuteChanged()); } -void CrasAudioHandler::SetActiveOutputNode(uint64 node_id, bool notify) { +void CrasAudioHandler::SetActiveOutputNode(uint64_t node_id, bool notify) { chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> SetActiveOutputNode(node_id); if (notify) NotifyActiveNodeChanged(false); } -void CrasAudioHandler::SetActiveInputNode(uint64 node_id, bool notify) { +void CrasAudioHandler::SetActiveInputNode(uint64_t node_id, bool notify) { chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> SetActiveInputNode(node_id); if (notify) NotifyActiveNodeChanged(true); } -void CrasAudioHandler::SetVolumeGainPercentForDevice(uint64 device_id, +void CrasAudioHandler::SetVolumeGainPercentForDevice(uint64_t device_id, int value) { const AudioDevice* device = GetDeviceFromId(device_id); if (!device) @@ -404,7 +409,7 @@ void CrasAudioHandler::SetVolumeGainPercentForDevice(uint64 device_id, SetOutputNodeVolumePercent(device_id, value); } -void CrasAudioHandler::SetMuteForDevice(uint64 device_id, bool mute_on) { +void CrasAudioHandler::SetMuteForDevice(uint64_t device_id, bool mute_on) { if (device_id == active_output_node_id_) { SetOutputMute(mute_on); return; @@ -482,7 +487,7 @@ void CrasAudioHandler::NodesChanged() { GetNodes(); } -void CrasAudioHandler::ActiveOutputNodeChanged(uint64 node_id) { +void CrasAudioHandler::ActiveOutputNodeChanged(uint64_t node_id) { if (active_output_node_id_ == node_id) return; @@ -496,7 +501,7 @@ void CrasAudioHandler::ActiveOutputNodeChanged(uint64 node_id) { } } -void CrasAudioHandler::ActiveInputNodeChanged(uint64 node_id) { +void CrasAudioHandler::ActiveInputNodeChanged(uint64_t node_id) { if (active_input_node_id_ == node_id) return; @@ -520,7 +525,7 @@ void CrasAudioHandler::EmitLoginPromptVisibleCalled() { LogErrors(); } -const AudioDevice* CrasAudioHandler::GetDeviceFromId(uint64 device_id) const { +const AudioDevice* CrasAudioHandler::GetDeviceFromId(uint64_t device_id) const { AudioDeviceMap::const_iterator it = audio_devices_.find(device_id); if (it == audio_devices_.end()) return NULL; @@ -571,7 +576,7 @@ void CrasAudioHandler::SetupAudioOutputState() { } // This sets up the state of an additional active node. -void CrasAudioHandler::SetupAdditionalActiveAudioNodeState(uint64 node_id) { +void CrasAudioHandler::SetupAdditionalActiveAudioNodeState(uint64_t node_id) { const AudioDevice* device = GetDeviceFromId(node_id); if (!device) { VLOG(1) << "Can't set up audio state for unknown device id =" @@ -615,12 +620,12 @@ void CrasAudioHandler::ApplyAudioPolicy() { // media system. } -void CrasAudioHandler::SetOutputNodeVolume(uint64 node_id, int volume) { +void CrasAudioHandler::SetOutputNodeVolume(uint64_t node_id, int volume) { chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> SetOutputNodeVolume(node_id, volume); } -void CrasAudioHandler::SetOutputNodeVolumePercent(uint64 node_id, +void CrasAudioHandler::SetOutputNodeVolumePercent(uint64_t node_id, int volume_percent) { const AudioDevice* device = this->GetDeviceFromId(node_id); if (!device || device->is_input) @@ -636,7 +641,8 @@ void CrasAudioHandler::SetOutputNodeVolumePercent(uint64 node_id, if (device->active) { SetOutputNodeVolume(node_id, volume_percent); - FOR_EACH_OBSERVER(AudioObserver, observers_, OnOutputVolumeChanged()); + FOR_EACH_OBSERVER(AudioObserver, observers_, + OnOutputNodeVolumeChanged(node_id, volume_percent)); } } @@ -650,12 +656,12 @@ bool CrasAudioHandler::SetOutputMuteInternal(bool mute_on) { return true; } -void CrasAudioHandler::SetInputNodeGain(uint64 node_id, int gain) { +void CrasAudioHandler::SetInputNodeGain(uint64_t node_id, int gain) { chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> SetInputNodeGain(node_id, gain); } -void CrasAudioHandler::SetInputNodeGainPercent(uint64 node_id, +void CrasAudioHandler::SetInputNodeGainPercent(uint64_t node_id, int gain_percent) { const AudioDevice* device = GetDeviceFromId(node_id); if (!device || !device->is_input) @@ -670,7 +676,8 @@ void CrasAudioHandler::SetInputNodeGainPercent(uint64 node_id, if (device->active) { SetInputNodeGain(node_id, gain_percent); - FOR_EACH_OBSERVER(AudioObserver, observers_, OnInputGainChanged()); + FOR_EACH_OBSERVER(AudioObserver, observers_, + OnInputNodeGainChanged(node_id, gain_percent)); } } @@ -689,7 +696,7 @@ void CrasAudioHandler::GetNodes() { } bool CrasAudioHandler::ChangeActiveDevice(const AudioDevice& new_active_device, - uint64* current_active_node_id) { + uint64_t* current_active_node_id) { // If the device we want to switch to is already the current active device, // do nothing. if (new_active_device.active && @@ -713,10 +720,9 @@ bool CrasAudioHandler::ChangeActiveDevice(const AudioDevice& new_active_device, return true; } -bool CrasAudioHandler::NonActiveDeviceUnplugged( - size_t old_devices_size, - size_t new_devices_size, - uint64 current_active_node) { +bool CrasAudioHandler::NonActiveDeviceUnplugged(size_t old_devices_size, + size_t new_devices_size, + uint64_t current_active_node) { return (new_devices_size < old_devices_size && GetDeviceFromId(current_active_node)); } @@ -909,7 +915,7 @@ void CrasAudioHandler::HandleGetNodesError(const std::string& error_name, << error_name << ": " << error_msg; } -void CrasAudioHandler::AddAdditionalActiveNode(uint64 node_id, bool notify) { +void CrasAudioHandler::AddAdditionalActiveNode(uint64_t node_id, bool notify) { const AudioDevice* device = GetDeviceFromId(node_id); if (!device) { VLOG(1) << "AddActiveInputNode: Cannot find device id=" @@ -937,7 +943,7 @@ void CrasAudioHandler::AddAdditionalActiveNode(uint64 node_id, bool notify) { } } -void CrasAudioHandler::RemoveActiveNodeInternal(uint64 node_id, bool notify) { +void CrasAudioHandler::RemoveActiveNodeInternal(uint64_t node_id, bool notify) { const AudioDevice* device = GetDeviceFromId(node_id); if (!device) { VLOG(1) << "RemoveActiveInputNode: Cannot find device id=" diff --git a/chromeos/audio/cras_audio_handler.h b/chromeos/audio/cras_audio_handler.h index 28a858b..081e20d 100644 --- a/chromeos/audio/cras_audio_handler.h +++ b/chromeos/audio/cras_audio_handler.h @@ -5,9 +5,9 @@ #ifndef CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_ #define CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_ +#include <stdint.h> #include <queue> -#include "base/basictypes.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "base/observer_list.h" @@ -32,18 +32,18 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, typedef std::priority_queue<AudioDevice, std::vector<AudioDevice>, AudioDeviceCompare> AudioDevicePriorityQueue; - typedef std::vector<uint64> NodeIdList; + typedef std::vector<uint64_t> NodeIdList; class AudioObserver { public: - // Called when output volume changed. - virtual void OnOutputVolumeChanged(); + // Called when an active output volume changed. + virtual void OnOutputNodeVolumeChanged(uint64_t node_id, int volume); // Called when output mute state changed. virtual void OnOutputMuteChanged(); - // Called when input mute state changed. - virtual void OnInputGainChanged(); + // Called when active input node's gain changed. + virtual void OnInputNodeGainChanged(uint64_t node_id, int gain); // Called when input mute state changed. virtual void OnInputMuteChanged(); @@ -92,13 +92,13 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, virtual bool IsOutputMuted(); // Returns true if audio output is muted for a device. - virtual bool IsOutputMutedForDevice(uint64 device_id); + virtual bool IsOutputMutedForDevice(uint64_t device_id); // Returns true if audio input is muted. virtual bool IsInputMuted(); // Returns true if audio input is muted for a device. - virtual bool IsInputMutedForDevice(uint64 device_id); + virtual bool IsInputMutedForDevice(uint64_t device_id); // Returns true if the output volume is below the default mute volume level. virtual bool IsOutputVolumeBelowDefaultMuteLevel(); @@ -111,20 +111,20 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, virtual int GetOutputVolumePercent(); // Gets volume level in 0-100% range (0 being pure silence) for a device. - virtual int GetOutputVolumePercentForDevice(uint64 device_id); + virtual int GetOutputVolumePercentForDevice(uint64_t device_id); // Gets gain level in 0-100% range (0 being pure silence) for the current // active node. virtual int GetInputGainPercent(); // Gets volume level in 0-100% range (0 being pure silence) for a device. - virtual int GetInputGainPercentForDevice(uint64 device_id); + virtual int GetInputGainPercentForDevice(uint64_t device_id); // Returns node_id of the primary active output node. - virtual uint64 GetPrimaryActiveOutputNode() const; + virtual uint64_t GetPrimaryActiveOutputNode() const; // Returns the node_id of the primary active input node. - virtual uint64 GetPrimaryActiveInputNode() const; + virtual uint64_t GetPrimaryActiveInputNode() const; // Gets the audio devices back in |device_list|. virtual void GetAudioDevices(AudioDeviceList* device_list) const; @@ -161,10 +161,10 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, virtual void SwitchToDevice(const AudioDevice& device, bool notify); // Sets volume/gain level for a device. - virtual void SetVolumeGainPercentForDevice(uint64 device_id, int value); + virtual void SetVolumeGainPercentForDevice(uint64_t device_id, int value); // Sets the mute for device. - virtual void SetMuteForDevice(uint64 device_id, bool mute_on); + virtual void SetMuteForDevice(uint64_t device_id, bool mute_on); // Activates or deactivates keyboard mic if there's one. virtual void SetKeyboardMicActive(bool active); @@ -199,8 +199,8 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, // CrasAudioClient::Observer overrides. void AudioClientRestarted() override; void NodesChanged() override; - void ActiveOutputNodeChanged(uint64 node_id) override; - void ActiveInputNodeChanged(uint64 node_id) override; + void ActiveOutputNodeChanged(uint64_t node_id) override; + void ActiveInputNodeChanged(uint64_t node_id) override; // AudioPrefObserver overrides. void OnAudioPolicyPrefChanged() override; @@ -210,8 +210,8 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, // Sets the active audio output/input node to the node with |node_id|. // If |notify|, notifies Active*NodeChange. - void SetActiveOutputNode(uint64 node_id, bool notify); - void SetActiveInputNode(uint64 node_id, bool notify); + void SetActiveOutputNode(uint64_t node_id, bool notify); + void SetActiveInputNode(uint64_t node_id, bool notify); // Sets up the audio device state based on audio policy and audio settings // saved in prefs. @@ -219,9 +219,9 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, void SetupAudioOutputState(); // Sets up the additional active audio node's state. - void SetupAdditionalActiveAudioNodeState(uint64 node_id); + void SetupAdditionalActiveAudioNodeState(uint64_t node_id); - const AudioDevice* GetDeviceFromId(uint64 device_id) const; + const AudioDevice* GetDeviceFromId(uint64_t device_id) const; const AudioDevice* GetKeyboardMic() const; // Initializes audio state, which should only be called when CrasAudioHandler @@ -233,18 +233,18 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, void ApplyAudioPolicy(); // Sets output volume of |node_id| to |volume|. - void SetOutputNodeVolume(uint64 node_id, int volume); + void SetOutputNodeVolume(uint64_t node_id, int volume); - void SetOutputNodeVolumePercent(uint64 node_id, int volume_percent); + void SetOutputNodeVolumePercent(uint64_t node_id, int volume_percent); // Sets output mute state to |mute_on| internally, returns true if output mute // is set. bool SetOutputMuteInternal(bool mute_on); // Sets input gain of |node_id| to |gain|. - void SetInputNodeGain(uint64 node_id, int gain); + void SetInputNodeGain(uint64_t node_id, int gain); - void SetInputNodeGainPercent(uint64 node_id, int gain_percent); + void SetInputNodeGainPercent(uint64_t node_id, int gain_percent); // Sets input mute state to |mute_on| internally. void SetInputMuteInternal(bool mute_on); @@ -259,13 +259,13 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, // Returns true if *|current_active_node_id| device is changed to // |new_active_device|. bool ChangeActiveDevice(const AudioDevice& new_active_device, - uint64* current_active_node_id); + uint64_t* current_active_node_id); // Returns true if the audio nodes change is caused by some non-active // audio nodes unplugged. bool NonActiveDeviceUnplugged(size_t old_devices_size, size_t new_device_size, - uint64 current_active_node); + uint64_t current_active_node); // Returns true if there is any device change for for input or output, // specified by |is_input|. @@ -285,13 +285,13 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, // If there is no active node, |node_id| will be switched to become the // primary active node. Otherwise, it will be added as an additional active // node. - void AddActiveNode(uint64 node_id, bool notify); + void AddActiveNode(uint64_t node_id, bool notify); // Adds |node_id| into additional active nodes. - void AddAdditionalActiveNode(uint64 node_id, bool notify); + void AddAdditionalActiveNode(uint64_t node_id, bool notify); // Removes |node_id| from additional active nodes. - void RemoveActiveNodeInternal(uint64 node_id, bool notify); + void RemoveActiveNodeInternal(uint64_t node_id, bool notify); enum DeviceStatus { OLD_DEVICE, @@ -318,8 +318,8 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, bool input_mute_on_; int output_volume_; int input_gain_; - uint64 active_output_node_id_; - uint64 active_input_node_id_; + uint64_t active_output_node_id_; + uint64_t active_input_node_id_; bool has_alternative_input_; bool has_alternative_output_; diff --git a/chromeos/audio/cras_audio_handler_unittest.cc b/chromeos/audio/cras_audio_handler_unittest.cc index 574b421..ac9493c 100644 --- a/chromeos/audio/cras_audio_handler_unittest.cc +++ b/chromeos/audio/cras_audio_handler_unittest.cc @@ -114,45 +114,37 @@ const AudioNode kOtherTypeInput( 0 ); -const AudioNode kBluetoothHeadset ( - false, - kBluetoothHeadsetId, - "Bluetooth Headset", - "BLUETOOTH", - "Bluetooth Headset 1", - false, - 0 -); - -const AudioNode kHDMIOutput ( - false, - kHDMIOutputId, - "HDMI output", - "HDMI", - "HDMI output", - false, - 0 -); - -const AudioNode kUSBHeadphone1 ( - false, - kUSBHeadphoneId1, - "USB Headphone", - "USB", - "USB Headphone 1", - false, - 0 -); - -const AudioNode kUSBHeadphone2 ( - false, - kUSBHeadphoneId2, - "USB Headphone", - "USB", - "USB Headphone 1", - false, - 0 -); +const AudioNode kBluetoothHeadset(false, + kBluetoothHeadsetId, + "Bluetooth Headset", + "BLUETOOTH", + "Bluetooth Headset 1", + false, + 0); + +const AudioNode kHDMIOutput(false, + kHDMIOutputId, + "HDMI output", + "HDMI", + "HDMI output", + false, + 0); + +const AudioNode kUSBHeadphone1(false, + kUSBHeadphoneId1, + "USB Headphone", + "USB", + "USB Headphone 1", + false, + 0); + +const AudioNode kUSBHeadphone2(false, + kUSBHeadphoneId2, + "USB Headphone", + "USB", + "USB Headphone 1", + false, + 0); const AudioNode kUSBJabraSpeakerOutput1(false, kUSBJabraSpeakerOutputId1, @@ -259,9 +251,14 @@ class TestObserver : public chromeos::CrasAudioHandler::AudioObserver { void OnInputMuteChanged() override { ++input_mute_changed_count_; } - void OnOutputVolumeChanged() override { ++output_volume_changed_count_; } + void OnOutputNodeVolumeChanged(uint64 /* node_id */, + int /* volume */) override { + ++output_volume_changed_count_; + } - void OnInputGainChanged() override { ++input_gain_changed_count_; } + void OnInputNodeGainChanged(uint64 /* node_id */, int /* gain */) override { + ++input_gain_changed_count_; + } private: int active_output_node_changed_count_; @@ -1811,7 +1808,7 @@ TEST_F(CrasAudioHandlerTest, SetOutputVolumePercent) { cras_audio_handler_->SetOutputVolumePercent(60); // Verify the output volume is changed to the designated value, - // OnOutputVolumeChanged event is fired, and the device volume value + // OnOutputNodeVolumeChanged event is fired, and the device volume value // is saved the preferences. const int kVolume = 60; EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent()); @@ -1831,7 +1828,7 @@ TEST_F(CrasAudioHandlerTest, SetInputGainPercent) { cras_audio_handler_->SetInputGainPercent(60); // Verify the input gain changed to the designated value, - // OnInputGainChanged event is fired, and the device gain value + // OnInputNodeGainChanged event is fired, and the device gain value // is saved in the preferences. const int kGain = 60; EXPECT_EQ(kGain, cras_audio_handler_->GetInputGainPercent()); diff --git a/extensions/browser/BUILD.gn b/extensions/browser/BUILD.gn index 4659457..b27f773 100644 --- a/extensions/browser/BUILD.gn +++ b/extensions/browser/BUILD.gn @@ -82,12 +82,6 @@ source_set("browser") { "//extensions") sources += linux_sources } else { - nonlinux_sources = rebase_path( - extensions_gypi_values.extensions_browser_sources_nonlinux, - ".", - "//extensions") - sources += nonlinux_sources - if (is_win || is_mac) { deps += [ "//components/wifi" ] diff --git a/extensions/browser/api/audio/audio_api.cc b/extensions/browser/api/audio/audio_api.cc index 659ae6c..4b4fa7d 100644 --- a/extensions/browser/api/audio/audio_api.cc +++ b/extensions/browser/api/audio/audio_api.cc @@ -45,6 +45,15 @@ void AudioAPI::OnDeviceChanged() { } } +void AudioAPI::OnLevelChanged(const std::string& id, int level) { + if (browser_context_ && EventRouter::Get(browser_context_)) { + scoped_ptr<base::ListValue> args = audio::OnLevelChanged::Create(id, level); + scoped_ptr<Event> event( + new Event(audio::OnLevelChanged::kEventName, args.Pass())); + EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); + } +} + /////////////////////////////////////////////////////////////////////////////// bool AudioGetInfoFunction::RunAsync() { @@ -107,4 +116,6 @@ bool AudioSetPropertiesFunction::RunSync() { return true; } +/////////////////////////////////////////////////////////////////////////////// + } // namespace extensions diff --git a/extensions/browser/api/audio/audio_api.h b/extensions/browser/api/audio/audio_api.h index ddee1d5..1a5c0c2 100644 --- a/extensions/browser/api/audio/audio_api.h +++ b/extensions/browser/api/audio/audio_api.h @@ -25,6 +25,7 @@ class AudioAPI : public BrowserContextKeyedAPI, public AudioService::Observer { // AudioService::Observer implementation. void OnDeviceChanged() override; + void OnLevelChanged(const std::string& id, int level) override; private: friend class BrowserContextKeyedAPIFactory<AudioAPI>; @@ -70,7 +71,6 @@ class AudioSetPropertiesFunction : public SyncExtensionFunction { bool RunSync() override; }; - } // namespace extensions #endif // EXTENSIONS_BROWSER_API_AUDIO_AUDIO_API_H_ diff --git a/extensions/browser/api/audio/audio_apitest.cc b/extensions/browser/api/audio/audio_apitest.cc index 7194802..96d72b4 100644 --- a/extensions/browser/api/audio/audio_apitest.cc +++ b/extensions/browser/api/audio/audio_apitest.cc @@ -2,16 +2,139 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/message_loop/message_loop.h" #include "extensions/shell/test/shell_apitest.h" +#if defined(OS_CHROMEOS) +#include "chromeos/audio/audio_devices_pref_handler_stub.h" +#include "chromeos/audio/cras_audio_handler.h" +#include "chromeos/dbus/dbus_thread_manager.h" +#include "chromeos/dbus/fake_cras_audio_client.h" +#endif +#include "extensions/test/extension_test_message_listener.h" namespace extensions { -using AudioApiTest = ShellApiTest; - #if defined(OS_CHROMEOS) +using chromeos::AudioDevice; +using chromeos::AudioDeviceList; +using chromeos::AudioNode; +using chromeos::AudioNodeList; + +const uint64_t kJabraSpeaker1Id = 30001; +const uint64_t kJabraSpeaker2Id = 30002; +const uint64_t kHDMIOutputId = 30003; +const uint64_t kJabraMic1Id = 40001; +const uint64_t kJabraMic2Id = 40002; +const uint64_t kWebcamMicId = 40003; + +const AudioNode kJabraSpeaker1(false, + kJabraSpeaker1Id, + "Jabra Speaker", + "USB", + "Jabra Speaker 1", + false, + 0); + +const AudioNode kJabraSpeaker2(false, + kJabraSpeaker2Id, + "Jabra Speaker", + "USB", + "Jabra Speaker 2", + false, + 0); + +const AudioNode kHDMIOutput(false, + kHDMIOutputId, + "HDMI output", + "HDMI", + "HDA Intel MID", + false, + 0); + +const AudioNode + kJabraMic1(true, kJabraMic1Id, "Jabra Mic", "USB", "Jabra Mic 1", false, 0); + +const AudioNode + kJabraMic2(true, kJabraMic2Id, "Jabra Mic", "USB", "Jabra Mic 2", false, 0); + +const AudioNode kUSBCameraMic(true, + kWebcamMicId, + "Webcam Mic", + "USB", + "Logitech Webcam", + false, + 0); + +class AudioApiTest : public ShellApiTest { + public: + AudioApiTest() : cras_audio_handler_(NULL) {} + ~AudioApiTest() override {} + + void SetUpCrasAudioHandlerWithTestingNodes(const AudioNodeList& audio_nodes) { + chromeos::DBusThreadManager* dbus_manager = + chromeos::DBusThreadManager::Get(); + DCHECK(dbus_manager); + chromeos::FakeCrasAudioClient* fake_cras_audio_client = + static_cast<chromeos::FakeCrasAudioClient*>( + dbus_manager->GetCrasAudioClient()); + fake_cras_audio_client->SetAudioNodesAndNotifyObserversForTesting( + audio_nodes); + cras_audio_handler_ = chromeos::CrasAudioHandler::Get(); + DCHECK(cras_audio_handler_); + message_loop_.RunUntilIdle(); + } + + protected: + base::MessageLoopForUI message_loop_; + chromeos::CrasAudioHandler* cras_audio_handler_; // Not owned. +}; + IN_PROC_BROWSER_TEST_F(AudioApiTest, Audio) { + // Set up the audio nodes for testing. + AudioNodeList audio_nodes; + audio_nodes.push_back(kJabraSpeaker1); + audio_nodes.push_back(kJabraSpeaker2); + audio_nodes.push_back(kHDMIOutput); + audio_nodes.push_back(kJabraMic1); + audio_nodes.push_back(kJabraMic2); + audio_nodes.push_back(kUSBCameraMic); + SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); + EXPECT_TRUE(RunAppTest("api_test/audio")) << message_; } -#endif + +IN_PROC_BROWSER_TEST_F(AudioApiTest, OnLevelChangedOutputDevice) { + AudioNodeList audio_nodes; + audio_nodes.push_back(kJabraSpeaker1); + audio_nodes.push_back(kHDMIOutput); + SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); + + // Verify the jabra speaker is the active output device. + AudioDevice device; + EXPECT_TRUE(cras_audio_handler_->GetPrimaryActiveOutputDevice(&device)); + EXPECT_EQ(device.id, kJabraSpeaker1.id); + + // Loads background app. + ExtensionTestMessageListener load_listener("loaded", false); + ExtensionTestMessageListener result_listener("success", false); + result_listener.set_failure_message("failure"); + ASSERT_TRUE(LoadApp("api_test/audio/volume_change")); + ASSERT_TRUE(load_listener.WaitUntilSatisfied()); + + // Change output device volume. + const int kVolume = 60; + cras_audio_handler_->SetOutputVolumePercent(kVolume); + + // Verify the output volume is changed to the designated value. + EXPECT_EQ(kVolume, cras_audio_handler_->GetOutputVolumePercent()); + EXPECT_EQ(kVolume, + cras_audio_handler_->GetOutputVolumePercentForDevice(device.id)); + + // Verify the background app got the OnOutputNodeVolumeChanged event + // with the expected node id and volume value. + ASSERT_TRUE(result_listener.WaitUntilSatisfied()); + EXPECT_EQ("success", result_listener.message()); +} +#endif // OS_CHROMEOS } // namespace extensions diff --git a/extensions/browser/api/audio/audio_service.h b/extensions/browser/api/audio/audio_service.h index 6d985eb..5d0ac07 100644 --- a/extensions/browser/api/audio/audio_service.h +++ b/extensions/browser/api/audio/audio_service.h @@ -26,6 +26,9 @@ class AudioService { // Called when anything changes to the audio device configuration. virtual void OnDeviceChanged() = 0; + // Called when the sound level of an active audio node changes. + virtual void OnLevelChanged(const std::string& id, int level) = 0; + protected: virtual ~Observer() {} }; diff --git a/extensions/browser/api/audio/audio_service_chromeos.cc b/extensions/browser/api/audio/audio_service_chromeos.cc index 8005ac6..0f652a0 100644 --- a/extensions/browser/api/audio/audio_service_chromeos.cc +++ b/extensions/browser/api/audio/audio_service_chromeos.cc @@ -38,8 +38,8 @@ class AudioServiceImpl : public AudioService, protected: // chromeos::CrasAudioHandler::AudioObserver overrides. - void OnOutputVolumeChanged() override; - void OnInputGainChanged() override; + void OnOutputNodeVolumeChanged(uint64_t id, int volume) override; + void OnInputNodeGainChanged(uint64_t id, int gain) override; void OnOutputMuteChanged() override; void OnInputMuteChanged() override; void OnAudioNodesChanged() override; @@ -48,9 +48,10 @@ class AudioServiceImpl : public AudioService, private: void NotifyDeviceChanged(); + void NotifyLevelChanged(uint64_t id, int level); - bool FindDevice(uint64 id, chromeos::AudioDevice* device); - uint64 GetIdFromStr(const std::string& id_str); + bool FindDevice(uint64_t id, chromeos::AudioDevice* device); + uint64_t GetIdFromStr(const std::string& id_str); // List of observers. ObserverList<AudioService::Observer> observer_list_; @@ -170,7 +171,7 @@ bool AudioServiceImpl::SetDeviceProperties(const std::string& device_id, return false; } -bool AudioServiceImpl::FindDevice(uint64 id, chromeos::AudioDevice* device) { +bool AudioServiceImpl::FindDevice(uint64_t id, chromeos::AudioDevice* device) { chromeos::AudioDeviceList devices; cras_audio_handler_->GetAudioDevices(&devices); @@ -183,24 +184,24 @@ bool AudioServiceImpl::FindDevice(uint64 id, chromeos::AudioDevice* device) { return false; } -uint64 AudioServiceImpl::GetIdFromStr(const std::string& id_str) { - uint64 device_id; +uint64_t AudioServiceImpl::GetIdFromStr(const std::string& id_str) { + uint64_t device_id; if (!base::StringToUint64(id_str, &device_id)) return 0; else return device_id; } -void AudioServiceImpl::OnOutputVolumeChanged() { - NotifyDeviceChanged(); +void AudioServiceImpl::OnOutputNodeVolumeChanged(uint64_t id, int volume) { + NotifyLevelChanged(id, volume); } void AudioServiceImpl::OnOutputMuteChanged() { NotifyDeviceChanged(); } -void AudioServiceImpl::OnInputGainChanged() { - NotifyDeviceChanged(); +void AudioServiceImpl::OnInputNodeGainChanged(uint64_t id, int gain) { + NotifyLevelChanged(id, gain); } void AudioServiceImpl::OnInputMuteChanged() { @@ -223,6 +224,15 @@ void AudioServiceImpl::NotifyDeviceChanged() { FOR_EACH_OBSERVER(AudioService::Observer, observer_list_, OnDeviceChanged()); } +void AudioServiceImpl::NotifyLevelChanged(uint64_t id, int level) { + FOR_EACH_OBSERVER(AudioService::Observer, observer_list_, + OnLevelChanged(base::Uint64ToString(id), level)); + + // Notify DeviceChanged event for backward compatibility. + // TODO(jennyz): remove this code when the old version of hotrod retires. + NotifyDeviceChanged(); +} + AudioService* AudioService::CreateInstance() { return new AudioServiceImpl; } diff --git a/extensions/browser/api/audio/audio_service_linux.cc b/extensions/browser/api/audio/audio_service_linux.cc deleted file mode 100644 index 4e70cef..0000000 --- a/extensions/browser/api/audio/audio_service_linux.cc +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "extensions/browser/api/audio/audio_service.h" - -#include "base/callback.h" -#include "base/memory/weak_ptr.h" -#include "base/observer_list.h" -#include "base/strings/string_number_conversions.h" -#include "base/threading/thread_checker.h" -#include "content/public/browser/browser_thread.h" - -using content::BrowserThread; - -namespace extensions { - -using core_api::audio::OutputDeviceInfo; -using core_api::audio::InputDeviceInfo; - -class AudioServiceImpl : public AudioService { - public: - AudioServiceImpl(); - ~AudioServiceImpl() override; - - private: - // Called by listeners to this service to add/remove themselves as observers. - void AddObserver(AudioService::Observer* observer) override; - void RemoveObserver(AudioService::Observer* observer) override; - - // Start to query audio device information. - void StartGetInfo(const GetInfoCallback& callback) override; - void SetActiveDevices(const DeviceIdList& device_list) override; - bool SetDeviceProperties(const std::string& device_id, - bool muted, - int volume, - int gain) override; - - // List of observers. - ObserverList<AudioService::Observer> observer_list_; - - base::ThreadChecker thread_checker_; - - // Note: This should remain the last member so it'll be destroyed and - // invalidate the weak pointers before any other members are destroyed. - base::WeakPtrFactory<AudioServiceImpl> weak_ptr_factory_; - - DISALLOW_COPY_AND_ASSIGN(AudioServiceImpl); -}; - -AudioServiceImpl::AudioServiceImpl() : weak_ptr_factory_(this) { - DCHECK(thread_checker_.CalledOnValidThread()); -} - -AudioServiceImpl::~AudioServiceImpl() { - DCHECK(thread_checker_.CalledOnValidThread()); -} - -void AudioServiceImpl::AddObserver(AudioService::Observer* observer) { - DCHECK(thread_checker_.CalledOnValidThread()); - observer_list_.AddObserver(observer); -} - -void AudioServiceImpl::RemoveObserver(AudioService::Observer* observer) { - DCHECK(thread_checker_.CalledOnValidThread()); - observer_list_.RemoveObserver(observer); -} - -void AudioServiceImpl::StartGetInfo(const GetInfoCallback& callback) { - DCHECK(thread_checker_.CalledOnValidThread()); - if (!callback.is_null()) - callback.Run(OutputInfo(), InputInfo(), false); -} - -void AudioServiceImpl::SetActiveDevices(const DeviceIdList& device_list) { - DCHECK(thread_checker_.CalledOnValidThread()); -} - -bool AudioServiceImpl::SetDeviceProperties(const std::string& device_id, - bool muted, - int volume, - int gain) { - DCHECK(thread_checker_.CalledOnValidThread()); - return false; -} - -AudioService* AudioService::CreateInstance() { - return new AudioServiceImpl; -} - -} // namespace extensions diff --git a/extensions/common/api/audio.idl b/extensions/common/api/audio.idl index 0f08827..9461cbd3 100644 --- a/extensions/common/api/audio.idl +++ b/extensions/common/api/audio.idl @@ -16,7 +16,7 @@ namespace audio { boolean isActive; // True if this is muted. boolean isMuted; - // The output volume ranging from 0.0 to 1.0. + // The output volume ranging from 0.0 to 100.0. double volume; }; @@ -29,7 +29,7 @@ namespace audio { boolean isActive; // True if this is muted. boolean isMuted; - // The input gain ranging from 0.0 to 1.0. + // The input gain ranging from 0.0 to 100.0. double gain; }; @@ -50,10 +50,17 @@ namespace audio { callback SetPropertiesCallback = void(); interface Functions { - // Get the information of all audio output and input devices. + // Gets the information of all audio output and input devices. static void getInfo(GetInfoCallback callback); - // Select a subset of audio devices as active. + // Sets the active nodes to the nodes specified by |ids|. + // It can pass in the "complete" active node id list of either input + // nodes, or output nodes, or both. If only input node ids are passed in, + // it will only change the input nodes' active status, output nodes will NOT + // be changed; similarly for the case if only output nodes are passed. + // If the nodes specified in |new_active_ids| are already active, they will + // remain active. Otherwise, the old active nodes will be de-activated before + // we activate the new nodes with the same type(input/output). static void setActiveDevices(DOMString[] ids, SetActiveDevicesCallback callback); @@ -61,10 +68,15 @@ namespace audio { static void setProperties(DOMString id, DeviceProperties properties, SetPropertiesCallback callback); - }; + }; interface Events { // Fired when anything changes to the audio device configuration. static void onDeviceChanged(); + + // Fired when sound level changes for an active audio node. + // |id|: id of the audio node. + // |level|: new sound level of the node(volume for output, gain for input). + static void OnLevelChanged(DOMString id, long level); }; }; diff --git a/extensions/extensions.gyp b/extensions/extensions.gyp index 9bf7e08..797d4cc 100644 --- a/extensions/extensions.gyp +++ b/extensions/extensions.gyp @@ -195,11 +195,6 @@ '<@(extensions_browser_sources_linux_nonchromeos)', ], }], - ['OS != "linux"', { - 'sources': [ - '<@(extensions_browser_sources_nonlinux)', - ] - }], ], # Disable c4267 warnings until we fix size_t to int truncations. 'msvs_disabled_warnings': [ 4267, ], diff --git a/extensions/extensions.gypi b/extensions/extensions.gypi index cbb1f0e..48e493b 100644 --- a/extensions/extensions.gypi +++ b/extensions/extensions.gypi @@ -794,18 +794,15 @@ 'browser/api/vpn_provider/vpn_service_factory.h', ], 'extensions_browser_sources_nonchromeos': [ - 'browser/api/document_scan/document_scan_interface_nonchromeos.cc', - ], - 'extensions_browser_sources_nonlinux': [ 'browser/api/audio/audio_service.cc', + 'browser/api/document_scan/document_scan_interface_nonchromeos.cc', ], 'extensions_browser_sources_win_or_mac': [ 'browser/api/networking_private/networking_private_event_router_nonchromeos.cc', 'browser/api/networking_private/networking_private_service_client.cc', 'browser/api/networking_private/networking_private_service_client.h', ], - 'extensions_browser_sources_linux_nonchromeos': [ - 'browser/api/audio/audio_service_linux.cc', + 'extensions_browser_sources_linux_nonchromeos': [ 'browser/api/networking_private/network_config_dbus_constants_linux.cc', 'browser/api/networking_private/network_config_dbus_constants_linux.h', 'browser/api/networking_private/networking_private_event_router_nonchromeos.cc', diff --git a/extensions/shell/browser/shell_audio_controller_chromeos.cc b/extensions/shell/browser/shell_audio_controller_chromeos.cc index 760da05..66a599d 100644 --- a/extensions/shell/browser/shell_audio_controller_chromeos.cc +++ b/extensions/shell/browser/shell_audio_controller_chromeos.cc @@ -15,7 +15,7 @@ namespace { // Returns a pointer to the device in |devices| with ID |node_id|, or NULL if it // isn't present. const chromeos::AudioDevice* GetDevice(const chromeos::AudioDeviceList& devices, - uint64 node_id) { + uint64_t node_id) { for (chromeos::AudioDeviceList::const_iterator it = devices.begin(); it != devices.end(); ++it) { if (it->id == node_id) @@ -35,11 +35,15 @@ ShellAudioController::~ShellAudioController() { chromeos::CrasAudioHandler::Get()->RemoveAudioObserver(this); } -void ShellAudioController::OnOutputVolumeChanged() {} +void ShellAudioController::OnOutputNodeVolumeChanged(uint64_t /* node_id */, + int /* volume */) { +} void ShellAudioController::OnOutputMuteChanged() {} -void ShellAudioController::OnInputGainChanged() {} +void ShellAudioController::OnInputNodeGainChanged(uint64_t /* node_id */, + int /* gain */) { +} void ShellAudioController::OnInputMuteChanged() {} @@ -58,7 +62,7 @@ void ShellAudioController::ActivateDevices() { handler->GetAudioDevices(&devices); sort(devices.begin(), devices.end(), chromeos::AudioDeviceCompare()); - uint64 best_input = 0, best_output = 0; + uint64_t best_input = 0, best_output = 0; for (chromeos::AudioDeviceList::const_reverse_iterator it = devices.rbegin(); it != devices.rend() && (!best_input || !best_output); ++it) { // TODO(derat): Need to check |plugged_time|? diff --git a/extensions/shell/browser/shell_audio_controller_chromeos.h b/extensions/shell/browser/shell_audio_controller_chromeos.h index c8b9646..f78cd90 100644 --- a/extensions/shell/browser/shell_audio_controller_chromeos.h +++ b/extensions/shell/browser/shell_audio_controller_chromeos.h @@ -17,9 +17,9 @@ class ShellAudioController : public chromeos::CrasAudioHandler::AudioObserver { ~ShellAudioController() override; // chromeos::CrasAudioHandler::Observer implementation: - void OnOutputVolumeChanged() override; + void OnOutputNodeVolumeChanged(uint64_t node_id, int volume) override; void OnOutputMuteChanged() override; - void OnInputGainChanged() override; + void OnInputNodeGainChanged(uint64_t node_id, int gain) override; void OnInputMuteChanged() override; void OnAudioNodesChanged() override; void OnActiveOutputNodeChanged() override; diff --git a/extensions/test/data/api_test/audio/test.js b/extensions/test/data/api_test/audio/test.js index 74aea07..6261cc4 100644 --- a/extensions/test/data/api_test/audio/test.js +++ b/extensions/test/data/api_test/audio/test.js @@ -2,6 +2,28 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +function verifyGetInfoOutput(outputs) { + chrome.test.assertEq("30001", outputs[0].id); + chrome.test.assertEq("Jabra Speaker: Jabra Speaker 1", outputs[0].name); + + chrome.test.assertEq("30002", outputs[1].id); + chrome.test.assertEq("Jabra Speaker: Jabra Speaker 2", outputs[1].name); + + chrome.test.assertEq("30003", outputs[2].id); + chrome.test.assertEq("HDMI output: HDA Intel MID", outputs[2].name); +} + +function verifyGetInfoInput(inputs) { + chrome.test.assertEq("40001", inputs[0].id); + chrome.test.assertEq("Jabra Mic: Jabra Mic 1", inputs[0].name); + + chrome.test.assertEq("40002", inputs[1].id); + chrome.test.assertEq("Jabra Mic: Jabra Mic 2", inputs[1].name); + + chrome.test.assertEq("40003", inputs[2].id); + chrome.test.assertEq("Webcam Mic: Logitech Webcam", inputs[2].name); +} + function verifyActiveDevices(output_id, input_id) { chrome.audio.getInfo( chrome.test.callbackPass(function(outputInfo, inputInfo) { @@ -81,6 +103,8 @@ chrome.test.runTests([ function getInfoTest() { chrome.audio.getInfo( chrome.test.callbackPass(function(outputInfo, inputInfo) { + verifyGetInfoOutput(outputInfo); + verifyGetInfoInput(inputInfo); })); }, diff --git a/extensions/test/data/api_test/audio/volume_change/background.js b/extensions/test/data/api_test/audio/volume_change/background.js new file mode 100644 index 0000000..952f96c --- /dev/null +++ b/extensions/test/data/api_test/audio/volume_change/background.js @@ -0,0 +1,14 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +chrome.audio.OnLevelChanged.addListener(function (id, level) { + if (id == 30001 && level == 60) { + chrome.test.sendMessage("success"); + } else { + console.error("Got unexpected OnLevelChanged event id:" + id + + " level:" + level); + chrome.test.sendMessage("failure"); + } +}); +chrome.test.sendMessage("loaded"); diff --git a/extensions/test/data/api_test/audio/volume_change/manifest.json b/extensions/test/data/api_test/audio/volume_change/manifest.json new file mode 100644 index 0000000..a039b94 --- /dev/null +++ b/extensions/test/data/api_test/audio/volume_change/manifest.json @@ -0,0 +1,13 @@ +{ + "name": "chrome.audio.OnOutputNodeVolumeChanged", + "version": "1.0", + "description": "browser test for chrome.audio.OnOutputNodeVolumeChanged event", + "app": { + "background": { + "scripts": ["background.js"] + } + }, + "permissions": [ + "audio" + ] +} |