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

Side by Side Diff: content/browser/speech/google_streaming_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_streaming_remote_engine.h" 5 #include "content/browser/speech/google_streaming_remote_engine.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 downstream_args.push_back( 320 downstream_args.push_back(
321 "key=" + net::EscapeQueryParamValue(GetAPIKey(), true)); 321 "key=" + net::EscapeQueryParamValue(GetAPIKey(), true));
322 downstream_args.push_back("pair=" + request_key); 322 downstream_args.push_back("pair=" + request_key);
323 downstream_args.push_back("output=pb"); 323 downstream_args.push_back("output=pb");
324 GURL downstream_url(std::string(kWebServiceBaseUrl) + 324 GURL downstream_url(std::string(kWebServiceBaseUrl) +
325 std::string(kDownstreamUrl) + 325 std::string(kDownstreamUrl) +
326 JoinString(downstream_args, '&')); 326 JoinString(downstream_args, '&'));
327 327
328 downstream_fetcher_.reset(URLFetcher::Create( 328 downstream_fetcher_.reset(URLFetcher::Create(
329 kDownstreamUrlFetcherIdForTests, downstream_url, URLFetcher::GET, this)); 329 kDownstreamUrlFetcherIdForTests, downstream_url, URLFetcher::GET, this));
330 downstream_fetcher_->SetRequestContext(url_context_); 330 downstream_fetcher_->SetRequestContext(url_context_.get());
331 downstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | 331 downstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
332 net::LOAD_DO_NOT_SEND_COOKIES | 332 net::LOAD_DO_NOT_SEND_COOKIES |
333 net::LOAD_DO_NOT_SEND_AUTH_DATA); 333 net::LOAD_DO_NOT_SEND_AUTH_DATA);
334 downstream_fetcher_->Start(); 334 downstream_fetcher_->Start();
335 335
336 // Setup upstream fetcher. 336 // Setup upstream fetcher.
337 // TODO(hans): Support for user-selected grammars. 337 // TODO(hans): Support for user-selected grammars.
338 std::vector<std::string> upstream_args; 338 std::vector<std::string> upstream_args;
339 upstream_args.push_back("key=" + 339 upstream_args.push_back("key=" +
340 net::EscapeQueryParamValue(GetAPIKey(), true)); 340 net::EscapeQueryParamValue(GetAPIKey(), true));
(...skipping 19 matching lines...) Expand all
360 if (config_.interim_results) 360 if (config_.interim_results)
361 upstream_args.push_back("interim"); 361 upstream_args.push_back("interim");
362 362
363 GURL upstream_url(std::string(kWebServiceBaseUrl) + 363 GURL upstream_url(std::string(kWebServiceBaseUrl) +
364 std::string(kUpstreamUrl) + 364 std::string(kUpstreamUrl) +
365 JoinString(upstream_args, '&')); 365 JoinString(upstream_args, '&'));
366 366
367 upstream_fetcher_.reset(URLFetcher::Create( 367 upstream_fetcher_.reset(URLFetcher::Create(
368 kUpstreamUrlFetcherIdForTests, upstream_url, URLFetcher::POST, this)); 368 kUpstreamUrlFetcherIdForTests, upstream_url, URLFetcher::POST, this));
369 upstream_fetcher_->SetChunkedUpload(encoder_->mime_type()); 369 upstream_fetcher_->SetChunkedUpload(encoder_->mime_type());
370 upstream_fetcher_->SetRequestContext(url_context_); 370 upstream_fetcher_->SetRequestContext(url_context_.get());
371 upstream_fetcher_->SetReferrer(config_.origin_url); 371 upstream_fetcher_->SetReferrer(config_.origin_url);
372 upstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | 372 upstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
373 net::LOAD_DO_NOT_SEND_COOKIES | 373 net::LOAD_DO_NOT_SEND_COOKIES |
374 net::LOAD_DO_NOT_SEND_AUTH_DATA); 374 net::LOAD_DO_NOT_SEND_AUTH_DATA);
375 upstream_fetcher_->Start(); 375 upstream_fetcher_->Start();
376 previous_response_length_ = 0; 376 previous_response_length_ = 0;
377 return STATE_BOTH_STREAMS_CONNECTED; 377 return STATE_BOTH_STREAMS_CONNECTED;
378 } 378 }
379 379
380 GoogleStreamingRemoteEngine::FSMState 380 GoogleStreamingRemoteEngine::FSMState
381 GoogleStreamingRemoteEngine::TransmitAudioUpstream( 381 GoogleStreamingRemoteEngine::TransmitAudioUpstream(
382 const FSMEventArgs& event_args) { 382 const FSMEventArgs& event_args) {
383 DCHECK(upstream_fetcher_.get()); 383 DCHECK(upstream_fetcher_.get());
384 DCHECK(event_args.audio_data.get()); 384 DCHECK(event_args.audio_data.get());
385 const AudioChunk& audio = *(event_args.audio_data); 385 const AudioChunk& audio = *(event_args.audio_data.get());
386 386
387 DCHECK_EQ(audio.bytes_per_sample(), config_.audio_num_bits_per_sample / 8); 387 DCHECK_EQ(audio.bytes_per_sample(), config_.audio_num_bits_per_sample / 8);
388 encoder_->Encode(audio); 388 encoder_->Encode(audio);
389 scoped_refptr<AudioChunk> encoded_data(encoder_->GetEncodedDataAndClear()); 389 scoped_refptr<AudioChunk> encoded_data(encoder_->GetEncodedDataAndClear());
390 upstream_fetcher_->AppendChunkToUpload(encoded_data->AsString(), false); 390 upstream_fetcher_->AppendChunkToUpload(encoded_data->AsString(), false);
391 return state_; 391 return state_;
392 } 392 }
393 393
394 GoogleStreamingRemoteEngine::FSMState 394 GoogleStreamingRemoteEngine::FSMState
395 GoogleStreamingRemoteEngine::ProcessDownstreamResponse( 395 GoogleStreamingRemoteEngine::ProcessDownstreamResponse(
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 DVLOG(1) << "Closing upstream."; 487 DVLOG(1) << "Closing upstream.";
488 488
489 // The encoder requires a non-empty final buffer. So we encode a packet 489 // The encoder requires a non-empty final buffer. So we encode a packet
490 // of silence in case encoder had no data already. 490 // of silence in case encoder had no data already.
491 std::vector<short> samples( 491 std::vector<short> samples(
492 config_.audio_sample_rate * kAudioPacketIntervalMs / 1000); 492 config_.audio_sample_rate * kAudioPacketIntervalMs / 1000);
493 scoped_refptr<AudioChunk> dummy_chunk = 493 scoped_refptr<AudioChunk> dummy_chunk =
494 new AudioChunk(reinterpret_cast<uint8*>(&samples[0]), 494 new AudioChunk(reinterpret_cast<uint8*>(&samples[0]),
495 samples.size() * sizeof(short), 495 samples.size() * sizeof(short),
496 encoder_->bits_per_sample() / 8); 496 encoder_->bits_per_sample() / 8);
497 encoder_->Encode(*dummy_chunk); 497 encoder_->Encode(*dummy_chunk.get());
498 encoder_->Flush(); 498 encoder_->Flush();
499 scoped_refptr<AudioChunk> encoded_dummy_data = 499 scoped_refptr<AudioChunk> encoded_dummy_data =
500 encoder_->GetEncodedDataAndClear(); 500 encoder_->GetEncodedDataAndClear();
501 DCHECK(!encoded_dummy_data->IsEmpty()); 501 DCHECK(!encoded_dummy_data->IsEmpty());
502 encoder_.reset(); 502 encoder_.reset();
503 503
504 upstream_fetcher_->AppendChunkToUpload(encoded_dummy_data->AsString(), true); 504 upstream_fetcher_->AppendChunkToUpload(encoded_dummy_data->AsString(), true);
505 got_last_definitive_result_ = false; 505 got_last_definitive_result_ = false;
506 return STATE_WAITING_DOWNSTREAM_RESULTS; 506 return STATE_WAITING_DOWNSTREAM_RESULTS;
507 } 507 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 547
548 GoogleStreamingRemoteEngine::FSMState 548 GoogleStreamingRemoteEngine::FSMState
549 GoogleStreamingRemoteEngine::NotFeasible(const FSMEventArgs& event_args) { 549 GoogleStreamingRemoteEngine::NotFeasible(const FSMEventArgs& event_args) {
550 NOTREACHED() << "Unfeasible event " << event_args.event 550 NOTREACHED() << "Unfeasible event " << event_args.event
551 << " in state " << state_; 551 << " in state " << state_;
552 return state_; 552 return state_;
553 } 553 }
554 554
555 std::string GoogleStreamingRemoteEngine::GetAcceptedLanguages() const { 555 std::string GoogleStreamingRemoteEngine::GetAcceptedLanguages() const {
556 std::string langs = config_.language; 556 std::string langs = config_.language;
557 if (langs.empty() && url_context_) { 557 if (langs.empty() && url_context_.get()) {
558 // If no language is provided then we use the first from the accepted 558 // If no language is provided then we use the first from the accepted
559 // language list. If this list is empty then it defaults to "en-US". 559 // language list. If this list is empty then it defaults to "en-US".
560 // Example of the contents of this list: "es,en-GB;q=0.8", "" 560 // Example of the contents of this list: "es,en-GB;q=0.8", ""
561 net::URLRequestContext* request_context = 561 net::URLRequestContext* request_context =
562 url_context_->GetURLRequestContext(); 562 url_context_->GetURLRequestContext();
563 DCHECK(request_context); 563 DCHECK(request_context);
564 // TODO(pauljensen): GoogleStreamingRemoteEngine should be constructed with 564 // TODO(pauljensen): GoogleStreamingRemoteEngine should be constructed with
565 // a reference to the HttpUserAgentSettings rather than accessing the 565 // a reference to the HttpUserAgentSettings rather than accessing the
566 // accept language through the URLRequestContext. 566 // accept language through the URLRequestContext.
567 std::string accepted_language_list = request_context->GetAcceptLanguage(); 567 std::string accepted_language_list = request_context->GetAcceptLanguage();
(...skipping 19 matching lines...) Expand all
587 } 587 }
588 588
589 GoogleStreamingRemoteEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) 589 GoogleStreamingRemoteEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value)
590 : event(event_value) { 590 : event(event_value) {
591 } 591 }
592 592
593 GoogleStreamingRemoteEngine::FSMEventArgs::~FSMEventArgs() { 593 GoogleStreamingRemoteEngine::FSMEventArgs::~FSMEventArgs() {
594 } 594 }
595 595
596 } // namespace content 596 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698