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

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

Issue 2557363002: [NTP Snippets] Refactor background scheduling for remote suggestions (Closed)
Patch Set: Rebase 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 4b78785ecf15c08b83b7a2af7511bd98ed9d5584..807d3254cf097e2314cee1b8a175a7f751579334 100644
--- a/chrome/browser/ui/webui/snippets_internals_message_handler.cc
+++ b/chrome/browser/ui/webui/snippets_internals_message_handler.cc
@@ -28,6 +28,7 @@
#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/ntp_snippets_fetcher.h"
#include "components/ntp_snippets/remote/remote_suggestions_provider.h"
#include "components/ntp_snippets/switches.h"
#include "components/prefs/pref_service.h"
@@ -38,6 +39,7 @@ using ntp_snippets::Category;
using ntp_snippets::CategoryInfo;
using ntp_snippets::CategoryStatus;
using ntp_snippets::KnownCategories;
+using ntp_snippets::RemoteSuggestionsProvider;
using ntp_snippets::UserClassifier;
namespace {
@@ -89,7 +91,8 @@ SnippetsInternalsMessageHandler::SnippetsInternalsMessageHandler(
dom_loaded_(false),
content_suggestions_service_(content_suggestions_service),
remote_suggestions_provider_(
- content_suggestions_service_->ntp_snippets_service()),
+ content_suggestions_service_
+ ->remote_suggestions_provider_for_debugging()),
pref_service_(pref_service),
weak_ptr_factory_(this) {}
@@ -196,7 +199,7 @@ void SnippetsInternalsMessageHandler::HandleDownload(
if (!remote_suggestions_provider_)
return;
- remote_suggestions_provider_->FetchSnippetsForAllCategories();
+ remote_suggestions_provider_->ReloadSuggestions();
}
void SnippetsInternalsMessageHandler::HandleClearCachedSuggestions(
@@ -266,7 +269,8 @@ void SnippetsInternalsMessageHandler::ClearClassification(
void SnippetsInternalsMessageHandler::FetchRemoteSuggestionsInTheBackground(
const base::ListValue* args) {
DCHECK_EQ(0u, args->GetSize());
- remote_suggestions_provider_->FetchSnippetsInTheBackground();
+ remote_suggestions_provider_->RefetchInTheBackground(
+ RemoteSuggestionsProvider::FetchStatusCallback());
}
void SnippetsInternalsMessageHandler::SendAllContent() {
@@ -296,8 +300,9 @@ void SnippetsInternalsMessageHandler::SendAllContent() {
SendLastRemoteSuggestionsBackgroundFetchTime();
if (remote_suggestions_provider_) {
- switch (
- remote_suggestions_provider_->snippets_fetcher()->personalization()) {
+ switch (remote_suggestions_provider_
+ ->snippets_fetcher_for_testing_and_debugging()
+ ->personalization()) {
case ntp_snippets::NTPSnippetsFetcher::Personalization::kPersonal:
SendString("switch-personalized", "Only personalized");
break;
@@ -310,13 +315,16 @@ void SnippetsInternalsMessageHandler::SendAllContent() {
break;
}
- SendString(
- "switch-fetch-url",
- remote_suggestions_provider_->snippets_fetcher()->fetch_url().spec());
+ SendString("switch-fetch-url",
+ remote_suggestions_provider_
+ ->snippets_fetcher_for_testing_and_debugging()
+ ->fetch_url()
+ .spec());
web_ui()->CallJavascriptFunctionUnsafe(
"chrome.SnippetsInternals.receiveJson",
- base::StringValue(
- remote_suggestions_provider_->snippets_fetcher()->last_json()));
+ base::StringValue(remote_suggestions_provider_
+ ->snippets_fetcher_for_testing_and_debugging()
+ ->last_json()));
}
SendContentSuggestions();
@@ -387,7 +395,9 @@ void SnippetsInternalsMessageHandler::SendContentSuggestions() {
if (remote_suggestions_provider_) {
const std::string& status =
- remote_suggestions_provider_->snippets_fetcher()->last_status();
+ remote_suggestions_provider_
+ ->snippets_fetcher_for_testing_and_debugging()
+ ->last_status();
if (!status.empty())
SendString("remote-status", "Finished: " + status);
}

Powered by Google App Engine
This is Rietveld 408576698