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 "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/traffic_annotation/network_traffic_annotation.h" |
13 #include "net/url_request/url_fetcher.h" | 13 #include "net/url_request/url_fetcher.h" |
14 #include "net/url_request/url_request_status.h" | 14 #include "net/url_request/url_request_status.h" |
15 | 15 |
16 namespace translate { | 16 namespace translate { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 // Retry parameter for fetching. | 20 // Retry parameter for fetching. |
21 const int kMaxRetry = 16; | 21 const int kMaxRetry = 16; |
22 | 22 |
23 } // namespace | 23 } // namespace |
24 | 24 |
25 TranslateURLFetcher::TranslateURLFetcher(int id) : id_(id), | 25 TranslateURLFetcher::TranslateURLFetcher(int id) |
26 state_(IDLE), | 26 : id_(id), state_(IDLE), retry_count_(0) {} |
27 retry_count_(0) { | |
28 } | |
29 | 27 |
30 TranslateURLFetcher::~TranslateURLFetcher() { | 28 TranslateURLFetcher::~TranslateURLFetcher() {} |
31 } | |
32 | 29 |
33 bool TranslateURLFetcher::Request( | 30 bool TranslateURLFetcher::Request( |
34 const GURL& url, | 31 const GURL& url, |
35 const TranslateURLFetcher::Callback& callback) { | 32 const TranslateURLFetcher::Callback& callback) { |
36 // This function is not supposed to be called if the previous operation is not | 33 // This function is not supposed to be called if the previous operation is not |
37 // finished. | 34 // finished. |
38 if (state_ == REQUESTING) { | 35 if (state_ == REQUESTING) { |
39 NOTREACHED(); | 36 NOTREACHED(); |
40 return false; | 37 return false; |
41 } | 38 } |
(...skipping 14 matching lines...) Expand all Loading... |
56 if (request_context_getter == nullptr) | 53 if (request_context_getter == nullptr) |
57 return false; | 54 return false; |
58 | 55 |
59 net::NetworkTrafficAnnotationTag traffic_annotation = | 56 net::NetworkTrafficAnnotationTag traffic_annotation = |
60 net::DefineNetworkTrafficAnnotation("translate_url_fetcher", R"( | 57 net::DefineNetworkTrafficAnnotation("translate_url_fetcher", R"( |
61 semantics { | 58 semantics { |
62 sender: "Translate" | 59 sender: "Translate" |
63 description: | 60 description: |
64 "Chrome can provide translations for the web sites visited by the " | 61 "Chrome can provide translations for the web sites visited by the " |
65 "user. If this feature is enabled, Chrome sends network requests " | 62 "user. If this feature is enabled, Chrome sends network requests " |
66 "to download the list of supported languages, a library to perform " | 63 "to download the list of supported languages and a library to " |
67 "translations, and a predictive model to know when to offer " | 64 "perform translations." |
68 "translation." | |
69 trigger: | 65 trigger: |
70 "When Chrome starts, it downloads the list of supported langagues " | 66 "When Chrome starts, it downloads the list of supported languages " |
71 "for translation, and a predictive model to infer whether a " | 67 "for translation. The first time Chrome decides to offer " |
72 "translation from the detected language to some other language " | 68 "translation of a web site, it triggers a popup to ask " |
73 "would be useful/accepted by the user. The model is cached and the " | 69 "if user wants a translation and if user approves, " |
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 " | 70 "translation library is downloaded. The library is cached for a " |
79 "day and is not fetched if it is available and fresh." | 71 "day and is not fetched if it is available and fresh." |
80 data: | 72 data: |
81 "Current locale is sent to fetch the list of supported lanaguges. " | 73 "Current locale is sent to fetch the list of supported languages. " |
82 "Translation library that is obtained via this interface would " | 74 "Translation library that is obtained via this interface would " |
83 "perform actual translation, and it will send words and phrases in " | 75 "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 " | 76 "the site to the server to translate it, but this request doesn't " |
85 "send any words." | 77 "send any words." |
86 destination: GOOGLE_OWNED_SERVICE | 78 destination: GOOGLE_OWNED_SERVICE |
87 } | 79 } |
88 policy { | 80 policy { |
89 cookies_allowed: false | 81 cookies_allowed: false |
90 setting: | 82 setting: |
91 "Users can enable/disable this feature by toggling 'Offer to " | 83 "Users can enable/disable this feature by toggling 'Offer to " |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } else { | 128 } else { |
137 state_ = FAILED; | 129 state_ = FAILED; |
138 } | 130 } |
139 | 131 |
140 // Transfer URLFetcher's ownership before invoking a callback. | 132 // Transfer URLFetcher's ownership before invoking a callback. |
141 std::unique_ptr<const net::URLFetcher> delete_ptr(fetcher_.release()); | 133 std::unique_ptr<const net::URLFetcher> delete_ptr(fetcher_.release()); |
142 callback_.Run(id_, state_ == COMPLETED, data); | 134 callback_.Run(id_, state_ == COMPLETED, data); |
143 } | 135 } |
144 | 136 |
145 } // namespace translate | 137 } // namespace translate |
OLD | NEW |