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/language_detection_logging_helper.h" | 5 #include "components/translate/core/common/language_detection_logging_helper.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "components/sync/protocol/user_event_specifics.pb.h" | 11 #include "components/sync/protocol/user_event_specifics.pb.h" |
12 #include "components/translate/core/common/language_detection_details.h" | 12 #include "components/translate/core/common/language_detection_details.h" |
13 | 13 |
14 namespace translate { | 14 namespace translate { |
15 | 15 |
16 std::unique_ptr<sync_pb::UserEventSpecifics> ConstructLanguageDetectionEvent( | 16 std::unique_ptr<sync_pb::UserEventSpecifics> ConstructLanguageDetectionEvent( |
| 17 const int64_t navigation_id, |
17 const LanguageDetectionDetails& details) { | 18 const LanguageDetectionDetails& details) { |
18 auto specifics = base::MakeUnique<sync_pb::UserEventSpecifics>(); | 19 auto specifics = base::MakeUnique<sync_pb::UserEventSpecifics>(); |
19 specifics->set_event_time_usec(base::Time::Now().ToInternalValue()); | 20 specifics->set_event_time_usec(base::Time::Now().ToInternalValue()); |
20 | 21 |
21 // TODO(renjieliu): Revisit this field when the best way to identify | 22 // TODO(renjieliu): Revisit this field when the best way to identify |
22 // navigations is determined. | 23 // navigations is determined. |
23 specifics->set_navigation_id(base::Time::Now().ToInternalValue()); | 24 specifics->set_navigation_id(navigation_id); |
24 | 25 |
25 sync_pb::LanguageDetection lang_detection; | 26 sync_pb::LanguageDetection lang_detection; |
26 auto* const lang = lang_detection.add_detected_languages(); | 27 auto* const lang = lang_detection.add_detected_languages(); |
27 lang->set_language_code(details.cld_language); | 28 lang->set_language_code(details.cld_language); |
28 lang->set_is_reliable(details.is_cld_reliable); | 29 lang->set_is_reliable(details.is_cld_reliable); |
29 // Only set adopted_language when it's different from cld_language. | 30 // Only set adopted_language when it's different from cld_language. |
30 if (details.adopted_language != details.cld_language) { | 31 if (details.adopted_language != details.cld_language) { |
31 lang_detection.set_adopted_language_code(details.adopted_language); | 32 lang_detection.set_adopted_language_code(details.adopted_language); |
32 } | 33 } |
33 *specifics->mutable_language_detection() = lang_detection; | 34 *specifics->mutable_language_detection() = lang_detection; |
34 return specifics; | 35 return specifics; |
35 } | 36 } |
| 37 |
36 } // namespace translate | 38 } // namespace translate |
OLD | NEW |