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

Side by Side Diff: content/browser/speech/google_one_shot_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, 1 month 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_one_shot_remote_engine.h" 5 #include "content/browser/speech/google_one_shot_remote_engine.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "content/browser/speech/audio_buffer.h" 13 #include "content/browser/speech/audio_buffer.h"
14 #include "content/public/common/speech_recognition_error.h" 14 #include "content/public/common/speech_recognition_error.h"
15 #include "content/public/common/speech_recognition_result.h" 15 #include "content/public/common/speech_recognition_result.h"
16 #include "google_apis/google_api_keys.h" 16 #include "google_apis/google_api_keys.h"
17 #include "net/base/escape.h" 17 #include "net/base/escape.h"
18 #include "net/base/load_flags.h" 18 #include "net/base/load_flags.h"
19 #include "net/url_request/http_user_agent_settings.h"
19 #include "net/url_request/url_fetcher.h" 20 #include "net/url_request/url_fetcher.h"
20 #include "net/url_request/url_request_context.h" 21 #include "net/url_request/url_request_context.h"
21 #include "net/url_request/url_request_context_getter.h" 22 #include "net/url_request/url_request_context_getter.h"
22 #include "net/url_request/url_request_status.h" 23 #include "net/url_request/url_request_status.h"
23 24
24 namespace content { 25 namespace content {
25 namespace { 26 namespace {
26 27
27 const char* const kDefaultSpeechRecognitionUrl = 28 const char* const kDefaultSpeechRecognitionUrl =
28 "https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&"; 29 "https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&";
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 DCHECK(!url_fetcher_.get()); 165 DCHECK(!url_fetcher_.get());
165 std::string lang_param = config_.language; 166 std::string lang_param = config_.language;
166 167
167 if (lang_param.empty() && url_context_.get()) { 168 if (lang_param.empty() && url_context_.get()) {
168 // If no language is provided then we use the first from the accepted 169 // If no language is provided then we use the first from the accepted
169 // language list. If this list is empty then it defaults to "en-US". 170 // language list. If this list is empty then it defaults to "en-US".
170 // Example of the contents of this list: "es,en-GB;q=0.8", "" 171 // Example of the contents of this list: "es,en-GB;q=0.8", ""
171 net::URLRequestContext* request_context = 172 net::URLRequestContext* request_context =
172 url_context_->GetURLRequestContext(); 173 url_context_->GetURLRequestContext();
173 DCHECK(request_context); 174 DCHECK(request_context);
174 // TODO(pauljensen): GoogleOneShotRemoteEngine should be constructed with 175 std::string accepted_language_list;
175 // a reference to the HttpUserAgentSettings rather than accessing the 176 if (request_context->http_user_agent_settings()) {
176 // accept language through the URLRequestContext. 177 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.
177 std::string accepted_language_list = request_context->GetAcceptLanguage(); 178 request_context->http_user_agent_settings()->GetAcceptLanguage();
179 }
178 size_t separator = accepted_language_list.find_first_of(",;"); 180 size_t separator = accepted_language_list.find_first_of(",;");
179 lang_param = accepted_language_list.substr(0, separator); 181 lang_param = accepted_language_list.substr(0, separator);
180 } 182 }
181 183
182 if (lang_param.empty()) 184 if (lang_param.empty())
183 lang_param = "en-US"; 185 lang_param = "en-US";
184 186
185 std::vector<std::string> parts; 187 std::vector<std::string> parts;
186 parts.push_back("lang=" + net::EscapeQueryParamValue(lang_param, true)); 188 parts.push_back("lang=" + net::EscapeQueryParamValue(lang_param, true));
187 189
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 288
287 bool GoogleOneShotRemoteEngine::IsRecognitionPending() const { 289 bool GoogleOneShotRemoteEngine::IsRecognitionPending() const {
288 return url_fetcher_ != NULL; 290 return url_fetcher_ != NULL;
289 } 291 }
290 292
291 int GoogleOneShotRemoteEngine::GetDesiredAudioChunkDurationMs() const { 293 int GoogleOneShotRemoteEngine::GetDesiredAudioChunkDurationMs() const {
292 return kAudioPacketIntervalMs; 294 return kAudioPacketIntervalMs;
293 } 295 }
294 296
295 } // namespace content 297 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698