Chromium Code Reviews| Index: chromeos/audio/cras_audio_handler.cc |
| diff --git a/chromeos/audio/cras_audio_handler.cc b/chromeos/audio/cras_audio_handler.cc |
| index 94c032e329554a7d0b40ae27e2e7bc409a445ca3..c67f078a42561b6e80570ae3c8649b5e86034be4 100644 |
| --- a/chromeos/audio/cras_audio_handler.cc |
| +++ b/chromeos/audio/cras_audio_handler.cc |
| @@ -301,7 +301,8 @@ CrasAudioHandler::CrasAudioHandler( |
| has_alternative_input_(false), |
| has_alternative_output_(false), |
| output_mute_locked_(false), |
| - input_mute_locked_(false) { |
| + input_mute_locked_(false), |
| + enable_log_(false) { |
| if (!audio_pref_handler.get()) |
| return; |
| // If the DBusThreadManager or the CrasAudioClient aren't available, there |
| @@ -312,6 +313,10 @@ CrasAudioHandler::CrasAudioHandler( |
| return; |
| chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->AddObserver(this); |
| audio_pref_handler_->AddAudioPrefObserver(this); |
| + if (chromeos::DBusThreadManager::Get()->GetSessionManagerClient()) { |
| + chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> |
| + AddObserver(this); |
| + } |
| InitializeAudioState(); |
| } |
| @@ -322,6 +327,8 @@ CrasAudioHandler::~CrasAudioHandler() { |
| return; |
| chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> |
| RemoveObserver(this); |
| + chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> |
| + RemoveObserver(this); |
| if (audio_pref_handler_.get()) |
| audio_pref_handler_->RemoveAudioPrefObserver(this); |
| audio_pref_handler_ = NULL; |
| @@ -341,8 +348,13 @@ void CrasAudioHandler::ActiveOutputNodeChanged(uint64 node_id) { |
| return; |
| // Active audio output device should always be changed by chrome. |
| - LOG(WARNING) << "Active output node changed unexpectedly by system node_id=" |
| - << "0x" << std::hex << node_id; |
| + // During system boot, cras may change active input to unknown device 0x1, |
| + // we don't need to log it, since it is not an valid device. |
| + if (GetDeviceFromId(node_id)) { |
| + LOG_IF(WARNING, enable_log_) |
| + << "Active output node changed unexpectedly by system node_id=" |
| + << "0x" << std::hex << node_id; |
| + } |
| } |
| void CrasAudioHandler::ActiveInputNodeChanged(uint64 node_id) { |
| @@ -350,14 +362,23 @@ void CrasAudioHandler::ActiveInputNodeChanged(uint64 node_id) { |
| return; |
| // Active audio input device should always be changed by chrome. |
| - LOG(WARNING) << "Active input node changed unexpectedly by system node_id=" |
| - << "0x" << std::hex << node_id; |
| + // During system boot, cras may change active input to unknown device 0x2, |
| + // we don't need to log it, since it is not an valid device. |
| + if (GetDeviceFromId(node_id)) { |
| + LOG_IF(WARNING, enable_log_) |
| + << "Active input node changed unexpectedly by system node_id=" |
| + << "0x" << std::hex << node_id; |
| + } |
| } |
| void CrasAudioHandler::OnAudioPolicyPrefChanged() { |
| ApplyAudioPolicy(); |
| } |
| +void CrasAudioHandler::EmitLoginPromptVisibleCalled() { |
| + enable_log_ = true; |
|
Daniel Erat
2013/09/12 21:10:05
what happens if chrome crashes and is restarted? i
jennyz
2013/09/12 22:34:45
Good pointed, enable CrasAudioHandler logging when
|
| +} |
| + |
| const AudioDevice* CrasAudioHandler::GetDeviceFromId(uint64 device_id) const { |
| AudioDeviceMap::const_iterator it = audio_devices_.find(device_id); |
| if (it == audio_devices_.end()) |
| @@ -370,7 +391,8 @@ void CrasAudioHandler::SetupAudioInputState() { |
| // Set the initial audio state to the ones read from audio prefs. |
| const AudioDevice* device = GetDeviceFromId(active_input_node_id_); |
| if (!device) { |
| - LOG(ERROR) << "Can't set up audio state for unknow input device id =" |
| + LOG_IF(ERROR, enable_log_) |
| + << "Can't set up audio state for unknown input device id =" |
| << "0x" << std::hex << active_input_node_id_; |
| return; |
| } |
| @@ -384,8 +406,9 @@ void CrasAudioHandler::SetupAudioInputState() { |
| void CrasAudioHandler::SetupAudioOutputState() { |
| const AudioDevice* device = GetDeviceFromId(active_output_node_id_); |
| if (!device) { |
| - LOG(ERROR) << "Can't set up audio state for unknow output device id =" |
| - << "0x" << std::hex << active_output_node_id_; |
| + LOG_IF(ERROR, enable_log_) |
| + << "Can't set up audio state for unknown output device id =" |
| + << "0x" << std::hex << active_output_node_id_; |
| return; |
| } |
| output_mute_on_ = audio_pref_handler_->GetMuteValue(*device); |
| @@ -415,7 +438,10 @@ void CrasAudioHandler::ApplyAudioPolicy() { |
| input_mute_locked_ = false; |
| if (audio_pref_handler_->GetAudioCaptureAllowedValue()) { |
| - SetInputMute(false); |
| + // Set input mute if we have discovered active input device. |
| + const AudioDevice* device = GetDeviceFromId(active_input_node_id_); |
| + if (device) |
| + SetInputMuteInternal(false); |
| } else { |
| SetInputMute(true); |
| input_mute_locked_ = true; |
| @@ -455,6 +481,8 @@ bool CrasAudioHandler::SetInputMuteInternal(bool mute_on) { |
| void CrasAudioHandler::GetNodes() { |
| chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->GetNodes( |
| base::Bind(&CrasAudioHandler::HandleGetNodes, |
| + weak_ptr_factory_.GetWeakPtr()), |
| + base::Bind(&CrasAudioHandler::HandleGetNodesError, |
| weak_ptr_factory_.GetWeakPtr())); |
| } |
| @@ -586,7 +614,7 @@ void CrasAudioHandler::UpdateDevicesAndSwitchActive( |
| void CrasAudioHandler::HandleGetNodes(const chromeos::AudioNodeList& node_list, |
| bool success) { |
| if (!success) { |
| - LOG(ERROR) << "Failed to retrieve audio nodes data"; |
| + LOG_IF(ERROR, enable_log_) << "Failed to retrieve audio nodes data"; |
| return; |
| } |
| @@ -594,4 +622,9 @@ void CrasAudioHandler::HandleGetNodes(const chromeos::AudioNodeList& node_list, |
| FOR_EACH_OBSERVER(AudioObserver, observers_, OnAudioNodesChanged()); |
| } |
| +void CrasAudioHandler::HandleGetNodesError(const std::string& error_name, |
| + const std::string& error_msg) { |
| + LOG_IF(ERROR, enable_log_) << "Failed to call GetNodes: " |
| + << error_name << ": " << error_msg; |
| +} |
| } // namespace chromeos |