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" |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 | 560 |
| 561 std::string GoogleStreamingRemoteEngine::GetAcceptedLanguages() const { | 561 std::string GoogleStreamingRemoteEngine::GetAcceptedLanguages() const { |
| 562 std::string langs = config_.language; | 562 std::string langs = config_.language; |
| 563 if (langs.empty() && url_context_) { | 563 if (langs.empty() && url_context_) { |
| 564 // If no language is provided then we use the first from the accepted | 564 // If no language is provided then we use the first from the accepted |
| 565 // language list. If this list is empty then it defaults to "en-US". | 565 // language list. If this list is empty then it defaults to "en-US". |
| 566 // Example of the contents of this list: "es,en-GB;q=0.8", "" | 566 // Example of the contents of this list: "es,en-GB;q=0.8", "" |
| 567 net::URLRequestContext* request_context = | 567 net::URLRequestContext* request_context = |
| 568 url_context_->GetURLRequestContext(); | 568 url_context_->GetURLRequestContext(); |
| 569 DCHECK(request_context); | 569 DCHECK(request_context); |
| 570 std::string accepted_language_list = request_context->accept_language(); | 570 std::string accepted_language_list = request_context->GetAcceptLanguage(); |
|
erikwright (departed)
2012/10/24 13:14:33
Presumably the TODO from the one-shot version also
| |
| 571 size_t separator = accepted_language_list.find_first_of(",;"); | 571 size_t separator = accepted_language_list.find_first_of(",;"); |
| 572 if (separator != std::string::npos) | 572 if (separator != std::string::npos) |
| 573 langs = accepted_language_list.substr(0, separator); | 573 langs = accepted_language_list.substr(0, separator); |
| 574 } | 574 } |
| 575 if (langs.empty()) | 575 if (langs.empty()) |
| 576 langs = "en-US"; | 576 langs = "en-US"; |
| 577 return langs; | 577 return langs; |
| 578 } | 578 } |
| 579 | 579 |
| 580 // 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? |
| 581 std::string GoogleStreamingRemoteEngine::GenerateRequestKey() const { | 581 std::string GoogleStreamingRemoteEngine::GenerateRequestKey() const { |
| 582 const int64 kKeepLowBytes = GG_LONGLONG(0x00000000FFFFFFFF); | 582 const int64 kKeepLowBytes = GG_LONGLONG(0x00000000FFFFFFFF); |
| 583 const int64 kKeepHighBytes = GG_LONGLONG(0xFFFFFFFF00000000); | 583 const int64 kKeepHighBytes = GG_LONGLONG(0xFFFFFFFF00000000); |
| 584 | 584 |
| 585 // 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 |
| 586 // probability of collisions. | 586 // probability of collisions. |
| 587 int64 key = (base::Time::Now().ToInternalValue() & kKeepLowBytes) | | 587 int64 key = (base::Time::Now().ToInternalValue() & kKeepLowBytes) | |
| 588 (base::RandUint64() & kKeepHighBytes); | 588 (base::RandUint64() & kKeepHighBytes); |
| 589 return base::HexEncode(reinterpret_cast<void*>(&key), sizeof(key)); | 589 return base::HexEncode(reinterpret_cast<void*>(&key), sizeof(key)); |
| 590 } | 590 } |
| 591 | 591 |
| 592 GoogleStreamingRemoteEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) | 592 GoogleStreamingRemoteEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) |
| 593 : event(event_value) { | 593 : event(event_value) { |
| 594 } | 594 } |
| 595 | 595 |
| 596 GoogleStreamingRemoteEngine::FSMEventArgs::~FSMEventArgs() { | 596 GoogleStreamingRemoteEngine::FSMEventArgs::~FSMEventArgs() { |
| 597 } | 597 } |
| 598 | 598 |
| 599 } // namespace speech | 599 } // namespace speech |
| OLD | NEW |