Chromium Code Reviews| 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/observer_list.h" | 9 #include "base/observer_list.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 12 #include "chrome/browser/api/prefs/pref_change_registrar.h" | |
| 13 #include "content/public/browser/notification_details.h" | |
| 14 #include "content/public/browser/notification_observer.h" | |
| 15 #include "content/public/browser/notification_registrar.h" | |
| 16 #include "content/public/browser/notification_source.h" | |
| 12 | 17 |
| 13 template <typename T> struct DefaultSingletonTraits; | 18 template <typename T> struct DefaultSingletonTraits; |
| 14 | 19 |
| 20 class PrefChangeRegistrar; | |
| 15 class PrefService; | 21 class PrefService; |
| 16 | 22 |
| 17 namespace chromeos { | 23 namespace chromeos { |
| 18 | 24 |
| 19 class AudioMixer; | 25 class AudioMixer; |
| 20 | 26 |
| 21 class AudioHandler { | 27 class AudioHandler : content::NotificationObserver { |
| 22 public: | 28 public: |
| 23 class VolumeObserver { | 29 class VolumeObserver { |
| 24 public: | 30 public: |
| 25 virtual void OnVolumeChanged() = 0; | 31 virtual void OnVolumeChanged() = 0; |
| 26 virtual void OnMuteToggled() = 0; | 32 virtual void OnMuteToggled() = 0; |
| 27 protected: | 33 protected: |
| 28 VolumeObserver() {} | 34 VolumeObserver() {} |
| 29 virtual ~VolumeObserver() {} | 35 virtual ~VolumeObserver() {} |
| 30 DISALLOW_COPY_AND_ASSIGN(VolumeObserver); | 36 DISALLOW_COPY_AND_ASSIGN(VolumeObserver); |
| 31 }; | 37 }; |
| 32 | 38 |
| 33 static void Initialize(); | 39 static void Initialize(); |
| 34 static void Shutdown(); | 40 static void Shutdown(); |
| 35 | 41 |
| 36 // Same as Initialize but using the specified audio mixer. It takes | 42 // Same as Initialize but using the specified audio mixer. It takes |
| 37 // ownership of |mixer|. | 43 // ownership of |mixer|. |
| 38 static void InitializeForTesting(AudioMixer* mixer); | 44 static void InitializeForTesting(AudioMixer* mixer); |
| 39 | 45 |
| 40 // GetInstance returns NULL if not initialized or if already shutdown. | 46 // GetInstance returns NULL if not initialized or if already shutdown. |
| 41 static AudioHandler* GetInstance(); | 47 static AudioHandler* GetInstance(); |
| 42 | 48 |
| 43 // Registers volume and mute preferences. | 49 // Registers volume and mute preferences. |
| 44 static void RegisterPrefs(PrefService* local_state); | 50 static void RegisterPrefs(PrefService* local_state); |
|
Mattias Nissler (ping if slow)
2012/08/28 12:24:24
Rename to disambiguate?
pastarmovj
2012/08/28 15:11:50
Done.
| |
| 51 static void RegisterUserPrefs(PrefService* user_prefs); | |
| 52 | |
| 53 // Initializes the observers for the policy prefs. | |
| 54 void InitializePrefObservers(PrefService* user_prefs); | |
| 45 | 55 |
| 46 // Gets volume level in our internal 0-100% range, 0 being pure silence. | 56 // Gets volume level in our internal 0-100% range, 0 being pure silence. |
| 47 double GetVolumePercent(); | 57 double GetVolumePercent(); |
| 48 | 58 |
| 49 // Sets volume level from 0-100%. | 59 // Sets volume level from 0-100%. |
| 50 void SetVolumePercent(double volume_percent); | 60 void SetVolumePercent(double volume_percent); |
| 51 | 61 |
| 52 // Adjusts volume up (positive percentage) or down (negative percentage). | 62 // Adjusts volume up (positive percentage) or down (negative percentage). |
| 53 void AdjustVolumeByPercent(double adjust_by_percent); | 63 void AdjustVolumeByPercent(double adjust_by_percent); |
| 54 | 64 |
| 55 // Is the volume currently muted? | 65 // Is the volume currently muted? |
| 56 bool IsMuted(); | 66 bool IsMuted(); |
| 57 | 67 |
| 58 // Mutes or unmutes all audio. | 68 // Mutes or unmutes all audio. |
| 59 void SetMuted(bool do_mute); | 69 void SetMuted(bool do_mute); |
| 60 | 70 |
| 71 // Is the mic volume currently muted? | |
| 72 bool IsMicMuted(); | |
| 73 | |
| 74 // Mutes or unmutes all mics. | |
| 75 void SetMicMuted(bool do_mute); | |
| 76 | |
| 61 void AddVolumeObserver(VolumeObserver* observer); | 77 void AddVolumeObserver(VolumeObserver* observer); |
| 62 void RemoveVolumeObserver(VolumeObserver* observer); | 78 void RemoveVolumeObserver(VolumeObserver* observer); |
| 63 | 79 |
| 80 // Overridden from content::NotificationObserver: | |
| 81 virtual void Observe(int type, | |
| 82 const content::NotificationSource& source, | |
| 83 const content::NotificationDetails& details) OVERRIDE; | |
| 84 | |
| 64 private: | 85 private: |
| 65 // Defines the delete on exit Singleton traits we like. Best to have this | 86 // Defines the delete on exit Singleton traits we like. Best to have this |
| 66 // and constructor/destructor private as recommended for Singletons. | 87 // and constructor/destructor private as recommended for Singletons. |
| 67 friend struct DefaultSingletonTraits<AudioHandler>; | 88 friend struct DefaultSingletonTraits<AudioHandler>; |
| 68 | 89 |
| 69 // Takes ownership of |mixer|. | 90 // Takes ownership of |mixer|. |
| 70 explicit AudioHandler(AudioMixer* mixer); | 91 explicit AudioHandler(AudioMixer* mixer); |
| 71 virtual ~AudioHandler(); | 92 virtual ~AudioHandler(); |
| 72 | 93 |
| 94 // Applies the audio muting policies whenever the user logs in or policy | |
| 95 // change notification is received. | |
| 96 void ApplyAudioPolicy(); | |
| 97 | |
| 73 scoped_ptr<AudioMixer> mixer_; | 98 scoped_ptr<AudioMixer> mixer_; |
| 74 | 99 |
| 75 ObserverList<VolumeObserver> volume_observers_; | 100 ObserverList<VolumeObserver> volume_observers_; |
| 76 | 101 |
| 77 PrefService* prefs_; // not owned | 102 PrefService* local_state_; // not owned |
| 103 PrefService* user_prefs_; | |
| 104 | |
| 105 PrefChangeRegistrar pref_change_registrar_; | |
| 106 content::NotificationRegistrar registrar_; | |
| 78 | 107 |
| 79 DISALLOW_COPY_AND_ASSIGN(AudioHandler); | 108 DISALLOW_COPY_AND_ASSIGN(AudioHandler); |
| 80 }; | 109 }; |
| 81 | 110 |
| 82 } // namespace chromeos | 111 } // namespace chromeos |
| 83 | 112 |
| 84 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_ | 113 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_ |
| OLD | NEW |