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

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

Issue 2346263002: Extending the UserClassifier to actually support classification. (Closed)
Patch Set: Minor rebase & larger refactoring 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..bd41b974531c888333d0e0590f99822ee99c8f1d 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"
@@ -73,7 +74,7 @@ std::string GetCategoryStatusName(CategoryStatus status) {
return std::string();
}
-} // namespace
+} // namespace
SnippetsInternalsMessageHandler::SnippetsInternalsMessageHandler()
: content_suggestions_service_observer_(this),
@@ -119,6 +120,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 +252,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 +279,8 @@ void SnippetsInternalsMessageHandler::SendAllContent() {
base::FeatureList::IsEnabled(
ntp_snippets::kPhysicalWebPageSuggestionsFeature));
+ SendClassification();
+
web_ui()->CallJavascriptFunctionUnsafe(
"chrome.SnippetsInternals.setHostRestricted",
base::FundamentalValue(
@@ -292,6 +309,19 @@ 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()
+ ->GetEstimatedAvgTimeToOpenNTP()),
+ base::FundamentalValue(content_suggestions_service_->user_classifier()
+ ->GetEstimatedAvgTimeToShowSuggestions()),
+ base::FundamentalValue(content_suggestions_service_->user_classifier()
+ ->GetEstimatedAvgTimeToUseSuggestions()));
+}
+
void SnippetsInternalsMessageHandler::SendHosts() {
std::unique_ptr<base::ListValue> hosts_list(new base::ListValue);

Powered by Google App Engine
This is Rietveld 408576698