Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "components/data_use_measurement/core/data_use_user_data.h" | 7 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 8 #include "components/translate/core/browser/translate_download_manager.h" | 8 #include "components/translate/core/browser/translate_download_manager.h" |
| 9 #include "net/base/load_flags.h" | 9 #include "net/base/load_flags.h" |
| 10 #include "net/http/http_status_code.h" | 10 #include "net/http/http_status_code.h" |
| 11 #include "net/traffic_annotation/network_traffic_annotation.h" | |
| 11 #include "net/url_request/url_fetcher.h" | 12 #include "net/url_request/url_fetcher.h" |
| 12 #include "net/url_request/url_request_status.h" | 13 #include "net/url_request/url_request_status.h" |
| 13 | 14 |
| 14 namespace translate { | 15 namespace translate { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 // Retry parameter for fetching. | 19 // Retry parameter for fetching. |
| 19 const int kMaxRetry = 16; | 20 const int kMaxRetry = 16; |
| 20 | 21 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 39 } | 40 } |
| 40 | 41 |
| 41 if (retry_count_ >= kMaxRetry) | 42 if (retry_count_ >= kMaxRetry) |
| 42 return false; | 43 return false; |
| 43 retry_count_++; | 44 retry_count_++; |
| 44 | 45 |
| 45 state_ = REQUESTING; | 46 state_ = REQUESTING; |
| 46 url_ = url; | 47 url_ = url; |
| 47 callback_ = callback; | 48 callback_ = callback; |
| 48 | 49 |
| 49 fetcher_ = net::URLFetcher::Create(id_, url_, net::URLFetcher::GET, this); | 50 net::NetworkTrafficAnnotationTag traffic_annotation = |
| 51 net::DefineNetworkTrafficAnnotation("translate_url_fetcher", R"( | |
| 52 semantics { | |
| 53 sender: "Translate" | |
| 54 description: | |
| 55 "Chromium can provide translations for the web sites visited by " | |
|
Takashi Toyoshima
2017/04/18 07:27:36
Sorry, one more nits.
According to the style guide
Ramin Halavati
2017/04/18 07:58:00
You are right. We had missed this rule. I will cha
| |
| 56 "the user. If this feature is enabled, Chromium sends network " | |
|
Takashi Toyoshima
2017/04/18 07:27:36
ditto
Ramin Halavati
2017/04/18 07:58:00
Done.
| |
| 57 "requests to download the list of supported languages, a library " | |
| 58 "to perform translations, and a predictive model to know when to " | |
| 59 "offer translation." | |
| 60 trigger: | |
| 61 "When Chromium starts, it downloads the list of supported " | |
|
Takashi Toyoshima
2017/04/18 07:27:36
ditto
Ramin Halavati
2017/04/18 07:58:00
Done.
| |
| 62 "langagues for translation, and a predictive model to detect the " | |
| 63 "language of web pages. The model is cached and the link to the " | |
| 64 "latest model is provided by field study. If latest model is " | |
| 65 "already cached, it is not fetched. The first time the model " | |
| 66 "decides to offer translation of a web site, it triggers a popup " | |
| 67 "to ask if user wants a translation and if user approves, " | |
| 68 "translation library is downloaded. The library is cached for a " | |
| 69 "day and is not fetched if it is available and fresh." | |
| 70 data: | |
| 71 "Current locale is sent to fetch the list of supperted lanaguges. " | |
| 72 "Translation library that is obtained via this interface would " | |
| 73 "perform actual translation, and it will send words and phrases in " | |
| 74 "the site to the server to translate it, but this request doesn't " | |
| 75 "send any words." | |
| 76 destination: GOOGLE_OWNED_SERVICE | |
| 77 } | |
| 78 policy { | |
| 79 cookies_allowed: false | |
| 80 setting: | |
| 81 "Users can enable/disable this feature by toggling 'Offer to " | |
| 82 "translate pages that aren't in a language you read.' in Chromium " | |
|
Takashi Toyoshima
2017/04/18 07:27:36
ditto
Ramin Halavati
2017/04/18 07:58:00
Done.
| |
| 83 "settings under Languages. The list of supported languages is " | |
| 84 "downloaded regardless of the settings." | |
| 85 chrome_policy { | |
| 86 TranslateEnabled { | |
| 87 policy_options {mode: MANDATORY} | |
| 88 TranslateEnabled: false | |
| 89 } | |
| 90 } | |
| 91 policy_exception_justification: | |
| 92 "There is no policy for disabling download of the list of " | |
| 93 "supported languages. It is considered not required as the list is " | |
| 94 "needed for rendering user interfaces, and Chrome does not send " | |
| 95 "privacy/security sensitive data to the server on downloading it." | |
| 96 })"); | |
| 97 fetcher_ = net::URLFetcher::Create(id_, url_, net::URLFetcher::GET, this, | |
| 98 traffic_annotation); | |
| 50 data_use_measurement::DataUseUserData::AttachToFetcher( | 99 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 51 fetcher_.get(), data_use_measurement::DataUseUserData::TRANSLATE); | 100 fetcher_.get(), data_use_measurement::DataUseUserData::TRANSLATE); |
| 52 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 101 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 53 net::LOAD_DO_NOT_SAVE_COOKIES); | 102 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 54 fetcher_->SetRequestContext( | 103 fetcher_->SetRequestContext( |
| 55 TranslateDownloadManager::GetInstance()->request_context()); | 104 TranslateDownloadManager::GetInstance()->request_context()); |
| 56 // Set retry parameter for HTTP status code 5xx. This doesn't work against | 105 // Set retry parameter for HTTP status code 5xx. This doesn't work against |
| 57 // 106 (net::ERR_INTERNET_DISCONNECTED) and so on. | 106 // 106 (net::ERR_INTERNET_DISCONNECTED) and so on. |
| 58 // TranslateLanguageList handles network status, and implements retry. | 107 // TranslateLanguageList handles network status, and implements retry. |
| 59 fetcher_->SetMaxRetriesOn5xx(max_retry_on_5xx_); | 108 fetcher_->SetMaxRetriesOn5xx(max_retry_on_5xx_); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 76 } else { | 125 } else { |
| 77 state_ = FAILED; | 126 state_ = FAILED; |
| 78 } | 127 } |
| 79 | 128 |
| 80 // Transfer URLFetcher's ownership before invoking a callback. | 129 // Transfer URLFetcher's ownership before invoking a callback. |
| 81 std::unique_ptr<const net::URLFetcher> delete_ptr(fetcher_.release()); | 130 std::unique_ptr<const net::URLFetcher> delete_ptr(fetcher_.release()); |
| 82 callback_.Run(id_, state_ == COMPLETED, data); | 131 callback_.Run(id_, state_ == COMPLETED, data); |
| 83 } | 132 } |
| 84 | 133 |
| 85 } // namespace translate | 134 } // namespace translate |
| OLD | NEW |