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

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

Issue 83433008: Cleanup: Remove legacy accessors from URLRequestContext. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments from xians Created 6 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) 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"
11 #include "base/rand_util.h" 11 #include "base/rand_util.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "content/browser/speech/audio_buffer.h" 16 #include "content/browser/speech/audio_buffer.h"
17 #include "content/browser/speech/proto/google_streaming_api.pb.h" 17 #include "content/browser/speech/proto/google_streaming_api.pb.h"
18 #include "content/public/common/content_switches.h" 18 #include "content/public/common/content_switches.h"
19 #include "content/public/common/speech_recognition_error.h" 19 #include "content/public/common/speech_recognition_error.h"
20 #include "content/public/common/speech_recognition_result.h" 20 #include "content/public/common/speech_recognition_result.h"
21 #include "google_apis/google_api_keys.h" 21 #include "google_apis/google_api_keys.h"
22 #include "net/base/escape.h" 22 #include "net/base/escape.h"
23 #include "net/base/load_flags.h" 23 #include "net/base/load_flags.h"
24 #include "net/url_request/http_user_agent_settings.h"
24 #include "net/url_request/url_fetcher.h" 25 #include "net/url_request/url_fetcher.h"
25 #include "net/url_request/url_request_context.h" 26 #include "net/url_request/url_request_context.h"
26 #include "net/url_request/url_request_context_getter.h" 27 #include "net/url_request/url_request_context_getter.h"
27 #include "net/url_request/url_request_status.h" 28 #include "net/url_request/url_request_status.h"
28 29
29 using net::URLFetcher; 30 using net::URLFetcher;
30 31
31 namespace content { 32 namespace content {
32 namespace { 33 namespace {
33 34
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 if (langs.empty() && url_context_.get()) { 557 if (langs.empty() && url_context_.get()) {
557 // 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
558 // 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".
559 // 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", ""
560 net::URLRequestContext* request_context = 561 net::URLRequestContext* request_context =
561 url_context_->GetURLRequestContext(); 562 url_context_->GetURLRequestContext();
562 DCHECK(request_context); 563 DCHECK(request_context);
563 // TODO(pauljensen): GoogleStreamingRemoteEngine should be constructed with 564 // TODO(pauljensen): GoogleStreamingRemoteEngine should be constructed with
564 // a reference to the HttpUserAgentSettings rather than accessing the 565 // a reference to the HttpUserAgentSettings rather than accessing the
565 // accept language through the URLRequestContext. 566 // accept language through the URLRequestContext.
566 std::string accepted_language_list = request_context->GetAcceptLanguage(); 567 if (request_context->http_user_agent_settings()) {
567 size_t separator = accepted_language_list.find_first_of(",;"); 568 std::string accepted_language_list =
568 if (separator != std::string::npos) 569 request_context->http_user_agent_settings()->GetAcceptLanguage();
569 langs = accepted_language_list.substr(0, separator); 570 size_t separator = accepted_language_list.find_first_of(",;");
571 if (separator != std::string::npos)
572 langs = accepted_language_list.substr(0, separator);
573 }
570 } 574 }
571 if (langs.empty()) 575 if (langs.empty())
572 langs = "en-US"; 576 langs = "en-US";
573 return langs; 577 return langs;
574 } 578 }
575 579
576 // TODO(primiano): Is there any utility in the codebase that already does this? 580 // TODO(primiano): Is there any utility in the codebase that already does this?
577 std::string GoogleStreamingRemoteEngine::GenerateRequestKey() const { 581 std::string GoogleStreamingRemoteEngine::GenerateRequestKey() const {
578 const int64 kKeepLowBytes = GG_LONGLONG(0x00000000FFFFFFFF); 582 const int64 kKeepLowBytes = GG_LONGLONG(0x00000000FFFFFFFF);
579 const int64 kKeepHighBytes = GG_LONGLONG(0xFFFFFFFF00000000); 583 const int64 kKeepHighBytes = GG_LONGLONG(0xFFFFFFFF00000000);
580 584
581 // Just keep the least significant bits of timestamp, in order to reduce 585 // Just keep the least significant bits of timestamp, in order to reduce
582 // probability of collisions. 586 // probability of collisions.
583 int64 key = (base::Time::Now().ToInternalValue() & kKeepLowBytes) | 587 int64 key = (base::Time::Now().ToInternalValue() & kKeepLowBytes) |
584 (base::RandUint64() & kKeepHighBytes); 588 (base::RandUint64() & kKeepHighBytes);
585 return base::HexEncode(reinterpret_cast<void*>(&key), sizeof(key)); 589 return base::HexEncode(reinterpret_cast<void*>(&key), sizeof(key));
586 } 590 }
587 591
588 GoogleStreamingRemoteEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) 592 GoogleStreamingRemoteEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value)
589 : event(event_value) { 593 : event(event_value) {
590 } 594 }
591 595
592 GoogleStreamingRemoteEngine::FSMEventArgs::~FSMEventArgs() { 596 GoogleStreamingRemoteEngine::FSMEventArgs::~FSMEventArgs() {
593 } 597 }
594 598
595 } // namespace content 599 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/speech/google_one_shot_remote_engine.cc ('k') | net/url_request/url_request_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698