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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/translate/core/common/translation_logging_helper.h"
6
7 #include "base/logging.h"
8 #include "base/time/time.h"
9 #include "components/metrics/proto/translate_event.pb.h"
10 #include "components/sync/protocol/user_event_specifics.pb.h"
11
12 namespace translate {
13 namespace {
14 using metrics::TranslateEventProto;
15 } // namespace
16
17 bool ConstructTranslateEvent(const int64_t navigation_id,
18 const TranslateEventProto& translate_event,
19 sync_pb::UserEventSpecifics* const specifics) {
20 specifics->set_event_time_usec(base::Time::Now().ToInternalValue());
21
22 // TODO(renjieliu): Revisit this field when the best way to identify
23 // navigations is determined.
24 specifics->set_navigation_id(navigation_id);
25 auto* const translation = specifics->mutable_translation();
26 translation->set_from_language_code(translate_event.source_language());
27 translation->set_to_language_code(translate_event.target_language());
28 switch (translate_event.event_type()) {
29 case TranslateEventProto::UNKNOWN:
30 translation->set_interaction(sync_pb::Translation::UNKNOWN);
31 break;
32 case TranslateEventProto::USER_ACCEPT:
33 if (translate_event.has_modified_source_language() ||
34 translate_event.has_modified_target_language()) {
35 // Special case, since we don't have event enum telling us it's actually
36 // modified by user, we do this by check whether this event has modified
37 // source or target language.
38 if (translate_event.has_modified_source_language()) {
39 translation->set_from_language_code(
40 translate_event.modified_source_language());
41 }
42 if (translate_event.has_modified_target_language()) {
43 translation->set_to_language_code(
44 translate_event.modified_target_language());
45 }
46 translation->set_interaction(sync_pb::Translation::MANUAL);
47 } else {
48 translation->set_interaction(sync_pb::Translation::ACCEPT);
49 }
50 break;
51 case TranslateEventProto::USER_DECLINE:
52 translation->set_interaction(sync_pb::Translation::DECLINE);
53 break;
54 case TranslateEventProto::USER_IGNORE:
55 translation->set_interaction(sync_pb::Translation::IGNORED);
56 break;
57 case TranslateEventProto::USER_DISMISS:
58 translation->set_interaction(sync_pb::Translation::DISMISSED);
59 break;
60 case TranslateEventProto::USER_REVERT:
61 translation->set_interaction(sync_pb::Translation::TRANSLATION_REVERTED);
62 break;
63 case TranslateEventProto::AUTOMATICALLY_TRANSLATED:
64 translation->set_interaction(sync_pb::Translation::AUTOMATIC_TRANSLATION);
65 break;
66 default: // We don't care about other events.
67 return false;
68 }
69 return true;
70 }
71 } // namespace translate
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698