Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Unified Diff: chromeos/audio/audio_devices_pref_handler_impl.cc

Issue 1746843002: Persist the user's active audio device choice across chromeos session and reboots. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nits. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 61b2fc5c03f80fdcfd49b8e9b73487d9f935c70b..968fb6ab522305e3f7189942dc744b37ad49cc92 100644
--- a/chromeos/audio/audio_devices_pref_handler_impl.cc
+++ b/chromeos/audio/audio_devices_pref_handler_impl.cc
@@ -85,24 +85,43 @@ void AudioDevicesPrefHandlerImpl::SetMuteValue(const AudioDevice& device,
SaveDevicesMutePref();
}
-AudioDeviceState AudioDevicesPrefHandlerImpl::GetDeviceState(
- const AudioDevice& device) {
- std::string device_id_str = GetDeviceIdString(device);
- if (!device_state_settings_->HasKey(device_id_str)) {
- device_state_settings_->SetInteger(
- device_id_str, static_cast<int>(AUDIO_STATE_NOT_AVAILABLE));
- SaveDevicesStatePref();
- }
- int state = static_cast<int>(AUDIO_STATE_NOT_AVAILABLE);
- device_state_settings_->GetInteger(device_id_str, &state);
- return (AudioDeviceState)state;
+void AudioDevicesPrefHandlerImpl::SetDeviceActive(const AudioDevice& device,
+ bool active,
+ bool activate_by_user) {
+ scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
+ dict->SetBoolean("active", active);
+ if (active)
+ dict->SetBoolean("activate_by_user", activate_by_user);
+
+ device_state_settings_->Set(GetDeviceIdString(device), std::move(dict));
+ SaveDevicesStatePref();
}
-void AudioDevicesPrefHandlerImpl::SetDeviceState(const AudioDevice& device,
- AudioDeviceState state) {
- device_state_settings_->SetInteger(GetDeviceIdString(device),
- static_cast<int>(state));
- SaveDevicesStatePref();
+bool AudioDevicesPrefHandlerImpl::GetDeviceActive(const AudioDevice& device,
+ bool* active,
+ bool* activate_by_user) {
+ const std::string device_id_str = GetDeviceIdString(device);
+ if (!device_state_settings_->HasKey(device_id_str))
+ return false;
+
+ base::DictionaryValue* dict = NULL;
+ if (!device_state_settings_->GetDictionary(device_id_str, &dict)) {
+ LOG(ERROR) << "Could not get device state for device:" << device.ToString();
+ return false;
+ }
+ if (!dict->GetBoolean("active", active)) {
+ LOG(ERROR) << "Could not get active value for device:" << device.ToString();
+ return false;
+ }
+
+ if (*active && !dict->GetBoolean("activate_by_user", activate_by_user)) {
+ LOG(ERROR) << "Could not get activate_by_user value for previously "
+ "active device:"
+ << device.ToString();
+ return false;
+ }
+
+ return true;
}
bool AudioDevicesPrefHandlerImpl::GetAudioOutputAllowedValue() {
« no previous file with comments | « chromeos/audio/audio_devices_pref_handler_impl.h ('k') | chromeos/audio/audio_devices_pref_handler_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698