OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 CHROMEOS_AUDIO_AUDIO_DEVICES_PREF_HANDLER_H_ | 5 #ifndef CHROMEOS_AUDIO_AUDIO_DEVICES_PREF_HANDLER_H_ |
6 #define CHROMEOS_AUDIO_AUDIO_DEVICES_PREF_HANDLER_H_ | 6 #define CHROMEOS_AUDIO_AUDIO_DEVICES_PREF_HANDLER_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "chromeos/audio/audio_pref_observer.h" | 9 #include "chromeos/audio/audio_pref_observer.h" |
10 #include "chromeos/chromeos_export.h" | 10 #include "chromeos/chromeos_export.h" |
11 | 11 |
12 class PrefService; | 12 class PrefService; |
13 | 13 |
14 namespace chromeos { | 14 namespace chromeos { |
15 | 15 |
16 struct AudioDevice; | 16 struct AudioDevice; |
17 | 17 |
18 // Used to represent an audio device's state. This state should be updated | |
19 // to AUDIO_STATE_ACTIVE when it is selected as active or set to | |
20 // AUDIO_STATE_INACTIVE when selected to a different device. When the audio | |
21 // device is unplugged, its last active/inactive state should be stored. | |
22 // The default value of device state will be AUDIO_STATE_NOT_AVAILABLE if | |
23 // the device is not found in the pref settings. | |
24 // Note that these states enum can't be renumbered or it would break existing | |
25 // preference. | |
26 enum AudioDeviceState { | |
27 AUDIO_STATE_ACTIVE = 0, | |
28 AUDIO_STATE_INACTIVE = 1, | |
29 AUDIO_STATE_NOT_AVAILABLE = 2, | |
30 }; | |
31 | |
32 // Interface that handles audio preference related work, reads and writes | 18 // Interface that handles audio preference related work, reads and writes |
33 // audio preferences, and notifies AudioPrefObserver for audio preference | 19 // audio preferences, and notifies AudioPrefObserver for audio preference |
34 // changes. | 20 // changes. |
35 class CHROMEOS_EXPORT AudioDevicesPrefHandler | 21 class CHROMEOS_EXPORT AudioDevicesPrefHandler |
36 : public base::RefCountedThreadSafe<AudioDevicesPrefHandler> { | 22 : public base::RefCountedThreadSafe<AudioDevicesPrefHandler> { |
37 public: | 23 public: |
38 // Integer because C++ does not allow static const double in header files. | 24 // Integer because C++ does not allow static const double in header files. |
39 static const int kDefaultOutputVolumePercent = 75; | 25 static const int kDefaultOutputVolumePercent = 75; |
40 static const int kDefaultHdmiOutputVolumePercent = 100; | 26 static const int kDefaultHdmiOutputVolumePercent = 100; |
41 | 27 |
42 // Gets the audio output volume value from prefs for a device. Since we can | 28 // Gets the audio output volume value from prefs for a device. Since we can |
43 // only have either a gain or a volume for a device (depending on whether it | 29 // only have either a gain or a volume for a device (depending on whether it |
44 // is input or output), we don't really care which value it is. | 30 // is input or output), we don't really care which value it is. |
45 virtual double GetOutputVolumeValue(const AudioDevice* device) = 0; | 31 virtual double GetOutputVolumeValue(const AudioDevice* device) = 0; |
46 virtual double GetInputGainValue(const AudioDevice* device) = 0; | 32 virtual double GetInputGainValue(const AudioDevice* device) = 0; |
47 // Sets the audio volume or gain value to prefs for a device. | 33 // Sets the audio volume or gain value to prefs for a device. |
48 virtual void SetVolumeGainValue(const AudioDevice& device, double value) = 0; | 34 virtual void SetVolumeGainValue(const AudioDevice& device, double value) = 0; |
49 | 35 |
50 // Reads the audio mute value from prefs for a device. | 36 // Reads the audio mute value from prefs for a device. |
51 virtual bool GetMuteValue(const AudioDevice& device) = 0; | 37 virtual bool GetMuteValue(const AudioDevice& device) = 0; |
52 // Sets the audio mute value to prefs for a device. | 38 // Sets the audio mute value to prefs for a device. |
53 virtual void SetMuteValue(const AudioDevice& device, bool mute_on) = 0; | 39 virtual void SetMuteValue(const AudioDevice& device, bool mute_on) = 0; |
54 | 40 |
55 virtual AudioDeviceState GetDeviceState(const AudioDevice& device) = 0; | 41 // Sets the device active state in prefs. |
56 virtual void SetDeviceState(const AudioDevice& device, | 42 // Note: |activate_by_user| indicates whether |device| is set to active |
57 AudioDeviceState state) = 0; | 43 // by user or by priority, and it only matters when |active| is true. |
| 44 virtual void SetDeviceActive(const AudioDevice& device, |
| 45 bool active, |
| 46 bool activate_by_user) = 0; |
| 47 // Returns false if it fails to get device active state from prefs. |
| 48 // Otherwise, returns true, pass the active state data in |*active| |
| 49 // and |*activate_by_user|. |
| 50 // Note: |*activate_by_user| only matters when |*active| is true. |
| 51 virtual bool GetDeviceActive(const AudioDevice& device, |
| 52 bool* active, |
| 53 bool* activate_by_user) = 0; |
58 | 54 |
59 // Reads the audio output allowed value from prefs. | 55 // Reads the audio output allowed value from prefs. |
60 virtual bool GetAudioOutputAllowedValue() = 0; | 56 virtual bool GetAudioOutputAllowedValue() = 0; |
61 | 57 |
62 // Adds an audio preference observer. | 58 // Adds an audio preference observer. |
63 virtual void AddAudioPrefObserver(AudioPrefObserver* observer) = 0; | 59 virtual void AddAudioPrefObserver(AudioPrefObserver* observer) = 0; |
64 // Removes an audio preference observer. | 60 // Removes an audio preference observer. |
65 virtual void RemoveAudioPrefObserver(AudioPrefObserver* observer) = 0; | 61 virtual void RemoveAudioPrefObserver(AudioPrefObserver* observer) = 0; |
66 | 62 |
67 protected: | 63 protected: |
68 virtual ~AudioDevicesPrefHandler() {} | 64 virtual ~AudioDevicesPrefHandler() {} |
69 | 65 |
70 private: | 66 private: |
71 friend class base::RefCountedThreadSafe<AudioDevicesPrefHandler>; | 67 friend class base::RefCountedThreadSafe<AudioDevicesPrefHandler>; |
72 }; | 68 }; |
73 | 69 |
74 } // namespace chromeos | 70 } // namespace chromeos |
75 | 71 |
76 #endif // CHROMEOS_AUDIO_AUDIO_DEVICES_PREF_HANDLER_H_ | 72 #endif // CHROMEOS_AUDIO_AUDIO_DEVICES_PREF_HANDLER_H_ |
OLD | NEW |