Chromium Code Reviews| Index: media/audio/audio_input_controller.cc |
| diff --git a/media/audio/audio_input_controller.cc b/media/audio/audio_input_controller.cc |
| index f7747b9d37fb77b948b34e0daf2e3a8407905f56..f814f271fd519819672dad3972fa756fde1cd7bd 100644 |
| --- a/media/audio/audio_input_controller.cc |
| +++ b/media/audio/audio_input_controller.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/threading/thread_restrictions.h" |
| #include "media/base/limits.h" |
| #include "media/base/scoped_histogram_timer.h" |
| +#include "media/base/user_input_monitor.h" |
| namespace { |
| const int kMaxInputChannels = 2; |
| @@ -46,7 +47,7 @@ AudioInputController::AudioInputController(EventHandler* handler, |
| sync_writer_(sync_writer), |
| max_volume_(0.0), |
| user_input_monitor_(user_input_monitor), |
| - key_pressed_(false) { |
| + prev_key_down_count_(0) { |
| DCHECK(creator_loop_.get()); |
| } |
| @@ -241,8 +242,10 @@ void AudioInputController::DoRecord() { |
| stream_->Start(this); |
| handler_->OnRecording(this); |
| - if (user_input_monitor_) |
| - user_input_monitor_->AddKeyStrokeListener(this); |
| + if (user_input_monitor_) { |
| + user_input_monitor_->EnableKeyPressMonitoring(); |
| + prev_key_down_count_ = user_input_monitor_->GetKeyPressCount(); |
| + } |
| } |
| void AudioInputController::DoClose() { |
| @@ -263,7 +266,7 @@ void AudioInputController::DoClose() { |
| state_ = kClosed; |
| if (user_input_monitor_) |
| - user_input_monitor_->RemoveKeyStrokeListener(this); |
| + user_input_monitor_->DisableKeyPressMonitoring(); |
| } |
| } |
| @@ -333,13 +336,17 @@ void AudioInputController::DoCheckForNoData() { |
| void AudioInputController::OnData(AudioInputStream* stream, const uint8* data, |
| uint32 size, uint32 hardware_delay_bytes, |
| double volume) { |
| - bool key_pressed = false; |
| { |
| base::AutoLock auto_lock(lock_); |
| if (state_ != kRecording) |
| return; |
| + } |
| - std::swap(key_pressed, key_pressed_); |
| + bool key_pressed = false; |
| + if (user_input_monitor_) { |
| + size_t current_count = user_input_monitor_->GetKeyPressCount(); |
| + key_pressed = (current_count != prev_key_down_count_); |
|
Mark Mentovai
2013/08/23 18:09:03
Outer (parentheses) are unnecessary.
|
| + prev_key_down_count_ = current_count; |
| } |
| // Mark data as active to ensure that the periodic calls to |
| @@ -369,11 +376,6 @@ void AudioInputController::OnError(AudioInputStream* stream) { |
| &AudioInputController::DoReportError, this)); |
| } |
| -void AudioInputController::OnKeyStroke() { |
| - base::AutoLock auto_lock(lock_); |
| - key_pressed_ = true; |
| -} |
| - |
| void AudioInputController::DoStopCloseAndClearStream( |
| base::WaitableEvent* done) { |
| DCHECK(message_loop_->BelongsToCurrentThread()); |