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

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: Created 7 years 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 std::string accepted_language_list;
568 if (request_context->http_user_agent_settings()) {
569 accepted_language_list =
570 request_context->http_user_agent_settings()->GetAcceptLanguage();
571 }
567 size_t separator = accepted_language_list.find_first_of(",;"); 572 size_t separator = accepted_language_list.find_first_of(",;");
568 if (separator != std::string::npos) 573 if (separator != std::string::npos)
569 langs = accepted_language_list.substr(0, separator); 574 langs = accepted_language_list.substr(0, separator);
no longer working on chromium 2013/12/30 12:35:15 ditto.
Lei Zhang 2014/01/08 22:44:25 Done.
570 } 575 }
571 if (langs.empty()) 576 if (langs.empty())
572 langs = "en-US"; 577 langs = "en-US";
573 return langs; 578 return langs;
574 } 579 }
575 580
576 // TODO(primiano): Is there any utility in the codebase that already does this? 581 // TODO(primiano): Is there any utility in the codebase that already does this?
577 std::string GoogleStreamingRemoteEngine::GenerateRequestKey() const { 582 std::string GoogleStreamingRemoteEngine::GenerateRequestKey() const {
578 const int64 kKeepLowBytes = GG_LONGLONG(0x00000000FFFFFFFF); 583 const int64 kKeepLowBytes = GG_LONGLONG(0x00000000FFFFFFFF);
579 const int64 kKeepHighBytes = GG_LONGLONG(0xFFFFFFFF00000000); 584 const int64 kKeepHighBytes = GG_LONGLONG(0xFFFFFFFF00000000);
580 585
581 // Just keep the least significant bits of timestamp, in order to reduce 586 // Just keep the least significant bits of timestamp, in order to reduce
582 // probability of collisions. 587 // probability of collisions.
583 int64 key = (base::Time::Now().ToInternalValue() & kKeepLowBytes) | 588 int64 key = (base::Time::Now().ToInternalValue() & kKeepLowBytes) |
584 (base::RandUint64() & kKeepHighBytes); 589 (base::RandUint64() & kKeepHighBytes);
585 return base::HexEncode(reinterpret_cast<void*>(&key), sizeof(key)); 590 return base::HexEncode(reinterpret_cast<void*>(&key), sizeof(key));
586 } 591 }
587 592
588 GoogleStreamingRemoteEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) 593 GoogleStreamingRemoteEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value)
589 : event(event_value) { 594 : event(event_value) {
590 } 595 }
591 596
592 GoogleStreamingRemoteEngine::FSMEventArgs::~FSMEventArgs() { 597 GoogleStreamingRemoteEngine::FSMEventArgs::~FSMEventArgs() {
593 } 598 }
594 599
595 } // namespace content 600 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698