Commit 21fbeb1f authored by Anthony Vallee-Dubois's avatar Anthony Vallee-Dubois Committed by Commit Bot

Remove some unused Translate code

This removes a few functions that were only related to logging translate
events in EventLogger, which isn't happening anymore as of r650268.

Bug: 911781
Change-Id: I5e78edb77c9723ed331e23a58a6d960ffbc15cf7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1584422Reviewed-by: default avatarAlexandre Frechette <frechette@chromium.org>
Commit-Queue: anthonyvd <anthonyvd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#656451}
parent e68291f7
...@@ -41,8 +41,6 @@ ...@@ -41,8 +41,6 @@
#include "components/translate/core/browser/translate_manager.h" #include "components/translate/core/browser/translate_manager.h"
#include "components/translate/core/browser/translate_prefs.h" #include "components/translate/core/browser/translate_prefs.h"
#include "components/translate/core/common/language_detection_details.h" #include "components/translate/core/common/language_detection_details.h"
#include "components/translate/core/common/language_detection_logging_helper.h"
#include "components/translate/core/common/translation_logging_helper.h"
#include "components/variations/service/variations_service.h" #include "components/variations/service/variations_service.h"
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
......
...@@ -6,8 +6,6 @@ static_library("common") { ...@@ -6,8 +6,6 @@ static_library("common") {
sources = [ sources = [
"language_detection_details.cc", "language_detection_details.cc",
"language_detection_details.h", "language_detection_details.h",
"language_detection_logging_helper.cc",
"language_detection_logging_helper.h",
"translate_constants.cc", "translate_constants.cc",
"translate_constants.h", "translate_constants.h",
"translate_errors.h", "translate_errors.h",
...@@ -17,14 +15,11 @@ static_library("common") { ...@@ -17,14 +15,11 @@ static_library("common") {
"translate_switches.h", "translate_switches.h",
"translate_util.cc", "translate_util.cc",
"translate_util.h", "translate_util.h",
"translation_logging_helper.cc",
"translation_logging_helper.h",
] ]
deps = [ deps = [
"//base", "//base",
"//components/language/core/common", "//components/language/core/common",
"//components/sync/protocol",
"//third_party/metrics_proto", "//third_party/metrics_proto",
"//url", "//url",
] ]
...@@ -33,15 +28,12 @@ static_library("common") { ...@@ -33,15 +28,12 @@ static_library("common") {
source_set("unit_tests") { source_set("unit_tests") {
testonly = true testonly = true
sources = [ sources = [
"language_detection_logging_helper_unittest.cc",
"translate_metrics_unittest.cc", "translate_metrics_unittest.cc",
"translate_util_unittest.cc", "translate_util_unittest.cc",
"translation_logging_helper_unittest.cc",
] ]
deps = [ deps = [
":common", ":common",
"//base", "//base",
"//components/sync/protocol",
"//testing/gtest", "//testing/gtest",
"//third_party/metrics_proto", "//third_party/metrics_proto",
"//url", "//url",
......
// 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/language_detection_logging_helper.h"
#include <memory>
#include "base/logging.h"
#include "components/sync/protocol/user_event_specifics.pb.h"
#include "components/translate/core/common/language_detection_details.h"
namespace translate {
std::unique_ptr<sync_pb::UserEventSpecifics> ConstructLanguageDetectionEvent(
const int64_t navigation_id,
const LanguageDetectionDetails& details) {
auto specifics = std::make_unique<sync_pb::UserEventSpecifics>();
specifics->set_event_time_usec(base::Time::Now().ToInternalValue());
specifics->set_navigation_id(navigation_id);
sync_pb::UserEventSpecifics::LanguageDetection lang_detection;
auto* const lang = lang_detection.add_detected_languages();
lang->set_language_code(details.cld_language);
lang->set_is_reliable(details.is_cld_reliable);
// Only set adopted_language when it's different from cld_language.
if (details.adopted_language != details.cld_language) {
lang_detection.set_adopted_language_code(details.adopted_language);
}
*specifics->mutable_language_detection_event() = lang_detection;
return specifics;
}
} // namespace translate
// 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.
#ifndef COMPONENTS_TRANSLATE_CORE_COMMON_LANGUAGE_DETECTION_LOGGING_HELPER_H_
#define COMPONENTS_TRANSLATE_CORE_COMMON_LANGUAGE_DETECTION_LOGGING_HELPER_H_
#include <memory>
namespace sync_pb {
class UserEventSpecifics;
}
namespace translate {
struct LanguageDetectionDetails;
// Construct language detection based on navigation_id and language detection
// details.
std::unique_ptr<sync_pb::UserEventSpecifics> ConstructLanguageDetectionEvent(
int64_t navigation_id,
const LanguageDetectionDetails& details);
} // namespace translate
#endif // COMPONENTS_TRANSLATE_CORE_COMMON_LANGUAGE_DETECTION_LOGGING_HELPER_H_
// 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/language_detection_logging_helper.h"
#include <string>
#include "components/sync/protocol/user_event_specifics.pb.h"
#include "components/translate/core/common/language_detection_details.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace translate {
// Tests that sync_pb::UserEventSpecifics is correctly build.
TEST(LanguageDetectionLoggingHelperTest, ConstructUserEventSpecifics) {
LanguageDetectionDetails details;
details.cld_language = "en";
details.is_cld_reliable = false;
details.adopted_language = "ja";
// Expected language detection.
sync_pb::UserEventSpecifics::LanguageDetection lang_detection;
auto* const lang = lang_detection.add_detected_languages();
lang->set_language_code(details.cld_language);
lang->set_is_reliable(details.is_cld_reliable);
lang_detection.set_adopted_language_code(details.adopted_language);
const int64_t navigation_id = 1000000000000000LL;
const std::unique_ptr<sync_pb::UserEventSpecifics> user_event =
ConstructLanguageDetectionEvent(navigation_id, details);
// Expect the navigation id is correctly set.
EXPECT_EQ(user_event->navigation_id(), navigation_id);
EXPECT_EQ(user_event->language_detection_event().SerializeAsString(),
lang_detection.SerializeAsString());
}
// Tests that sync_pb::UserEventSpecifics is correctly build.
// If adopted_language is the same as cld_language, we don't set it.
TEST(LanguageDetectionLoggingHelperTest, DontSetAdoptedLanguage) {
LanguageDetectionDetails details;
details.cld_language = "en";
details.is_cld_reliable = true;
details.adopted_language = "en";
// Expected language detection.
sync_pb::UserEventSpecifics::LanguageDetection lang_detection;
auto* const lang = lang_detection.add_detected_languages();
lang->set_language_code(details.cld_language);
lang->set_is_reliable(details.is_cld_reliable);
const std::unique_ptr<sync_pb::UserEventSpecifics> user_event =
ConstructLanguageDetectionEvent(100, details);
// Expect the navigation id is correctly set.
EXPECT_EQ(user_event->navigation_id(), 100);
EXPECT_EQ(user_event->language_detection_event().SerializeAsString(),
lang_detection.SerializeAsString());
}
} // namespace translate
// 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/sync/protocol/user_event_specifics.pb.h"
#include "third_party/metrics_proto/translate_event.pb.h"
using Translation = sync_pb::UserEventSpecifics::Translation;
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());
specifics->set_navigation_id(navigation_id);
auto* const translation = specifics->mutable_translation_event();
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(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(Translation::MANUAL);
} else {
translation->set_interaction(Translation::ACCEPT);
}
break;
case TranslateEventProto::USER_DECLINE:
translation->set_interaction(Translation::DECLINE);
break;
case TranslateEventProto::USER_IGNORE:
translation->set_interaction(Translation::IGNORED);
break;
case TranslateEventProto::USER_DISMISS:
translation->set_interaction(Translation::DISMISSED);
break;
case TranslateEventProto::USER_REVERT:
translation->set_interaction(Translation::TRANSLATION_REVERTED);
break;
case TranslateEventProto::AUTO_TRANSLATION_BY_PREF:
translation->set_interaction(Translation::AUTO_TRANSLATION_BY_PREF);
break;
case TranslateEventProto::AUTO_TRANSLATION_BY_LINK:
translation->set_interaction(Translation::AUTO_TRANSLATION_BY_LINK);
break;
case TranslateEventProto::INITIALIZATION_ERROR:
translation->set_interaction(Translation::INITIALIZATION_ERROR);
break;
default: // We don't care about other events.
return false;
}
return true;
}
} // namespace translate
// 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.
#ifndef COMPONENTS_TRANSLATE_CORE_COMMON_TRANSLATION_LOGGING_HELPER_H_
#define COMPONENTS_TRANSLATE_CORE_COMMON_TRANSLATION_LOGGING_HELPER_H_
#include <stdint.h>
namespace metrics {
class TranslateEventProto;
} // namespace metrics
namespace sync_pb {
class UserEventSpecifics;
} // namespace sync_pb
namespace translate {
// Construct the sync_pb::Translation proto.
// If the event is the event that we care about, will return true, otherwise,
// will return false.
bool ConstructTranslateEvent(
int64_t navigation_id,
const metrics::TranslateEventProto& translate_event,
sync_pb::UserEventSpecifics* const specifics);
} // namespace translate
#endif // COMPONENTS_TRANSLATE_CORE_COMMON_TRANSLATION_LOGGING_HELPER_H_
\ No newline at end of file
// 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 <string>
#include "base/logging.h"
#include "components/sync/protocol/user_event_specifics.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/metrics_proto/translate_event.pb.h"
using metrics::TranslateEventProto;
using Translation = sync_pb::UserEventSpecifics::Translation;
void EqualTranslationProto(const Translation& first,
const Translation& second) {
EXPECT_EQ(first.from_language_code(), second.from_language_code());
EXPECT_EQ(first.to_language_code(), second.to_language_code());
EXPECT_EQ(first.interaction(), second.interaction());
}
namespace translate {
// Tests that UserEventSpecifics is correctly built.
TEST(TranslationLoggingHelperTest, ConstructUserEventSpecifics) {
// The event we have.
TranslateEventProto translation_event;
translation_event.set_source_language("ja");
translation_event.set_target_language("en");
translation_event.set_event_type(TranslateEventProto::USER_DECLINE);
// Expected user_event.
Translation user_translation_event;
user_translation_event.set_from_language_code("ja");
user_translation_event.set_to_language_code("en");
user_translation_event.set_interaction(Translation::DECLINE);
// The user event.
sync_pb::UserEventSpecifics user_specifics;
const int64_t navigation_id = 1000000000000000LL;
const bool needs_logging = ConstructTranslateEvent(
navigation_id, translation_event, &user_specifics);
EXPECT_TRUE(needs_logging);
EXPECT_EQ(user_specifics.navigation_id(), navigation_id);
EqualTranslationProto(user_translation_event,
user_specifics.translation_event());
}
// Tests that if user change the target language, the event is MANUAL.
TEST(TranslationLoggingHelperTest, UserManualEvent) {
// The event we have.
TranslateEventProto translation_event;
translation_event.set_source_language("ja");
translation_event.set_target_language("en");
translation_event.set_modified_target_language("fr");
translation_event.set_event_type(TranslateEventProto::USER_ACCEPT);
// Expected user_event.
Translation user_translation_event;
user_translation_event.set_from_language_code("ja");
user_translation_event.set_to_language_code("fr");
user_translation_event.set_interaction(Translation::MANUAL);
// The user event.
sync_pb::UserEventSpecifics user_specifics;
const int64_t navigation_id = 100;
const bool needs_logging = ConstructTranslateEvent(
navigation_id, translation_event, &user_specifics);
EXPECT_TRUE(needs_logging);
EXPECT_EQ(user_specifics.navigation_id(), navigation_id);
EqualTranslationProto(user_translation_event,
user_specifics.translation_event());
}
// Tests that we don't build unnecessary events.
TEST(TranslationLoggingHelperTest, DontBuildUnnecessaryEvent) {
// The event we have.
TranslateEventProto translation_event;
translation_event.set_source_language("ja");
translation_event.set_target_language("en");
// The event we don't care.
translation_event.set_event_type(TranslateEventProto::DISABLED_BY_RANKER);
// The user event.
sync_pb::UserEventSpecifics user_specifics;
const bool needs_logging =
ConstructTranslateEvent(100, translation_event, &user_specifics);
// We don't expect the event to be logged.
EXPECT_FALSE(needs_logging);
}
} // namespace translate
...@@ -21,8 +21,6 @@ ...@@ -21,8 +21,6 @@
#include "components/translate/core/browser/translate_prefs.h" #include "components/translate/core/browser/translate_prefs.h"
#include "components/translate/core/browser/translate_step.h" #include "components/translate/core/browser/translate_step.h"
#include "components/translate/core/common/language_detection_details.h" #include "components/translate/core/common/language_detection_details.h"
#include "components/translate/core/common/language_detection_logging_helper.h"
#include "components/translate/core/common/translation_logging_helper.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/infobars/infobar.h" #include "ios/chrome/browser/infobars/infobar.h"
#include "ios/chrome/browser/infobars/infobar_controller.h" #include "ios/chrome/browser/infobars/infobar_controller.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment