Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: chrome/browser/chromeos/audio/audio_handler.h

Issue 14314002: Implement new audio handler which talks to the new audio dbus apis. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix browser_tests compiling issue. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 class AudioHandler : public AudioPrefObserver {
25 public: 26 public:
26 class VolumeObserver { 27 class VolumeObserver {
27 public: 28 public:
28 virtual void OnVolumeChanged() = 0; 29 virtual void OnVolumeChanged() = 0;
29 virtual void OnMuteToggled() = 0; 30 virtual void OnMuteToggled() = 0;
30 protected: 31 protected:
31 VolumeObserver() {} 32 VolumeObserver() {}
32 virtual ~VolumeObserver() {} 33 virtual ~VolumeObserver() {}
33 DISALLOW_COPY_AND_ASSIGN(VolumeObserver); 34 DISALLOW_COPY_AND_ASSIGN(VolumeObserver);
34 }; 35 };
35 36
36 static void Initialize(); 37 static void Initialize(scoped_refptr<AudioPrefHandler> audio_pref_handler);
37 static void Shutdown(); 38 static void Shutdown();
38 39
39 // Same as Initialize but using the specified audio mixer. It takes 40 // Same as Initialize but using the specified audio mixer. It takes
40 // ownership of |mixer|. 41 // ownership of |mixer|.
41 static void InitializeForTesting(AudioMixer* mixer); 42 static void InitializeForTesting(
43 AudioMixer* mixer,
44 scoped_refptr<AudioPrefHandler> audio_pref_handler);
42 45
43 // GetInstance returns NULL if not initialized or if already shutdown. 46 // GetInstance returns NULL if not initialized or if already shutdown.
44 static AudioHandler* GetInstance(); 47 static AudioHandler* GetInstance();
45 48
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. 49 // Gets volume level in our internal 0-100% range, 0 being pure silence.
50 double GetVolumePercent(); 50 double GetVolumePercent();
51 51
52 // Sets volume level from 0-100%. If less than kMuteThresholdPercent, then 52 // 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 53 // mutes the sound. If it was muted, and |volume_percent| is larger than
54 // the threshold, then the sound is unmuted. 54 // the threshold, then the sound is unmuted.
55 void SetVolumePercent(double volume_percent); 55 void SetVolumePercent(double volume_percent);
56 56
57 // Adjusts volume up (positive percentage) or down (negative percentage). 57 // Adjusts volume up (positive percentage) or down (negative percentage).
58 void AdjustVolumeByPercent(double adjust_by_percent); 58 void AdjustVolumeByPercent(double adjust_by_percent);
(...skipping 13 matching lines...) Expand all
72 72
73 void AddVolumeObserver(VolumeObserver* observer); 73 void AddVolumeObserver(VolumeObserver* observer);
74 void RemoveVolumeObserver(VolumeObserver* observer); 74 void RemoveVolumeObserver(VolumeObserver* observer);
75 75
76 private: 76 private:
77 // Defines the delete on exit Singleton traits we like. Best to have this 77 // Defines the delete on exit Singleton traits we like. Best to have this
78 // and constructor/destructor private as recommended for Singletons. 78 // and constructor/destructor private as recommended for Singletons.
79 friend struct DefaultSingletonTraits<AudioHandler>; 79 friend struct DefaultSingletonTraits<AudioHandler>;
80 80
81 // Takes ownership of |mixer|. 81 // Takes ownership of |mixer|.
82 explicit AudioHandler(AudioMixer* mixer); 82 explicit AudioHandler(AudioMixer* mixer,
83 scoped_refptr<AudioPrefHandler> audio_pref_handler);
83 virtual ~AudioHandler(); 84 virtual ~AudioHandler();
84 85
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 86 // Applies the audio muting policies whenever the user logs in or policy
89 // change notification is received. 87 // change notification is received.
90 void ApplyAudioPolicy(); 88 void ApplyAudioPolicy();
91 89
92 // Sets volume to specified value and notifies observers. 90 // Sets volume to specified value and notifies observers.
93 void SetVolumePercentInternal(double volume_percent); 91 void SetVolumePercentInternal(double volume_percent);
94 92
93 // Overriden from AudioPrefObserver.
94 virtual void OnAudioPolicyPrefChanged() OVERRIDE;
95
95 scoped_ptr<AudioMixer> mixer_; 96 scoped_ptr<AudioMixer> mixer_;
96 97
97 ObserverList<VolumeObserver> volume_observers_; 98 ObserverList<VolumeObserver> volume_observers_;
98 99
99 PrefService* local_state_; // not owned
100
101 PrefChangeRegistrar pref_change_registrar_;
102
103 // Track state for triggering callbacks 100 // Track state for triggering callbacks
104 double volume_percent_; 101 double volume_percent_;
105 bool muted_; 102 bool muted_;
106 103
104 scoped_refptr<AudioPrefHandler> audio_pref_handler_;
105
107 DISALLOW_COPY_AND_ASSIGN(AudioHandler); 106 DISALLOW_COPY_AND_ASSIGN(AudioHandler);
108 }; 107 };
109 108
110 } // namespace chromeos 109 } // namespace chromeos
111 110
112 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_ 111 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/audio/audio_handler.cc » ('j') | chromeos/audio/audio_pref_observer.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698