Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 553 | 554 |
| 554 std::string GoogleStreamingRemoteEngine::GetAcceptedLanguages() const { | 555 std::string GoogleStreamingRemoteEngine::GetAcceptedLanguages() const { |
| 555 std::string langs = config_.language; | 556 std::string langs = config_.language; |
| 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 std::string accepted_language_list; |
| 564 // a reference to the HttpUserAgentSettings rather than accessing the | 565 if (request_context->http_user_agent_settings()) { |
| 565 // accept language through the URLRequestContext. | 566 accepted_language_list = |
|
pauljensen
2013/12/02 15:24:42
This comment should not be removed as the TODO has
Lei Zhang
2013/12/11 03:32:24
Done.
| |
| 566 std::string accepted_language_list = request_context->GetAcceptLanguage(); | 567 request_context->http_user_agent_settings()->GetAcceptLanguage(); |
| 568 } | |
| 567 size_t separator = accepted_language_list.find_first_of(",;"); | 569 size_t separator = accepted_language_list.find_first_of(",;"); |
| 568 if (separator != std::string::npos) | 570 if (separator != std::string::npos) |
| 569 langs = accepted_language_list.substr(0, separator); | 571 langs = accepted_language_list.substr(0, separator); |
| 570 } | 572 } |
| 571 if (langs.empty()) | 573 if (langs.empty()) |
| 572 langs = "en-US"; | 574 langs = "en-US"; |
| 573 return langs; | 575 return langs; |
| 574 } | 576 } |
| 575 | 577 |
| 576 // TODO(primiano): Is there any utility in the codebase that already does this? | 578 // TODO(primiano): Is there any utility in the codebase that already does this? |
| 577 std::string GoogleStreamingRemoteEngine::GenerateRequestKey() const { | 579 std::string GoogleStreamingRemoteEngine::GenerateRequestKey() const { |
| 578 const int64 kKeepLowBytes = GG_LONGLONG(0x00000000FFFFFFFF); | 580 const int64 kKeepLowBytes = GG_LONGLONG(0x00000000FFFFFFFF); |
| 579 const int64 kKeepHighBytes = GG_LONGLONG(0xFFFFFFFF00000000); | 581 const int64 kKeepHighBytes = GG_LONGLONG(0xFFFFFFFF00000000); |
| 580 | 582 |
| 581 // Just keep the least significant bits of timestamp, in order to reduce | 583 // Just keep the least significant bits of timestamp, in order to reduce |
| 582 // probability of collisions. | 584 // probability of collisions. |
| 583 int64 key = (base::Time::Now().ToInternalValue() & kKeepLowBytes) | | 585 int64 key = (base::Time::Now().ToInternalValue() & kKeepLowBytes) | |
| 584 (base::RandUint64() & kKeepHighBytes); | 586 (base::RandUint64() & kKeepHighBytes); |
| 585 return base::HexEncode(reinterpret_cast<void*>(&key), sizeof(key)); | 587 return base::HexEncode(reinterpret_cast<void*>(&key), sizeof(key)); |
| 586 } | 588 } |
| 587 | 589 |
| 588 GoogleStreamingRemoteEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) | 590 GoogleStreamingRemoteEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) |
| 589 : event(event_value) { | 591 : event(event_value) { |
| 590 } | 592 } |
| 591 | 593 |
| 592 GoogleStreamingRemoteEngine::FSMEventArgs::~FSMEventArgs() { | 594 GoogleStreamingRemoteEngine::FSMEventArgs::~FSMEventArgs() { |
| 593 } | 595 } |
| 594 | 596 |
| 595 } // namespace content | 597 } // namespace content |
| OLD | NEW |