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

Unified Diff: chrome/browser/translate/chrome_translate_client.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/translate/chrome_translate_client.h ('k') | components/translate/DEPS » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/translate/chrome_translate_client.cc
diff --git a/chrome/browser/translate/chrome_translate_client.cc b/chrome/browser/translate/chrome_translate_client.cc
index c29d82fc79b9440dc06d7cac05cc956683739d89..7aadf49de88c89b3242c5f0ffe42c9e159389d1c 100644
--- a/chrome/browser/translate/chrome_translate_client.cc
+++ b/chrome/browser/translate/chrome_translate_client.cc
@@ -43,6 +43,7 @@
#include "components/translate/core/browser/translate_prefs.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 "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h"
@@ -51,26 +52,29 @@
#include "url/gurl.h"
namespace {
+using metrics::TranslateEventProto;
-metrics::TranslateEventProto::EventType BubbleResultToTranslateEvent(
+TranslateEventProto::EventType BubbleResultToTranslateEvent(
ShowTranslateBubbleResult result) {
switch (result) {
case ShowTranslateBubbleResult::BROWSER_WINDOW_NOT_VALID:
- return metrics::TranslateEventProto::BROWSER_WINDOW_IS_INVALID;
+ return TranslateEventProto::BROWSER_WINDOW_IS_INVALID;
case ShowTranslateBubbleResult::BROWSER_WINDOW_MINIMIZED:
- return metrics::TranslateEventProto::BROWSER_WINDOW_IS_MINIMIZED;
+ return TranslateEventProto::BROWSER_WINDOW_IS_MINIMIZED;
case ShowTranslateBubbleResult::BROWSER_WINDOW_NOT_ACTIVE:
- return metrics::TranslateEventProto::BROWSER_WINDOW_NOT_ACTIVE;
+ return TranslateEventProto::BROWSER_WINDOW_NOT_ACTIVE;
case ShowTranslateBubbleResult::WEB_CONTENTS_NOT_ACTIVE:
- return metrics::TranslateEventProto::WEB_CONTENTS_NOT_ACTIVE;
+ return TranslateEventProto::WEB_CONTENTS_NOT_ACTIVE;
case ShowTranslateBubbleResult::EDITABLE_FIELD_IS_ACTIVE:
- return metrics::TranslateEventProto::EDITABLE_FIELD_IS_ACTIVE;
+ return TranslateEventProto::EDITABLE_FIELD_IS_ACTIVE;
default:
NOTREACHED();
return metrics::TranslateEventProto::UNKNOWN;
}
}
+// ========== LOG LANGUAGE DETECTION EVENT ==============
+
void LogLanguageDetectionEvent(
const content::WebContents* const web_contents,
const translate::LanguageDetectionDetails& details) {
@@ -92,6 +96,36 @@ void LogLanguageDetectionEvent(
}
}
+// ========== LOG TRANSLATE EVENT ==============
+
+void LogTranslateEvent(const content::WebContents* const web_contents,
+ const metrics::TranslateEventProto& translate_event) {
+ DCHECK(web_contents);
+ auto* const profile =
+ Profile::FromBrowserContext(web_contents->GetBrowserContext());
+
+ syncer::UserEventService* const user_event_service =
+ browser_sync::UserEventServiceFactory::GetForProfile(profile);
+
+ const auto* const entry =
+ web_contents->GetController().GetLastCommittedEntry();
+
+ // If entry is null, we don't record the page.
+ // The navigation entry can be null in situations like download or initial
+ // blank page.
+ if (entry == nullptr)
+ return;
+
+ auto specifics = base::MakeUnique<sync_pb::UserEventSpecifics>();
+ // We only log the event we care about.
+ const bool needs_logging = translate::ConstructTranslateEvent(
+ entry->GetTimestamp().ToInternalValue(), translate_event,
+ specifics.get());
+ if (needs_logging) {
+ user_event_service->RecordUserEvent(std::move(specifics));
+ }
+}
+
} // namespace
DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeTranslateClient);
@@ -196,6 +230,11 @@ void ChromeTranslateClient::GetTranslateLanguages(
translate::TranslateManager::GetTargetLanguage(translate_prefs.get());
}
+void ChromeTranslateClient::RecordTranslateEvent(
+ const TranslateEventProto& translate_event) {
+ LogTranslateEvent(web_contents(), translate_event);
+}
+
// static
void ChromeTranslateClient::BindContentTranslateDriver(
content::RenderFrameHost* render_frame_host,
« no previous file with comments | « chrome/browser/translate/chrome_translate_client.h ('k') | components/translate/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698