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

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

Issue 2395253002: Send TranslateEventProtos to UMA. (Closed)
Patch Set: Remove Record interface from client. 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 #include "components/translate/core/browser/translate_ranker.h" 5 #include "components/translate/core/browser/translate_ranker.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
13 #include "base/profiler/scoped_tracker.h" 13 #include "base/profiler/scoped_tracker.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "components/metrics/proto/translate_event.pb.h"
15 #include "components/translate/core/browser/proto/translate_ranker_model.pb.h" 16 #include "components/translate/core/browser/proto/translate_ranker_model.pb.h"
16 #include "components/translate/core/browser/translate_download_manager.h" 17 #include "components/translate/core/browser/translate_download_manager.h"
17 #include "components/translate/core/browser/translate_prefs.h" 18 #include "components/translate/core/browser/translate_prefs.h"
18 #include "components/translate/core/browser/translate_url_fetcher.h" 19 #include "components/translate/core/browser/translate_url_fetcher.h"
19 #include "components/translate/core/common/translate_switches.h" 20 #include "components/translate/core/common/translate_switches.h"
20 21
21 namespace translate { 22 namespace translate {
22 23
23 namespace { 24 namespace {
24 25
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 80 }
80 81
81 } // namespace 82 } // namespace
82 83
83 const base::Feature kTranslateRankerQuery{"TranslateRankerQuery", 84 const base::Feature kTranslateRankerQuery{"TranslateRankerQuery",
84 base::FEATURE_DISABLED_BY_DEFAULT}; 85 base::FEATURE_DISABLED_BY_DEFAULT};
85 86
86 const base::Feature kTranslateRankerEnforcement{ 87 const base::Feature kTranslateRankerEnforcement{
87 "TranslateRankerEnforcement", base::FEATURE_DISABLED_BY_DEFAULT}; 88 "TranslateRankerEnforcement", base::FEATURE_DISABLED_BY_DEFAULT};
88 89
90 const base::Feature kTranslateRankerLogging{"TranslateRankerLogging",
91 base::FEATURE_DISABLED_BY_DEFAULT};
92
89 TranslateRanker::~TranslateRanker() {} 93 TranslateRanker::~TranslateRanker() {}
90 94
91 // static 95 // static
92 bool TranslateRanker::IsEnabled() { 96 bool TranslateRanker::IsEnabled() {
93 return IsQueryEnabled() || IsEnforcementEnabled(); 97 return IsQueryEnabled() || IsEnforcementEnabled();
94 } 98 }
95 99
96 // static 100 // static
101 bool TranslateRanker::IsLoggingEnabled() {
102 return base::FeatureList::IsEnabled(kTranslateRankerLogging);
103 }
104
105 // static
97 TranslateRanker* TranslateRanker::GetInstance() { 106 TranslateRanker* TranslateRanker::GetInstance() {
98 return base::Singleton<TranslateRanker>::get(); 107 return base::Singleton<TranslateRanker>::get();
99 } 108 }
100 109
101 std::unique_ptr<TranslateRanker> TranslateRanker::CreateForTesting( 110 std::unique_ptr<TranslateRanker> TranslateRanker::CreateForTesting(
102 const std::string& model_data) { 111 const std::string& model_data) {
103 std::unique_ptr<TranslateRanker> ranker(new TranslateRanker()); 112 std::unique_ptr<TranslateRanker> ranker(new TranslateRanker());
104 CHECK(ranker != nullptr); 113 CHECK(ranker != nullptr);
105 ranker->ParseModel(0, true, model_data); 114 ranker->ParseModel(0, true, model_data);
106 CHECK(ranker->model_ != nullptr); 115 CHECK(ranker->model_ != nullptr);
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 if (!is_valid) { 284 if (!is_valid) {
276 ReportModelStatus(MODEL_STATUS_VALIDATION_FAILED); 285 ReportModelStatus(MODEL_STATUS_VALIDATION_FAILED);
277 return; 286 return;
278 } 287 }
279 288
280 ReportModelStatus(MODEL_STATUS_OK); 289 ReportModelStatus(MODEL_STATUS_OK);
281 model_ = std::move(new_model); 290 model_ = std::move(new_model);
282 model_fetcher_.reset(); 291 model_fetcher_.reset();
283 } 292 }
284 293
294 void TranslateRanker::FlushTranslateEvents(
295 std::vector<metrics::TranslateEventProto>* translate_events) {
296 if (IsLoggingEnabled()) {
297 translate_events->swap(translate_events_cache_);
298 translate_events_cache_.clear();
299 }
300 }
301
302 void TranslateRanker::RecordTranslateEvent(
303 const metrics::TranslateEventProto& translate_event) {
304 if (IsLoggingEnabled())
305 translate_events_cache_.push_back(translate_event);
306 }
307
285 } // namespace translate 308 } // namespace translate
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698