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 a8f8036134ead71310d5a6748f4230045971f1f3..be055fbce4dd0df021356207e893320eea1ab089 100644 |
| --- a/chromeos/audio/cras_audio_handler.cc |
| +++ b/chromeos/audio/cras_audio_handler.cc |
| @@ -25,6 +25,11 @@ namespace chromeos { |
| namespace { |
| +enum AutomatedVolumeChangeReason { |
| + VOLUME_CHANGE_INITIALIZING_AUDIO_STATE = 1 << 0, |
| + VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT = 1 << 1, |
| +}; |
| + |
| // Default value for unmuting, as a percent in the range [0, 100]. |
| // Used when sound is unmuted, but volume was less than kMuteThresholdPercent. |
| const int kDefaultUnmuteVolumePercent = 4; |
| @@ -376,6 +381,16 @@ void CrasAudioHandler::SetOutputVolumePercent(int volume_percent) { |
| } |
| } |
| +void CrasAudioHandler::SetOutputVolumePercentWithoutNotifyingObservers( |
| + int volume_percent) { |
| + // Currently SetOutputVolumePercentInQuietMode is only called from |
| + // maximize mode screenshot in PowerButtonController. Everytime this method |
| + // is called, DCHECK if MAXIMIZE_MODE_SCREENSHOT is already released. |
| + DCHECK(!(automated_volume_change_ & VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT)); |
|
Daniel Erat
2016/07/29 17:53:38
this dcheck makes me nervous. if MAXIMIZE_MODE_SCR
Qiang(Joe) Xu
2016/07/29 18:58:23
Your concern is reasonable. I am assuming CRAS is
|
| + automated_volume_change_ |= VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT; |
| + SetOutputVolumePercent(volume_percent); |
| +} |
| + |
| // TODO: Rename the 'Percent' to something more meaningful. |
| void CrasAudioHandler::SetInputGainPercent(int gain_percent) { |
| // TODO(jennyz): Should we set all input devices' gain to the same level? |
| @@ -613,27 +628,38 @@ void CrasAudioHandler::OutputNodeVolumeChanged(uint64_t node_id, int volume) { |
| output_volume_ = volume; |
| audio_pref_handler_->SetVolumeGainValue(*device, volume); |
| - if (initializing_audio_state_) { |
| + bool should_not_notify_observers = false; |
| + if (automated_volume_change_ & VOLUME_CHANGE_INITIALIZING_AUDIO_STATE) { |
| // Do not notify the observers for volume changed event if CrasAudioHandler |
| // is initializing its state, i.e., the volume change event is in responding |
| - // to SetOutputNodeVolume request from intializaing audio state, not |
| - // from user action, no need to notify UI to pop uo the volume slider bar. |
| + // to SetOutputNodeVolume request from intializaing audio state, not from |
|
Daniel Erat
2016/07/29 17:53:38
nit: s/intializaing/initializing/
Qiang(Joe) Xu
2016/07/29 18:58:23
Done.
|
| + // user action, no need to notify UI to pop up the volume slider bar. |
| if (init_node_id_ == node_id && init_volume_ == volume) { |
| init_volume_count_--; |
| if (!init_volume_count_) |
| - initializing_audio_state_ = false; |
| - return; |
| + automated_volume_change_ ^= VOLUME_CHANGE_INITIALIZING_AUDIO_STATE; |
| + should_not_notify_observers = true; |
| } else { |
| - // Reset the initializing_audio_state_ in case SetOutputNodeVolume request |
| - // is lost by cras due to cras is not ready when CrasAudioHandler is being |
| - // initialized. |
| - initializing_audio_state_ = false; |
| + // Reset the INITIALIZING_AUDIO_STATE in case SetOutputNodeVolume request |
| + // is lost by cras due to cras is not ready when CrasAudioHandler is |
| + // being initialized. |
| + automated_volume_change_ ^= VOLUME_CHANGE_INITIALIZING_AUDIO_STATE; |
| init_volume_count_ = 0; |
| } |
| } |
| - FOR_EACH_OBSERVER(AudioObserver, observers_, |
| - OnOutputNodeVolumeChanged(node_id, volume)); |
| + if (automated_volume_change_ & VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT) { |
| + // Do not notify the observers for the volume changed event if that is |
| + // coming from a restoring volume after a maximize mode screenshot is |
| + // taken. Reset the MAXIMIZE_MODE_SCREENSHOT. |
| + automated_volume_change_ ^= VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT; |
| + should_not_notify_observers = true; |
| + } |
| + |
| + if (!should_not_notify_observers) { |
| + FOR_EACH_OBSERVER(AudioObserver, observers_, |
| + OnOutputNodeVolumeChanged(node_id, volume)); |
| + } |
| } |
| void CrasAudioHandler::ActiveOutputNodeChanged(uint64_t node_id) { |
| @@ -738,7 +764,7 @@ void CrasAudioHandler::SetupAudioOutputState() { |
| SetOutputMuteInternal(output_mute_on_); |
| - if (initializing_audio_state_) { |
| + if (automated_volume_change_ & VOLUME_CHANGE_INITIALIZING_AUDIO_STATE) { |
| // During power up, InitializeAudioState() could be called twice, first |
| // by CrasAudioHandler constructor, then by cras server restarting signal, |
| // both sending SetOutputNodeVolume requests, and could lead to two |
| @@ -774,7 +800,7 @@ void CrasAudioHandler::SetupAdditionalActiveAudioNodeState(uint64_t node_id) { |
| } |
| void CrasAudioHandler::InitializeAudioState() { |
| - initializing_audio_state_ = true; |
| + automated_volume_change_ |= VOLUME_CHANGE_INITIALIZING_AUDIO_STATE; |
| ApplyAudioPolicy(); |
| // Defer querying cras for GetNodes until cras service becomes available. |