OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 "chromeos/audio/audio_devices_pref_handler_impl.h" | 5 #include "chromeos/audio/audio_devices_pref_handler_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 return (mute == kPrefMuteOn); | 78 return (mute == kPrefMuteOn); |
79 } | 79 } |
80 | 80 |
81 void AudioDevicesPrefHandlerImpl::SetMuteValue(const AudioDevice& device, | 81 void AudioDevicesPrefHandlerImpl::SetMuteValue(const AudioDevice& device, |
82 bool mute) { | 82 bool mute) { |
83 device_mute_settings_->SetInteger(GetDeviceIdString(device), | 83 device_mute_settings_->SetInteger(GetDeviceIdString(device), |
84 mute ? kPrefMuteOn : kPrefMuteOff); | 84 mute ? kPrefMuteOn : kPrefMuteOff); |
85 SaveDevicesMutePref(); | 85 SaveDevicesMutePref(); |
86 } | 86 } |
87 | 87 |
88 | |
89 bool AudioDevicesPrefHandlerImpl::GetAudioCaptureAllowedValue() { | |
90 if (audio_capture_allowed_pref_.empty()) | |
91 return true; | |
92 | |
93 return local_state_->GetBoolean(audio_capture_allowed_pref_); | |
94 } | |
95 | |
96 bool AudioDevicesPrefHandlerImpl::GetAudioOutputAllowedValue() { | 88 bool AudioDevicesPrefHandlerImpl::GetAudioOutputAllowedValue() { |
97 return local_state_->GetBoolean(prefs::kAudioOutputAllowed); | 89 return local_state_->GetBoolean(prefs::kAudioOutputAllowed); |
98 } | 90 } |
99 | 91 |
100 void AudioDevicesPrefHandlerImpl::AddAudioPrefObserver( | 92 void AudioDevicesPrefHandlerImpl::AddAudioPrefObserver( |
101 AudioPrefObserver* observer) { | 93 AudioPrefObserver* observer) { |
102 observers_.AddObserver(observer); | 94 observers_.AddObserver(observer); |
103 } | 95 } |
104 | 96 |
105 void AudioDevicesPrefHandlerImpl::RemoveAudioPrefObserver( | 97 void AudioDevicesPrefHandlerImpl::RemoveAudioPrefObserver( |
(...skipping 22 matching lines...) Expand all Loading... |
128 | 120 |
129 double AudioDevicesPrefHandlerImpl::GetDeviceDefaultOutputVolume( | 121 double AudioDevicesPrefHandlerImpl::GetDeviceDefaultOutputVolume( |
130 const AudioDevice& device) { | 122 const AudioDevice& device) { |
131 if (device.type == AUDIO_TYPE_HDMI) | 123 if (device.type == AUDIO_TYPE_HDMI) |
132 return kDefaultHdmiOutputVolumePercent; | 124 return kDefaultHdmiOutputVolumePercent; |
133 else | 125 else |
134 return kDefaultOutputVolumePercent; | 126 return kDefaultOutputVolumePercent; |
135 } | 127 } |
136 | 128 |
137 AudioDevicesPrefHandlerImpl::AudioDevicesPrefHandlerImpl( | 129 AudioDevicesPrefHandlerImpl::AudioDevicesPrefHandlerImpl( |
138 PrefService* local_state, | 130 PrefService* local_state) |
139 const std::string& audio_capture_allowed_pref) | |
140 : device_mute_settings_(new base::DictionaryValue()), | 131 : device_mute_settings_(new base::DictionaryValue()), |
141 device_volume_settings_(new base::DictionaryValue()), | 132 device_volume_settings_(new base::DictionaryValue()), |
142 local_state_(local_state), | 133 local_state_(local_state) { |
143 audio_capture_allowed_pref_(audio_capture_allowed_pref) { | |
144 InitializePrefObservers(); | 134 InitializePrefObservers(); |
145 | 135 |
146 UpdateDevicesMutePref(); | 136 UpdateDevicesMutePref(); |
147 UpdateDevicesVolumePref(); | 137 UpdateDevicesVolumePref(); |
148 } | 138 } |
149 | 139 |
150 AudioDevicesPrefHandlerImpl::~AudioDevicesPrefHandlerImpl() { | 140 AudioDevicesPrefHandlerImpl::~AudioDevicesPrefHandlerImpl() { |
151 } | 141 } |
152 | 142 |
153 void AudioDevicesPrefHandlerImpl::InitializePrefObservers() { | 143 void AudioDevicesPrefHandlerImpl::InitializePrefObservers() { |
154 pref_change_registrar_.Init(local_state_); | 144 pref_change_registrar_.Init(local_state_); |
155 base::Closure callback = | 145 base::Closure callback = |
156 base::Bind(&AudioDevicesPrefHandlerImpl::NotifyAudioPolicyChange, | 146 base::Bind(&AudioDevicesPrefHandlerImpl::NotifyAudioPolicyChange, |
157 base::Unretained(this)); | 147 base::Unretained(this)); |
158 pref_change_registrar_.Add(prefs::kAudioOutputAllowed, callback); | 148 pref_change_registrar_.Add(prefs::kAudioOutputAllowed, callback); |
159 | |
160 if (!audio_capture_allowed_pref_.empty()) | |
161 pref_change_registrar_.Add(audio_capture_allowed_pref_, callback); | |
162 } | 149 } |
163 | 150 |
164 void AudioDevicesPrefHandlerImpl::UpdateDevicesMutePref() { | 151 void AudioDevicesPrefHandlerImpl::UpdateDevicesMutePref() { |
165 const base::DictionaryValue* mute_prefs = | 152 const base::DictionaryValue* mute_prefs = |
166 local_state_->GetDictionary(prefs::kAudioDevicesMute); | 153 local_state_->GetDictionary(prefs::kAudioDevicesMute); |
167 if (mute_prefs) | 154 if (mute_prefs) |
168 device_mute_settings_.reset(mute_prefs->DeepCopy()); | 155 device_mute_settings_.reset(mute_prefs->DeepCopy()); |
169 } | 156 } |
170 | 157 |
171 void AudioDevicesPrefHandlerImpl::SaveDevicesMutePref() { | 158 void AudioDevicesPrefHandlerImpl::SaveDevicesMutePref() { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 SaveDevicesVolumePref(); | 200 SaveDevicesVolumePref(); |
214 } | 201 } |
215 | 202 |
216 void AudioDevicesPrefHandlerImpl::NotifyAudioPolicyChange() { | 203 void AudioDevicesPrefHandlerImpl::NotifyAudioPolicyChange() { |
217 FOR_EACH_OBSERVER(AudioPrefObserver, | 204 FOR_EACH_OBSERVER(AudioPrefObserver, |
218 observers_, | 205 observers_, |
219 OnAudioPolicyPrefChanged()); | 206 OnAudioPolicyPrefChanged()); |
220 } | 207 } |
221 | 208 |
222 // static | 209 // static |
223 void AudioDevicesPrefHandlerImpl::RegisterPrefs( | 210 void AudioDevicesPrefHandlerImpl::RegisterPrefs(PrefRegistrySimple* registry) { |
224 PrefRegistrySimple* registry, | |
225 const std::string& audio_capture_allowed_pref) { | |
226 registry->RegisterDictionaryPref(prefs::kAudioDevicesVolumePercent); | 211 registry->RegisterDictionaryPref(prefs::kAudioDevicesVolumePercent); |
227 registry->RegisterDictionaryPref(prefs::kAudioDevicesMute); | 212 registry->RegisterDictionaryPref(prefs::kAudioDevicesMute); |
228 | 213 |
229 // Register the prefs backing the audio muting policies. | 214 // Register the prefs backing the audio muting policies. |
| 215 // Policy for audio input is handled by kAudioCaptureAllowed in the Chrome |
| 216 // media system. |
230 registry->RegisterBooleanPref(prefs::kAudioOutputAllowed, true); | 217 registry->RegisterBooleanPref(prefs::kAudioOutputAllowed, true); |
231 | 218 |
232 // This pref has moved to the media subsystem but we should verify it is there | |
233 // before we use it. | |
234 // NOTE: This registers the pref in the device-wide local state pref registry. | |
235 // In Chrome the media subsystem also registers kAudioCaptureAllowed in the | |
236 // per-user profile pref registry. | |
237 if (!audio_capture_allowed_pref.empty()) | |
238 registry->RegisterBooleanPref(audio_capture_allowed_pref, true); | |
239 | |
240 // Register the legacy audio prefs for migration. | 219 // Register the legacy audio prefs for migration. |
241 registry->RegisterDoublePref(prefs::kAudioVolumePercent, | 220 registry->RegisterDoublePref(prefs::kAudioVolumePercent, |
242 kDefaultOutputVolumePercent); | 221 kDefaultOutputVolumePercent); |
243 registry->RegisterIntegerPref(prefs::kAudioMute, kPrefMuteOff); | 222 registry->RegisterIntegerPref(prefs::kAudioMute, kPrefMuteOff); |
244 } | 223 } |
245 | 224 |
246 } // namespace chromeos | 225 } // namespace chromeos |
OLD | NEW |