Chromium Code Reviews| Index: chrome/browser/chromeos/audio/audio_handler.cc |
| diff --git a/chrome/browser/chromeos/audio/audio_handler.cc b/chrome/browser/chromeos/audio/audio_handler.cc |
| index 76eb60a9af31f2e8584ba5b8b559e42073439018..72233f58900739a77758457b2a0aec0b87281635 100644 |
| --- a/chrome/browser/chromeos/audio/audio_handler.cc |
| +++ b/chrome/browser/chromeos/audio/audio_handler.cc |
| @@ -15,9 +15,13 @@ |
| #else |
| #include "chrome/browser/chromeos/audio/audio_mixer_alsa.h" |
| #endif |
| +#include "chrome/browser/chromeos/login/user_manager.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/common/chrome_notification_types.h" |
| #include "chrome/common/pref_names.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/notification_service.h" |
| using std::max; |
| using std::min; |
| @@ -80,6 +84,14 @@ void AudioHandler::RegisterPrefs(PrefService* local_state) { |
| kPrefMuteOff, |
| PrefService::UNSYNCABLE_PREF); |
| + // Register the prefs backing the audio muting policies. |
| + local_state->RegisterBooleanPref(prefs::kAudioOutputEnabled, |
|
Daniel Erat
2012/08/29 15:37:00
i'm a bit concerned that having both kAudioOutputE
pastarmovj
2012/08/29 16:15:52
How strong do you feel about changing the name her
|
| + true, |
| + PrefService::UNSYNCABLE_PREF); |
| + local_state->RegisterBooleanPref(prefs::kAudioCaptureEnabled, |
| + true, |
| + PrefService::UNSYNCABLE_PREF); |
| + |
| // Register the old decibel-based pref so we can clear it. |
| // TODO(derat): Remove this after R20: http://crbug.com/112039 |
| if (!local_state->FindPreference(prefs::kAudioVolumeDb)) |
| @@ -99,7 +111,7 @@ void AudioHandler::SetVolumePercent(double volume_percent) { |
| if (IsMuted() && volume_percent > 0.0) |
| SetMuted(false); |
| mixer_->SetVolumePercent(volume_percent); |
| - prefs_->SetDouble(prefs::kAudioVolumePercent, volume_percent); |
| + local_state_->SetDouble(prefs::kAudioVolumePercent, volume_percent); |
| FOR_EACH_OBSERVER(VolumeObserver, volume_observers_, OnVolumeChanged()); |
| } |
| @@ -112,11 +124,23 @@ bool AudioHandler::IsMuted() { |
| } |
| void AudioHandler::SetMuted(bool mute) { |
| - mixer_->SetMuted(mute); |
| - prefs_->SetInteger(prefs::kAudioMute, mute ? kPrefMuteOn : kPrefMuteOff); |
| + if (!mixer_->IsMuteLocked()) { |
| + mixer_->SetMuted(mute); |
| + local_state_->SetInteger(prefs::kAudioMute, |
| + mute ? kPrefMuteOn : kPrefMuteOff); |
| + } |
| FOR_EACH_OBSERVER(VolumeObserver, volume_observers_, OnMuteToggled()); |
| } |
| +bool AudioHandler::IsCaptureMuted() { |
| + return mixer_->IsCaptureMuted(); |
| +} |
| + |
| +void AudioHandler::SetCaptureMuted(bool mute) { |
| + if (!mixer_->IsCaptureMuteLocked()) |
| + mixer_->SetCaptureMuted(mute); |
| +} |
| + |
| void AudioHandler::AddVolumeObserver(VolumeObserver* observer) { |
| volume_observers_.AddObserver(observer); |
| } |
| @@ -125,11 +149,26 @@ void AudioHandler::RemoveVolumeObserver(VolumeObserver* observer) { |
| volume_observers_.RemoveObserver(observer); |
| } |
| +void AudioHandler::Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
| + std::string* pref_name = content::Details<std::string>(details).ptr(); |
| + if (*pref_name == prefs::kAudioOutputEnabled || |
| + *pref_name == prefs::kAudioCaptureEnabled) { |
| + ApplyAudioPolicy(); |
| + } |
| + } else { |
| + NOTREACHED(); |
|
Daniel Erat
2012/08/29 15:37:00
nit: NOTREACHED() << "Unexpected notification " <<
pastarmovj
2012/08/29 16:15:52
Done.
|
| + } |
| +} |
| + |
| AudioHandler::AudioHandler(AudioMixer* mixer) |
| : mixer_(mixer), |
| - prefs_(g_browser_process->local_state()) { |
| - mixer_->SetVolumePercent(prefs_->GetDouble(prefs::kAudioVolumePercent)); |
| - mixer_->SetMuted(prefs_->GetInteger(prefs::kAudioMute) == kPrefMuteOn); |
| + local_state_(g_browser_process->local_state()) { |
| + InitializePrefObservers(); |
| + ApplyAudioPolicy(); |
| + mixer_->SetVolumePercent(local_state_->GetDouble(prefs::kAudioVolumePercent)); |
| mixer_->Init(); |
| } |
| @@ -137,4 +176,30 @@ AudioHandler::~AudioHandler() { |
| mixer_.reset(); |
| }; |
| +void AudioHandler::InitializePrefObservers() { |
| + pref_change_registrar_.Init(local_state_); |
| + pref_change_registrar_.Add(prefs::kAudioOutputEnabled, this); |
| + pref_change_registrar_.Add(prefs::kAudioCaptureEnabled, this); |
| +} |
| + |
| +void AudioHandler::ApplyAudioPolicy() { |
| + if (local_state_->GetBoolean(prefs::kAudioOutputEnabled)) { |
| + mixer_->SetMuteLocked(false); |
| + mixer_->SetMuted( |
| + local_state_->GetInteger(prefs::kAudioMute) == kPrefMuteOn); |
| + } else { |
| + mixer_->SetMuted(true); |
| + mixer_->SetMuteLocked(true); |
| + } |
| + FOR_EACH_OBSERVER(VolumeObserver, volume_observers_, OnMuteToggled()); |
| + if (local_state_->GetBoolean(prefs::kAudioCaptureEnabled)) { |
| + mixer_->SetCaptureMuteLocked(false); |
| + mixer_->SetCaptureMuted(false); |
| + } else { |
| + mixer_->SetCaptureMuted(true); |
| + mixer_->SetCaptureMuteLocked(true); |
| + } |
| +} |
| + |
| + |
| } // namespace chromeos |