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

Side by Side Diff: chromeos/audio/audio_devices_pref_handler_impl.cc

Issue 2270693005: Fix the corner case for new audio device is not selected as active if it is plugged in for the firs… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | chromeos/audio/audio_devices_pref_handler_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "chromeos/audio/audio_device.h" 15 #include "chromeos/audio/audio_device.h"
16 #include "chromeos/chromeos_pref_names.h" 16 #include "chromeos/chromeos_pref_names.h"
17 #include "components/prefs/pref_registry_simple.h" 17 #include "components/prefs/pref_registry_simple.h"
18 #include "components/prefs/pref_service.h" 18 #include "components/prefs/pref_service.h"
19 #include "components/prefs/scoped_user_pref_update.h" 19 #include "components/prefs/scoped_user_pref_update.h"
20 20
21 namespace { 21 namespace {
22 22
23 // Values used for muted preference. 23 // Values used for muted preference.
24 const int kPrefMuteOff = 0; 24 const int kPrefMuteOff = 0;
25 const int kPrefMuteOn = 1; 25 const int kPrefMuteOn = 1;
26 26
27 // Prefs keys.
28 const char kActiveKey[] = "active";
29 const char kActivateByUserKey[] = "activate_by_user";
30
27 // Gets the device id string for storing audio preference. The format of 31 // Gets the device id string for storing audio preference. The format of
28 // device string is a string consisting of 2 parts. 32 // device string is a string consisting of 2 parts.
29 // |integer from lower 32 bit of device id| : 33 // |integer from lower 32 bit of device id| :
30 // |0(output device) or 1(input device)| 34 // |0(output device) or 1(input device)|
31 // If an audio device has both integrated input and output devices, the first 2 35 // If an audio device has both integrated input and output devices, the first 2
32 // parts of the string could be identical, only the last part will differentiate 36 // parts of the string could be identical, only the last part will differentiate
33 // them. 37 // them.
34 std::string GetDeviceIdString(const chromeos::AudioDevice& device) { 38 std::string GetDeviceIdString(const chromeos::AudioDevice& device) {
35 std::string device_id_string = 39 std::string device_id_string =
36 base::Uint64ToString(device.stable_device_id & 40 base::Uint64ToString(device.stable_device_id &
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 bool mute) { 86 bool mute) {
83 device_mute_settings_->SetInteger(GetDeviceIdString(device), 87 device_mute_settings_->SetInteger(GetDeviceIdString(device),
84 mute ? kPrefMuteOn : kPrefMuteOff); 88 mute ? kPrefMuteOn : kPrefMuteOff);
85 SaveDevicesMutePref(); 89 SaveDevicesMutePref();
86 } 90 }
87 91
88 void AudioDevicesPrefHandlerImpl::SetDeviceActive(const AudioDevice& device, 92 void AudioDevicesPrefHandlerImpl::SetDeviceActive(const AudioDevice& device,
89 bool active, 93 bool active,
90 bool activate_by_user) { 94 bool activate_by_user) {
91 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 95 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
92 dict->SetBoolean("active", active); 96 dict->SetBoolean(kActiveKey, active);
93 if (active) 97 if (active)
94 dict->SetBoolean("activate_by_user", activate_by_user); 98 dict->SetBoolean(kActivateByUserKey, activate_by_user);
95 99
96 device_state_settings_->Set(GetDeviceIdString(device), std::move(dict)); 100 device_state_settings_->Set(GetDeviceIdString(device), std::move(dict));
97 SaveDevicesStatePref(); 101 SaveDevicesStatePref();
98 } 102 }
99 103
100 bool AudioDevicesPrefHandlerImpl::GetDeviceActive(const AudioDevice& device, 104 bool AudioDevicesPrefHandlerImpl::GetDeviceActive(const AudioDevice& device,
101 bool* active, 105 bool* active,
102 bool* activate_by_user) { 106 bool* activate_by_user) {
103 const std::string device_id_str = GetDeviceIdString(device); 107 const std::string device_id_str = GetDeviceIdString(device);
104 if (!device_state_settings_->HasKey(device_id_str)) 108 if (!device_state_settings_->HasKey(device_id_str))
105 return false; 109 return false;
106 110
107 base::DictionaryValue* dict = NULL; 111 base::DictionaryValue* dict = NULL;
108 if (!device_state_settings_->GetDictionary(device_id_str, &dict)) { 112 if (!device_state_settings_->GetDictionary(device_id_str, &dict)) {
109 LOG(ERROR) << "Could not get device state for device:" << device.ToString(); 113 LOG(ERROR) << "Could not get device state for device:" << device.ToString();
110 return false; 114 return false;
111 } 115 }
112 if (!dict->GetBoolean("active", active)) { 116 if (!dict->GetBoolean(kActiveKey, active)) {
113 LOG(ERROR) << "Could not get active value for device:" << device.ToString(); 117 LOG(ERROR) << "Could not get active value for device:" << device.ToString();
114 return false; 118 return false;
115 } 119 }
116 120
117 if (*active && !dict->GetBoolean("activate_by_user", activate_by_user)) { 121 if (*active && !dict->GetBoolean(kActivateByUserKey, activate_by_user)) {
118 LOG(ERROR) << "Could not get activate_by_user value for previously " 122 LOG(ERROR) << "Could not get activate_by_user value for previously "
119 "active device:" 123 "active device:"
120 << device.ToString(); 124 << device.ToString();
121 return false; 125 return false;
122 } 126 }
123 127
124 return true; 128 return true;
125 } 129 }
126 130
127 bool AudioDevicesPrefHandlerImpl::GetAudioOutputAllowedValue() { 131 bool AudioDevicesPrefHandlerImpl::GetAudioOutputAllowedValue() {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 // media system. 260 // media system.
257 registry->RegisterBooleanPref(prefs::kAudioOutputAllowed, true); 261 registry->RegisterBooleanPref(prefs::kAudioOutputAllowed, true);
258 262
259 // Register the legacy audio prefs for migration. 263 // Register the legacy audio prefs for migration.
260 registry->RegisterDoublePref(prefs::kAudioVolumePercent, 264 registry->RegisterDoublePref(prefs::kAudioVolumePercent,
261 kDefaultOutputVolumePercent); 265 kDefaultOutputVolumePercent);
262 registry->RegisterIntegerPref(prefs::kAudioMute, kPrefMuteOff); 266 registry->RegisterIntegerPref(prefs::kAudioMute, kPrefMuteOff);
263 } 267 }
264 268
265 } // namespace chromeos 269 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chromeos/audio/audio_devices_pref_handler_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698