OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/audio/audio_pref_handler_impl.h" |
| 6 |
| 7 #include <algorithm> |
| 8 #include <cmath> |
| 9 |
| 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" |
| 12 #include "base/logging.h" |
| 13 #include "base/prefs/pref_registry_simple.h" |
| 14 #include "base/prefs/pref_service.h" |
| 15 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/common/pref_names.h" |
| 17 |
| 18 using std::max; |
| 19 using std::min; |
| 20 |
| 21 namespace chromeos { |
| 22 |
| 23 namespace { |
| 24 |
| 25 // Default value for the volume pref, as a percent in the range [0.0, 100.0]. |
| 26 const double kDefaultVolumePercent = 75.0; |
| 27 |
| 28 // Values used for muted preference. |
| 29 const int kPrefMuteOff = 0; |
| 30 const int kPrefMuteOn = 1; |
| 31 |
| 32 } // namespace |
| 33 |
| 34 double AudioPrefHandlerImpl::GetOutputVolumeValue() { |
| 35 return local_state_->GetDouble(prefs::kAudioVolumePercent); |
| 36 } |
| 37 |
| 38 void AudioPrefHandlerImpl::SetOutputVolumeValue(double volume_percent) { |
| 39 local_state_->SetDouble(prefs::kAudioVolumePercent, volume_percent); |
| 40 } |
| 41 |
| 42 bool AudioPrefHandlerImpl::GetOutputMuteValue() { |
| 43 return (local_state_->GetInteger(prefs::kAudioMute) == kPrefMuteOn); |
| 44 } |
| 45 |
| 46 void AudioPrefHandlerImpl::SetOutputMuteValue(bool mute) { |
| 47 local_state_->SetInteger(prefs::kAudioMute, |
| 48 mute ? kPrefMuteOn : kPrefMuteOff); |
| 49 } |
| 50 |
| 51 bool AudioPrefHandlerImpl::GetAudioCaptureAllowedValue() { |
| 52 return local_state_->GetBoolean(::prefs::kAudioCaptureAllowed); |
| 53 } |
| 54 |
| 55 bool AudioPrefHandlerImpl::GetAudioOutputAllowedValue() { |
| 56 return local_state_->GetBoolean(prefs::kAudioOutputAllowed); |
| 57 } |
| 58 |
| 59 void AudioPrefHandlerImpl::AddAudioPrefObserver( |
| 60 AudioPrefObserver* observer) { |
| 61 observers_.AddObserver(observer); |
| 62 } |
| 63 |
| 64 void AudioPrefHandlerImpl::RemoveAudioPrefObserver( |
| 65 AudioPrefObserver* observer) { |
| 66 observers_.RemoveObserver(observer); |
| 67 } |
| 68 |
| 69 AudioPrefHandlerImpl::AudioPrefHandlerImpl(PrefService* local_state) |
| 70 : local_state_(local_state) { |
| 71 InitializePrefObservers(); |
| 72 } |
| 73 |
| 74 AudioPrefHandlerImpl::~AudioPrefHandlerImpl() { |
| 75 }; |
| 76 |
| 77 void AudioPrefHandlerImpl::InitializePrefObservers() { |
| 78 pref_change_registrar_.Init(local_state_); |
| 79 base::Closure callback = |
| 80 base::Bind(&AudioPrefHandlerImpl::NotifyAudioPolicyChange, |
| 81 base::Unretained(this)); |
| 82 pref_change_registrar_.Add(prefs::kAudioOutputAllowed, callback); |
| 83 pref_change_registrar_.Add(::prefs::kAudioCaptureAllowed, callback); |
| 84 } |
| 85 |
| 86 void AudioPrefHandlerImpl::NotifyAudioPolicyChange() { |
| 87 FOR_EACH_OBSERVER(AudioPrefObserver, |
| 88 observers_, |
| 89 OnAudioPolicyPrefChanged()); |
| 90 } |
| 91 |
| 92 // static |
| 93 void AudioPrefHandlerImpl::RegisterPrefs(PrefRegistrySimple* registry) { |
| 94 registry->RegisterDoublePref(prefs::kAudioVolumePercent, |
| 95 kDefaultVolumePercent); |
| 96 registry->RegisterIntegerPref(prefs::kAudioMute, kPrefMuteOff); |
| 97 // Register the prefs backing the audio muting policies. |
| 98 registry->RegisterBooleanPref(prefs::kAudioOutputAllowed, true); |
| 99 // This pref has moved to the media subsystem but we should verify it is there |
| 100 // before we use it. |
| 101 registry->RegisterBooleanPref(::prefs::kAudioCaptureAllowed, true); |
| 102 } |
| 103 |
| 104 // static |
| 105 AudioPrefHandler* AudioPrefHandler::Create(PrefService* local_state) { |
| 106 return new AudioPrefHandlerImpl(local_state); |
| 107 } |
| 108 |
| 109 } // namespace chromeos |
OLD | NEW |