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