| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| 11 #include "base/prefs/pref_change_registrar.h" | |
| 12 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 12 #include "chromeos/audio/audio_pref_observer.h" |
| 13 | 13 |
| 14 template <typename T> struct DefaultSingletonTraits; | 14 template <typename T> struct DefaultSingletonTraits; |
| 15 | 15 |
| 16 class PrefChangeRegistrar; | 16 class PrefChangeRegistrar; |
| 17 class PrefRegistrySimple; | 17 class PrefRegistrySimple; |
| 18 class PrefService; | 18 class PrefService; |
| 19 | 19 |
| 20 namespace chromeos { | 20 namespace chromeos { |
| 21 | 21 |
| 22 class AudioMixer; | 22 class AudioMixer; |
| 23 class AudioPrefHandler; |
| 23 | 24 |
| 24 class AudioHandler { | 25 // TODO(jennyz): crbug.com/233301. |
| 26 // Retire the old AudioHandler and the old audio library code once |
| 27 // the new audio dbus and handler code stabilizes. |
| 28 class AudioHandler : public AudioPrefObserver { |
| 25 public: | 29 public: |
| 26 class VolumeObserver { | 30 class VolumeObserver { |
| 27 public: | 31 public: |
| 28 virtual void OnVolumeChanged() = 0; | 32 virtual void OnVolumeChanged() = 0; |
| 29 virtual void OnMuteToggled() = 0; | 33 virtual void OnMuteToggled() = 0; |
| 30 protected: | 34 protected: |
| 31 VolumeObserver() {} | 35 VolumeObserver() {} |
| 32 virtual ~VolumeObserver() {} | 36 virtual ~VolumeObserver() {} |
| 33 DISALLOW_COPY_AND_ASSIGN(VolumeObserver); | 37 DISALLOW_COPY_AND_ASSIGN(VolumeObserver); |
| 34 }; | 38 }; |
| 35 | 39 |
| 36 static void Initialize(); | 40 static void Initialize(scoped_refptr<AudioPrefHandler> audio_pref_handler); |
| 37 static void Shutdown(); | 41 static void Shutdown(); |
| 38 | 42 |
| 39 // Same as Initialize but using the specified audio mixer. It takes | 43 // Same as Initialize but using the specified audio mixer. It takes |
| 40 // ownership of |mixer|. | 44 // ownership of |mixer|. |
| 41 static void InitializeForTesting(AudioMixer* mixer); | 45 static void InitializeForTesting( |
| 46 AudioMixer* mixer, |
| 47 scoped_refptr<AudioPrefHandler> audio_pref_handler); |
| 42 | 48 |
| 43 // GetInstance returns NULL if not initialized or if already shutdown. | 49 // GetInstance returns NULL if not initialized or if already shutdown. |
| 44 static AudioHandler* GetInstance(); | 50 static AudioHandler* GetInstance(); |
| 45 | 51 |
| 46 // Registers volume and mute preferences. | |
| 47 static void RegisterPrefs(PrefRegistrySimple* registry); | |
| 48 | |
| 49 // Gets volume level in our internal 0-100% range, 0 being pure silence. | 52 // Gets volume level in our internal 0-100% range, 0 being pure silence. |
| 50 double GetVolumePercent(); | 53 double GetVolumePercent(); |
| 51 | 54 |
| 52 // Sets volume level from 0-100%. If less than kMuteThresholdPercent, then | 55 // Sets volume level from 0-100%. If less than kMuteThresholdPercent, then |
| 53 // mutes the sound. If it was muted, and |volume_percent| is larger than | 56 // mutes the sound. If it was muted, and |volume_percent| is larger than |
| 54 // the threshold, then the sound is unmuted. | 57 // the threshold, then the sound is unmuted. |
| 55 void SetVolumePercent(double volume_percent); | 58 void SetVolumePercent(double volume_percent); |
| 56 | 59 |
| 57 // Adjusts volume up (positive percentage) or down (negative percentage). | 60 // Adjusts volume up (positive percentage) or down (negative percentage). |
| 58 void AdjustVolumeByPercent(double adjust_by_percent); | 61 void AdjustVolumeByPercent(double adjust_by_percent); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 72 | 75 |
| 73 void AddVolumeObserver(VolumeObserver* observer); | 76 void AddVolumeObserver(VolumeObserver* observer); |
| 74 void RemoveVolumeObserver(VolumeObserver* observer); | 77 void RemoveVolumeObserver(VolumeObserver* observer); |
| 75 | 78 |
| 76 private: | 79 private: |
| 77 // Defines the delete on exit Singleton traits we like. Best to have this | 80 // Defines the delete on exit Singleton traits we like. Best to have this |
| 78 // and constructor/destructor private as recommended for Singletons. | 81 // and constructor/destructor private as recommended for Singletons. |
| 79 friend struct DefaultSingletonTraits<AudioHandler>; | 82 friend struct DefaultSingletonTraits<AudioHandler>; |
| 80 | 83 |
| 81 // Takes ownership of |mixer|. | 84 // Takes ownership of |mixer|. |
| 82 explicit AudioHandler(AudioMixer* mixer); | 85 explicit AudioHandler(AudioMixer* mixer, |
| 86 scoped_refptr<AudioPrefHandler> audio_pref_handler); |
| 83 virtual ~AudioHandler(); | 87 virtual ~AudioHandler(); |
| 84 | 88 |
| 85 // Initializes the observers for the policy prefs. | |
| 86 void InitializePrefObservers(); | |
| 87 | |
| 88 // Applies the audio muting policies whenever the user logs in or policy | 89 // Applies the audio muting policies whenever the user logs in or policy |
| 89 // change notification is received. | 90 // change notification is received. |
| 90 void ApplyAudioPolicy(); | 91 void ApplyAudioPolicy(); |
| 91 | 92 |
| 92 // Sets volume to specified value and notifies observers. | 93 // Sets volume to specified value and notifies observers. |
| 93 void SetVolumePercentInternal(double volume_percent); | 94 void SetVolumePercentInternal(double volume_percent); |
| 94 | 95 |
| 96 // Overriden from AudioPrefObserver. |
| 97 virtual void OnAudioPolicyPrefChanged() OVERRIDE; |
| 98 |
| 95 scoped_ptr<AudioMixer> mixer_; | 99 scoped_ptr<AudioMixer> mixer_; |
| 96 | 100 |
| 97 ObserverList<VolumeObserver> volume_observers_; | 101 ObserverList<VolumeObserver> volume_observers_; |
| 98 | 102 |
| 99 PrefService* local_state_; // not owned | |
| 100 | |
| 101 PrefChangeRegistrar pref_change_registrar_; | |
| 102 | |
| 103 // Track state for triggering callbacks | 103 // Track state for triggering callbacks |
| 104 double volume_percent_; | 104 double volume_percent_; |
| 105 bool muted_; | 105 bool muted_; |
| 106 | 106 |
| 107 scoped_refptr<AudioPrefHandler> audio_pref_handler_; |
| 108 |
| 107 DISALLOW_COPY_AND_ASSIGN(AudioHandler); | 109 DISALLOW_COPY_AND_ASSIGN(AudioHandler); |
| 108 }; | 110 }; |
| 109 | 111 |
| 110 } // namespace chromeos | 112 } // namespace chromeos |
| 111 | 113 |
| 112 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_ | 114 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_ |
| OLD | NEW |