Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1236)

Unified Diff: components/test_runner/mock_web_speech_recognizer.cc

Issue 1737953003: Have mock speech recognizer reset and release its recognizer upon ending. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/test_runner/mock_web_speech_recognizer.cc
diff --git a/components/test_runner/mock_web_speech_recognizer.cc b/components/test_runner/mock_web_speech_recognizer.cc
index 880152a9c3ef9fe09d0a0954d7e56a890e14d66b..9504feab97598ea15e17e3312dec5d44961825bd 100644
--- a/components/test_runner/mock_web_speech_recognizer.cc
+++ b/components/test_runner/mock_web_speech_recognizer.cc
@@ -108,6 +108,28 @@ class ErrorTask : public MockWebSpeechRecognizer::Task {
DISALLOW_COPY_AND_ASSIGN(ErrorTask);
};
+// Task for tidying up after recognition task has ended.
+class EndedTask : public MockWebSpeechRecognizer::Task {
+ public:
+ EndedTask(MockWebSpeechRecognizer* mock,
+ blink::WebSpeechRecognitionHandle handle)
+ : MockWebSpeechRecognizer::Task(mock), handle_(handle) {}
+
+ ~EndedTask() override {}
+
+ void run() override {
+ // Reset recognizer's handle if it hasn't been replaced.
+ if (recognizer_->Handle() == handle_)
+ recognizer_->Handle().reset();
+ handle_.reset();
+ }
+
+ private:
+ blink::WebSpeechRecognitionHandle handle_;
+
+ DISALLOW_COPY_AND_ASSIGN(EndedTask);
+};
+
} // namespace
MockWebSpeechRecognizer::MockWebSpeechRecognizer()
@@ -155,6 +177,7 @@ void MockWebSpeechRecognizer::start(
new ClientCallTask(this, &blink::WebSpeechRecognizerClient::didEndAudio));
task_queue_.push_back(
new ClientCallTask(this, &blink::WebSpeechRecognizerClient::didEnd));
+ task_queue_.push_back(new EndedTask(this, handle_));
StartTaskQueue();
}
@@ -179,6 +202,8 @@ void MockWebSpeechRecognizer::abort(
was_aborted_ = true;
task_queue_.push_back(
new ClientCallTask(this, &blink::WebSpeechRecognizerClient::didEnd));
+ task_queue_.push_back(new EndedTask(this, handle_));
+
StartTaskQueue();
}
@@ -216,6 +241,8 @@ void MockWebSpeechRecognizer::SetError(const blink::WebString& error,
task_queue_.push_back(new ErrorTask(this, code, message));
task_queue_.push_back(
new ClientCallTask(this, &blink::WebSpeechRecognizerClient::didEnd));
+ task_queue_.push_back(new EndedTask(this, handle_));
+
StartTaskQueue();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698