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

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

Issue 2897563002: Implement client side logging for language detection. (Closed)
Patch Set: updates 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
« no previous file with comments | « no previous file | components/sync/protocol/proto_visitors.h » ('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 830d647c55473048a8813db47a967be9b8bbf6bb..4e88a35169336c8dde76cdecd56674920cd5610a 100644
--- a/chrome/browser/translate/chrome_translate_client.cc
+++ b/chrome/browser/translate/chrome_translate_client.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/translate/chrome_translate_client.h"
+#include <memory>
#include <vector>
#include "base/logging.h"
@@ -14,6 +15,7 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/sync/user_event_service_factory.h"
#include "chrome/browser/translate/language_model_factory.h"
#include "chrome/browser/translate/translate_accept_languages_factory.h"
#include "chrome/browser/translate/translate_ranker_factory.h"
@@ -29,6 +31,8 @@
#include "chrome/grit/theme_resources.h"
#include "components/metrics/proto/translate_event.pb.h"
#include "components/prefs/pref_service.h"
+#include "components/sync/protocol/user_event_specifics.pb.h"
+#include "components/sync/user_events/user_event_service.h"
#include "components/translate/core/browser/language_model.h"
#include "components/translate/core/browser/language_state.h"
#include "components/translate/core/browser/page_translated_details.h"
@@ -39,6 +43,7 @@
#include "components/translate/core/browser/translate_prefs.h"
#include "components/translate/core/common/language_detection_details.h"
#include "components/variations/service/variations_service.h"
+#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
@@ -65,6 +70,47 @@ metrics::TranslateEventProto::EventType BubbleResultToTranslateEvent(
}
}
+std::unique_ptr<sync_pb::UserEventSpecifics> ConstructLanguageDetectionEvent(
+ const int entry_id,
+ const translate::LanguageDetectionDetails& details) {
+ auto specifics = base::MakeUnique<sync_pb::UserEventSpecifics>();
+ specifics->set_event_time_usec(base::Time::Now().ToInternalValue());
+
+ // TODO(renjieliu): Revisit this field when the best way to identify
+ // navigations is determined.
+ specifics->set_navigation_id(base::Time::Now().ToInternalValue());
groby-ooo-7-16 2017/05/25 21:35:29 Note: Time::Now() is not guaranteed to be increasi
napper 2017/05/25 21:49:26 See here for the ongoing discussion: https://docs.
renjieliu1 2017/05/26 00:26:45 Acknowledged.
renjieliu1 2017/05/26 00:26:45 currently the suggested way is to use time to iden
groby-ooo-7-16 2017/05/26 01:28:48 I'm not sure what your requirements are, so pick w
+
+ sync_pb::LanguageDetection lang_detection;
+ auto* const lang = lang_detection.add_detected_languages();
groby-ooo-7-16 2017/05/25 21:35:29 Wait - isn't this a mutable pointer to a constant
napper 2017/05/25 21:49:26 Note that the pointer is const (so lang++ won't wo
renjieliu1 2017/05/26 00:26:45 this is to a const pointer to a mutable object
renjieliu1 2017/05/26 00:26:45 thanks for the clarification! :)
groby-ooo-7-16 2017/05/26 01:28:47 Indeed. Thank you. I can't believe I *still* read
+ 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() = lang_detection;
+ return specifics;
+}
+
+void LogLanguageDetectionEvent(
+ const content::WebContents* const web_contents,
+ const translate::LanguageDetectionDetails& details) {
+ 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.
groby-ooo-7-16 2017/05/25 21:35:29 The logic is clear from the code - can you change
renjieliu1 2017/05/26 00:26:45 Added a comment. I wonder are you suggesting web
groby-ooo-7-16 2017/05/26 01:28:48 No, I meant the NavigationObserver :) It gets noti
+ if (entry != nullptr) {
+ user_event_service->RecordUserEvent(
+ ConstructLanguageDetectionEvent(entry->GetUniqueID(), details));
+ }
+}
+
} // namespace
DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeTranslateClient);
@@ -309,6 +355,7 @@ void ChromeTranslateClient::OnLanguageDetermined(
content::Source<content::WebContents>(web_contents()),
content::Details<const translate::LanguageDetectionDetails>(&details));
+ LogLanguageDetectionEvent(web_contents(), details);
// Unless we have no language model (e.g., in incognito), notify the model
// about detected language of every page visited.
if (language_model_ && details.is_cld_reliable)
« no previous file with comments | « no previous file | components/sync/protocol/proto_visitors.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698