| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/speech/speech_recognition_engine.h" | 5 #include "content/browser/speech/speech_recognition_engine.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/big_endian.h" | 10 #include "base/big_endian.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 95 |
| 96 SpeechRecognitionEngine::SpeechRecognitionEngine( | 96 SpeechRecognitionEngine::SpeechRecognitionEngine( |
| 97 net::URLRequestContextGetter* context) | 97 net::URLRequestContextGetter* context) |
| 98 : url_context_(context), | 98 : url_context_(context), |
| 99 previous_response_length_(0), | 99 previous_response_length_(0), |
| 100 got_last_definitive_result_(false), | 100 got_last_definitive_result_(false), |
| 101 is_dispatching_event_(false), | 101 is_dispatching_event_(false), |
| 102 use_framed_post_data_(false), | 102 use_framed_post_data_(false), |
| 103 state_(STATE_IDLE) {} | 103 state_(STATE_IDLE) {} |
| 104 | 104 |
| 105 SpeechRecognitionEngine::~SpeechRecognitionEngine() {} | 105 SpeechRecognitionEngine::~SpeechRecognitionEngine() { |
| 106 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 107 } |
| 106 | 108 |
| 107 void SpeechRecognitionEngine::SetConfig(const Config& config) { | 109 void SpeechRecognitionEngine::SetConfig(const Config& config) { |
| 108 config_ = config; | 110 config_ = config; |
| 109 } | 111 } |
| 110 | 112 |
| 111 void SpeechRecognitionEngine::StartRecognition() { | 113 void SpeechRecognitionEngine::StartRecognition() { |
| 112 FSMEventArgs event_args(EVENT_START_RECOGNITION); | 114 FSMEventArgs event_args(EVENT_START_RECOGNITION); |
| 113 DispatchEvent(event_args); | 115 DispatchEvent(event_args); |
| 114 } | 116 } |
| 115 | 117 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 138 const URLFetcher* source, | 140 const URLFetcher* source, |
| 139 int64_t current, | 141 int64_t current, |
| 140 int64_t total, | 142 int64_t total, |
| 141 int64_t current_network_bytes) { | 143 int64_t current_network_bytes) { |
| 142 const bool kPartialResponse = false; | 144 const bool kPartialResponse = false; |
| 143 DispatchHTTPResponse(source, kPartialResponse); | 145 DispatchHTTPResponse(source, kPartialResponse); |
| 144 } | 146 } |
| 145 | 147 |
| 146 void SpeechRecognitionEngine::DispatchHTTPResponse(const URLFetcher* source, | 148 void SpeechRecognitionEngine::DispatchHTTPResponse(const URLFetcher* source, |
| 147 bool end_of_response) { | 149 bool end_of_response) { |
| 148 DCHECK(CalledOnValidThread()); | 150 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 149 DCHECK(source); | 151 DCHECK(source); |
| 150 const bool response_is_good = source->GetStatus().is_success() && | 152 const bool response_is_good = source->GetStatus().is_success() && |
| 151 source->GetResponseCode() == 200; | 153 source->GetResponseCode() == 200; |
| 152 std::string response; | 154 std::string response; |
| 153 if (response_is_good) | 155 if (response_is_good) |
| 154 source->GetResponseAsString(&response); | 156 source->GetResponseAsString(&response); |
| 155 const size_t current_response_length = response.size(); | 157 const size_t current_response_length = response.size(); |
| 156 | 158 |
| 157 DVLOG(1) << (source == downstream_fetcher_.get() ? "Downstream" : "Upstream") | 159 DVLOG(1) << (source == downstream_fetcher_.get() ? "Downstream" : "Upstream") |
| 158 << "HTTP, code: " << source->GetResponseCode() | 160 << "HTTP, code: " << source->GetResponseCode() |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 event_args.response->end())); | 209 event_args.response->end())); |
| 208 DispatchEvent(event_args); | 210 DispatchEvent(event_args); |
| 209 } | 211 } |
| 210 if (end_of_response) { | 212 if (end_of_response) { |
| 211 FSMEventArgs event_args(EVENT_DOWNSTREAM_CLOSED); | 213 FSMEventArgs event_args(EVENT_DOWNSTREAM_CLOSED); |
| 212 DispatchEvent(event_args); | 214 DispatchEvent(event_args); |
| 213 } | 215 } |
| 214 } | 216 } |
| 215 | 217 |
| 216 bool SpeechRecognitionEngine::IsRecognitionPending() const { | 218 bool SpeechRecognitionEngine::IsRecognitionPending() const { |
| 217 DCHECK(CalledOnValidThread()); | 219 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 218 return state_ != STATE_IDLE; | 220 return state_ != STATE_IDLE; |
| 219 } | 221 } |
| 220 | 222 |
| 221 int SpeechRecognitionEngine::GetDesiredAudioChunkDurationMs() const { | 223 int SpeechRecognitionEngine::GetDesiredAudioChunkDurationMs() const { |
| 222 return kAudioPacketIntervalMs; | 224 return kAudioPacketIntervalMs; |
| 223 } | 225 } |
| 224 | 226 |
| 225 // ----------------------- Core FSM implementation --------------------------- | 227 // ----------------------- Core FSM implementation --------------------------- |
| 226 | 228 |
| 227 void SpeechRecognitionEngine::DispatchEvent( | 229 void SpeechRecognitionEngine::DispatchEvent( |
| 228 const FSMEventArgs& event_args) { | 230 const FSMEventArgs& event_args) { |
| 229 DCHECK(CalledOnValidThread()); | 231 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 230 DCHECK_LE(event_args.event, EVENT_MAX_VALUE); | 232 DCHECK_LE(event_args.event, EVENT_MAX_VALUE); |
| 231 DCHECK_LE(state_, STATE_MAX_VALUE); | 233 DCHECK_LE(state_, STATE_MAX_VALUE); |
| 232 | 234 |
| 233 // Event dispatching must be sequential, otherwise it will break all the rules | 235 // Event dispatching must be sequential, otherwise it will break all the rules |
| 234 // and the assumptions of the finite state automata model. | 236 // and the assumptions of the finite state automata model. |
| 235 DCHECK(!is_dispatching_event_); | 237 DCHECK(!is_dispatching_event_); |
| 236 is_dispatching_event_ = true; | 238 is_dispatching_event_ = true; |
| 237 | 239 |
| 238 state_ = ExecuteTransitionAndGetNextState(event_args); | 240 state_ = ExecuteTransitionAndGetNextState(event_args); |
| 239 | 241 |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 } | 724 } |
| 723 | 725 |
| 724 SpeechRecognitionEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) | 726 SpeechRecognitionEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) |
| 725 : event(event_value) { | 727 : event(event_value) { |
| 726 } | 728 } |
| 727 | 729 |
| 728 SpeechRecognitionEngine::FSMEventArgs::~FSMEventArgs() { | 730 SpeechRecognitionEngine::FSMEventArgs::~FSMEventArgs() { |
| 729 } | 731 } |
| 730 | 732 |
| 731 } // namespace content | 733 } // namespace content |
| OLD | NEW |