Chromium Code Reviews| 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_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/notification_service.h" | |
| 23 | 22 |
| 24 using std::max; | 23 using std::max; |
| 25 using std::min; | 24 using std::min; |
| 26 | 25 |
| 27 namespace chromeos { | 26 namespace chromeos { |
| 28 | 27 |
| 29 namespace { | 28 namespace { |
| 30 | 29 |
| 31 // Default value for the volume pref, as a percent in the range [0.0, 100.0]. | 30 // Default value for the volume pref, as a percent in the range [0.0, 100.0]. |
| 32 const double kDefaultVolumePercent = 75.0; | 31 const double kDefaultVolumePercent = 75.0; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 } | 153 } |
| 155 | 154 |
| 156 void AudioHandler::AddVolumeObserver(VolumeObserver* observer) { | 155 void AudioHandler::AddVolumeObserver(VolumeObserver* observer) { |
| 157 volume_observers_.AddObserver(observer); | 156 volume_observers_.AddObserver(observer); |
| 158 } | 157 } |
| 159 | 158 |
| 160 void AudioHandler::RemoveVolumeObserver(VolumeObserver* observer) { | 159 void AudioHandler::RemoveVolumeObserver(VolumeObserver* observer) { |
| 161 volume_observers_.RemoveObserver(observer); | 160 volume_observers_.RemoveObserver(observer); |
| 162 } | 161 } |
| 163 | 162 |
| 164 void AudioHandler::Observe(int type, | 163 void AudioHandler::OnPreferenceChanged(PrefServiceBase* service, |
| 165 const content::NotificationSource& source, | 164 const std::string& pref_name) { |
| 166 const content::NotificationDetails& details) { | 165 DCHECK(pref_name == prefs::kAudioOutputAllowed || |
| 167 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 166 pref_name == prefs::kAudioCaptureAllowed); |
|
Mattias Nissler (ping if slow)
2012/10/30 13:37:07
This should probably be
if(..)
ApplyAudioPolicy
| |
| 168 std::string* pref_name = content::Details<std::string>(details).ptr(); | 167 ApplyAudioPolicy(); |
| 169 if (*pref_name == prefs::kAudioOutputAllowed || | |
| 170 *pref_name == prefs::kAudioCaptureAllowed) { | |
| 171 ApplyAudioPolicy(); | |
| 172 } | |
| 173 } else { | |
| 174 NOTREACHED() << "Unexpected notification type : " << type; | |
| 175 } | |
| 176 } | 168 } |
| 177 | 169 |
| 178 AudioHandler::AudioHandler(AudioMixer* mixer) | 170 AudioHandler::AudioHandler(AudioMixer* mixer) |
| 179 : mixer_(mixer), | 171 : mixer_(mixer), |
| 180 local_state_(g_browser_process->local_state()) { | 172 local_state_(g_browser_process->local_state()) { |
| 181 InitializePrefObservers(); | 173 InitializePrefObservers(); |
| 182 ApplyAudioPolicy(); | 174 ApplyAudioPolicy(); |
| 183 SetVolumePercent(local_state_->GetDouble(prefs::kAudioVolumePercent)); | 175 SetVolumePercent(local_state_->GetDouble(prefs::kAudioVolumePercent)); |
| 184 mixer_->Init(); | 176 mixer_->Init(); |
| 185 } | 177 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 207 mixer_->SetCaptureMuteLocked(false); | 199 mixer_->SetCaptureMuteLocked(false); |
| 208 if (local_state_->GetBoolean(prefs::kAudioCaptureAllowed)) { | 200 if (local_state_->GetBoolean(prefs::kAudioCaptureAllowed)) { |
| 209 mixer_->SetCaptureMuted(false); | 201 mixer_->SetCaptureMuted(false); |
| 210 } else { | 202 } else { |
| 211 mixer_->SetCaptureMuted(true); | 203 mixer_->SetCaptureMuted(true); |
| 212 mixer_->SetCaptureMuteLocked(true); | 204 mixer_->SetCaptureMuteLocked(true); |
| 213 } | 205 } |
| 214 } | 206 } |
| 215 | 207 |
| 216 } // namespace chromeos | 208 } // namespace chromeos |
| OLD | NEW |