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 " | |
| 56 "the user. If this feature is enabled, Chromium sends network " | |
| 57 "requests on startup to download the list of supported languages, " | |
| 58 "a library to perform translations, and a predictive model to know " | |
| 59 "when to offer translation." | |
| 60 trigger: | |
| 61 "When Chromium translates a web site, it triggers a request to " | |
|
Roger McFarlane (Chromium)
2017/04/11 14:04:19
I'm not sure what level of detail/precision is req
Takashi Toyoshima
2017/04/12 05:49:18
Do you think the predictive model downloading can
Ramin Halavati
2017/04/12 05:54:43
Done.
Ramin Halavati
2017/04/12 05:54:44
Acknowledged.
Roger McFarlane (Chromium)
2017/04/12 14:04:12
That's a good idea. But currently no, the download
| |
| 62 "fetch the supporting language list in the first translation, and " | |
| 63 "will trigger another request to fetch the library once a day to " | |
| 64 "make sure it is up to date." | |
| 65 data: | |
| 66 "Language id of the library that is required. Translation library " | |
|
Takashi Toyoshima
2017/04/11 10:00:06
Precisely said, Chrome send the current locale on
Ramin Halavati
2017/04/12 05:54:43
Done.
| |
| 67 "that is obtained via this interface would perform actual " | |
| 68 "translation, and it will send words and phrases in the site to " | |
| 69 "the server to translate it, but this request doesn't send any " | |
| 70 "words." | |
| 71 destination: GOOGLE_OWNED_SERVICE | |
| 72 } | |
| 73 policy { | |
| 74 cookies_allowed: false | |
| 75 setting: | |
| 76 "Users can enable/disable this feature by toggling 'Offer to " | |
| 77 "translate pages that aren't in a language you read.' in Chromium " | |
| 78 "settings under Languages." | |
| 79 chrome_policy { | |
| 80 TranslateEnabled { | |
| 81 policy_options {mode: MANDATORY} | |
| 82 TranslateEnabled: false | |
| 83 } | |
| 84 } | |
| 85 })"); | |
| 86 fetcher_ = net::URLFetcher::Create(id_, url_, net::URLFetcher::GET, this, | |
| 87 traffic_annotation); | |
| 50 data_use_measurement::DataUseUserData::AttachToFetcher( | 88 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 51 fetcher_.get(), data_use_measurement::DataUseUserData::TRANSLATE); | 89 fetcher_.get(), data_use_measurement::DataUseUserData::TRANSLATE); |
| 52 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 90 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 53 net::LOAD_DO_NOT_SAVE_COOKIES); | 91 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 54 fetcher_->SetRequestContext( | 92 fetcher_->SetRequestContext( |
| 55 TranslateDownloadManager::GetInstance()->request_context()); | 93 TranslateDownloadManager::GetInstance()->request_context()); |
| 56 // Set retry parameter for HTTP status code 5xx. This doesn't work against | 94 // Set retry parameter for HTTP status code 5xx. This doesn't work against |
| 57 // 106 (net::ERR_INTERNET_DISCONNECTED) and so on. | 95 // 106 (net::ERR_INTERNET_DISCONNECTED) and so on. |
| 58 // TranslateLanguageList handles network status, and implements retry. | 96 // TranslateLanguageList handles network status, and implements retry. |
| 59 fetcher_->SetMaxRetriesOn5xx(max_retry_on_5xx_); | 97 fetcher_->SetMaxRetriesOn5xx(max_retry_on_5xx_); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 76 } else { | 114 } else { |
| 77 state_ = FAILED; | 115 state_ = FAILED; |
| 78 } | 116 } |
| 79 | 117 |
| 80 // Transfer URLFetcher's ownership before invoking a callback. | 118 // Transfer URLFetcher's ownership before invoking a callback. |
| 81 std::unique_ptr<const net::URLFetcher> delete_ptr(fetcher_.release()); | 119 std::unique_ptr<const net::URLFetcher> delete_ptr(fetcher_.release()); |
| 82 callback_.Run(id_, state_ == COMPLETED, data); | 120 callback_.Run(id_, state_ == COMPLETED, data); |
| 83 } | 121 } |
| 84 | 122 |
| 85 } // namespace translate | 123 } // namespace translate |
| OLD | NEW |