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

Unified Diff: components/translate/core/common/translation_logging_helper.cc

Issue 2913593002: Implementation of translation event logging. (Closed)
Patch Set: fix 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 side-by-side diff with in-line comments
Download patch
Index: components/translate/core/common/translation_logging_helper.cc
diff --git a/components/translate/core/common/translation_logging_helper.cc b/components/translate/core/common/translation_logging_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ac6c0d2ed9b37fffd83a45036b23fecfcae3edc0
--- /dev/null
+++ b/components/translate/core/common/translation_logging_helper.cc
@@ -0,0 +1,71 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/translate/core/common/translation_logging_helper.h"
+
+#include "base/logging.h"
+#include "base/time/time.h"
+#include "components/metrics/proto/translate_event.pb.h"
+#include "components/sync/protocol/user_event_specifics.pb.h"
+
+namespace translate {
+namespace {
+using metrics::TranslateEventProto;
+} // namespace
+
+bool ConstructTranslateEvent(const int64_t navigation_id,
+ const TranslateEventProto& translate_event,
+ sync_pb::UserEventSpecifics* const specifics) {
+ specifics->set_event_time_usec(base::Time::Now().ToInternalValue());
+
+ // TODO(renjieliu): Revisit this field when the best way to identify
+ // navigations is determined.
+ specifics->set_navigation_id(navigation_id);
+ auto* const translation = specifics->mutable_translation();
+ translation->set_from_language_code(translate_event.source_language());
+ translation->set_to_language_code(translate_event.target_language());
+ switch (translate_event.event_type()) {
+ case TranslateEventProto::UNKNOWN:
+ translation->set_interaction(sync_pb::Translation::UNKNOWN);
+ break;
+ case TranslateEventProto::USER_ACCEPT:
+ if (translate_event.has_modified_source_language() ||
+ translate_event.has_modified_target_language()) {
+ // Special case, since we don't have event enum telling us it's actually
+ // modified by user, we do this by check whether this event has modified
+ // source or target language.
+ if (translate_event.has_modified_source_language()) {
+ translation->set_from_language_code(
+ translate_event.modified_source_language());
+ }
+ if (translate_event.has_modified_target_language()) {
+ translation->set_to_language_code(
+ translate_event.modified_target_language());
+ }
+ translation->set_interaction(sync_pb::Translation::MANUAL);
+ } else {
+ translation->set_interaction(sync_pb::Translation::ACCEPT);
+ }
+ break;
+ case TranslateEventProto::USER_DECLINE:
+ translation->set_interaction(sync_pb::Translation::DECLINE);
+ break;
+ case TranslateEventProto::USER_IGNORE:
+ translation->set_interaction(sync_pb::Translation::IGNORED);
+ break;
+ case TranslateEventProto::USER_DISMISS:
+ translation->set_interaction(sync_pb::Translation::DISMISSED);
+ break;
+ case TranslateEventProto::USER_REVERT:
+ translation->set_interaction(sync_pb::Translation::TRANSLATION_REVERTED);
+ break;
+ case TranslateEventProto::AUTOMATICALLY_TRANSLATED:
+ translation->set_interaction(sync_pb::Translation::AUTOMATIC_TRANSLATION);
+ break;
+ default: // We don't care about other events.
+ return false;
+ }
+ return true;
+}
+} // namespace translate

Powered by Google App Engine
This is Rietveld 408576698