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 "chrome/browser/chromeos/audio/audio_devices_pref_handler_impl.h" | 5 #include "chrome/browser/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 15 matching lines...) Expand all Loading... |
26 const int kPrefMuteOn = 1; | 26 const int kPrefMuteOn = 1; |
27 | 27 |
28 // Gets the device id string for storing audio preference. The format of | 28 // Gets the device id string for storing audio preference. The format of |
29 // device string is a string consisting of 3 parts. | 29 // device string is a string consisting of 3 parts. |
30 // |device_name| : |integer from lower 32 bit of device id| : | 30 // |device_name| : |integer from lower 32 bit of device id| : |
31 // |0(output device) or 1(input device)| | 31 // |0(output device) or 1(input device)| |
32 // If an audio device has both integrated input and output devices, the first 2 | 32 // If an audio device has both integrated input and output devices, the first 2 |
33 // parts of the string could be identical, only the last part will differentiate | 33 // parts of the string could be identical, only the last part will differentiate |
34 // them. | 34 // them. |
35 std::string GetDeviceIdString(const chromeos::AudioDevice& device) { | 35 std::string GetDeviceIdString(const chromeos::AudioDevice& device) { |
36 return device.device_name + " : " + | 36 std::string device_id_string = |
37 base::Uint64ToString(device.id & static_cast<uint64>(0xffffffff)) + | 37 device.device_name + " : " + |
38 " : " + (device.is_input ? "1" : "0"); | 38 base::Uint64ToString(device.id & static_cast<uint64>(0xffffffff)) + |
| 39 " : " + (device.is_input ? "1" : "0"); |
| 40 // Replace any periods from the device id string with a space, since setting |
| 41 // names cannot contain periods. |
| 42 std::replace(device_id_string.begin(), device_id_string.end(), '.', ' '); |
| 43 return device_id_string; |
39 } | 44 } |
40 | 45 |
41 } // namespace | 46 } // namespace |
42 | 47 |
43 namespace chromeos { | 48 namespace chromeos { |
44 | 49 |
45 double AudioDevicesPrefHandlerImpl::GetOutputVolumeValue( | 50 double AudioDevicesPrefHandlerImpl::GetOutputVolumeValue( |
46 const AudioDevice* device) { | 51 const AudioDevice* device) { |
47 if (!device) | 52 if (!device) |
48 return kDefaultOutputVolume; | 53 return kDefaultOutputVolume; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 UpdateDevicesVolumePref(); | 112 UpdateDevicesVolumePref(); |
108 | 113 |
109 std::string device_id_str = GetDeviceIdString(device); | 114 std::string device_id_str = GetDeviceIdString(device); |
110 if (!device_volume_settings_->HasKey(device_id_str)) | 115 if (!device_volume_settings_->HasKey(device_id_str)) |
111 MigrateDeviceVolumeSettings(device_id_str); | 116 MigrateDeviceVolumeSettings(device_id_str); |
112 | 117 |
113 // TODO(jennyz, rkc): Return a meaningful input gain default value, when | 118 // TODO(jennyz, rkc): Return a meaningful input gain default value, when |
114 // cras has added support for normalizing input gain range. | 119 // cras has added support for normalizing input gain range. |
115 double value = device.is_input ? | 120 double value = device.is_input ? |
116 0.0 : GetDeviceDefaultOutputVolume(device); | 121 0.0 : GetDeviceDefaultOutputVolume(device); |
| 122 // TODO(rkc): The above code is completely ignored since we 'always' have a |
| 123 // default pref value. Fix this. http://crbug.com/442489 |
117 device_volume_settings_->GetDouble(device_id_str, &value); | 124 device_volume_settings_->GetDouble(device_id_str, &value); |
118 | 125 |
119 return value; | 126 return value; |
120 } | 127 } |
121 | 128 |
122 double AudioDevicesPrefHandlerImpl::GetDeviceDefaultOutputVolume( | 129 double AudioDevicesPrefHandlerImpl::GetDeviceDefaultOutputVolume( |
123 const AudioDevice& device) { | 130 const AudioDevice& device) { |
124 if (device.type == AUDIO_TYPE_HDMI) | 131 if (device.type == AUDIO_TYPE_HDMI) |
125 return kDefaultHDMIOutputVolume; | 132 return kDefaultHDMIOutputVolume; |
126 else | 133 else |
127 return kDefaultOutputVolume; | 134 return kDefaultOutputVolume; |
128 } | 135 } |
129 | 136 |
130 AudioDevicesPrefHandlerImpl::AudioDevicesPrefHandlerImpl( | 137 AudioDevicesPrefHandlerImpl::AudioDevicesPrefHandlerImpl( |
131 PrefService* local_state) | 138 PrefService* local_state) |
132 : device_mute_settings_(new base::DictionaryValue()), | 139 : device_mute_settings_(new base::DictionaryValue()), |
133 device_volume_settings_(new base::DictionaryValue()), | 140 device_volume_settings_(new base::DictionaryValue()), |
134 local_state_(local_state) { | 141 local_state_(local_state) { |
135 InitializePrefObservers(); | 142 InitializePrefObservers(); |
136 | 143 |
137 UpdateDevicesMutePref(); | 144 UpdateDevicesMutePref(); |
138 UpdateDevicesVolumePref(); | 145 UpdateDevicesVolumePref(); |
139 } | 146 } |
140 | 147 |
141 AudioDevicesPrefHandlerImpl::~AudioDevicesPrefHandlerImpl() { | 148 AudioDevicesPrefHandlerImpl::~AudioDevicesPrefHandlerImpl() { |
142 }; | 149 } |
143 | 150 |
144 void AudioDevicesPrefHandlerImpl::InitializePrefObservers() { | 151 void AudioDevicesPrefHandlerImpl::InitializePrefObservers() { |
145 pref_change_registrar_.Init(local_state_); | 152 pref_change_registrar_.Init(local_state_); |
146 base::Closure callback = | 153 base::Closure callback = |
147 base::Bind(&AudioDevicesPrefHandlerImpl::NotifyAudioPolicyChange, | 154 base::Bind(&AudioDevicesPrefHandlerImpl::NotifyAudioPolicyChange, |
148 base::Unretained(this)); | 155 base::Unretained(this)); |
149 pref_change_registrar_.Add(prefs::kAudioOutputAllowed, callback); | 156 pref_change_registrar_.Add(prefs::kAudioOutputAllowed, callback); |
150 pref_change_registrar_.Add(prefs::kAudioCaptureAllowed, callback); | 157 pref_change_registrar_.Add(prefs::kAudioCaptureAllowed, callback); |
151 } | 158 } |
152 | 159 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 registry->RegisterIntegerPref(prefs::kAudioMute, kPrefMuteOff); | 232 registry->RegisterIntegerPref(prefs::kAudioMute, kPrefMuteOff); |
226 } | 233 } |
227 | 234 |
228 // static | 235 // static |
229 AudioDevicesPrefHandler* AudioDevicesPrefHandler::Create( | 236 AudioDevicesPrefHandler* AudioDevicesPrefHandler::Create( |
230 PrefService* local_state) { | 237 PrefService* local_state) { |
231 return new AudioDevicesPrefHandlerImpl(local_state); | 238 return new AudioDevicesPrefHandlerImpl(local_state); |
232 } | 239 } |
233 | 240 |
234 } // namespace chromeos | 241 } // namespace chromeos |
OLD | NEW |