summaryrefslogtreecommitdiffstats
path: root/media/audio/audio_input_controller.cc
diff options
context:
space:
mode:
authorjbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-27 00:18:57 +0000
committerjbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-27 00:18:57 +0000
commitdf9076ace1150780d9f696942f1aa377f3ffad9a (patch)
tree44426a38c6f222699f028a4d2a02e4f6095c35f5 /media/audio/audio_input_controller.cc
parent43866cd42bd433961d3b631ebbd9afe2ae85699f (diff)
downloadchromium_src-df9076ace1150780d9f696942f1aa377f3ffad9a.zip
chromium_src-df9076ace1150780d9f696942f1aa377f3ffad9a.tar.gz
chromium_src-df9076ace1150780d9f696942f1aa377f3ffad9a.tar.bz2
Revert 129018 - Revert 128993 - Refactor BaseTimer to avoid spamming the MessageLoop with orphaned tasks.
This change maintains the same API promises*, but instead of orphaning tasks when they are stopped, the BaseTimer_Helper class holds on to the task until either (1) it expires or (2) the user requests a delay that would arrive earlier than the pending task. If the user requests a longer delay than the pending task, a followup task will be posted when the pending task fires to span the remaining time. * The one change of usage is related to threading. The threading requirements are now more strict. It is not allowed to destruct a timer on a different thread than the one used to post tasks. A thread ID DCHECK is now in place that will help catch misuse. Some existing instances are changed as part of this CL. A side effect of this change is that the BaseTimer and DelayTimer are simplified to use features of BaseTimer_Helper (which is now called Timer). As suggested in timer.h, I ran the disabled TimerTest tests from linux, and they pass consistently. I also added some new tests to verify correct run states. BUG=117451,103667,119714,119750 Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=128412 Reverted: http://src.chromium.org/viewvc/chrome?view=rev&revision=128506 Review URL: https://chromiumcodereview.appspot.com/9655006 TBR=jbates@chromium.org Review URL: https://chromiumcodereview.appspot.com/9791009 TBR=aa@chromium.org Review URL: https://chromiumcodereview.appspot.com/9860014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@129062 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/audio_input_controller.cc')
-rw-r--r--media/audio/audio_input_controller.cc16
1 files changed, 11 insertions, 5 deletions
diff --git a/media/audio/audio_input_controller.cc b/media/audio/audio_input_controller.cc
index 67623da..bf6f2ea 100644
--- a/media/audio/audio_input_controller.cc
+++ b/media/audio/audio_input_controller.cc
@@ -23,13 +23,13 @@ AudioInputController::AudioInputController(EventHandler* handler,
: creator_loop_(base::MessageLoopProxy::current()),
handler_(handler),
stream_(NULL),
- ALLOW_THIS_IN_INITIALIZER_LIST(no_data_timer_(FROM_HERE,
- base::TimeDelta::FromSeconds(kTimerResetInterval),
- this,
- &AudioInputController::DoReportNoDataError)),
state_(kEmpty),
sync_writer_(sync_writer) {
DCHECK(creator_loop_);
+ no_data_timer_.reset(new base::DelayTimer<AudioInputController>(FROM_HERE,
+ base::TimeDelta::FromSeconds(kTimerResetInterval),
+ this,
+ &AudioInputController::DoReportNoDataError));
}
AudioInputController::~AudioInputController() {
@@ -103,6 +103,11 @@ void AudioInputController::Record() {
void AudioInputController::Close(const base::Closure& closed_task) {
DCHECK(!closed_task.is_null());
+ DCHECK(creator_loop_->BelongsToCurrentThread());
+ // See crbug.com/119783: Deleting the timer now to avoid disaster if
+ // AudioInputController is destructed on a thread other than the creator
+ // thread.
+ no_data_timer_.reset();
message_loop_->PostTaskAndReply(
FROM_HERE, base::Bind(&AudioInputController::DoClose, this), closed_task);
}
@@ -180,7 +185,8 @@ void AudioInputController::DoReportNoDataError() {
void AudioInputController::DoResetNoDataTimer() {
DCHECK(creator_loop_->BelongsToCurrentThread());
- no_data_timer_.Reset();
+ if (no_data_timer_.get())
+ no_data_timer_->Reset();
}
void AudioInputController::OnData(AudioInputStream* stream, const uint8* data,