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

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

Issue 2801663002: Network traffic annotation added to speech_recognition_engine. (Closed)
Patch Set: Annotation updated. Created 3 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/speech_recognition_engine.h" 5 #include "content/browser/speech/speech_recognition_engine.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/big_endian.h" 10 #include "base/big_endian.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/rand_util.h" 12 #include "base/rand_util.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "content/browser/speech/audio_buffer.h" 17 #include "content/browser/speech/audio_buffer.h"
18 #include "content/browser/speech/proto/google_streaming_api.pb.h" 18 #include "content/browser/speech/proto/google_streaming_api.pb.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/traffic_annotation/network_traffic_annotation.h"
24 #include "net/url_request/http_user_agent_settings.h" 25 #include "net/url_request/http_user_agent_settings.h"
25 #include "net/url_request/url_fetcher.h" 26 #include "net/url_request/url_fetcher.h"
26 #include "net/url_request/url_request_context.h" 27 #include "net/url_request/url_request_context.h"
27 #include "net/url_request/url_request_context_getter.h" 28 #include "net/url_request/url_request_context_getter.h"
28 #include "net/url_request/url_request_status.h" 29 #include "net/url_request/url_request_status.h"
29 30
30 using net::URLFetcher; 31 using net::URLFetcher;
31 32
32 namespace content { 33 namespace content {
33 namespace { 34 namespace {
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 // Setup downstream fetcher. 331 // Setup downstream fetcher.
331 std::vector<std::string> downstream_args; 332 std::vector<std::string> downstream_args;
332 downstream_args.push_back( 333 downstream_args.push_back(
333 "key=" + net::EscapeQueryParamValue(google_apis::GetAPIKey(), true)); 334 "key=" + net::EscapeQueryParamValue(google_apis::GetAPIKey(), true));
334 downstream_args.push_back("pair=" + request_key); 335 downstream_args.push_back("pair=" + request_key);
335 downstream_args.push_back("output=pb"); 336 downstream_args.push_back("output=pb");
336 GURL downstream_url(std::string(kWebServiceBaseUrl) + 337 GURL downstream_url(std::string(kWebServiceBaseUrl) +
337 std::string(kDownstreamUrl) + 338 std::string(kDownstreamUrl) +
338 base::JoinString(downstream_args, "&")); 339 base::JoinString(downstream_args, "&"));
339 340
340 downstream_fetcher_ = URLFetcher::Create( 341 net::NetworkTrafficAnnotationTag downstream_traffic_annotation =
341 kDownstreamUrlFetcherIdForTesting, downstream_url, URLFetcher::GET, this); 342 net::DefineNetworkTrafficAnnotation("speech_recognition_downstream", R"(
343 semantics {
344 sender: "Speech Recognition"
345 description:
346 "Chrome provides translation from speech audio recorded with a "
347 "microphone to text, by using the Google speech recognition web "
348 "service. Audio is sent to Google's servers (upstream) and text is "
349 "returned (downstream). This network request (downstream) sends an "
350 "id for getting the text response. Then the (upstream) request "
351 "sends the audio data along with the id. When the server has "
352 "finished processing the audio data and produced a text response, "
353 "it replies to this request."
354 trigger:
355 "The user chooses to start the recognition by clicking the "
356 "microphone icon in the Google search field."
357 data: "A unique random id for this speech recognition request."
358 destination: GOOGLE_OWNED_SERVICE
359 }
360 policy {
361 cookies_allowed: false
362 setting:
363 "The user must allow the browser to access the microphone in a "
364 "popup notification. This is set per site (hostname pattern). In "
365 "the content settings, microphone access can be turned off for all "
366 "sites and site specific settings can be changed."
367 policy_exception_justification: "Not implemented."
368 })");
369 downstream_fetcher_ =
370 URLFetcher::Create(kDownstreamUrlFetcherIdForTesting, downstream_url,
371 URLFetcher::GET, this, downstream_traffic_annotation);
342 downstream_fetcher_->SetRequestContext(url_context_.get()); 372 downstream_fetcher_->SetRequestContext(url_context_.get());
343 downstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | 373 downstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
344 net::LOAD_DO_NOT_SEND_COOKIES | 374 net::LOAD_DO_NOT_SEND_COOKIES |
345 net::LOAD_DO_NOT_SEND_AUTH_DATA); 375 net::LOAD_DO_NOT_SEND_AUTH_DATA);
346 downstream_fetcher_->Start(); 376 downstream_fetcher_->Start();
347 377
348 // Setup upstream fetcher. 378 // Setup upstream fetcher.
349 // TODO(hans): Support for user-selected grammars. 379 // TODO(hans): Support for user-selected grammars.
350 std::vector<std::string> upstream_args; 380 std::vector<std::string> upstream_args;
351 upstream_args.push_back("key=" + 381 upstream_args.push_back("key=" +
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 if (preamble_encoder_) 416 if (preamble_encoder_)
387 audio_format = preamble_encoder_->GetMimeType() + ","; 417 audio_format = preamble_encoder_->GetMimeType() + ",";
388 audio_format += encoder_->GetMimeType(); 418 audio_format += encoder_->GetMimeType();
389 upstream_args.push_back( 419 upstream_args.push_back(
390 "audioFormat=" + net::EscapeQueryParamValue(audio_format, true)); 420 "audioFormat=" + net::EscapeQueryParamValue(audio_format, true));
391 } 421 }
392 GURL upstream_url(std::string(kWebServiceBaseUrl) + 422 GURL upstream_url(std::string(kWebServiceBaseUrl) +
393 std::string(kUpstreamUrl) + 423 std::string(kUpstreamUrl) +
394 base::JoinString(upstream_args, "&")); 424 base::JoinString(upstream_args, "&"));
395 425
396 upstream_fetcher_ = URLFetcher::Create(kUpstreamUrlFetcherIdForTesting, 426 net::NetworkTrafficAnnotationTag upstream_traffic_annotation =
397 upstream_url, URLFetcher::POST, this); 427 net::DefineNetworkTrafficAnnotation("speech_recognition_upstream", R"(
428 semantics {
429 sender: "Speech Recognition"
430 description:
431 "Chrome provides translation from speech audio recorded with a "
432 "microphone to text, by using the Google speech recognition web "
433 "service. Audio is sent to Google's servers (upstream) and text is "
434 "returned (downstream)."
435 trigger:
436 "The user chooses to start the recognition by clicking the "
437 "microphone icon in the Google search field."
438 data: "Audio recorded with the microphone."
Henrik Grunell 2017/05/11 08:22:35 Perhaps add that the id is sent here as well?
Ramin Halavati 2017/05/11 08:38:06 Done.
439 destination: GOOGLE_OWNED_SERVICE
440 }
441 policy {
442 cookies_allowed: false
443 setting:
444 "The user must allow the browser to access the microphone in a "
445 "popup notification. This is set per site (hostname pattern). In "
446 "the content settings, microphone access can be turned off for all "
447 "sites and site specific settings can be changed."
448 policy_exception_justification: "Not implemented."
449 })");
450 upstream_fetcher_ =
451 URLFetcher::Create(kUpstreamUrlFetcherIdForTesting, upstream_url,
452 URLFetcher::POST, this, upstream_traffic_annotation);
398 if (use_framed_post_data_) 453 if (use_framed_post_data_)
399 upstream_fetcher_->SetChunkedUpload("application/octet-stream"); 454 upstream_fetcher_->SetChunkedUpload("application/octet-stream");
400 else 455 else
401 upstream_fetcher_->SetChunkedUpload(encoder_->GetMimeType()); 456 upstream_fetcher_->SetChunkedUpload(encoder_->GetMimeType());
402 upstream_fetcher_->SetRequestContext(url_context_.get()); 457 upstream_fetcher_->SetRequestContext(url_context_.get());
403 upstream_fetcher_->SetReferrer(config_.origin_url); 458 upstream_fetcher_->SetReferrer(config_.origin_url);
404 upstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | 459 upstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
405 net::LOAD_DO_NOT_SEND_COOKIES | 460 net::LOAD_DO_NOT_SEND_COOKIES |
406 net::LOAD_DO_NOT_SEND_AUTH_DATA); 461 net::LOAD_DO_NOT_SEND_AUTH_DATA);
407 upstream_fetcher_->Start(); 462 upstream_fetcher_->Start();
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 } 698 }
644 699
645 SpeechRecognitionEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) 700 SpeechRecognitionEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value)
646 : event(event_value) { 701 : event(event_value) {
647 } 702 }
648 703
649 SpeechRecognitionEngine::FSMEventArgs::~FSMEventArgs() { 704 SpeechRecognitionEngine::FSMEventArgs::~FSMEventArgs() {
650 } 705 }
651 706
652 } // namespace content 707 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698