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 #include "chrome/browser/chromeos/audio/audio_handler.h" | 5 #include "chrome/browser/chromeos/audio/audio_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #if defined(USE_CRAS) | 15 #if defined(USE_CRAS) |
16 #include "chrome/browser/chromeos/audio/audio_mixer_cras.h" | 16 #include "chrome/browser/chromeos/audio/audio_mixer_cras.h" |
17 #else | 17 #else |
18 #include "chrome/browser/chromeos/audio/audio_mixer_alsa.h" | 18 #include "chrome/browser/chromeos/audio/audio_mixer_alsa.h" |
19 #endif | 19 #endif |
20 #include "chrome/browser/prefs/pref_registry_simple.h" | |
20 #include "chrome/browser/prefs/pref_service.h" | 21 #include "chrome/browser/prefs/pref_service.h" |
Mattias Nissler (ping if slow)
2013/01/31 13:06:25
required?
Jói
2013/01/31 13:43:42
Removed.
| |
21 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
23 | 24 |
24 using std::max; | 25 using std::max; |
25 using std::min; | 26 using std::min; |
26 | 27 |
27 namespace chromeos { | 28 namespace chromeos { |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 } | 73 } |
73 | 74 |
74 // static | 75 // static |
75 AudioHandler* AudioHandler::GetInstance() { | 76 AudioHandler* AudioHandler::GetInstance() { |
76 VLOG_IF(1, !g_audio_handler) | 77 VLOG_IF(1, !g_audio_handler) |
77 << "AudioHandler::GetInstance() called with NULL global instance."; | 78 << "AudioHandler::GetInstance() called with NULL global instance."; |
78 return g_audio_handler; | 79 return g_audio_handler; |
79 } | 80 } |
80 | 81 |
81 // static | 82 // static |
82 void AudioHandler::RegisterPrefs(PrefServiceSimple* local_state) { | 83 void AudioHandler::RegisterPrefs(PrefRegistrySimple* local_state) { |
83 if (!local_state->FindPreference(prefs::kAudioVolumePercent)) { | 84 local_state->RegisterDoublePref(prefs::kAudioVolumePercent, |
84 local_state->RegisterDoublePref(prefs::kAudioVolumePercent, | 85 kDefaultVolumePercent); |
85 kDefaultVolumePercent); | 86 local_state->RegisterIntegerPref(prefs::kAudioMute, |
86 } | 87 kPrefMuteOff); |
87 if (!local_state->FindPreference(prefs::kAudioMute)) { | 88 // Register the prefs backing the audio muting policies. |
88 local_state->RegisterIntegerPref(prefs::kAudioMute, | 89 local_state->RegisterBooleanPref(prefs::kAudioOutputAllowed, |
89 kPrefMuteOff); | 90 true); |
90 } | |
91 | |
92 if (!local_state->FindPreference(prefs::kAudioOutputAllowed)) { | |
93 // Register the prefs backing the audio muting policies. | |
94 local_state->RegisterBooleanPref(prefs::kAudioOutputAllowed, | |
95 true); | |
96 } | |
97 // This pref has moved to the media subsystem but we should verify it is there | 91 // This pref has moved to the media subsystem but we should verify it is there |
98 // before we use it. | 92 // before we use it. |
99 if (!local_state->FindPreference(prefs::kAudioCaptureAllowed)) { | 93 local_state->RegisterBooleanPref(prefs::kAudioCaptureAllowed, |
100 local_state->RegisterBooleanPref(prefs::kAudioCaptureAllowed, | 94 true); |
101 true); | |
102 } | |
103 } | 95 } |
104 | 96 |
105 double AudioHandler::GetVolumePercent() { | 97 double AudioHandler::GetVolumePercent() { |
106 return mixer_->GetVolumePercent(); | 98 return mixer_->GetVolumePercent(); |
107 } | 99 } |
108 | 100 |
109 void AudioHandler::SetVolumePercent(double volume_percent) { | 101 void AudioHandler::SetVolumePercent(double volume_percent) { |
110 volume_percent = min(max(volume_percent, 0.0), 100.0); | 102 volume_percent = min(max(volume_percent, 0.0), 100.0); |
111 if (volume_percent <= kMuteThresholdPercent) | 103 if (volume_percent <= kMuteThresholdPercent) |
112 volume_percent = 0.0; | 104 volume_percent = 0.0; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 mixer_->SetCaptureMuteLocked(false); | 192 mixer_->SetCaptureMuteLocked(false); |
201 if (local_state_->GetBoolean(prefs::kAudioCaptureAllowed)) { | 193 if (local_state_->GetBoolean(prefs::kAudioCaptureAllowed)) { |
202 mixer_->SetCaptureMuted(false); | 194 mixer_->SetCaptureMuted(false); |
203 } else { | 195 } else { |
204 mixer_->SetCaptureMuted(true); | 196 mixer_->SetCaptureMuted(true); |
205 mixer_->SetCaptureMuteLocked(true); | 197 mixer_->SetCaptureMuteLocked(true); |
206 } | 198 } |
207 } | 199 } |
208 | 200 |
209 } // namespace chromeos | 201 } // namespace chromeos |
OLD | NEW |