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

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

Issue 2569663004: [NTPSnippets] Switch from TickClock to Clock for storing the last background fetched time. (Closed)
Patch Set: Created 4 years 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 988dc19ce21135d458c7272408c78501d1934be9..a5b5342e775207848e30f6d5c5d2bf8837ae11f3 100644
--- a/chrome/browser/ui/webui/snippets_internals_message_handler.cc
+++ b/chrome/browser/ui/webui/snippets_internals_message_handler.cc
@@ -19,13 +19,17 @@
#include "base/optional.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
+#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_features.h"
#include "components/ntp_snippets/category_info.h"
#include "components/ntp_snippets/features.h"
+#include "components/ntp_snippets/pref_names.h"
+#include "components/ntp_snippets/remote/remote_suggestions_provider.h"
#include "components/ntp_snippets/switches.h"
+#include "components/prefs/pref_service.h"
#include "content/public/browser/web_ui.h"
using ntp_snippets::ContentSuggestion;
@@ -77,11 +81,13 @@ std::string GetCategoryStatusName(CategoryStatus status) {
} // namespace
-SnippetsInternalsMessageHandler::SnippetsInternalsMessageHandler()
+SnippetsInternalsMessageHandler::SnippetsInternalsMessageHandler(
+ PrefService* pref_service)
: content_suggestions_service_observer_(this),
dom_loaded_(false),
ntp_snippets_service_(nullptr),
content_suggestions_service_(nullptr),
+ pref_service_(pref_service),
Bernhard Bauer 2016/12/13 13:06:54 Couldn't you get the PrefService from the profile
markusheintz_ 2016/12/13 14:01:28 Oh good catch I didn't notice this. I think this l
weak_ptr_factory_(this) {}
SnippetsInternalsMessageHandler::~SnippetsInternalsMessageHandler() {}
@@ -97,17 +103,13 @@ void SnippetsInternalsMessageHandler::RegisterMessages() {
ntp_snippets_service_ = content_suggestions_service_->ntp_snippets_service();
web_ui()->RegisterMessageCallback(
- "refreshContent",
- base::Bind(&SnippetsInternalsMessageHandler::HandleRefreshContent,
+ "clearCachedSuggestions",
+ base::Bind(&SnippetsInternalsMessageHandler::HandleClearCachedSuggestions,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
- "download", base::Bind(&SnippetsInternalsMessageHandler::HandleDownload,
- base::Unretained(this)));
-
- web_ui()->RegisterMessageCallback(
- "clearCachedSuggestions",
- base::Bind(&SnippetsInternalsMessageHandler::HandleClearCachedSuggestions,
+ "clearClassification",
+ base::Bind(&SnippetsInternalsMessageHandler::ClearClassification,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
@@ -117,15 +119,24 @@ void SnippetsInternalsMessageHandler::RegisterMessages() {
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
- "toggleDismissedSuggestions",
- base::Bind(
- &SnippetsInternalsMessageHandler::HandleToggleDismissedSuggestions,
- base::Unretained(this)));
+ "download", base::Bind(&SnippetsInternalsMessageHandler::HandleDownload,
+ base::Unretained(this)));
web_ui()->RegisterMessageCallback(
- "clearClassification",
+ "fetchRemoteSuggestionsInTheBackground",
+ base::Bind(&SnippetsInternalsMessageHandler::
+ FetchRemoteSuggestionsInTheBackground,
+ base::Unretained(this)));
+
+ web_ui()->RegisterMessageCallback(
+ "refreshContent",
+ base::Bind(&SnippetsInternalsMessageHandler::HandleRefreshContent,
+ base::Unretained(this)));
+
+ web_ui()->RegisterMessageCallback(
+ "toggleDismissedSuggestions",
base::Bind(
- &SnippetsInternalsMessageHandler::ClearClassification,
+ &SnippetsInternalsMessageHandler::HandleToggleDismissedSuggestions,
base::Unretained(this)));
}
@@ -271,6 +282,11 @@ void SnippetsInternalsMessageHandler::ClearClassification(
SendClassification();
}
+void SnippetsInternalsMessageHandler::FetchRemoteSuggestionsInTheBackground(
+ const base::ListValue* args) {
+ ntp_snippets_service_->FetchSnippetsInTheBackground();
+}
+
void SnippetsInternalsMessageHandler::SendAllContent() {
SendBoolean("flag-snippets", base::FeatureList::IsEnabled(
ntp_snippets::kContentSuggestionsFeature));
@@ -295,6 +311,7 @@ void SnippetsInternalsMessageHandler::SendAllContent() {
ntp_snippets::kPhysicalWebPageSuggestionsFeature));
SendClassification();
+ SendLastRemoteSuggestionsBackgroundFetchTime();
if (ntp_snippets_service_) {
switch (ntp_snippets_service_->snippets_fetcher()->personalization()) {
@@ -337,6 +354,16 @@ void SnippetsInternalsMessageHandler::SendClassification() {
UserClassifier::Metric::SUGGESTIONS_USED)));
}
+void SnippetsInternalsMessageHandler::
+ SendLastRemoteSuggestionsBackgroundFetchTime() {
+ base::Time time = base::Time::FromInternalValue(pref_service_->GetInt64(
+ ntp_snippets::prefs::kLastSuccessfulBackgroundFetchTime));
+ web_ui()->CallJavascriptFunctionUnsafe(
+ "chrome.SnippetsInternals."
+ "receiveLastRemoteSuggestionsBackgroundFetchTime",
+ base::StringValue(base::TimeFormatShortDateAndTime(time)));
+}
+
void SnippetsInternalsMessageHandler::SendContentSuggestions() {
std::unique_ptr<base::ListValue> categories_list(new base::ListValue);

Powered by Google App Engine
This is Rietveld 408576698