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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 virtual void OnVolumeChanged() = 0; | 26 virtual void OnVolumeChanged() = 0; |
27 protected: | 27 protected: |
28 VolumeObserver() {} | 28 VolumeObserver() {} |
29 virtual ~VolumeObserver() {} | 29 virtual ~VolumeObserver() {} |
30 DISALLOW_COPY_AND_ASSIGN(VolumeObserver); | 30 DISALLOW_COPY_AND_ASSIGN(VolumeObserver); |
31 }; | 31 }; |
32 | 32 |
33 static void Initialize(); | 33 static void Initialize(); |
34 static void Shutdown(); | 34 static void Shutdown(); |
35 | 35 |
36 // Same as Initialize but using the specified audio mixer. It takes | |
37 // ownership of |mixer|. | |
38 static void InitializeForTesting(AudioMixer* mixer); | |
39 | |
40 // GetInstance returns NULL if not initialized or if already shutdown. | 36 // GetInstance returns NULL if not initialized or if already shutdown. |
41 static AudioHandler* GetInstance(); | 37 static AudioHandler* GetInstance(); |
42 | 38 |
43 // Registers volume and mute preferences. | 39 // Registers volume and mute preferences. |
44 static void RegisterPrefs(PrefService* local_state); | 40 static void RegisterPrefs(PrefService* local_state); |
45 | 41 |
46 // Gets volume level in our internal 0-100% range, 0 being pure silence. | 42 // Gets volume level in our internal 0-100% range, 0 being pure silence. |
47 double GetVolumePercent(); | 43 double GetVolumePercent(); |
48 | 44 |
49 // Sets volume level from 0-100%. | 45 // Sets volume level from 0-100%. |
50 void SetVolumePercent(double volume_percent); | 46 void SetVolumePercent(double volume_percent); |
51 | 47 |
52 // Adjusts volume up (positive percentage) or down (negative percentage). | 48 // Adjusts volume up (positive percentage) or down (negative percentage). |
53 void AdjustVolumeByPercent(double adjust_by_percent); | 49 void AdjustVolumeByPercent(double adjust_by_percent); |
54 | 50 |
55 // Is the volume currently muted? | 51 // Is the volume currently muted? |
56 bool IsMuted(); | 52 bool IsMuted(); |
57 | 53 |
58 // Mutes or unmutes all audio. | 54 // Mutes or unmutes all audio. |
59 void SetMuted(bool do_mute); | 55 void SetMuted(bool do_mute); |
60 | 56 |
61 void AddVolumeObserver(VolumeObserver* observer); | 57 void AddVolumeObserver(VolumeObserver* observer); |
62 void RemoveVolumeObserver(VolumeObserver* observer); | 58 void RemoveVolumeObserver(VolumeObserver* observer); |
63 | 59 |
64 private: | 60 private: |
65 // Defines the delete on exit Singleton traits we like. Best to have this | 61 // Defines the delete on exit Singleton traits we like. Best to have this |
66 // and constructor/destructor private as recommended for Singletons. | 62 // and constructor/destructor private as recommended for Singletons. |
67 friend struct DefaultSingletonTraits<AudioHandler>; | 63 friend struct DefaultSingletonTraits<AudioHandler>; |
68 | 64 |
69 // Takes ownership of |mixer|. | 65 AudioHandler(); |
70 explicit AudioHandler(AudioMixer* mixer); | |
71 virtual ~AudioHandler(); | 66 virtual ~AudioHandler(); |
72 | 67 |
73 scoped_ptr<AudioMixer> mixer_; | 68 scoped_ptr<AudioMixer> mixer_; |
74 | 69 |
75 ObserverList<VolumeObserver> volume_observers_; | 70 ObserverList<VolumeObserver> volume_observers_; |
76 | 71 |
77 PrefService* prefs_; // not owned | 72 PrefService* prefs_; // not owned |
78 | 73 |
79 DISALLOW_COPY_AND_ASSIGN(AudioHandler); | 74 DISALLOW_COPY_AND_ASSIGN(AudioHandler); |
80 }; | 75 }; |
81 | 76 |
82 } // namespace chromeos | 77 } // namespace chromeos |
83 | 78 |
84 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_ | 79 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_ |
OLD | NEW |