• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 GetOutputVolumeValue(const AudioDevice* device) OVERRIDE;
26   virtual double GetInputGainValue(const AudioDevice* device) OVERRIDE;
27   virtual void SetVolumeGainValue(const AudioDevice& device,
28                                   double value) OVERRIDE;
29 
30   virtual bool GetMuteValue(const AudioDevice& device) OVERRIDE;
31   virtual void SetMuteValue(const AudioDevice& device, bool mute_on) OVERRIDE;
32 
33   virtual bool GetAudioCaptureAllowedValue() OVERRIDE;
34   virtual bool GetAudioOutputAllowedValue() OVERRIDE;
35 
36   virtual void AddAudioPrefObserver(AudioPrefObserver* observer) OVERRIDE;
37   virtual void RemoveAudioPrefObserver(AudioPrefObserver* observer) OVERRIDE;
38 
39   // Registers volume and mute preferences.
40   static void RegisterPrefs(PrefRegistrySimple* registry);
41 
42  protected:
43   virtual ~AudioDevicesPrefHandlerImpl();
44 
45  private:
46   // Initializes the observers for the policy prefs.
47   void InitializePrefObservers();
48 
49   // Update and save methods for the mute preferences for all devices.
50   void UpdateDevicesMutePref();
51   void SaveDevicesMutePref();
52 
53   // Update and save methods for the volume preferences for all devices.
54   void UpdateDevicesVolumePref();
55   void SaveDevicesVolumePref();
56 
57   double GetVolumeGainPrefValue(const AudioDevice& device);
58   double GetDeviceDefaultOutputVolume(const AudioDevice& device);
59 
60   // Methods to migrate the mute and volume settings for a device from the
61   // previous global pref value to the new per device pref value for the
62   // current active device. If a previous global setting doesn't exist, we'll
63   // use default values of mute = off and volume = 75%.
64   void MigrateDeviceMuteSettings(std::string active_device);
65   void MigrateDeviceVolumeSettings(std::string active_device);
66 
67   // Notifies the AudioPrefObserver for audio policy pref changes.
68   void NotifyAudioPolicyChange();
69 
70   scoped_ptr<base::DictionaryValue> device_mute_settings_;
71   scoped_ptr<base::DictionaryValue> device_volume_settings_;
72 
73   PrefService* local_state_;  // not owned
74   PrefChangeRegistrar pref_change_registrar_;
75   ObserverList<AudioPrefObserver> observers_;
76 
77   DISALLOW_COPY_AND_ASSIGN(AudioDevicesPrefHandlerImpl);
78 };
79 
80 }  // namespace chromeos
81 
82 #endif  // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_DEVICES_PREF_HANDLER_IMPL_H_
83