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

Side by Side Diff: third_party/WebKit/Source/modules/speech/SpeechRecognition.cpp

Issue 2583093002: Reduce SuspendableObjects (Closed)
Patch Set: Created 4 years 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright 9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 22 matching lines...) Expand all
33 #include "modules/speech/SpeechRecognitionController.h" 33 #include "modules/speech/SpeechRecognitionController.h"
34 #include "modules/speech/SpeechRecognitionError.h" 34 #include "modules/speech/SpeechRecognitionError.h"
35 #include "modules/speech/SpeechRecognitionEvent.h" 35 #include "modules/speech/SpeechRecognitionEvent.h"
36 36
37 namespace blink { 37 namespace blink {
38 38
39 SpeechRecognition* SpeechRecognition::create(ExecutionContext* context) { 39 SpeechRecognition* SpeechRecognition::create(ExecutionContext* context) {
40 ASSERT(context && context->isDocument()); 40 ASSERT(context && context->isDocument());
41 Document* document = toDocument(context); 41 Document* document = toDocument(context);
42 ASSERT(document); 42 ASSERT(document);
43 SpeechRecognition* speechRecognition = 43 return new SpeechRecognition(document->page(), context);
44 new SpeechRecognition(document->page(), context);
45 speechRecognition->suspendIfNeeded();
46 return speechRecognition;
47 } 44 }
48 45
49 void SpeechRecognition::start(ExceptionState& exceptionState) { 46 void SpeechRecognition::start(ExceptionState& exceptionState) {
50 if (!m_controller) 47 if (!m_controller)
51 return; 48 return;
52 49
53 if (m_started) { 50 if (m_started) {
54 exceptionState.throwDOMException(InvalidStateError, 51 exceptionState.throwDOMException(InvalidStateError,
55 "recognition has already started."); 52 "recognition has already started.");
56 return; 53 return;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // being detached, so don't dispatch an event. 138 // being detached, so don't dispatch an event.
142 if (m_controller) 139 if (m_controller)
143 dispatchEvent(Event::create(EventTypeNames::end)); 140 dispatchEvent(Event::create(EventTypeNames::end));
144 } 141 }
145 142
146 const AtomicString& SpeechRecognition::interfaceName() const { 143 const AtomicString& SpeechRecognition::interfaceName() const {
147 return EventTargetNames::SpeechRecognition; 144 return EventTargetNames::SpeechRecognition;
148 } 145 }
149 146
150 ExecutionContext* SpeechRecognition::getExecutionContext() const { 147 ExecutionContext* SpeechRecognition::getExecutionContext() const {
151 return SuspendableObject::getExecutionContext(); 148 return ContextLifecycleObserver::getExecutionContext();
152 } 149 }
153 150
154 void SpeechRecognition::contextDestroyed() { 151 void SpeechRecognition::contextDestroyed() {
155 m_controller = nullptr; 152 m_controller = nullptr;
156 if (hasPendingActivity()) 153 if (hasPendingActivity())
157 abort(); 154 abort();
158 } 155 }
159 156
160 bool SpeechRecognition::hasPendingActivity() const { 157 bool SpeechRecognition::hasPendingActivity() const {
161 return m_started; 158 return m_started;
162 } 159 }
163 160
164 SpeechRecognition::SpeechRecognition(Page* page, ExecutionContext* context) 161 SpeechRecognition::SpeechRecognition(Page* page, ExecutionContext* context)
165 : SuspendableObject(context), 162 : ContextLifecycleObserver(context),
166 m_grammars(SpeechGrammarList::create()), // FIXME: The spec is not clear 163 m_grammars(SpeechGrammarList::create()), // FIXME: The spec is not clear
167 // on the default value for the 164 // on the default value for the
168 // grammars attribute. 165 // grammars attribute.
169 m_audioTrack(nullptr), 166 m_audioTrack(nullptr),
170 m_continuous(false), 167 m_continuous(false),
171 m_interimResults(false), 168 m_interimResults(false),
172 m_maxAlternatives(1), 169 m_maxAlternatives(1),
173 m_controller(SpeechRecognitionController::from(page)), 170 m_controller(SpeechRecognitionController::from(page)),
174 m_started(false), 171 m_started(false),
175 m_stopping(false) { 172 m_stopping(false) {
176 // FIXME: Need to hook up with Page to get notified when the visibility 173 // FIXME: Need to hook up with Page to get notified when the visibility
177 // changes. 174 // changes.
178 } 175 }
179 176
180 SpeechRecognition::~SpeechRecognition() {} 177 SpeechRecognition::~SpeechRecognition() {}
181 178
182 DEFINE_TRACE(SpeechRecognition) { 179 DEFINE_TRACE(SpeechRecognition) {
183 visitor->trace(m_grammars); 180 visitor->trace(m_grammars);
184 visitor->trace(m_audioTrack); 181 visitor->trace(m_audioTrack);
185 visitor->trace(m_controller); 182 visitor->trace(m_controller);
186 visitor->trace(m_finalResults); 183 visitor->trace(m_finalResults);
187 EventTargetWithInlineData::trace(visitor); 184 EventTargetWithInlineData::trace(visitor);
188 SuspendableObject::trace(visitor); 185 ContextLifecycleObserver::trace(visitor);
189 } 186 }
190 187
191 } // namespace blink 188 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698