Chromium Code Reviews| Index: chromeos/audio/audio_devices_pref_handler_impl.cc |
| diff --git a/chromeos/audio/audio_devices_pref_handler_impl.cc b/chromeos/audio/audio_devices_pref_handler_impl.cc |
| index 17b5681ebce457ca4feffe8a9f1479fa95ee4832..124e1dc6b901e060190dc5ce1feb7820f5d346f3 100644 |
| --- a/chromeos/audio/audio_devices_pref_handler_impl.cc |
| +++ b/chromeos/audio/audio_devices_pref_handler_impl.cc |
| @@ -31,8 +31,8 @@ const int kPrefMuteOn = 1; |
| // them. |
| std::string GetDeviceIdString(const chromeos::AudioDevice& device) { |
| std::string device_id_string = |
| - device.device_name + " : " + |
| - base::Uint64ToString(device.id & static_cast<uint64>(0xffffffff)) + |
| + base::Uint64ToString(device.stable_device_id & |
| + static_cast<uint64>(0xffffffff)) + |
| " : " + (device.is_input ? "1" : "0"); |
| // Replace any periods from the device id string with a space, since setting |
| // names cannot contain periods. |
| @@ -85,6 +85,27 @@ void AudioDevicesPrefHandlerImpl::SetMuteValue(const AudioDevice& device, |
| SaveDevicesMutePref(); |
| } |
| +AudioDeviceState AudioDevicesPrefHandlerImpl::GetDeviceState( |
| + const AudioDevice& device) { |
| + UpdateDevicesStatePref(); |
| + std::string device_id_str = GetDeviceIdString(device); |
| + if (!device_state_settings_->HasKey(device_id_str)) { |
| + device_state_settings_->SetInteger(device_id_str, |
| + (int)AUDIO_STATE_NOT_AVAILABLE); |
|
jennyz
2015/12/17 22:50:21
I guess this is what you mean in the .h comment fo
hychao
2015/12/29 10:57:25
Updated the header file.
|
| + SaveDevicesStatePref(); |
| + } |
| + int state = (int)AUDIO_STATE_NOT_AVAILABLE; |
| + device_state_settings_->GetInteger(device_id_str, &state); |
| + return (AudioDeviceState)state; |
| +} |
| + |
| +void AudioDevicesPrefHandlerImpl::SetDeviceState(const AudioDevice& device, |
| + AudioDeviceState state) { |
| + device_state_settings_->SetInteger(GetDeviceIdString(device), |
| + (int)state); |
| + SaveDevicesStatePref(); |
| +} |
| + |
| bool AudioDevicesPrefHandlerImpl::GetAudioOutputAllowedValue() { |
| return local_state_->GetBoolean(prefs::kAudioOutputAllowed); |
| } |
| @@ -130,6 +151,7 @@ AudioDevicesPrefHandlerImpl::AudioDevicesPrefHandlerImpl( |
| PrefService* local_state) |
| : device_mute_settings_(new base::DictionaryValue()), |
| device_volume_settings_(new base::DictionaryValue()), |
| + device_state_settings_(new base::DictionaryValue()), |
| local_state_(local_state) { |
| InitializePrefObservers(); |
| @@ -186,6 +208,26 @@ void AudioDevicesPrefHandlerImpl::SaveDevicesVolumePref() { |
| } |
| } |
| +void AudioDevicesPrefHandlerImpl::UpdateDevicesStatePref() { |
| + const base::DictionaryValue* state_prefs = |
| + local_state_->GetDictionary(prefs::kAudioDevicesState); |
| + if (state_prefs) |
| + device_state_settings_.reset(state_prefs->DeepCopy()); |
| +} |
| + |
| +void AudioDevicesPrefHandlerImpl::SaveDevicesStatePref() { |
| + DictionaryPrefUpdate dict_update(local_state_, |
| + prefs::kAudioDevicesState); |
| + base::DictionaryValue::Iterator it(*device_state_settings_); |
| + while (!it.IsAtEnd()) { |
| + int state = AUDIO_STATE_NOT_AVAILABLE; |
| + bool success = it.value().GetAsInteger(&state); |
| + DCHECK(success); |
| + dict_update->SetInteger(it.key(), state); |
| + it.Advance(); |
| + } |
| +} |
| + |
| void AudioDevicesPrefHandlerImpl::MigrateDeviceMuteSettings( |
| const std::string& active_device) { |
| int old_mute = local_state_->GetInteger(prefs::kAudioMute); |
| @@ -210,6 +252,7 @@ void AudioDevicesPrefHandlerImpl::NotifyAudioPolicyChange() { |
| void AudioDevicesPrefHandlerImpl::RegisterPrefs(PrefRegistrySimple* registry) { |
| registry->RegisterDictionaryPref(prefs::kAudioDevicesVolumePercent); |
| registry->RegisterDictionaryPref(prefs::kAudioDevicesMute); |
| + registry->RegisterDictionaryPref(prefs::kAudioDevicesState); |
| // Register the prefs backing the audio muting policies. |
| // Policy for audio input is handled by kAudioCaptureAllowed in the Chrome |