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

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 TranslateEventProto& translate_event,
18 sync_pb::UserEventSpecifics* const specifics) {
19 specifics->set_event_time_usec(base::Time::Now().ToInternalValue());
20
21 // TODO(renjieliu): Revisit this field when the best way to identify
22 // navigations is determined.
23 specifics->set_navigation_id(base::Time::Now().ToInternalValue());
24 auto* const translation = specifics->mutable_translation();
25 translation->set_from_language_code(translate_event.source_language());
26 translation->set_to_language_code(translate_event.target_language());
27 switch (translate_event.event_type()) {
28 case TranslateEventProto::UNKNOWN:
29 translation->set_interaction(sync_pb::Translation::UNKNOWN);
30 break;
31 case TranslateEventProto::USER_ACCEPT:
32 if (translate_event.has_modified_source_language() ||
33 translate_event.has_modified_target_language()) {
34 // Special case, since we don't have event enum telling us it's actually
35 // modified by user, we do this by check whether this event has modified
36 // source or target language.
37 if (translate_event.has_modified_source_language()) {
38 translation->set_from_language_code(
39 translate_event.modified_source_language());
40 }
41 if (translate_event.has_modified_target_language()) {
42 translation->set_to_language_code(
43 translate_event.modified_target_language());
44 }
45 translation->set_interaction(sync_pb::Translation::MANUAL);
napper 2017/05/31 04:49:56 Why do we need MANUAL? Don't you know it is manual
renjieliu1 2017/05/31 05:22:32 currently in our proto (https://codereview.chromiu
46 } else {
47 translation->set_interaction(sync_pb::Translation::ACCEPT);
48 }
49 break;
50 case TranslateEventProto::USER_DECLINE:
51 translation->set_interaction(sync_pb::Translation::DECLINE);
52 break;
53 case TranslateEventProto::USER_IGNORE:
54 translation->set_interaction(sync_pb::Translation::IGNORED);
55 break;
56 case TranslateEventProto::USER_DISMISS:
57 translation->set_interaction(sync_pb::Translation::DISMISSED);
58 break;
59 case TranslateEventProto::USER_REVERT:
60 translation->set_interaction(sync_pb::Translation::TRANSLATION_REVERTED);
61 break;
62 case TranslateEventProto::AUTOMATICALLY_TRANSLATED:
63 translation->set_interaction(sync_pb::Translation::AUTOMATIC_TRANSLATION);
64 break;
65 default: // We don't care about other events.
66 return false;
67 }
68 return true;
69 }
70 } // namespace translate
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698