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

Unified Diff: chrome/browser/translate/chrome_translate_client.cc

Issue 2913593002: Implementation of translation event logging. (Closed)
Patch Set: fix Created 3 years, 7 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
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 85eed92770a043ee3b1ae9246f4b6b31153f6d27..2ba65b647d57c3411beeb27edff196f2fd3c71b6 100644
--- a/chrome/browser/translate/chrome_translate_client.cc
+++ b/chrome/browser/translate/chrome_translate_client.cc
@@ -42,6 +42,7 @@
#include "components/translate/core/browser/translate_manager.h"
#include "components/translate/core/browser/translate_prefs.h"
#include "components/translate/core/common/language_detection_details.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"
@@ -50,26 +51,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 ==============
+
std::unique_ptr<sync_pb::UserEventSpecifics> ConstructLanguageDetectionEvent(
const int entry_id,
const translate::LanguageDetectionDetails& details) {
@@ -113,6 +117,35 @@ 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(translate_event, specifics.get());
+ if (needs_logging) {
+ user_event_service->RecordUserEvent(std::move(specifics));
+ }
+}
+
} // namespace
DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeTranslateClient);
@@ -217,6 +250,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,

Powered by Google App Engine
This is Rietveld 408576698