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

Side by Side Diff: chrome/browser/speech/speech_recognition_request.cc

Issue 6134003: Prototype of chunked transfer encoded POST. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/speech/speech_recognition_request.h" 5 #include "chrome/browser/speech/speech_recognition_request.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 SpeechRecognitionRequest::SpeechRecognitionRequest( 114 SpeechRecognitionRequest::SpeechRecognitionRequest(
115 URLRequestContextGetter* context, Delegate* delegate) 115 URLRequestContextGetter* context, Delegate* delegate)
116 : url_context_(context), 116 : url_context_(context),
117 delegate_(delegate) { 117 delegate_(delegate) {
118 DCHECK(delegate); 118 DCHECK(delegate);
119 } 119 }
120 120
121 SpeechRecognitionRequest::~SpeechRecognitionRequest() {} 121 SpeechRecognitionRequest::~SpeechRecognitionRequest() {}
122 122
123 bool SpeechRecognitionRequest::Send(const std::string& language, 123 void SpeechRecognitionRequest::Start(const std::string& language,
124 const std::string& grammar, 124 const std::string& grammar,
125 const std::string& hardware_info, 125 const std::string& hardware_info,
126 const std::string& content_type, 126 const std::string& content_type) {
127 const std::string& audio_data) {
128 DCHECK(!url_fetcher_.get()); 127 DCHECK(!url_fetcher_.get());
129 128
130 std::vector<std::string> parts; 129 std::vector<std::string> parts;
131 130
132 std::string lang_param = language; 131 std::string lang_param = language;
133 if (lang_param.empty() && url_context_) { 132 if (lang_param.empty() && url_context_) {
134 // If no language is provided then we use the first from the accepted 133 // If no language is provided then we use the first from the accepted
135 // language list. If this list is empty then it defaults to "en-US". 134 // language list. If this list is empty then it defaults to "en-US".
136 // Example of the contents of this list: "es,en-GB;q=0.8", "" 135 // Example of the contents of this list: "es,en-GB;q=0.8", ""
137 URLRequestContext* request_context = url_context_->GetURLRequestContext(); 136 URLRequestContext* request_context = url_context_->GetURLRequestContext();
(...skipping 13 matching lines...) Expand all
151 // TODO(satish): Remove this hardcoded value once the page is allowed to 150 // TODO(satish): Remove this hardcoded value once the page is allowed to
152 // set this via an attribute. 151 // set this via an attribute.
153 parts.push_back("maxresults=3"); 152 parts.push_back("maxresults=3");
154 153
155 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&')); 154 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&'));
156 155
157 url_fetcher_.reset(URLFetcher::Create(url_fetcher_id_for_tests, 156 url_fetcher_.reset(URLFetcher::Create(url_fetcher_id_for_tests,
158 url, 157 url,
159 URLFetcher::POST, 158 URLFetcher::POST,
160 this)); 159 this));
161 url_fetcher_->set_upload_data(content_type, audio_data); 160 url_fetcher_->set_chunked_upload(content_type);
162 url_fetcher_->set_request_context(url_context_); 161 url_fetcher_->set_request_context(url_context_);
163 162
164 // The speech recognition API does not require user identification as part 163 // The speech recognition API does not require user identification as part
165 // of requests, so we don't send cookies or auth data for these requests to 164 // of requests, so we don't send cookies or auth data for these requests to
166 // prevent any accidental connection between users who are logged into the 165 // prevent any accidental connection between users who are logged into the
167 // domain for other services (e.g. bookmark sync) with the speech requests. 166 // domain for other services (e.g. bookmark sync) with the speech requests.
168 url_fetcher_->set_load_flags( 167 url_fetcher_->set_load_flags(
169 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES | 168 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES |
170 net::LOAD_DO_NOT_SEND_AUTH_DATA); 169 net::LOAD_DO_NOT_SEND_AUTH_DATA);
171 url_fetcher_->Start(); 170 url_fetcher_->Start();
172 return true; 171 }
172
173 void SpeechRecognitionRequest::UploadAudioChunk(const std::string& audio_data) {
174 DCHECK(url_fetcher_.get());
175 url_fetcher_->AppendChunkToUpload(audio_data);
176 }
177
178 void SpeechRecognitionRequest::FinishAudioUpload() {
179 DCHECK(url_fetcher_.get());
180 url_fetcher_->MarkEndOfChunks();
173 } 181 }
174 182
175 void SpeechRecognitionRequest::OnURLFetchComplete( 183 void SpeechRecognitionRequest::OnURLFetchComplete(
176 const URLFetcher* source, 184 const URLFetcher* source,
177 const GURL& url, 185 const GURL& url,
178 const net::URLRequestStatus& status, 186 const net::URLRequestStatus& status,
179 int response_code, 187 int response_code,
180 const ResponseCookies& cookies, 188 const ResponseCookies& cookies,
181 const std::string& data) { 189 const std::string& data) {
182 DCHECK_EQ(url_fetcher_.get(), source); 190 DCHECK_EQ(url_fetcher_.get(), source);
183 191
184 bool error = !status.is_success() || response_code != 200; 192 bool error = !status.is_success() || response_code != 200;
185 SpeechInputResultArray result; 193 SpeechInputResultArray result;
186 if (!error) 194 if (!error)
187 error = !ParseServerResponse(data, &result); 195 error = !ParseServerResponse(data, &result);
188 url_fetcher_.reset(); 196 url_fetcher_.reset();
189 197
190 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result."; 198 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result.";
191 delegate_->SetRecognitionResult(error, result); 199 delegate_->SetRecognitionResult(error, result);
192 } 200 }
193 201
194 } // namespace speech_input 202 } // namespace speech_input
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698