diff options
author | jamescook <jamescook@chromium.org> | 2014-12-18 18:55:00 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-19 02:56:00 +0000 |
commit | 15015851a7e550512dd4edc4e422b683f1b54e04 (patch) | |
tree | 9f5d6e43a659bdc7777f5d63dd4d40cfec61dbb9 /chromeos/audio | |
parent | 41d028d8cf10b1714f897617c2daed62ab87056a (diff) | |
download | chromium_src-15015851a7e550512dd4edc4e422b683f1b54e04.zip chromium_src-15015851a7e550512dd4edc4e422b683f1b54e04.tar.gz chromium_src-15015851a7e550512dd4edc4e422b683f1b54e04.tar.bz2 |
app_shell: Use real audio preferences and save them to local state
This allows app_shell to support the chrome.audio extension API in the same
way that Chrome does.
* Introduce "local state" for device wide preferences
* Use a real AudioDevicesPrefHandlerImpl in app_shell
This also sets the default output volume for app_shell (for non-HDMI output)
to 75%, which is consistent with Chrome on Chrome OS.
BUG=442401
TEST=chromeos_unittests and app_shell_unittests for audio
TBR=yoz@chromium.org for adding a test data file to extensions/test/data
Review URL: https://codereview.chromium.org/816793002
Cr-Commit-Position: refs/heads/master@{#309138}
Diffstat (limited to 'chromeos/audio')
-rw-r--r-- | chromeos/audio/audio_devices_pref_handler.h | 4 | ||||
-rw-r--r-- | chromeos/audio/audio_devices_pref_handler_impl.cc | 13 | ||||
-rw-r--r-- | chromeos/audio/audio_devices_pref_handler_stub.cc | 10 | ||||
-rw-r--r-- | chromeos/audio/audio_devices_pref_handler_stub.h | 33 |
4 files changed, 31 insertions, 29 deletions
diff --git a/chromeos/audio/audio_devices_pref_handler.h b/chromeos/audio/audio_devices_pref_handler.h index 53a3fce..aeb7b3d 100644 --- a/chromeos/audio/audio_devices_pref_handler.h +++ b/chromeos/audio/audio_devices_pref_handler.h @@ -22,6 +22,10 @@ struct AudioDevice; class CHROMEOS_EXPORT AudioDevicesPrefHandler : public base::RefCountedThreadSafe<AudioDevicesPrefHandler> { public: + // Integer because C++ does not allow static const double in header files. + static const int kDefaultOutputVolumePercent = 75; + static const int kDefaultHdmiOutputVolumePercent = 100; + // Gets the audio output volume value from prefs for a device. Since we can // only have either a gain or a volume for a device (depending on whether it // is input or output), we don't really care which value it is. diff --git a/chromeos/audio/audio_devices_pref_handler_impl.cc b/chromeos/audio/audio_devices_pref_handler_impl.cc index 77987c7..d262369 100644 --- a/chromeos/audio/audio_devices_pref_handler_impl.cc +++ b/chromeos/audio/audio_devices_pref_handler_impl.cc @@ -18,9 +18,6 @@ namespace { -const double kDefaultOutputVolume = 75.0; -const double kDefaultHDMIOutputVolume = 100.0; - // Values used for muted preference. const int kPrefMuteOff = 0; const int kPrefMuteOn = 1; @@ -50,7 +47,7 @@ namespace chromeos { double AudioDevicesPrefHandlerImpl::GetOutputVolumeValue( const AudioDevice* device) { if (!device) - return kDefaultOutputVolume; + return kDefaultOutputVolumePercent; else return GetVolumeGainPrefValue(*device); } @@ -132,9 +129,9 @@ double AudioDevicesPrefHandlerImpl::GetVolumeGainPrefValue( double AudioDevicesPrefHandlerImpl::GetDeviceDefaultOutputVolume( const AudioDevice& device) { if (device.type == AUDIO_TYPE_HDMI) - return kDefaultHDMIOutputVolume; + return kDefaultHdmiOutputVolumePercent; else - return kDefaultOutputVolume; + return kDefaultOutputVolumePercent; } AudioDevicesPrefHandlerImpl::AudioDevicesPrefHandlerImpl( @@ -194,7 +191,7 @@ void AudioDevicesPrefHandlerImpl::SaveDevicesVolumePref() { prefs::kAudioDevicesVolumePercent); base::DictionaryValue::Iterator it(*device_volume_settings_); while (!it.IsAtEnd()) { - double volume = kDefaultOutputVolume; + double volume = kDefaultOutputVolumePercent; bool success = it.value().GetAsDouble(&volume); DCHECK(success); dict_update->SetDouble(it.key(), volume); @@ -242,7 +239,7 @@ void AudioDevicesPrefHandlerImpl::RegisterPrefs( // Register the legacy audio prefs for migration. registry->RegisterDoublePref(prefs::kAudioVolumePercent, - kDefaultOutputVolume); + kDefaultOutputVolumePercent); registry->RegisterIntegerPref(prefs::kAudioMute, kPrefMuteOff); } diff --git a/chromeos/audio/audio_devices_pref_handler_stub.cc b/chromeos/audio/audio_devices_pref_handler_stub.cc index 83b9aab..84810af 100644 --- a/chromeos/audio/audio_devices_pref_handler_stub.cc +++ b/chromeos/audio/audio_devices_pref_handler_stub.cc @@ -4,6 +4,7 @@ #include "chromeos/audio/audio_devices_pref_handler_stub.h" +#include "base/stl_util.h" #include "chromeos/audio/audio_device.h" namespace chromeos { @@ -16,15 +17,16 @@ AudioDevicesPrefHandlerStub::~AudioDevicesPrefHandlerStub() { double AudioDevicesPrefHandlerStub::GetOutputVolumeValue( const AudioDevice* device) { - if (!device) - return 75.0; + if (!device || !ContainsKey(audio_device_volume_gain_map_, device->id)) + return kDefaultOutputVolumePercent; return audio_device_volume_gain_map_[device->id]; } double AudioDevicesPrefHandlerStub::GetInputGainValue( const AudioDevice* device) { - if (!device) - return 0.0; + // TODO(rkc): The default value for gain is wrong. http://crbug.com/442489 + if (!device || !ContainsKey(audio_device_volume_gain_map_, device->id)) + return 75.0; return audio_device_volume_gain_map_[device->id]; } diff --git a/chromeos/audio/audio_devices_pref_handler_stub.h b/chromeos/audio/audio_devices_pref_handler_stub.h index 756038d..077f230 100644 --- a/chromeos/audio/audio_devices_pref_handler_stub.h +++ b/chromeos/audio/audio_devices_pref_handler_stub.h @@ -5,36 +5,35 @@ #ifndef CHROMEOS_AUDIO_AUDIO_DEVICES_PREF_HANDLER_STUB_H_ #define CHROMEOS_AUDIO_AUDIO_DEVICES_PREF_HANDLER_STUB_H_ -#include "chromeos/audio/audio_devices_pref_handler.h" - #include <map> -namespace chromeos { +#include "base/macros.h" +#include "chromeos/audio/audio_devices_pref_handler.h" -struct AudioDevice; +namespace chromeos { // Stub class for AudioDevicesPrefHandler, used for testing. class CHROMEOS_EXPORT AudioDevicesPrefHandlerStub : public AudioDevicesPrefHandler { public: - typedef std::map<uint64, bool> AudioDeviceMute; - typedef std::map<uint64, int> AudioDeviceVolumeGain; + using AudioDeviceMute = std::map<uint64_t, bool>; + using AudioDeviceVolumeGain = std::map<uint64_t, int>; AudioDevicesPrefHandlerStub(); - virtual double GetOutputVolumeValue(const AudioDevice* device) override; - virtual double GetInputGainValue(const AudioDevice* device) override; - virtual void SetVolumeGainValue(const AudioDevice& device, - double value) override; - virtual bool GetMuteValue(const AudioDevice& device) override; - virtual void SetMuteValue(const AudioDevice& device, bool mute_on) override; - virtual bool GetAudioCaptureAllowedValue() override; - virtual bool GetAudioOutputAllowedValue() override; - virtual void AddAudioPrefObserver(AudioPrefObserver* observer) override; - virtual void RemoveAudioPrefObserver(AudioPrefObserver* observer) override; + // AudioDevicesPrefHandler: + double GetOutputVolumeValue(const AudioDevice* device) override; + double GetInputGainValue(const AudioDevice* device) override; + void SetVolumeGainValue(const AudioDevice& device, double value) override; + bool GetMuteValue(const AudioDevice& device) override; + void SetMuteValue(const AudioDevice& device, bool mute_on) override; + bool GetAudioCaptureAllowedValue() override; + bool GetAudioOutputAllowedValue() override; + void AddAudioPrefObserver(AudioPrefObserver* observer) override; + void RemoveAudioPrefObserver(AudioPrefObserver* observer) override; protected: - virtual ~AudioDevicesPrefHandlerStub(); + ~AudioDevicesPrefHandlerStub() override; private: AudioDeviceMute audio_device_mute_map_; |