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