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

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

Issue 2557363002: [NTP Snippets] Refactor background scheduling for remote suggestions (Closed)
Patch Set: Tim's comments + fix ios compilation 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 e1fd28ca55d3e30e7e9b3369711a3aeffd7bfa7c..7d12283858f1c0d4c4f40f985089cdc6bf817be3 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 {
@@ -88,7 +90,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) {}
@@ -195,7 +198,7 @@ void SnippetsInternalsMessageHandler::HandleDownload(
if (!remote_suggestions_provider_)
return;
- remote_suggestions_provider_->FetchSnippetsForAllCategories();
+ remote_suggestions_provider_->ReloadSuggestions();
}
void SnippetsInternalsMessageHandler::HandleClearCachedSuggestions(
@@ -265,7 +268,8 @@ void SnippetsInternalsMessageHandler::ClearClassification(
void SnippetsInternalsMessageHandler::FetchRemoteSuggestionsInTheBackground(
const base::ListValue* args) {
DCHECK_EQ(0u, args->GetSize());
- remote_suggestions_provider_->FetchSnippetsInTheBackground();
+ remote_suggestions_provider_->RefetchInTheBackground(
+ std::unique_ptr<RemoteSuggestionsProvider::FetchStatusCallback>(nullptr));
Bernhard Bauer 2016/12/21 10:38:42 Can you see whether just passing nullptr directly
jkrcal 2016/12/21 11:54:40 Much better, thanks!
}
void SnippetsInternalsMessageHandler::SendAllContent() {
@@ -297,16 +301,20 @@ void SnippetsInternalsMessageHandler::SendAllContent() {
if (remote_suggestions_provider_) {
// TODO(fhorschig): Read this string from variations directly.
SendString("switch-personalized",
- remote_suggestions_provider_->snippets_fetcher()
+ remote_suggestions_provider_
+ ->snippets_fetcher_for_testing_and_debugging()
Bernhard Bauer 2016/12/21 10:38:42 Maybe pull this out into a local variable?
jkrcal 2016/12/21 11:54:40 Done.
->PersonalizationModeString());
- 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();
@@ -377,7 +385,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