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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/snippets_internals_message_handler.h" 5 #include "chrome/browser/ui/webui/snippets_internals_message_handler.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 19 matching lines...) Expand all
30 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" 30 #include "components/ntp_snippets/remote/remote_suggestions_provider.h"
31 #include "components/ntp_snippets/switches.h" 31 #include "components/ntp_snippets/switches.h"
32 #include "components/prefs/pref_service.h" 32 #include "components/prefs/pref_service.h"
33 #include "content/public/browser/web_ui.h" 33 #include "content/public/browser/web_ui.h"
34 34
35 using ntp_snippets::ContentSuggestion; 35 using ntp_snippets::ContentSuggestion;
36 using ntp_snippets::Category; 36 using ntp_snippets::Category;
37 using ntp_snippets::CategoryInfo; 37 using ntp_snippets::CategoryInfo;
38 using ntp_snippets::CategoryStatus; 38 using ntp_snippets::CategoryStatus;
39 using ntp_snippets::KnownCategories; 39 using ntp_snippets::KnownCategories;
40 using ntp_snippets::RemoteSuggestionsProvider;
40 using ntp_snippets::UserClassifier; 41 using ntp_snippets::UserClassifier;
41 42
42 namespace { 43 namespace {
43 44
44 std::unique_ptr<base::DictionaryValue> PrepareSuggestion( 45 std::unique_ptr<base::DictionaryValue> PrepareSuggestion(
45 const ContentSuggestion& suggestion, 46 const ContentSuggestion& suggestion,
46 int index) { 47 int index) {
47 auto entry = base::MakeUnique<base::DictionaryValue>(); 48 auto entry = base::MakeUnique<base::DictionaryValue>();
48 entry->SetString("idWithinCategory", suggestion.id().id_within_category()); 49 entry->SetString("idWithinCategory", suggestion.id().id_within_category());
49 entry->SetString("url", suggestion.url().spec()); 50 entry->SetString("url", suggestion.url().spec());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 82
82 } // namespace 83 } // namespace
83 84
84 SnippetsInternalsMessageHandler::SnippetsInternalsMessageHandler( 85 SnippetsInternalsMessageHandler::SnippetsInternalsMessageHandler(
85 ntp_snippets::ContentSuggestionsService* content_suggestions_service, 86 ntp_snippets::ContentSuggestionsService* content_suggestions_service,
86 PrefService* pref_service) 87 PrefService* pref_service)
87 : content_suggestions_service_observer_(this), 88 : content_suggestions_service_observer_(this),
88 dom_loaded_(false), 89 dom_loaded_(false),
89 content_suggestions_service_(content_suggestions_service), 90 content_suggestions_service_(content_suggestions_service),
90 remote_suggestions_provider_( 91 remote_suggestions_provider_(
91 content_suggestions_service_->ntp_snippets_service()), 92 content_suggestions_service_
93 ->remote_suggestions_provider_for_debugging()),
92 pref_service_(pref_service), 94 pref_service_(pref_service),
93 weak_ptr_factory_(this) {} 95 weak_ptr_factory_(this) {}
94 96
95 SnippetsInternalsMessageHandler::~SnippetsInternalsMessageHandler() {} 97 SnippetsInternalsMessageHandler::~SnippetsInternalsMessageHandler() {}
96 98
97 void SnippetsInternalsMessageHandler::RegisterMessages() { 99 void SnippetsInternalsMessageHandler::RegisterMessages() {
98 web_ui()->RegisterMessageCallback( 100 web_ui()->RegisterMessageCallback(
99 "clearCachedSuggestions", 101 "clearCachedSuggestions",
100 base::Bind(&SnippetsInternalsMessageHandler::HandleClearCachedSuggestions, 102 base::Bind(&SnippetsInternalsMessageHandler::HandleClearCachedSuggestions,
101 base::Unretained(this))); 103 base::Unretained(this)));
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 190
189 void SnippetsInternalsMessageHandler::HandleDownload( 191 void SnippetsInternalsMessageHandler::HandleDownload(
190 const base::ListValue* args) { 192 const base::ListValue* args) {
191 DCHECK_EQ(0u, args->GetSize()); 193 DCHECK_EQ(0u, args->GetSize());
192 194
193 SendString("remote-status", std::string()); 195 SendString("remote-status", std::string());
194 196
195 if (!remote_suggestions_provider_) 197 if (!remote_suggestions_provider_)
196 return; 198 return;
197 199
198 remote_suggestions_provider_->FetchSnippetsForAllCategories(); 200 remote_suggestions_provider_->ReloadSuggestions();
199 } 201 }
200 202
201 void SnippetsInternalsMessageHandler::HandleClearCachedSuggestions( 203 void SnippetsInternalsMessageHandler::HandleClearCachedSuggestions(
202 const base::ListValue* args) { 204 const base::ListValue* args) {
203 DCHECK_EQ(1u, args->GetSize()); 205 DCHECK_EQ(1u, args->GetSize());
204 206
205 int category_id; 207 int category_id;
206 if (!args->GetInteger(0, &category_id)) 208 if (!args->GetInteger(0, &category_id))
207 return; 209 return;
208 210
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 const base::ListValue* args) { 266 const base::ListValue* args) {
265 DCHECK_EQ(0u, args->GetSize()); 267 DCHECK_EQ(0u, args->GetSize());
266 content_suggestions_service_->user_classifier() 268 content_suggestions_service_->user_classifier()
267 ->ClearClassificationForDebugging(); 269 ->ClearClassificationForDebugging();
268 SendClassification(); 270 SendClassification();
269 } 271 }
270 272
271 void SnippetsInternalsMessageHandler::FetchRemoteSuggestionsInTheBackground( 273 void SnippetsInternalsMessageHandler::FetchRemoteSuggestionsInTheBackground(
272 const base::ListValue* args) { 274 const base::ListValue* args) {
273 DCHECK_EQ(0u, args->GetSize()); 275 DCHECK_EQ(0u, args->GetSize());
274 remote_suggestions_provider_->FetchSnippetsInTheBackground(); 276 remote_suggestions_provider_->RefetchInTheBackground(
277 RemoteSuggestionsProvider::FetchStatusCallback());
275 } 278 }
276 279
277 void SnippetsInternalsMessageHandler::SendAllContent() { 280 void SnippetsInternalsMessageHandler::SendAllContent() {
278 SendBoolean("flag-snippets", base::FeatureList::IsEnabled( 281 SendBoolean("flag-snippets", base::FeatureList::IsEnabled(
279 ntp_snippets::kContentSuggestionsFeature)); 282 ntp_snippets::kContentSuggestionsFeature));
280 SendBoolean( 283 SendBoolean(
281 "flag-article-suggestions", 284 "flag-article-suggestions",
282 base::FeatureList::IsEnabled(ntp_snippets::kArticleSuggestionsFeature)); 285 base::FeatureList::IsEnabled(ntp_snippets::kArticleSuggestionsFeature));
283 SendBoolean("flag-recent-offline-tab-suggestions", 286 SendBoolean("flag-recent-offline-tab-suggestions",
284 base::FeatureList::IsEnabled( 287 base::FeatureList::IsEnabled(
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 422
420 void SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded( 423 void SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded(
421 Category category, 424 Category category,
422 std::vector<ContentSuggestion> dismissed_suggestions) { 425 std::vector<ContentSuggestion> dismissed_suggestions) {
423 if (dismissed_state_[category] == DismissedState::HIDDEN) 426 if (dismissed_state_[category] == DismissedState::HIDDEN)
424 return; 427 return;
425 dismissed_suggestions_[category] = std::move(dismissed_suggestions); 428 dismissed_suggestions_[category] = std::move(dismissed_suggestions);
426 dismissed_state_[category] = DismissedState::VISIBLE; 429 dismissed_state_[category] = DismissedState::VISIBLE;
427 SendContentSuggestions(); 430 SendContentSuggestions();
428 } 431 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698