Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: components/translate/core/browser/translate_ranker_impl.h

Issue 2925733002: Move ranker_model_loader to a new component. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/ranker/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 ranker {
24 class RankerModel; 24 class RankerModel;
25 } // namespace chrome_intelligence 25 } // namespace ranker
26 26
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 {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 std::vector<metrics::TranslateEventProto>* events) override; 101 std::vector<metrics::TranslateEventProto>* events) override;
102 void RecordTranslateEvent( 102 void RecordTranslateEvent(
103 int event_type, 103 int event_type,
104 const GURL& url, 104 const GURL& url,
105 metrics::TranslateEventProto* translate_event) override; 105 metrics::TranslateEventProto* translate_event) override;
106 bool ShouldOverrideDecision( 106 bool ShouldOverrideDecision(
107 int event_type, 107 int event_type,
108 const GURL& url, 108 const GURL& url,
109 metrics::TranslateEventProto* translate_event) override; 109 metrics::TranslateEventProto* translate_event) override;
110 110
111 void OnModelAvailable( 111 void OnModelAvailable(std::unique_ptr<ranker::RankerModel> model);
112 std::unique_ptr<chrome_intelligence::RankerModel> model);
113 112
114 // Get the model decision on whether we should show the translate 113 // Get the model decision on whether we should show the translate
115 // UI or not given |translate_event|. 114 // UI or not given |translate_event|.
116 bool GetModelDecision(const metrics::TranslateEventProto& translate_event); 115 bool GetModelDecision(const metrics::TranslateEventProto& translate_event);
117 116
118 // Check if the ModelLoader has been initialized. Used to test ModelLoader 117 // Check if the ModelLoader has been initialized. Used to test ModelLoader
119 // logic. 118 // logic.
120 bool CheckModelLoaderForTesting(); 119 bool CheckModelLoaderForTesting();
121 120
122 private: 121 private:
123 void SendEventToUKM(const metrics::TranslateEventProto& translate_event, 122 void SendEventToUKM(const metrics::TranslateEventProto& translate_event,
124 const GURL& url); 123 const GURL& url);
125 124
126 // Caches the translate event. 125 // Caches the translate event.
127 void AddTranslateEvent(const metrics::TranslateEventProto& translate_event, 126 void AddTranslateEvent(const metrics::TranslateEventProto& translate_event,
128 const GURL& url); 127 const GURL& url);
129 128
130 // Used to log URL-keyed metrics. This pointer will outlive |this|. 129 // Used to log URL-keyed metrics. This pointer will outlive |this|.
131 ukm::UkmRecorder* ukm_recorder_; 130 ukm::UkmRecorder* ukm_recorder_;
132 131
133 // Used to sanity check the threading of this ranker. 132 // Used to sanity check the threading of this ranker.
134 base::SequenceChecker sequence_checker_; 133 base::SequenceChecker sequence_checker_;
135 134
136 // A helper to load the translate ranker model from disk cache or a URL. 135 // A helper to load the translate ranker model from disk cache or a URL.
137 std::unique_ptr<RankerModelLoader> model_loader_; 136 std::unique_ptr<ranker::RankerModelLoader> model_loader_;
138 137
139 // The translation ranker model. 138 // The translation ranker model.
140 std::unique_ptr<chrome_intelligence::RankerModel> model_; 139 std::unique_ptr<ranker::RankerModel> model_;
141 140
142 // Tracks whether or not translate event logging is enabled. 141 // Tracks whether or not translate event logging is enabled.
143 bool is_logging_enabled_ = true; 142 bool is_logging_enabled_ = true;
144 143
145 // Tracks whether or not translate ranker querying is enabled. 144 // Tracks whether or not translate ranker querying is enabled.
146 bool is_query_enabled_ = true; 145 bool is_query_enabled_ = true;
147 146
148 // Tracks whether or not translate ranker enforcement is enabled. Note that 147 // Tracks whether or not translate ranker enforcement is enabled. Note that
149 // that also enables the code paths for translate ranker querying. 148 // that also enables the code paths for translate ranker querying.
150 bool is_enforcement_enabled_ = true; 149 bool is_enforcement_enabled_ = true;
(...skipping 11 matching lines...) Expand all
162 161
163 DISALLOW_COPY_AND_ASSIGN(TranslateRankerImpl); 162 DISALLOW_COPY_AND_ASSIGN(TranslateRankerImpl);
164 }; 163 };
165 164
166 } // namespace translate 165 } // namespace translate
167 166
168 std::ostream& operator<<(std::ostream& stream, 167 std::ostream& operator<<(std::ostream& stream,
169 const translate::TranslateRankerFeatures& features); 168 const translate::TranslateRankerFeatures& features);
170 169
171 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_IMPL_H_ 170 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698