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

Side by Side Diff: content/browser/speech/google_one_shot_remote_engine.cc

Issue 16294003: Update content/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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) 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/google_one_shot_remote_engine.h" 5 #include "content/browser/speech/google_one_shot_remote_engine.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 void GoogleOneShotRemoteEngine::SetConfig( 157 void GoogleOneShotRemoteEngine::SetConfig(
158 const SpeechRecognitionEngineConfig& config) { 158 const SpeechRecognitionEngineConfig& config) {
159 config_ = config; 159 config_ = config;
160 } 160 }
161 161
162 void GoogleOneShotRemoteEngine::StartRecognition() { 162 void GoogleOneShotRemoteEngine::StartRecognition() {
163 DCHECK(delegate()); 163 DCHECK(delegate());
164 DCHECK(!url_fetcher_.get()); 164 DCHECK(!url_fetcher_.get());
165 std::string lang_param = config_.language; 165 std::string lang_param = config_.language;
166 166
167 if (lang_param.empty() && url_context_) { 167 if (lang_param.empty() && url_context_.get()) {
168 // If no language is provided then we use the first from the accepted 168 // If no language is provided then we use the first from the accepted
169 // language list. If this list is empty then it defaults to "en-US". 169 // language list. If this list is empty then it defaults to "en-US".
170 // Example of the contents of this list: "es,en-GB;q=0.8", "" 170 // Example of the contents of this list: "es,en-GB;q=0.8", ""
171 net::URLRequestContext* request_context = 171 net::URLRequestContext* request_context =
172 url_context_->GetURLRequestContext(); 172 url_context_->GetURLRequestContext();
173 DCHECK(request_context); 173 DCHECK(request_context);
174 // TODO(pauljensen): GoogleOneShotRemoteEngine should be constructed with 174 // TODO(pauljensen): GoogleOneShotRemoteEngine should be constructed with
175 // a reference to the HttpUserAgentSettings rather than accessing the 175 // a reference to the HttpUserAgentSettings rather than accessing the
176 // accept language through the URLRequestContext. 176 // accept language through the URLRequestContext.
177 std::string accepted_language_list = request_context->GetAcceptLanguage(); 177 std::string accepted_language_list = request_context->GetAcceptLanguage();
(...skipping 26 matching lines...) Expand all
204 204
205 encoder_.reset(AudioEncoder::Create(kDefaultAudioCodec, 205 encoder_.reset(AudioEncoder::Create(kDefaultAudioCodec,
206 config_.audio_sample_rate, 206 config_.audio_sample_rate,
207 config_.audio_num_bits_per_sample)); 207 config_.audio_num_bits_per_sample));
208 DCHECK(encoder_.get()); 208 DCHECK(encoder_.get());
209 url_fetcher_.reset(net::URLFetcher::Create(url_fetcher_id_for_tests, 209 url_fetcher_.reset(net::URLFetcher::Create(url_fetcher_id_for_tests,
210 url, 210 url,
211 net::URLFetcher::POST, 211 net::URLFetcher::POST,
212 this)); 212 this));
213 url_fetcher_->SetChunkedUpload(encoder_->mime_type()); 213 url_fetcher_->SetChunkedUpload(encoder_->mime_type());
214 url_fetcher_->SetRequestContext(url_context_); 214 url_fetcher_->SetRequestContext(url_context_.get());
215 url_fetcher_->SetReferrer(config_.origin_url); 215 url_fetcher_->SetReferrer(config_.origin_url);
216 216
217 // The speech recognition API does not require user identification as part 217 // The speech recognition API does not require user identification as part
218 // of requests, so we don't send cookies or auth data for these requests to 218 // of requests, so we don't send cookies or auth data for these requests to
219 // prevent any accidental connection between users who are logged into the 219 // prevent any accidental connection between users who are logged into the
220 // domain for other services (e.g. bookmark sync) with the speech requests. 220 // domain for other services (e.g. bookmark sync) with the speech requests.
221 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | 221 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
222 net::LOAD_DO_NOT_SEND_COOKIES | 222 net::LOAD_DO_NOT_SEND_COOKIES |
223 net::LOAD_DO_NOT_SEND_AUTH_DATA); 223 net::LOAD_DO_NOT_SEND_AUTH_DATA);
224 url_fetcher_->Start(); 224 url_fetcher_->Start();
(...skipping 17 matching lines...) Expand all
242 DCHECK(encoder_.get()); 242 DCHECK(encoder_.get());
243 243
244 // UploadAudioChunk requires a non-empty final buffer. So we encode a packet 244 // UploadAudioChunk requires a non-empty final buffer. So we encode a packet
245 // of silence in case encoder had no data already. 245 // of silence in case encoder had no data already.
246 std::vector<int16> samples( 246 std::vector<int16> samples(
247 config_.audio_sample_rate * kAudioPacketIntervalMs / 1000); 247 config_.audio_sample_rate * kAudioPacketIntervalMs / 1000);
248 scoped_refptr<AudioChunk> dummy_chunk( 248 scoped_refptr<AudioChunk> dummy_chunk(
249 new AudioChunk(reinterpret_cast<uint8*>(&samples[0]), 249 new AudioChunk(reinterpret_cast<uint8*>(&samples[0]),
250 samples.size() * sizeof(int16), 250 samples.size() * sizeof(int16),
251 encoder_->bits_per_sample() / 8)); 251 encoder_->bits_per_sample() / 8));
252 encoder_->Encode(*dummy_chunk); 252 encoder_->Encode(*dummy_chunk.get());
253 encoder_->Flush(); 253 encoder_->Flush();
254 scoped_refptr<AudioChunk> encoded_dummy_data( 254 scoped_refptr<AudioChunk> encoded_dummy_data(
255 encoder_->GetEncodedDataAndClear()); 255 encoder_->GetEncodedDataAndClear());
256 DCHECK(!encoded_dummy_data->IsEmpty()); 256 DCHECK(!encoded_dummy_data->IsEmpty());
257 encoder_.reset(); 257 encoder_.reset();
258 258
259 url_fetcher_->AppendChunkToUpload(encoded_dummy_data->AsString(), true); 259 url_fetcher_->AppendChunkToUpload(encoded_dummy_data->AsString(), true);
260 } 260 }
261 261
262 void GoogleOneShotRemoteEngine::OnURLFetchComplete( 262 void GoogleOneShotRemoteEngine::OnURLFetchComplete(
(...skipping 23 matching lines...) Expand all
286 286
287 bool GoogleOneShotRemoteEngine::IsRecognitionPending() const { 287 bool GoogleOneShotRemoteEngine::IsRecognitionPending() const {
288 return url_fetcher_ != NULL; 288 return url_fetcher_ != NULL;
289 } 289 }
290 290
291 int GoogleOneShotRemoteEngine::GetDesiredAudioChunkDurationMs() const { 291 int GoogleOneShotRemoteEngine::GetDesiredAudioChunkDurationMs() const {
292 return kAudioPacketIntervalMs; 292 return kAudioPacketIntervalMs;
293 } 293 }
294 294
295 } // namespace content 295 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698