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

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

Issue 9169033: Support for showing/hiding status area volume controls in desktop devices (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rebase Created 8 years, 10 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/audio/audio_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
11 #include "base/threading/thread.h" 12 #include "base/threading/thread.h"
12 13
13 template <typename T> struct DefaultSingletonTraits; 14 template <typename T> struct DefaultSingletonTraits;
14 15
15 namespace chromeos { 16 namespace chromeos {
16 17
17 class AudioMixer; 18 class AudioMixer;
18 19
19 class AudioHandler { 20 class AudioHandler {
20 public: 21 public:
22 class VolumeObserver {
23 public:
24 virtual void OnVolumeChanged() = 0;
25 protected:
26 VolumeObserver() {}
27 virtual ~VolumeObserver() {}
28 DISALLOW_COPY_AND_ASSIGN(VolumeObserver);
29 };
30
21 static void Initialize(); 31 static void Initialize();
22 static void Shutdown(); 32 static void Shutdown();
23 // GetInstance returns NULL if not initialized or if already shutdown. 33 // GetInstance returns NULL if not initialized or if already shutdown.
34 // The mixer may be uninitialized, so use GetInstanceIfInitialized
35 // for volume control until the TODO below is resolved.
24 static AudioHandler* GetInstance(); 36 static AudioHandler* GetInstance();
25 37
26 // Is the mixer initialized? 38 // GetInstanceIfInitialized returns NULL if GetInstance returns NULL or if
39 // the mixer has not finished initializing.
27 // TODO(derat): All of the volume-percent methods will produce "interesting" 40 // TODO(derat): All of the volume-percent methods will produce "interesting"
28 // results before the mixer is initialized, since the driver's volume range 41 // results before the mixer is initialized, since the driver's volume range
29 // isn't known at that point. This could be avoided if AudioMixer objects 42 // isn't known at that point. This could be avoided if AudioMixer objects
30 // instead took percentages and did their own conversions to decibels. 43 // instead took percentages and did their own conversions to decibels.
31 bool IsInitialized(); 44 static AudioHandler* GetInstanceIfInitialized();
32 45
33 // Gets volume level in our internal 0-100% range, 0 being pure silence. 46 // Gets volume level in our internal 0-100% range, 0 being pure silence.
34 double GetVolumePercent(); 47 double GetVolumePercent();
35 48
36 // Sets volume level from 0-100%. 49 // Sets volume level from 0-100%.
37 void SetVolumePercent(double volume_percent); 50 void SetVolumePercent(double volume_percent);
38 51
39 // Adjusts volume up (positive percentage) or down (negative percentage). 52 // Adjusts volume up (positive percentage) or down (negative percentage).
40 void AdjustVolumeByPercent(double adjust_by_percent); 53 void AdjustVolumeByPercent(double adjust_by_percent);
41 54
42 // Is the volume currently muted? 55 // Is the volume currently muted?
43 bool IsMuted(); 56 bool IsMuted();
44 57
45 // Mutes or unmutes all audio. 58 // Mutes or unmutes all audio.
46 void SetMuted(bool do_mute); 59 void SetMuted(bool do_mute);
47 60
61 void AddVolumeObserver(VolumeObserver* observer);
62 void RemoveVolumeObserver(VolumeObserver* observer);
63
48 private: 64 private:
49 // Defines the delete on exit Singleton traits we like. Best to have this 65 // Defines the delete on exit Singleton traits we like. Best to have this
50 // and constructor/destructor private as recommended for Singletons. 66 // and constructor/destructor private as recommended for Singletons.
51 friend struct DefaultSingletonTraits<AudioHandler>; 67 friend struct DefaultSingletonTraits<AudioHandler>;
52 68
53 AudioHandler(); 69 AudioHandler();
54 virtual ~AudioHandler(); 70 virtual ~AudioHandler();
55 71
72 bool IsMixerInitialized();
73
56 // Conversion between our internal scaling (0-100%) and decibels. 74 // Conversion between our internal scaling (0-100%) and decibels.
57 double VolumeDbToPercent(double volume_db) const; 75 double VolumeDbToPercent(double volume_db) const;
58 double PercentToVolumeDb(double volume_percent) const; 76 double PercentToVolumeDb(double volume_percent) const;
59 77
60 scoped_ptr<AudioMixer> mixer_; 78 scoped_ptr<AudioMixer> mixer_;
61 79
80 ObserverList<VolumeObserver> volume_observers_;
81
62 DISALLOW_COPY_AND_ASSIGN(AudioHandler); 82 DISALLOW_COPY_AND_ASSIGN(AudioHandler);
63 }; 83 };
64 84
65 } // namespace chromeos 85 } // namespace chromeos
66 86
67 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_ 87 #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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698