| 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 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 namespace ukm { | 27 namespace ukm { |
| 28 class UkmRecorder; | 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; | |
| 38 | |
| 39 // Features used to enable ranker query, enforcement and logging. Note that | 37 // Features used to enable ranker query, enforcement and logging. Note that |
| 40 // enabling enforcement implies (forces) enabling queries. | 38 // enabling enforcement implies (forces) enabling queries. |
| 41 extern const base::Feature kTranslateRankerQuery; | 39 extern const base::Feature kTranslateRankerQuery; |
| 42 extern const base::Feature kTranslateRankerEnforcement; | 40 extern const base::Feature kTranslateRankerEnforcement; |
| 43 extern const base::Feature kTranslateRankerDecisionOverride; | 41 extern const base::Feature kTranslateRankerDecisionOverride; |
| 44 | 42 |
| 45 struct TranslateRankerFeatures { | 43 struct TranslateRankerFeatures { |
| 46 TranslateRankerFeatures(); | 44 TranslateRankerFeatures(); |
| 47 | 45 |
| 48 TranslateRankerFeatures(int accepted, | 46 TranslateRankerFeatures(int accepted, |
| 49 int denied, | 47 int denied, |
| 50 int ignored, | 48 int ignored, |
| 51 const std::string& src, | 49 const std::string& src, |
| 52 const std::string& dst, | 50 const std::string& dst, |
| 53 const std::string& cntry, | 51 const std::string& cntry, |
| 54 const std::string& locale); | 52 const std::string& locale); |
| 55 | 53 |
| 56 TranslateRankerFeatures(const TranslatePrefs& prefs, | 54 TranslateRankerFeatures(const metrics::TranslateEventProto& tep); |
| 57 const std::string& src, | |
| 58 const std::string& dst, | |
| 59 const std::string& locale); | |
| 60 | 55 |
| 61 ~TranslateRankerFeatures(); | 56 ~TranslateRankerFeatures(); |
| 62 | 57 |
| 63 void WriteTo(std::ostream& stream) const; | 58 void WriteTo(std::ostream& stream) const; |
| 64 | 59 |
| 65 // Input value used to generate the features. | 60 // Input value used to generate the features. |
| 66 int accepted_count; | 61 int accepted_count; |
| 67 int denied_count; | 62 int denied_count; |
| 68 int ignored_count; | 63 int ignored_count; |
| 69 int total_count; | 64 int total_count; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 94 // Get the URL from which the download the translate ranker model, by default | 89 // Get the URL from which the download the translate ranker model, by default |
| 95 // from Finch. | 90 // from Finch. |
| 96 static GURL GetModelURL(); | 91 static GURL GetModelURL(); |
| 97 | 92 |
| 98 // Override the default enabled/disabled state of translate event logging. | 93 // Override the default enabled/disabled state of translate event logging. |
| 99 void EnableLogging(bool value); | 94 void EnableLogging(bool value); |
| 100 | 95 |
| 101 // TranslateRanker... | 96 // TranslateRanker... |
| 102 uint32_t GetModelVersion() const override; | 97 uint32_t GetModelVersion() const override; |
| 103 bool ShouldOfferTranslation( | 98 bool ShouldOfferTranslation( |
| 104 const TranslatePrefs& translate_prefs, | |
| 105 const std::string& src_lang, | |
| 106 const std::string& dst_lang, | |
| 107 metrics::TranslateEventProto* translate_event) override; | 99 metrics::TranslateEventProto* translate_event) override; |
| 108 void FlushTranslateEvents( | 100 void FlushTranslateEvents( |
| 109 std::vector<metrics::TranslateEventProto>* events) override; | 101 std::vector<metrics::TranslateEventProto>* events) override; |
| 110 void RecordTranslateEvent( | 102 void RecordTranslateEvent( |
| 111 int event_type, | 103 int event_type, |
| 112 const GURL& url, | 104 const GURL& url, |
| 113 metrics::TranslateEventProto* translate_event) override; | 105 metrics::TranslateEventProto* translate_event) override; |
| 114 bool ShouldOverrideDecision( | 106 bool ShouldOverrideDecision( |
| 115 int event_type, | 107 int event_type, |
| 116 const GURL& url, | 108 const GURL& url, |
| 117 metrics::TranslateEventProto* translate_event) override; | 109 metrics::TranslateEventProto* translate_event) override; |
| 118 | 110 |
| 119 void OnModelAvailable( | 111 void OnModelAvailable( |
| 120 std::unique_ptr<chrome_intelligence::RankerModel> model); | 112 std::unique_ptr<chrome_intelligence::RankerModel> model); |
| 121 | 113 |
| 122 // Get the model decision on whether we should show the translate | 114 // Get the model decision on whether we should show the translate |
| 123 // UI or not given |features|. | 115 // UI or not given |translate_event|. |
| 124 bool GetModelDecision(const TranslateRankerFeatures& features); | 116 bool GetModelDecision(const metrics::TranslateEventProto& translate_event); |
| 125 | 117 |
| 126 // Check if the ModelLoader has been initialized. Used to test ModelLoader | 118 // Check if the ModelLoader has been initialized. Used to test ModelLoader |
| 127 // logic. | 119 // logic. |
| 128 bool CheckModelLoaderForTesting(); | 120 bool CheckModelLoaderForTesting(); |
| 129 | 121 |
| 130 private: | 122 private: |
| 131 void SendEventToUKM(const metrics::TranslateEventProto& translate_event, | 123 void SendEventToUKM(const metrics::TranslateEventProto& translate_event, |
| 132 const GURL& url); | 124 const GURL& url); |
| 133 | 125 |
| 134 // Caches the translate event. | 126 // Caches the translate event. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 162 |
| 171 DISALLOW_COPY_AND_ASSIGN(TranslateRankerImpl); | 163 DISALLOW_COPY_AND_ASSIGN(TranslateRankerImpl); |
| 172 }; | 164 }; |
| 173 | 165 |
| 174 } // namespace translate | 166 } // namespace translate |
| 175 | 167 |
| 176 std::ostream& operator<<(std::ostream& stream, | 168 std::ostream& operator<<(std::ostream& stream, |
| 177 const translate::TranslateRankerFeatures& features); | 169 const translate::TranslateRankerFeatures& features); |
| 178 | 170 |
| 179 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_IMPL_H_ | 171 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_IMPL_H_ |
| OLD | NEW |