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

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: Adressing sdefresne's comments. Created 3 years, 5 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/machine_intelligence/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 machine_intelligence {
24 class RankerModel; 24 class RankerModel;
25 } // namespace chrome_intelligence 25 } // namespace machine_intelligence
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 void RecordTranslateEvent( 100 void RecordTranslateEvent(
101 int event_type, 101 int event_type,
102 const GURL& url, 102 const GURL& url,
103 metrics::TranslateEventProto* translate_event) override; 103 metrics::TranslateEventProto* translate_event) override;
104 bool ShouldOverrideDecision( 104 bool ShouldOverrideDecision(
105 int event_type, 105 int event_type,
106 const GURL& url, 106 const GURL& url,
107 metrics::TranslateEventProto* translate_event) override; 107 metrics::TranslateEventProto* translate_event) override;
108 108
109 void OnModelAvailable( 109 void OnModelAvailable(
110 std::unique_ptr<chrome_intelligence::RankerModel> model); 110 std::unique_ptr<machine_intelligence::RankerModel> model);
111 111
112 // Get the model decision on whether we should show the translate 112 // Get the model decision on whether we should show the translate
113 // UI or not given |translate_event|. 113 // UI or not given |translate_event|.
114 bool GetModelDecision(const metrics::TranslateEventProto& translate_event); 114 bool GetModelDecision(const metrics::TranslateEventProto& translate_event);
115 115
116 // Check if the ModelLoader has been initialized. Used to test ModelLoader 116 // Check if the ModelLoader has been initialized. Used to test ModelLoader
117 // logic. 117 // logic.
118 bool CheckModelLoaderForTesting(); 118 bool CheckModelLoaderForTesting();
119 119
120 private: 120 private:
121 void SendEventToUKM(const metrics::TranslateEventProto& translate_event, 121 void SendEventToUKM(const metrics::TranslateEventProto& translate_event,
122 const GURL& url); 122 const GURL& url);
123 123
124 // Caches the translate event. 124 // Caches the translate event.
125 void AddTranslateEvent(const metrics::TranslateEventProto& translate_event, 125 void AddTranslateEvent(const metrics::TranslateEventProto& translate_event,
126 const GURL& url); 126 const GURL& url);
127 127
128 // Used to log URL-keyed metrics. This pointer will outlive |this|. 128 // Used to log URL-keyed metrics. This pointer will outlive |this|.
129 ukm::UkmRecorder* ukm_recorder_; 129 ukm::UkmRecorder* ukm_recorder_;
130 130
131 // Used to sanity check the threading of this ranker. 131 // Used to sanity check the threading of this ranker.
132 base::SequenceChecker sequence_checker_; 132 base::SequenceChecker sequence_checker_;
133 133
134 // A helper to load the translate ranker model from disk cache or a URL. 134 // A helper to load the translate ranker model from disk cache or a URL.
135 std::unique_ptr<RankerModelLoader> model_loader_; 135 std::unique_ptr<machine_intelligence::RankerModelLoader> model_loader_;
136 136
137 // The translation ranker model. 137 // The translation ranker model.
138 std::unique_ptr<chrome_intelligence::RankerModel> model_; 138 std::unique_ptr<machine_intelligence::RankerModel> model_;
139 139
140 // Tracks whether or not translate event logging is enabled. 140 // Tracks whether or not translate event logging is enabled.
141 bool is_logging_enabled_ = true; 141 bool is_logging_enabled_ = true;
142 142
143 // Tracks whether or not translate ranker querying is enabled. 143 // Tracks whether or not translate ranker querying is enabled.
144 bool is_query_enabled_ = true; 144 bool is_query_enabled_ = true;
145 145
146 // Tracks whether or not translate ranker enforcement is enabled. Note that 146 // Tracks whether or not translate ranker enforcement is enabled. Note that
147 // that also enables the code paths for translate ranker querying. 147 // that also enables the code paths for translate ranker querying.
148 bool is_enforcement_enabled_ = true; 148 bool is_enforcement_enabled_ = true;
149 149
150 // Tracks whether or not translate ranker decision override is enabled. This 150 // Tracks whether or not translate ranker decision override is enabled. This
151 // will override suppression heuristics. 151 // will override suppression heuristics.
152 bool is_decision_override_enabled_ = true; 152 bool is_decision_override_enabled_ = true;
153 153
154 // Saved cache of translate event protos. 154 // Saved cache of translate event protos.
155 std::vector<metrics::TranslateEventProto> event_cache_; 155 std::vector<metrics::TranslateEventProto> event_cache_;
156 156
157 base::WeakPtrFactory<TranslateRankerImpl> weak_ptr_factory_; 157 base::WeakPtrFactory<TranslateRankerImpl> weak_ptr_factory_;
158 158
159 DISALLOW_COPY_AND_ASSIGN(TranslateRankerImpl); 159 DISALLOW_COPY_AND_ASSIGN(TranslateRankerImpl);
160 }; 160 };
161 161
162 } // namespace translate 162 } // namespace translate
163 163
164 std::ostream& operator<<(std::ostream& stream, 164 std::ostream& operator<<(std::ostream& stream,
165 const translate::TranslateRankerFeatures& features); 165 const translate::TranslateRankerFeatures& features);
166 166
167 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_IMPL_H_ 167 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_IMPL_H_
OLDNEW
« no previous file with comments | « components/translate/core/browser/ranker_model_unittest.cc ('k') | components/translate/core/browser/translate_ranker_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698