| 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/callback_forward.h" |
| 9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 11 #include "base/prefs/public/pref_change_registrar.h" | 12 #include "base/prefs/public/pref_change_registrar.h" |
| 12 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 13 #include "content/public/browser/notification_details.h" | 14 #include "content/public/browser/notification_details.h" |
| 14 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
| 15 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
| 16 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
| 17 | 18 |
| 18 template <typename T> struct DefaultSingletonTraits; | 19 template <typename T> struct DefaultSingletonTraits; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 29 class VolumeObserver { | 30 class VolumeObserver { |
| 30 public: | 31 public: |
| 31 virtual void OnVolumeChanged() = 0; | 32 virtual void OnVolumeChanged() = 0; |
| 32 virtual void OnMuteToggled() = 0; | 33 virtual void OnMuteToggled() = 0; |
| 33 protected: | 34 protected: |
| 34 VolumeObserver() {} | 35 VolumeObserver() {} |
| 35 virtual ~VolumeObserver() {} | 36 virtual ~VolumeObserver() {} |
| 36 DISALLOW_COPY_AND_ASSIGN(VolumeObserver); | 37 DISALLOW_COPY_AND_ASSIGN(VolumeObserver); |
| 37 }; | 38 }; |
| 38 | 39 |
| 39 static void Initialize(); | 40 static void Initialize(const base::Closure& on_connected); |
| 40 static void Shutdown(); | 41 static void Shutdown(); |
| 41 | 42 |
| 42 // Same as Initialize but using the specified audio mixer. It takes | 43 // Same as Initialize but using the specified audio mixer. It takes |
| 43 // ownership of |mixer|. | 44 // ownership of |mixer|. |
| 44 static void InitializeForTesting(AudioMixer* mixer); | 45 static void InitializeForTesting(AudioMixer* mixer); |
| 45 | 46 |
| 46 // GetInstance returns NULL if not initialized or if already shutdown. | 47 // GetInstance returns NULL if not initialized or if already shutdown. |
| 47 static AudioHandler* GetInstance(); | 48 static AudioHandler* GetInstance(); |
| 48 | 49 |
| 49 // Registers volume and mute preferences. | 50 // Registers volume and mute preferences. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 80 virtual void Observe(int type, | 81 virtual void Observe(int type, |
| 81 const content::NotificationSource& source, | 82 const content::NotificationSource& source, |
| 82 const content::NotificationDetails& details) OVERRIDE; | 83 const content::NotificationDetails& details) OVERRIDE; |
| 83 | 84 |
| 84 private: | 85 private: |
| 85 // 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 |
| 86 // and constructor/destructor private as recommended for Singletons. | 87 // and constructor/destructor private as recommended for Singletons. |
| 87 friend struct DefaultSingletonTraits<AudioHandler>; | 88 friend struct DefaultSingletonTraits<AudioHandler>; |
| 88 | 89 |
| 89 // Takes ownership of |mixer|. | 90 // Takes ownership of |mixer|. |
| 90 explicit AudioHandler(AudioMixer* mixer); | 91 AudioHandler(AudioMixer* mixer, const base::Closure& on_connected); |
| 91 virtual ~AudioHandler(); | 92 virtual ~AudioHandler(); |
| 92 | 93 |
| 93 // Initializes the observers for the policy prefs. | 94 // Initializes the observers for the policy prefs. |
| 94 void InitializePrefObservers(); | 95 void InitializePrefObservers(); |
| 95 | 96 |
| 96 // Applies the audio muting policies whenever the user logs in or policy | 97 // Applies the audio muting policies whenever the user logs in or policy |
| 97 // change notification is received. | 98 // change notification is received. |
| 98 void ApplyAudioPolicy(); | 99 void ApplyAudioPolicy(); |
| 99 | 100 |
| 100 // Sets volume to specified value and notifies observers. | 101 // Sets volume to specified value and notifies observers. |
| 101 void SetVolumePercentInternal(double volume_percent); | 102 void SetVolumePercentInternal(double volume_percent); |
| 102 | 103 |
| 103 scoped_ptr<AudioMixer> mixer_; | 104 scoped_ptr<AudioMixer> mixer_; |
| 104 | 105 |
| 105 ObserverList<VolumeObserver> volume_observers_; | 106 ObserverList<VolumeObserver> volume_observers_; |
| 106 | 107 |
| 107 PrefService* local_state_; // not owned | 108 PrefService* local_state_; // not owned |
| 108 | 109 |
| 109 PrefChangeRegistrar pref_change_registrar_; | 110 PrefChangeRegistrar pref_change_registrar_; |
| 110 content::NotificationRegistrar registrar_; | 111 content::NotificationRegistrar registrar_; |
| 111 | 112 |
| 112 DISALLOW_COPY_AND_ASSIGN(AudioHandler); | 113 DISALLOW_COPY_AND_ASSIGN(AudioHandler); |
| 113 }; | 114 }; |
| 114 | 115 |
| 115 } // namespace chromeos | 116 } // namespace chromeos |
| 116 | 117 |
| 117 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_ | 118 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_ |
| OLD | NEW |