OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_IMPL_H_ | 5 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_IMPL_H_ |
6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_IMPL_H_ | 6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_IMPL_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/feature_list.h" | 11 #include "base/feature_list.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/sequence_checker.h" | 14 #include "base/sequence_checker.h" |
15 #include "base/sequenced_task_runner.h" | 15 #include "base/sequenced_task_runner.h" |
16 #include "components/keyed_service/core/keyed_service.h" | 16 #include "components/keyed_service/core/keyed_service.h" |
17 #include "components/translate/core/browser/ranker_model_loader.h" | 17 #include "components/translate/core/browser/ranker_model_loader.h" |
18 #include "components/translate/core/browser/translate_ranker.h" | 18 #include "components/translate/core/browser/translate_ranker.h" |
19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
20 | 20 |
21 class GURL; | 21 class GURL; |
22 | 22 |
23 namespace chrome_intelligence { | 23 namespace chrome_intelligence { |
24 class RankerModel; | 24 class RankerModel; |
25 } // namespace chrome_intelligence | 25 } // namespace chrome_intelligence |
26 | 26 |
27 namespace ukm { | 27 namespace ukm { |
28 class UkmService; | 28 class UkmRecorder; |
29 } // namespace ukm | 29 } // namespace ukm |
30 | 30 |
31 namespace metrics { | 31 namespace metrics { |
32 class TranslateEventProto; | 32 class TranslateEventProto; |
33 } // namespace metrics | 33 } // namespace metrics |
34 | 34 |
35 namespace translate { | 35 namespace translate { |
36 | 36 |
37 class TranslatePrefs; | 37 class TranslatePrefs; |
38 | 38 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 double denied_ratio; | 77 double denied_ratio; |
78 double ignored_ratio; | 78 double ignored_ratio; |
79 }; | 79 }; |
80 | 80 |
81 // If enabled, downloads a translate ranker model and uses it to determine | 81 // If enabled, downloads a translate ranker model and uses it to determine |
82 // whether the user should be given a translation prompt or not. | 82 // whether the user should be given a translation prompt or not. |
83 class TranslateRankerImpl : public TranslateRanker { | 83 class TranslateRankerImpl : public TranslateRanker { |
84 public: | 84 public: |
85 TranslateRankerImpl(const base::FilePath& model_path, | 85 TranslateRankerImpl(const base::FilePath& model_path, |
86 const GURL& model_url, | 86 const GURL& model_url, |
87 ukm::UkmService* ukm_service); | 87 ukm::UkmRecorder* ukm_recorder); |
88 ~TranslateRankerImpl() override; | 88 ~TranslateRankerImpl() override; |
89 | 89 |
90 // Get the file path of the translate ranker model, by default with a fixed | 90 // Get the file path of the translate ranker model, by default with a fixed |
91 // name within |data_dir|. | 91 // name within |data_dir|. |
92 static base::FilePath GetModelPath(const base::FilePath& data_dir); | 92 static base::FilePath GetModelPath(const base::FilePath& data_dir); |
93 | 93 |
94 // Get the URL from which the download the translate ranker model, by default | 94 // Get the URL from which the download the translate ranker model, by default |
95 // from Finch. | 95 // from Finch. |
96 static GURL GetModelURL(); | 96 static GURL GetModelURL(); |
97 | 97 |
(...skipping 30 matching lines...) Expand all Loading... |
128 | 128 |
129 private: | 129 private: |
130 void SendEventToUKM(const metrics::TranslateEventProto& translate_event, | 130 void SendEventToUKM(const metrics::TranslateEventProto& translate_event, |
131 const GURL& url); | 131 const GURL& url); |
132 | 132 |
133 // Caches the translate event. | 133 // Caches the translate event. |
134 void AddTranslateEvent(const metrics::TranslateEventProto& translate_event, | 134 void AddTranslateEvent(const metrics::TranslateEventProto& translate_event, |
135 const GURL& url); | 135 const GURL& url); |
136 | 136 |
137 // Used to log URL-keyed metrics. This pointer will outlive |this|. | 137 // Used to log URL-keyed metrics. This pointer will outlive |this|. |
138 ukm::UkmService* ukm_service_; | 138 ukm::UkmRecorder* ukm_recorder_; |
139 | 139 |
140 // Used to sanity check the threading of this ranker. | 140 // Used to sanity check the threading of this ranker. |
141 base::SequenceChecker sequence_checker_; | 141 base::SequenceChecker sequence_checker_; |
142 | 142 |
143 // A helper to load the translate ranker model from disk cache or a URL. | 143 // A helper to load the translate ranker model from disk cache or a URL. |
144 std::unique_ptr<RankerModelLoader> model_loader_; | 144 std::unique_ptr<RankerModelLoader> model_loader_; |
145 | 145 |
146 // The translation ranker model. | 146 // The translation ranker model. |
147 std::unique_ptr<chrome_intelligence::RankerModel> model_; | 147 std::unique_ptr<chrome_intelligence::RankerModel> model_; |
148 | 148 |
(...skipping 20 matching lines...) Expand all Loading... |
169 | 169 |
170 DISALLOW_COPY_AND_ASSIGN(TranslateRankerImpl); | 170 DISALLOW_COPY_AND_ASSIGN(TranslateRankerImpl); |
171 }; | 171 }; |
172 | 172 |
173 } // namespace translate | 173 } // namespace translate |
174 | 174 |
175 std::ostream& operator<<(std::ostream& stream, | 175 std::ostream& operator<<(std::ostream& stream, |
176 const translate::TranslateRankerFeatures& features); | 176 const translate::TranslateRankerFeatures& features); |
177 | 177 |
178 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_IMPL_H_ | 178 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_IMPL_H_ |
OLD | NEW |