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 | |
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
-rw-r--r-- | chrome/browser/chromeos/audio/audio_devices_pref_handler_impl.cc | 192 | ||||
-rw-r--r-- | chrome/browser/chromeos/audio/audio_devices_pref_handler_impl.h | 74 | ||||
-rw-r--r-- | chrome/browser/chromeos/audio/audio_pref_handler_impl.h | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/chrome_browser_main_chromeos.cc | 3 | ||||
-rw-r--r-- | chrome/browser/prefs/browser_prefs.cc | 2 | ||||
-rw-r--r-- | chrome/chrome_browser_chromeos.gypi | 2 | ||||
-rw-r--r-- | chrome/common/pref_names.cc | 17 | ||||
-rw-r--r-- | chrome/common/pref_names.h | 2 | ||||
-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 | ||||
-rw-r--r-- | chromeos/chromeos.gyp | 1 |
14 files changed, 369 insertions, 29 deletions
diff --git a/chrome/browser/chromeos/audio/audio_devices_pref_handler_impl.cc b/chrome/browser/chromeos/audio/audio_devices_pref_handler_impl.cc new file mode 100644 index 0000000..c8d5b03 --- /dev/null +++ b/chrome/browser/chromeos/audio/audio_devices_pref_handler_impl.cc @@ -0,0 +1,192 @@ +// 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. + +#include "chrome/browser/chromeos/audio/audio_devices_pref_handler_impl.h" + +#include "base/bind.h" +#include "base/bind_helpers.h" +#include "base/logging.h" +#include "base/prefs/pref_registry_simple.h" +#include "base/prefs/pref_service.h" +#include "base/strings/string_number_conversions.h" +#include "chrome/browser/prefs/scoped_user_pref_update.h" +#include "chrome/common/chrome_notification_types.h" +#include "chrome/common/pref_names.h" +#include "chromeos/audio/cras_audio_handler.h" + +namespace chromeos { + +namespace { + +// Default value for the volume pref, as a percent in the range [0.0, 100.0]. +const double kDefaultVolumePercent = 75.0; + +// Values used for muted preference. +const int kPrefMuteOff = 0; +const int kPrefMuteOn = 1; + +} // namespace + +double AudioDevicesPrefHandlerImpl::GetOutputVolumeValue() { + if (!CrasAudioHandler::IsInitialized()) + return kDefaultVolumePercent; + + UpdateDevicesVolumePref(); + std::string active_device_id = base::Uint64ToString( + CrasAudioHandler::Get()->GetActiveOutputNode()); + if (!device_volume_settings_->HasKey(active_device_id)) + MigrateDeviceVolumeSettings(active_device_id); + double volume = kDefaultVolumePercent; + device_volume_settings_->GetDouble(active_device_id, &volume); + return volume; +} + +void AudioDevicesPrefHandlerImpl::SetOutputVolumeValue(double volume_percent) { + std::string active_device_id = base::Uint64ToString( + CrasAudioHandler::Get()->GetActiveOutputNode()); + if (volume_percent > 100.0) + volume_percent = 100.0; + if (volume_percent < 0.0) + volume_percent = 0.0; + device_volume_settings_->SetDouble(active_device_id, volume_percent); + SaveDevicesVolumePref(); +} + +bool AudioDevicesPrefHandlerImpl::GetOutputMuteValue() { + if (!CrasAudioHandler::IsInitialized()) + return false; + + UpdateDevicesVolumePref(); + std::string active_device_id = base::Uint64ToString( + CrasAudioHandler::Get()->GetActiveOutputNode()); + if (!device_mute_settings_->HasKey(active_device_id)) + MigrateDeviceMuteSettings(active_device_id); + int mute = kPrefMuteOff; + device_mute_settings_->GetInteger(active_device_id, &mute); + return (mute == kPrefMuteOn); +} + +void AudioDevicesPrefHandlerImpl::SetOutputMuteValue(bool mute) { + std::string active_device_id = base::Uint64ToString( + CrasAudioHandler::Get()->GetActiveOutputNode()); + device_mute_settings_->SetBoolean(active_device_id, + mute ? kPrefMuteOn : kPrefMuteOff); + SaveDevicesVolumePref(); +} + +bool AudioDevicesPrefHandlerImpl::GetAudioCaptureAllowedValue() { + return local_state_->GetBoolean(prefs::kAudioCaptureAllowed); +} + +bool AudioDevicesPrefHandlerImpl::GetAudioOutputAllowedValue() { + return local_state_->GetBoolean(prefs::kAudioOutputAllowed); +} + +void AudioDevicesPrefHandlerImpl::AddAudioPrefObserver( + AudioPrefObserver* observer) { + observers_.AddObserver(observer); +} + +void AudioDevicesPrefHandlerImpl::RemoveAudioPrefObserver( + AudioPrefObserver* observer) { + observers_.RemoveObserver(observer); +} + +AudioDevicesPrefHandlerImpl::AudioDevicesPrefHandlerImpl( + PrefService* local_state) + : device_mute_settings_(new base::DictionaryValue()), + device_volume_settings_(new base::DictionaryValue()), + local_state_(local_state) { + InitializePrefObservers(); + + UpdateDevicesMutePref(); + UpdateDevicesVolumePref(); +} + +AudioDevicesPrefHandlerImpl::~AudioDevicesPrefHandlerImpl() { +}; + +void AudioDevicesPrefHandlerImpl::InitializePrefObservers() { + pref_change_registrar_.Init(local_state_); + base::Closure callback = + base::Bind(&AudioDevicesPrefHandlerImpl::NotifyAudioPolicyChange, + base::Unretained(this)); + pref_change_registrar_.Add(prefs::kAudioOutputAllowed, callback); + pref_change_registrar_.Add(prefs::kAudioCaptureAllowed, callback); +} + +void AudioDevicesPrefHandlerImpl::UpdateDevicesMutePref() { + const base::DictionaryValue* mute_prefs = + local_state_->GetDictionary(prefs::kAudioDevicesMute); + if (mute_prefs) + device_mute_settings_.reset(mute_prefs->DeepCopy()); +} + +void AudioDevicesPrefHandlerImpl::SaveDevicesMutePref() { + DictionaryPrefUpdate dict_update(local_state_, prefs::kAudioDevicesMute); + base::DictionaryValue::Iterator it(*device_mute_settings_); + while (!it.IsAtEnd()) { + int mute = kPrefMuteOff; + it.value().GetAsInteger(&mute); + dict_update->Set(it.key(), new base::FundamentalValue(mute)); + it.Advance(); + } +} + +void AudioDevicesPrefHandlerImpl::UpdateDevicesVolumePref() { + const base::DictionaryValue* volume_prefs = + local_state_->GetDictionary(prefs::kAudioDevicesVolumePercent); + if (volume_prefs) + device_volume_settings_.reset(volume_prefs->DeepCopy()); +} + +void AudioDevicesPrefHandlerImpl::SaveDevicesVolumePref() { + DictionaryPrefUpdate dict_update(local_state_, + prefs::kAudioDevicesVolumePercent); + base::DictionaryValue::Iterator it(*device_volume_settings_); + while (!it.IsAtEnd()) { + double volume = kDefaultVolumePercent; + it.value().GetAsDouble(&volume); + dict_update->Set(it.key(), new base::FundamentalValue(volume)); + it.Advance(); + } +} + +void AudioDevicesPrefHandlerImpl::MigrateDeviceMuteSettings( + std::string active_device) { + int old_mute = local_state_->GetInteger(prefs::kAudioMute); + device_mute_settings_->SetInteger(active_device, old_mute); + SaveDevicesMutePref(); +} + +void AudioDevicesPrefHandlerImpl::MigrateDeviceVolumeSettings( + std::string active_device) { + double old_volume = local_state_->GetDouble(prefs::kAudioVolumePercent); + device_volume_settings_->SetDouble(active_device, old_volume); + SaveDevicesVolumePref(); +} + +void AudioDevicesPrefHandlerImpl::NotifyAudioPolicyChange() { + FOR_EACH_OBSERVER(AudioPrefObserver, + observers_, + OnAudioPolicyPrefChanged()); +} + +// static +void AudioDevicesPrefHandlerImpl::RegisterPrefs(PrefRegistrySimple* registry) { + registry->RegisterDictionaryPref(prefs::kAudioDevicesVolumePercent); + registry->RegisterDictionaryPref(prefs::kAudioDevicesMute); + + // TODO(jennyz,rkc): Move the rest of the preferences registered by + // AudioPrefHandlerImpl::RegisterPrefs here once we remove the old audio + // handler code. +} + +// static +AudioDevicesPrefHandler* AudioDevicesPrefHandler::Create( + PrefService* local_state) { + return new AudioDevicesPrefHandlerImpl(local_state); +} + +} // namespace chromeos diff --git a/chrome/browser/chromeos/audio/audio_devices_pref_handler_impl.h b/chrome/browser/chromeos/audio/audio_devices_pref_handler_impl.h new file mode 100644 index 0000000..44dafe5 --- /dev/null +++ b/chrome/browser/chromeos/audio/audio_devices_pref_handler_impl.h @@ -0,0 +1,74 @@ +// 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 CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_DEVICES_PREF_HANDLER_IMPL_H_ +#define CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_DEVICES_PREF_HANDLER_IMPL_H_ + +#include "base/observer_list.h" +#include "base/prefs/pref_change_registrar.h" +#include "base/values.h" +#include "chromeos/audio/audio_devices_pref_handler.h" + +class PrefRegistrySimple; +class PrefService; + +namespace chromeos { + +// Class which implements AudioDevicesPrefHandler interface and register audio +// preferences as well. +class AudioDevicesPrefHandlerImpl : public AudioDevicesPrefHandler { + public: + explicit AudioDevicesPrefHandlerImpl(PrefService* local_state); + + // Overridden from AudioDevicesPrefHandler. + virtual double GetOutputVolumeValue() OVERRIDE; + virtual bool GetOutputMuteValue() OVERRIDE; + virtual void SetOutputVolumeValue(double volume_percent) OVERRIDE; + virtual void SetOutputMuteValue(bool mute_on) OVERRIDE; + virtual bool GetAudioCaptureAllowedValue() OVERRIDE; + virtual bool GetAudioOutputAllowedValue() OVERRIDE; + virtual void AddAudioPrefObserver(AudioPrefObserver* observer) OVERRIDE; + virtual void RemoveAudioPrefObserver(AudioPrefObserver* observer) OVERRIDE; + + // Registers volume and mute preferences. + static void RegisterPrefs(PrefRegistrySimple* registry); + + protected: + virtual ~AudioDevicesPrefHandlerImpl(); + + private: + // Initializes the observers for the policy prefs. + void InitializePrefObservers(); + + // Update and save methods for the mute preferences for all devices. + void UpdateDevicesMutePref(); + void SaveDevicesMutePref(); + + // Update and save methods for the volume preferences for all devices. + void UpdateDevicesVolumePref(); + void SaveDevicesVolumePref(); + + // Methods to migrate the mute and volume settings for a device from the + // previous global pref value to the new per device pref value for the + // current active device. If a previous global setting doesn't exist, we'll + // use default values of mute = off and volume = 75%. + void MigrateDeviceMuteSettings(std::string active_device); + void MigrateDeviceVolumeSettings(std::string active_device); + + // Notifies the AudioPrefObserver for audio policy pref changes. + void NotifyAudioPolicyChange(); + + scoped_ptr<base::DictionaryValue> device_mute_settings_; + scoped_ptr<base::DictionaryValue> device_volume_settings_; + + PrefService* local_state_; // not owned + PrefChangeRegistrar pref_change_registrar_; + ObserverList<AudioPrefObserver> observers_; + + DISALLOW_COPY_AND_ASSIGN(AudioDevicesPrefHandlerImpl); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_DEVICES_PREF_HANDLER_IMPL_H_ diff --git a/chrome/browser/chromeos/audio/audio_pref_handler_impl.h b/chrome/browser/chromeos/audio/audio_pref_handler_impl.h index 454180f..47f8da0 100644 --- a/chrome/browser/chromeos/audio/audio_pref_handler_impl.h +++ b/chrome/browser/chromeos/audio/audio_pref_handler_impl.h @@ -14,6 +14,8 @@ class PrefService; namespace chromeos { +// TODO(jennyz,rkc): This class will be removed once we remove the old Audio +// Handler code. // Class which implements AudioPrefHandler interface and register audio // preferences as well. class AudioPrefHandlerImpl : public AudioPrefHandler { diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc index 1f395f1..3e570f1 100644 --- a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc +++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc @@ -91,6 +91,7 @@ #include "chrome/common/chrome_version_info.h" #include "chrome/common/logging_chrome.h" #include "chrome/common/pref_names.h" +#include "chromeos/audio/audio_devices_pref_handler.h" #include "chromeos/audio/audio_pref_handler.h" #include "chromeos/audio/cras_audio_handler.h" #include "chromeos/audio/cras_audio_switch_handler.h" @@ -485,7 +486,7 @@ void ChromeBrowserMainPartsChromeos::PreMainMessageLoopRun() { CrasAudioSwitchHandler::Initialize(); if (UseNewAudioHandler()) { CrasAudioHandler::Initialize( - AudioPrefHandler::Create(g_browser_process->local_state())); + AudioDevicesPrefHandler::Create(g_browser_process->local_state())); } else { AudioHandler::Initialize( AudioPrefHandler::Create(g_browser_process->local_state())); diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc index 291c1cde..fac503e 100644 --- a/chrome/browser/prefs/browser_prefs.cc +++ b/chrome/browser/prefs/browser_prefs.cc @@ -117,6 +117,7 @@ #if defined(OS_CHROMEOS) #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" +#include "chrome/browser/chromeos/audio/audio_devices_pref_handler_impl.h" #include "chrome/browser/chromeos/audio/audio_handler.h" #include "chrome/browser/chromeos/audio/audio_pref_handler_impl.h" #include "chrome/browser/chromeos/customization_document.h" @@ -241,6 +242,7 @@ void RegisterLocalState(PrefRegistrySimple* registry) { #endif #if defined(OS_CHROMEOS) + chromeos::AudioDevicesPrefHandlerImpl::RegisterPrefs(registry); chromeos::AudioPrefHandlerImpl::RegisterPrefs(registry); chromeos::DataPromoNotification::RegisterPrefs(registry); chromeos::DeviceOAuth2TokenService::RegisterPrefs(registry); diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi index 61bb92a..5fab399 100644 --- a/chrome/chrome_browser_chromeos.gypi +++ b/chrome/chrome_browser_chromeos.gypi @@ -134,6 +134,8 @@ 'browser/chromeos/attestation/attestation_ca_client.h', 'browser/chromeos/attestation/attestation_policy_observer.cc', 'browser/chromeos/attestation/attestation_policy_observer.h', + 'browser/chromeos/audio/audio_devices_pref_handler_impl.cc', + 'browser/chromeos/audio/audio_devices_pref_handler_impl.h', 'browser/chromeos/audio/audio_handler.cc', 'browser/chromeos/audio/audio_handler.h', 'browser/chromeos/audio/audio_pref_handler_impl.cc', diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index 58a075b..1d2ce8e 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -541,12 +541,25 @@ const char kDefaultAppsInstallState[] = "default_apps_install_state"; const char kHideWebStoreIcon[] = "hide_web_store_icon"; #if defined(OS_CHROMEOS) +// A dictionary pref to hold the mute setting for all the currently known +// audio devices. +const char kAudioDevicesMute[] = "settings.audio.devices.mute"; + +// A dictionary pref storing the volume settings for all the currently known +// audio devices. +const char kAudioDevicesVolumePercent[] = + "settings.audio.devices.volume_percent"; + // An integer pref to initially mute volume if 1. This pref is ignored if // |kAudioOutputAllowed| is set to false, but its value is preserved, therefore -// when the policy is lifted the original mute state is restored. +// when the policy is lifted the original mute state is restored. This setting +// is here only for migration purposes now. It is being replaced by the +// |kAudioDevicesMute| setting. const char kAudioMute[] = "settings.audio.mute"; -// A double pref storing the user-requested volume. +// A double pref storing the user-requested volume. This setting is here only +// for migration purposes now. It is being replaced by the +// |kAudioDevicesVolumePercent| setting. const char kAudioVolumePercent[] = "settings.audio.volume_percent"; // A boolean pref set to true if touchpad tap-to-click is enabled. diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index 8958e1b..985096d 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -205,6 +205,8 @@ extern const char kNetworkPredictionEnabled[]; extern const char kDefaultAppsInstallState[]; extern const char kHideWebStoreIcon[]; #if defined(OS_CHROMEOS) +extern const char kAudioDevicesMute[]; +extern const char kAudioDevicesVolumePercent[]; extern const char kAudioMute[]; extern const char kAudioVolumePercent[]; extern const char kTapToClickEnabled[]; 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 { diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp index 251bbfe..c1466d1 100644 --- a/chromeos/chromeos.gyp +++ b/chromeos/chromeos.gyp @@ -32,6 +32,7 @@ 'sources': [ 'audio/audio_device.cc', 'audio/audio_device.h', + 'audio/audio_devices_pref_handler.h', 'audio/audio_pref_observer.h', 'audio/audio_pref_handler.h', 'audio/cras_audio_handler.cc', |