diff options
author | rkc@chromium.org <rkc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-02 23:45:47 +0000 |
---|---|---|
committer | rkc@chromium.org <rkc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-02 23:45:47 +0000 |
commit | 36221c692eff34d6a50d6c660de05fac0523ea2d (patch) | |
tree | fed0e7c7648c63e8de3c5a7b80b45b2f2b0f58a8 /chromeos/audio | |
parent | 983efa80454f41c0d7eee0bb3e2de910badeece1 (diff) | |
download | chromium_src-36221c692eff34d6a50d6c660de05fac0523ea2d.zip chromium_src-36221c692eff34d6a50d6c660de05fac0523ea2d.tar.gz chromium_src-36221c692eff34d6a50d6c660de05fac0523ea2d.tar.bz2 |
Switch Audio Preferences to per device.
Currently Chrome stores one global audio volume pref; if a user switches devices, this value remains the same. Change this so that we remember what volume (and mute setting) a user switched to when on a particular device, so when we switch to that device, we can set the volume/mute setting back to it again.
R=brettw@chromium.org, hshi@chromium.org, stevenjb@chromium.org
BUG=175798
TEST=Switched between speakers and USB headphones to verify that audio settings were rememebered and switched to correctly.
Review URL: https://codereview.chromium.org/14801002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@198011 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/audio')
-rw-r--r-- | chromeos/audio/audio_devices_pref_handler.h | 55 | ||||
-rw-r--r-- | chromeos/audio/audio_pref_handler.h | 2 | ||||
-rw-r--r-- | chromeos/audio/cras_audio_handler.cc | 28 | ||||
-rw-r--r-- | chromeos/audio/cras_audio_handler.h | 16 | ||||
-rw-r--r-- | chromeos/audio/mock_cras_audio_handler.cc | 2 |
5 files changed, 77 insertions, 26 deletions
diff --git a/chromeos/audio/audio_devices_pref_handler.h b/chromeos/audio/audio_devices_pref_handler.h new file mode 100644 index 0000000..63e3ed7 --- /dev/null +++ b/chromeos/audio/audio_devices_pref_handler.h @@ -0,0 +1,55 @@ +// Copyright (c) 2013 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. + +#ifndef CHROMEOS_AUDIO_AUDIO_DEVICES_PREF_HANDLER_H_ +#define CHROMEOS_AUDIO_AUDIO_DEVICES_PREF_HANDLER_H_ + +#include "base/basictypes.h" +#include "base/memory/ref_counted.h" +#include "chromeos/audio/audio_pref_observer.h" +#include "chromeos/chromeos_export.h" + +class PrefRegistrySimple; + +namespace chromeos { + +// Interface that handles audio preference related work, reads and writes +// audio preferences, and notifies AudioPrefObserver for audio preference +// changes. +class CHROMEOS_EXPORT AudioDevicesPrefHandler + : public base::RefCountedThreadSafe<AudioDevicesPrefHandler> { + public: + // Gets the audio output volume value from prefs for the active device. + virtual double GetOutputVolumeValue() = 0; + // Reads the audio output mute value from prefs for the active device. + virtual bool GetOutputMuteValue() = 0; + + // Sets the output audio volume value to prefs for the active device. + virtual void SetOutputVolumeValue(double volume_percent) = 0; + // Sets the audio output mute value to prefs for the active device. + virtual void SetOutputMuteValue(bool mute_on) = 0; + + // Reads the audio capture allowed value from prefs. + virtual bool GetAudioCaptureAllowedValue() = 0; + // Reads the audio output allowed value from prefs. + virtual bool GetAudioOutputAllowedValue() = 0; + + // Adds an audio preference observer. + virtual void AddAudioPrefObserver(AudioPrefObserver* observer) = 0; + // Removes an audio preference observer. + virtual void RemoveAudioPrefObserver(AudioPrefObserver* observer) = 0; + + // Creates the instance. + static AudioDevicesPrefHandler* Create(PrefService* local_state); + + protected: + virtual ~AudioDevicesPrefHandler() {} + + private: + friend class base::RefCountedThreadSafe<AudioDevicesPrefHandler>; +}; + +} // namespace chromeos + +#endif // CHROMEOS_AUDIO_AUDIO_DEVICES_PREF_HANDLER_H_ diff --git a/chromeos/audio/audio_pref_handler.h b/chromeos/audio/audio_pref_handler.h index 08f38c0..89e4b7b 100644 --- a/chromeos/audio/audio_pref_handler.h +++ b/chromeos/audio/audio_pref_handler.h @@ -14,6 +14,8 @@ class PrefRegistrySimple; namespace chromeos { +// TODO(jennyz,rkc): This class will be removed once we remove the old Audio +// Handler code. // Interface that handles audio preference related work, reads and writes // audio preferences, and notifies AudioPrefObserver for audio preference // changes. diff --git a/chromeos/audio/cras_audio_handler.cc b/chromeos/audio/cras_audio_handler.cc index fc0a2eb..733fac9 100644 --- a/chromeos/audio/cras_audio_handler.cc +++ b/chromeos/audio/cras_audio_handler.cc @@ -10,7 +10,7 @@ #include "base/bind.h" #include "base/bind_helpers.h" #include "base/logging.h" -#include "chromeos/audio/audio_pref_handler.h" +#include "chromeos/audio/audio_devices_pref_handler.h" #include "chromeos/audio/mock_cras_audio_handler.h" #include "chromeos/dbus/dbus_thread_manager.h" @@ -58,7 +58,7 @@ void CrasAudioHandler::AudioObserver::OnActiveInputNodeChanged() { // static void CrasAudioHandler::Initialize( - scoped_refptr<AudioPrefHandler> audio_pref_handler) { + scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler) { CHECK(!g_cras_audio_handler); g_cras_audio_handler = new CrasAudioHandler(audio_pref_handler); } @@ -128,7 +128,6 @@ bool CrasAudioHandler::GetActiveOutputDevice(AudioDevice* device) const { return true; } } - NOTREACHED() << "Can't find active output audio device"; return false; } @@ -156,10 +155,8 @@ void CrasAudioHandler::AdjustOutputVolumeByPercent(int adjust_by_percent) { } void CrasAudioHandler::SetOutputMute(bool mute_on) { - if (output_mute_locked_) { - NOTREACHED() << "Output mute has been locked"; + if (output_mute_locked_) return; - } chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> SetOutputMute(mute_on); @@ -174,10 +171,8 @@ void CrasAudioHandler::SetOutputMute(bool mute_on) { } void CrasAudioHandler::SetInputMute(bool mute_on) { - if (input_mute_locked_) { - NOTREACHED() << "Input mute has been locked"; + if (input_mute_locked_) return; - } chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> SetInputMute(mute_on); @@ -194,7 +189,7 @@ void CrasAudioHandler::SetActiveInputNode(uint64 node_id) { } CrasAudioHandler::CrasAudioHandler( - scoped_refptr<AudioPrefHandler> audio_pref_handler) + scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler) : audio_pref_handler_(audio_pref_handler), weak_ptr_factory_(this), output_mute_on_(false), @@ -216,7 +211,7 @@ CrasAudioHandler::CrasAudioHandler( return; chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->AddObserver(this); audio_pref_handler_->AddAudioPrefObserver(this); - SetupInitialAudioState(); + GetNodes(); } CrasAudioHandler::~CrasAudioHandler() { @@ -232,7 +227,7 @@ CrasAudioHandler::~CrasAudioHandler() { } void CrasAudioHandler::AudioClientRestarted() { - SetupInitialAudioState(); + GetNodes(); } void CrasAudioHandler::OutputVolumeChanged(int volume) { @@ -271,7 +266,7 @@ void CrasAudioHandler::ActiveOutputNodeChanged(uint64 node_id) { return; active_output_node_id_ = node_id; - GetNodes(); + SetupAudioState(); FOR_EACH_OBSERVER(AudioObserver, observers_, OnActiveOutputNodeChanged()); } @@ -280,7 +275,6 @@ void CrasAudioHandler::ActiveInputNodeChanged(uint64 node_id) { return; active_input_node_id_ = node_id; - GetNodes(); FOR_EACH_OBSERVER(AudioObserver, observers_, OnActiveInputNodeChanged()); } @@ -288,7 +282,7 @@ void CrasAudioHandler::OnAudioPolicyPrefChanged() { ApplyAudioPolicy(); } -void CrasAudioHandler::SetupInitialAudioState() { +void CrasAudioHandler::SetupAudioState() { ApplyAudioPolicy(); // Set the initial audio state to the ones read from audio prefs. @@ -296,9 +290,6 @@ void CrasAudioHandler::SetupInitialAudioState() { output_volume_ = audio_pref_handler_->GetOutputVolumeValue(); SetOutputVolumeInternal(output_volume_); SetOutputMute(output_mute_on_); - - // Get the initial audio data. - GetNodes(); } void CrasAudioHandler::ApplyAudioPolicy() { @@ -359,6 +350,7 @@ void CrasAudioHandler::HandleGetNodes(const chromeos::AudioNodeList& node_list, } } + SetupAudioState(); FOR_EACH_OBSERVER(AudioObserver, observers_, OnAudioNodesChanged()); } diff --git a/chromeos/audio/cras_audio_handler.h b/chromeos/audio/cras_audio_handler.h index 808d0e6..fd9ac03 100644 --- a/chromeos/audio/cras_audio_handler.h +++ b/chromeos/audio/cras_audio_handler.h @@ -20,7 +20,7 @@ class PrefService; namespace chromeos { -class AudioPrefHandler; +class AudioDevicesPrefHandler; class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, public AudioPrefObserver { @@ -52,7 +52,8 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, }; // Sets the global instance. Must be called before any calls to Get(). - static void Initialize(scoped_refptr<AudioPrefHandler> audio_pref_handler); + static void Initialize( + scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler); // Sets the global instance for testing. static void InitializeForTesting(); @@ -117,7 +118,8 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, virtual void SetActiveInputNode(uint64 node_id); protected: - explicit CrasAudioHandler(scoped_refptr<AudioPrefHandler> audio_pref_handler); + explicit CrasAudioHandler( + scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler); virtual ~CrasAudioHandler(); private: @@ -133,9 +135,9 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, // Overriden from AudioPrefObserver. virtual void OnAudioPolicyPrefChanged() OVERRIDE; - // Sets up the initial audio device state based on audio policy and - // audio settings saved in prefs. - void SetupInitialAudioState(); + // Sets up the audio device state based on audio policy and audio settings + // saved in prefs. + void SetupAudioState(); // Applies the audio muting policies whenever the user logs in or policy // change notification is received. @@ -150,7 +152,7 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, // Handles dbus callback for GetNodes. void HandleGetNodes(const chromeos::AudioNodeList& node_list, bool success); - scoped_refptr<AudioPrefHandler> audio_pref_handler_; + scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler_; base::WeakPtrFactory<CrasAudioHandler> weak_ptr_factory_; ObserverList<AudioObserver> observers_; diff --git a/chromeos/audio/mock_cras_audio_handler.cc b/chromeos/audio/mock_cras_audio_handler.cc index 84cd207..c6a47a9 100644 --- a/chromeos/audio/mock_cras_audio_handler.cc +++ b/chromeos/audio/mock_cras_audio_handler.cc @@ -4,7 +4,7 @@ #include "chromeos/audio/mock_cras_audio_handler.h" -#include "chromeos/audio/audio_pref_handler.h" +#include "chromeos/audio/audio_devices_pref_handler.h" namespace chromeos { |