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

Side by Side Diff: components/translate/core/browser/translate_url_fetcher.cc

Issue 2796323002: Network traffic annotation added to translate_url_fetcher. (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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/translate/core/browser/translate_url_fetcher.h" 5 #include "components/translate/core/browser/translate_url_fetcher.h"
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "components/data_use_measurement/core/data_use_user_data.h" 8 #include "components/data_use_measurement/core/data_use_user_data.h"
9 #include "components/translate/core/browser/translate_download_manager.h" 9 #include "components/translate/core/browser/translate_download_manager.h"
10 #include "net/base/load_flags.h" 10 #include "net/base/load_flags.h"
11 #include "net/http/http_status_code.h" 11 #include "net/http/http_status_code.h"
12 #include "net/traffic_annotation/network_traffic_annotation.h"
12 #include "net/url_request/url_fetcher.h" 13 #include "net/url_request/url_fetcher.h"
13 #include "net/url_request/url_request_status.h" 14 #include "net/url_request/url_request_status.h"
14 15
15 namespace translate { 16 namespace translate {
16 17
17 namespace { 18 namespace {
18 19
19 // Retry parameter for fetching. 20 // Retry parameter for fetching.
20 const int kMaxRetry = 16; 21 const int kMaxRetry = 16;
21 22
(...skipping 26 matching lines...) Expand all
48 callback_ = callback; 49 callback_ = callback;
49 50
50 // If the TranslateDownloadManager's request context getter is nullptr then 51 // If the TranslateDownloadManager's request context getter is nullptr then
51 // shutdown is in progress. Abort the request, which can't proceed with a 52 // shutdown is in progress. Abort the request, which can't proceed with a
52 // null request_context_getter. 53 // null request_context_getter.
53 scoped_refptr<net::URLRequestContextGetter> request_context_getter = 54 scoped_refptr<net::URLRequestContextGetter> request_context_getter =
54 TranslateDownloadManager::GetInstance()->request_context(); 55 TranslateDownloadManager::GetInstance()->request_context();
55 if (request_context_getter == nullptr) 56 if (request_context_getter == nullptr)
56 return false; 57 return false;
57 58
59 net::NetworkTrafficAnnotationTag traffic_annotation =
60 net::DefineNetworkTrafficAnnotation("translate_url_fetcher", R"(
61 semantics {
62 sender: "Translate"
63 description:
64 "Chrome can provide translations for the web sites visited by the "
65 "user. If this feature is enabled, Chrome sends network requests "
66 "to download the list of supported languages, a library to perform "
67 "translations, and a predictive model to know when to offer "
68 "translation."
69 trigger:
70 "When Chrome starts, it downloads the list of supported langagues "
71 "for translation, and a predictive model to infer whether a "
72 "translation from the detected language to some other language "
73 "would be useful/accepted by the user. The model is cached and the "
74 "link to the latest model is provided by field study. If the "
75 "latest model is already cached, it is not fetched. The first time "
76 "the model decides to offer translation of a web site, it triggers "
77 "a popup to ask if user wants a translation and if user approves, "
78 "translation library is downloaded. The library is cached for a "
79 "day and is not fetched if it is available and fresh."
80 data:
81 "Current locale is sent to fetch the list of supperted lanaguges. "
msramek 2017/05/03 16:43:14 typo: supported
Ramin Halavati 2017/05/04 04:51:47 Done.
82 "Translation library that is obtained via this interface would "
83 "perform actual translation, and it will send words and phrases in "
84 "the site to the server to translate it, but this request doesn't "
85 "send any words."
86 destination: GOOGLE_OWNED_SERVICE
87 }
88 policy {
89 cookies_allowed: false
90 setting:
91 "Users can enable/disable this feature by toggling 'Offer to "
92 "translate pages that aren't in a language you read.' in Chrome "
93 "settings under Languages. The list of supported languages is "
94 "downloaded regardless of the settings."
95 chrome_policy {
96 TranslateEnabled {
97 policy_options {mode: MANDATORY}
98 TranslateEnabled: false
99 }
100 }
101 policy_exception_justification:
102 "There is no policy for disabling download of the list of "
103 "supported languages. It is considered not required as the list is "
104 "needed for rendering user interfaces, and Chrome does not send "
105 "privacy/security sensitive data to the server on downloading it."
106 })");
58 // Create and initialize the URL fetcher. 107 // Create and initialize the URL fetcher.
59 fetcher_ = net::URLFetcher::Create(id_, url_, net::URLFetcher::GET, this); 108 fetcher_ = net::URLFetcher::Create(id_, url_, net::URLFetcher::GET, this,
109 traffic_annotation);
60 data_use_measurement::DataUseUserData::AttachToFetcher( 110 data_use_measurement::DataUseUserData::AttachToFetcher(
61 fetcher_.get(), data_use_measurement::DataUseUserData::TRANSLATE); 111 fetcher_.get(), data_use_measurement::DataUseUserData::TRANSLATE);
62 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 112 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
63 net::LOAD_DO_NOT_SAVE_COOKIES); 113 net::LOAD_DO_NOT_SAVE_COOKIES);
64 fetcher_->SetRequestContext(request_context_getter.get()); 114 fetcher_->SetRequestContext(request_context_getter.get());
65 115
66 // Set retry parameter for HTTP status code 5xx. This doesn't work against 116 // Set retry parameter for HTTP status code 5xx. This doesn't work against
67 // 106 (net::ERR_INTERNET_DISCONNECTED) and so on. 117 // 106 (net::ERR_INTERNET_DISCONNECTED) and so on.
68 // TranslateLanguageList handles network status, and implements retry. 118 // TranslateLanguageList handles network status, and implements retry.
69 fetcher_->SetMaxRetriesOn5xx(max_retry_on_5xx_); 119 fetcher_->SetMaxRetriesOn5xx(max_retry_on_5xx_);
(...skipping 16 matching lines...) Expand all
86 } else { 136 } else {
87 state_ = FAILED; 137 state_ = FAILED;
88 } 138 }
89 139
90 // Transfer URLFetcher's ownership before invoking a callback. 140 // Transfer URLFetcher's ownership before invoking a callback.
91 std::unique_ptr<const net::URLFetcher> delete_ptr(fetcher_.release()); 141 std::unique_ptr<const net::URLFetcher> delete_ptr(fetcher_.release());
92 callback_.Run(id_, state_ == COMPLETED, data); 142 callback_.Run(id_, state_ == COMPLETED, data);
93 } 143 }
94 144
95 } // namespace translate 145 } // namespace translate
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