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

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

Issue 2395253002: Send TranslateEventProtos to UMA. (Closed)
Patch Set: nit Created 4 years, 2 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_H_ 5 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_H_
6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_H_ 6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_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/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
14 14
15 namespace chrome_intelligence { 15 namespace chrome_intelligence {
16 class TranslateRankerModel; 16 class TranslateRankerModel;
17 } 17 }
18 18
19 namespace metrics {
20 class TranslateEventProto;
21 }
22
19 namespace translate { 23 namespace translate {
20 24
21 class TranslatePrefs; 25 class TranslatePrefs;
22 class TranslateRankerMetricsProvider; 26 class TranslateRankerMetricsProvider;
23 class TranslateURLFetcher; 27 class TranslateURLFetcher;
24 28
25 // Features used to enable ranker query and enforcement. Note that enabling 29 // Features used to enable ranker query and enforcement. Note that enabling
26 // enforcement implies (forces) enabling queries. 30 // enforcement implies (forces) enabling queries.
27 extern const base::Feature kTranslateRankerQuery; 31 extern const base::Feature kTranslateRankerQuery;
28 extern const base::Feature kTranslateRankerEnforcement; 32 extern const base::Feature kTranslateRankerEnforcement;
(...skipping 23 matching lines...) Expand all
52 // context described by |translate_prefs|, |src_lang|, |dst_lang| and possibly 56 // context described by |translate_prefs|, |src_lang|, |dst_lang| and possibly
53 // other global browser context attributes suggests that the user should be 57 // other global browser context attributes suggests that the user should be
54 // prompted as to whether translation should be performed. 58 // prompted as to whether translation should be performed.
55 bool ShouldOfferTranslation(const TranslatePrefs& translate_prefs, 59 bool ShouldOfferTranslation(const TranslatePrefs& translate_prefs,
56 const std::string& src_lang, 60 const std::string& src_lang,
57 const std::string& dst_lang); 61 const std::string& dst_lang);
58 62
59 // Returns the model version (a date stamp) or 0 if there is no valid model. 63 // Returns the model version (a date stamp) or 0 if there is no valid model.
60 int GetModelVersion() const; 64 int GetModelVersion() const;
61 65
66 // Caches the translate event.
67 void RecordTranslateEvent(
68 const metrics::TranslateEventProto& translate_event);
69
70 // Transfers cached translate events to the given vector pointer and clears
71 // the cache.
72 void FlushTranslateEvents(
73 std::vector<metrics::TranslateEventProto>* translate_events);
74
62 private: 75 private:
63 // The ID which is assigned to the underlying URLFetcher. 76 // The ID which is assigned to the underlying URLFetcher.
64 static constexpr int kFetcherId = 2; 77 static constexpr int kFetcherId = 2;
65 78
66 TranslateRanker(); 79 TranslateRanker();
67 80
68 // Exposed for testing via FRIEND_TEST. 81 // Exposed for testing via FRIEND_TEST.
69 double CalculateScore(double accept_ratio, 82 double CalculateScore(double accept_ratio,
70 double decline_ratio, 83 double decline_ratio,
71 double ignore_ratio, 84 double ignore_ratio,
(...skipping 12 matching lines...) Expand all
84 std::unique_ptr<TranslateURLFetcher> model_fetcher_; 97 std::unique_ptr<TranslateURLFetcher> model_fetcher_;
85 98
86 // The next time before which no new attempts to download the model should be 99 // The next time before which no new attempts to download the model should be
87 // attempted. 100 // attempted.
88 base::Time next_earliest_download_time_; 101 base::Time next_earliest_download_time_;
89 102
90 // Tracks the last time the translate ranker attempted to download its model. 103 // Tracks the last time the translate ranker attempted to download its model.
91 // Used for UMA reporting of timing. 104 // Used for UMA reporting of timing.
92 base::Time download_start_time_; 105 base::Time download_start_time_;
93 106
107 // Saved cache of translate event protos.
108 std::vector<metrics::TranslateEventProto> translate_events_cache_;
109
94 FRIEND_TEST_ALL_PREFIXES(TranslateRankerTest, CalculateScore); 110 FRIEND_TEST_ALL_PREFIXES(TranslateRankerTest, CalculateScore);
95 111
96 friend struct base::DefaultSingletonTraits<TranslateRanker>; 112 friend struct base::DefaultSingletonTraits<TranslateRanker>;
97 113
98 DISALLOW_COPY_AND_ASSIGN(TranslateRanker); 114 DISALLOW_COPY_AND_ASSIGN(TranslateRanker);
99 }; 115 };
100 116
101 } // namespace translate 117 } // namespace translate
102 118
103 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_H_ 119 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698