1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_DEVICES_PREF_HANDLER_IMPL_H_ 6 #define CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_DEVICES_PREF_HANDLER_IMPL_H_ 7 8 #include "base/observer_list.h" 9 #include "base/prefs/pref_change_registrar.h" 10 #include "base/values.h" 11 #include "chromeos/audio/audio_devices_pref_handler.h" 12 13 class PrefRegistrySimple; 14 class PrefService; 15 16 namespace chromeos { 17 18 // Class which implements AudioDevicesPrefHandler interface and register audio 19 // preferences as well. 20 class AudioDevicesPrefHandlerImpl : public AudioDevicesPrefHandler { 21 public: 22 explicit AudioDevicesPrefHandlerImpl(PrefService* local_state); 23 24 // Overridden from AudioDevicesPrefHandler. 25 virtual double GetVolumeGainValue(const AudioDevice& device) OVERRIDE; 26 virtual void SetVolumeGainValue(const AudioDevice& device, 27 double value) OVERRIDE; 28 29 virtual bool GetMuteValue(const AudioDevice& device) OVERRIDE; 30 virtual void SetMuteValue(const AudioDevice& device, bool mute_on) OVERRIDE; 31 32 virtual bool GetAudioCaptureAllowedValue() OVERRIDE; 33 virtual bool GetAudioOutputAllowedValue() OVERRIDE; 34 35 virtual void AddAudioPrefObserver(AudioPrefObserver* observer) OVERRIDE; 36 virtual void RemoveAudioPrefObserver(AudioPrefObserver* observer) OVERRIDE; 37 38 // Registers volume and mute preferences. 39 static void RegisterPrefs(PrefRegistrySimple* registry); 40 41 protected: 42 virtual ~AudioDevicesPrefHandlerImpl(); 43 44 private: 45 // Initializes the observers for the policy prefs. 46 void InitializePrefObservers(); 47 48 // Update and save methods for the mute preferences for all devices. 49 void UpdateDevicesMutePref(); 50 void SaveDevicesMutePref(); 51 52 // Update and save methods for the volume preferences for all devices. 53 void UpdateDevicesVolumePref(); 54 void SaveDevicesVolumePref(); 55 56 // Methods to migrate the mute and volume settings for a device from the 57 // previous global pref value to the new per device pref value for the 58 // current active device. If a previous global setting doesn't exist, we'll 59 // use default values of mute = off and volume = 75%. 60 void MigrateDeviceMuteSettings(std::string active_device); 61 void MigrateDeviceVolumeSettings(std::string active_device); 62 63 // Notifies the AudioPrefObserver for audio policy pref changes. 64 void NotifyAudioPolicyChange(); 65 66 scoped_ptr<base::DictionaryValue> device_mute_settings_; 67 scoped_ptr<base::DictionaryValue> device_volume_settings_; 68 69 PrefService* local_state_; // not owned 70 PrefChangeRegistrar pref_change_registrar_; 71 ObserverList<AudioPrefObserver> observers_; 72 73 DISALLOW_COPY_AND_ASSIGN(AudioDevicesPrefHandlerImpl); 74 }; 75 76 } // namespace chromeos 77 78 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_DEVICES_PREF_HANDLER_IMPL_H_ 79