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

Unified Diff: chrome/browser/ui/webui/snippets_internals_message_handler.cc

Issue 2346263002: Extending the UserClassifier to actually support classification. (Closed)
Patch Set: Bernhard's comments Created 4 years, 3 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/ui/webui/snippets_internals_message_handler.cc
diff --git a/chrome/browser/ui/webui/snippets_internals_message_handler.cc b/chrome/browser/ui/webui/snippets_internals_message_handler.cc
index f06d83e50a3228999b86ca6a74ab37be1dc0c2e4..761bad9674211e3f3b2e68e8a39aa98de73725fa 100644
--- a/chrome/browser/ui/webui/snippets_internals_message_handler.cc
+++ b/chrome/browser/ui/webui/snippets_internals_message_handler.cc
@@ -6,6 +6,7 @@
#include <memory>
#include <set>
+#include <utility>
#include <vector>
#include "base/bind.h"
@@ -32,6 +33,7 @@ using ntp_snippets::Category;
using ntp_snippets::CategoryInfo;
using ntp_snippets::CategoryStatus;
using ntp_snippets::KnownCategories;
+using ntp_snippets::UserClassifier;
namespace {
@@ -73,7 +75,7 @@ std::string GetCategoryStatusName(CategoryStatus status) {
return std::string();
}
-} // namespace
+} // namespace
SnippetsInternalsMessageHandler::SnippetsInternalsMessageHandler()
: content_suggestions_service_observer_(this),
@@ -119,6 +121,12 @@ void SnippetsInternalsMessageHandler::RegisterMessages() {
base::Bind(
&SnippetsInternalsMessageHandler::HandleToggleDismissedSuggestions,
base::Unretained(this)));
+
+ web_ui()->RegisterMessageCallback(
+ "clearClassification",
+ base::Bind(
+ &SnippetsInternalsMessageHandler::ClearClassification,
+ base::Unretained(this)));
}
void SnippetsInternalsMessageHandler::OnNewSuggestions(Category category) {
@@ -245,6 +253,14 @@ void SnippetsInternalsMessageHandler::HandleToggleDismissedSuggestions(
}
}
+void SnippetsInternalsMessageHandler::ClearClassification(
+ const base::ListValue* args) {
+ DCHECK_EQ(0u, args->GetSize());
+ content_suggestions_service_->user_classifier()
+ ->ClearClassificationForDebugging();
+ SendClassification();
+}
+
void SnippetsInternalsMessageHandler::SendAllContent() {
SendHosts();
@@ -264,6 +280,8 @@ void SnippetsInternalsMessageHandler::SendAllContent() {
base::FeatureList::IsEnabled(
ntp_snippets::kPhysicalWebPageSuggestionsFeature));
+ SendClassification();
+
web_ui()->CallJavascriptFunctionUnsafe(
"chrome.SnippetsInternals.setHostRestricted",
base::FundamentalValue(
@@ -292,6 +310,22 @@ void SnippetsInternalsMessageHandler::SendAllContent() {
SendContentSuggestions();
}
+void SnippetsInternalsMessageHandler::SendClassification() {
+ web_ui()->CallJavascriptFunctionUnsafe(
+ "chrome.SnippetsInternals.receiveClassification",
+ base::StringValue(content_suggestions_service_->user_classifier()
+ ->GetUserClassDescriptionForDebugging()),
+ base::FundamentalValue(
+ content_suggestions_service_->user_classifier()->GetEstimatedAvgTime(
+ UserClassifier::Metric::NTP_OPENED)),
+ base::FundamentalValue(
+ content_suggestions_service_->user_classifier()->GetEstimatedAvgTime(
+ UserClassifier::Metric::SUGGESTIONS_SHOWN)),
+ base::FundamentalValue(
+ content_suggestions_service_->user_classifier()->GetEstimatedAvgTime(
+ UserClassifier::Metric::SUGGESTIONS_USED)));
+}
+
void SnippetsInternalsMessageHandler::SendHosts() {
std::unique_ptr<base::ListValue> hosts_list(new base::ListValue);
« no previous file with comments | « chrome/browser/ui/webui/snippets_internals_message_handler.h ('k') | components/ntp_snippets/user_classifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698