From 19b88c5ddc50ae43b56fefd354f6bb26ef0937f0 Mon Sep 17 00:00:00 2001 From: "satish@chromium.org" Date: Wed, 1 Sep 2010 14:28:51 +0000 Subject: Fix data race in destroying the info bubble. The info bubble is a member variable of the class and the controller class's lifetime is managed in the IO thread. However the info bubble's lifetime is managed in the UI thread and in this case it was not destroyed before the IO thread was notified of the event. So the IO thread could process the notification and destroy the controller object before it finished with releasing the bubble. This change destroys the bubble before notifying the delegate to prevent such cases. BUG=53765 TEST=running unit_tests --gtest_filter="*Speech*Cancelled*" under RaceChecker should find no data races. Review URL: http://codereview.chromium.org/3328001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58169 0039d316-1c4b-4281-b951-d872f2087c98 --- .../browser/speech/speech_input_bubble_controller.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'chrome') diff --git a/chrome/browser/speech/speech_input_bubble_controller.cc b/chrome/browser/speech/speech_input_bubble_controller.cc index 98bf620..6b7c650 100644 --- a/chrome/browser/speech/speech_input_bubble_controller.cc +++ b/chrome/browser/speech/speech_input_bubble_controller.cc @@ -74,26 +74,32 @@ void SpeechInputBubbleController::SetBubbleToRecognizingMode(int caller_id) { void SpeechInputBubbleController::RecognitionCancelled() { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + + int old_bubble_caller_id = current_bubble_caller_id_; + current_bubble_caller_id_ = 0; + bubble_.reset(); + ChromeThread::PostTask( ChromeThread::IO, FROM_HERE, NewRunnableMethod( this, &SpeechInputBubbleController::InvokeDelegateRecognitionCancelled, - current_bubble_caller_id_)); - current_bubble_caller_id_ = 0; - bubble_.reset(); + old_bubble_caller_id)); } void SpeechInputBubbleController::InfoBubbleClosed() { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + + int old_bubble_caller_id = current_bubble_caller_id_; + current_bubble_caller_id_ = 0; + bubble_.reset(); + ChromeThread::PostTask( ChromeThread::IO, FROM_HERE, NewRunnableMethod( this, &SpeechInputBubbleController::InvokeDelegateFocusChanged, - current_bubble_caller_id_)); - current_bubble_caller_id_ = 0; - bubble_.reset(); + old_bubble_caller_id)); } void SpeechInputBubbleController::InvokeDelegateRecognitionCancelled( -- cgit v1.1