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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...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 AudioDeviceState AudioDevicesPrefHandlerImpl::GetDeviceState( | 88 void AudioDevicesPrefHandlerImpl::SetDeviceActive(const AudioDevice& device, |
89 const AudioDevice& device) { | 89 bool active, |
90 std::string device_id_str = GetDeviceIdString(device); | 90 bool activate_by_user) { |
91 if (!device_state_settings_->HasKey(device_id_str)) { | 91 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
92 device_state_settings_->SetInteger( | 92 dict->SetBoolean("active", active); |
93 device_id_str, static_cast<int>(AUDIO_STATE_NOT_AVAILABLE)); | 93 if (active) |
94 SaveDevicesStatePref(); | 94 dict->SetBoolean("activate_by_user", activate_by_user); |
95 } | |
96 int state = static_cast<int>(AUDIO_STATE_NOT_AVAILABLE); | |
97 device_state_settings_->GetInteger(device_id_str, &state); | |
98 return (AudioDeviceState)state; | |
99 } | |
100 | 95 |
101 void AudioDevicesPrefHandlerImpl::SetDeviceState(const AudioDevice& device, | 96 device_state_settings_->Set(GetDeviceIdString(device), std::move(dict)); |
102 AudioDeviceState state) { | |
103 device_state_settings_->SetInteger(GetDeviceIdString(device), | |
104 static_cast<int>(state)); | |
105 SaveDevicesStatePref(); | 97 SaveDevicesStatePref(); |
106 } | 98 } |
107 | 99 |
| 100 bool AudioDevicesPrefHandlerImpl::GetDeviceActive(const AudioDevice& device, |
| 101 bool* active, |
| 102 bool* activate_by_user) { |
| 103 const std::string device_id_str = GetDeviceIdString(device); |
| 104 if (!device_state_settings_->HasKey(device_id_str)) |
| 105 return false; |
| 106 |
| 107 base::DictionaryValue* dict = NULL; |
| 108 if (!device_state_settings_->GetDictionary(device_id_str, &dict)) { |
| 109 LOG(ERROR) << "Could not get device state for device:" << device.ToString(); |
| 110 return false; |
| 111 } |
| 112 if (!dict->GetBoolean("active", active)) { |
| 113 LOG(ERROR) << "Could not get active value for device:" << device.ToString(); |
| 114 return false; |
| 115 } |
| 116 |
| 117 if (*active && !dict->GetBoolean("activate_by_user", activate_by_user)) { |
| 118 LOG(ERROR) << "Could not get activate_by_user value for previously " |
| 119 "active device:" |
| 120 << device.ToString(); |
| 121 return false; |
| 122 } |
| 123 |
| 124 return true; |
| 125 } |
| 126 |
108 bool AudioDevicesPrefHandlerImpl::GetAudioOutputAllowedValue() { | 127 bool AudioDevicesPrefHandlerImpl::GetAudioOutputAllowedValue() { |
109 return local_state_->GetBoolean(prefs::kAudioOutputAllowed); | 128 return local_state_->GetBoolean(prefs::kAudioOutputAllowed); |
110 } | 129 } |
111 | 130 |
112 void AudioDevicesPrefHandlerImpl::AddAudioPrefObserver( | 131 void AudioDevicesPrefHandlerImpl::AddAudioPrefObserver( |
113 AudioPrefObserver* observer) { | 132 AudioPrefObserver* observer) { |
114 observers_.AddObserver(observer); | 133 observers_.AddObserver(observer); |
115 } | 134 } |
116 | 135 |
117 void AudioDevicesPrefHandlerImpl::RemoveAudioPrefObserver( | 136 void AudioDevicesPrefHandlerImpl::RemoveAudioPrefObserver( |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 // media system. | 256 // media system. |
238 registry->RegisterBooleanPref(prefs::kAudioOutputAllowed, true); | 257 registry->RegisterBooleanPref(prefs::kAudioOutputAllowed, true); |
239 | 258 |
240 // Register the legacy audio prefs for migration. | 259 // Register the legacy audio prefs for migration. |
241 registry->RegisterDoublePref(prefs::kAudioVolumePercent, | 260 registry->RegisterDoublePref(prefs::kAudioVolumePercent, |
242 kDefaultOutputVolumePercent); | 261 kDefaultOutputVolumePercent); |
243 registry->RegisterIntegerPref(prefs::kAudioMute, kPrefMuteOff); | 262 registry->RegisterIntegerPref(prefs::kAudioMute, kPrefMuteOff); |
244 } | 263 } |
245 | 264 |
246 } // namespace chromeos | 265 } // namespace chromeos |
OLD | NEW |