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

Unified Diff: components/ntp_snippets/content_suggestions_service.cc

Issue 2519053002: 📰 Let the backend trigger sign in related refreshes (Closed)
Patch Set: Fix iOS build Created 4 years, 1 month 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: components/ntp_snippets/content_suggestions_service.cc
diff --git a/components/ntp_snippets/content_suggestions_service.cc b/components/ntp_snippets/content_suggestions_service.cc
index 3a55707b6af3f815b8641546d0ee7e917d966389..92ef4b46aea07264201b3124a229e25d8fc8cab1 100644
--- a/components/ntp_snippets/content_suggestions_service.cc
+++ b/components/ntp_snippets/content_suggestions_service.cc
@@ -23,14 +23,20 @@ namespace ntp_snippets {
ContentSuggestionsService::ContentSuggestionsService(
State state,
+ SigninManagerBase* signin_manager,
history::HistoryService* history_service,
PrefService* pref_service)
: state_(state),
+ signin_observer_(this),
history_service_observer_(this),
ntp_snippets_service_(nullptr),
pref_service_(pref_service),
user_classifier_(pref_service) {
// Can be null in tests.
+ if (signin_manager) {
+ signin_observer_.Add(signin_manager);
+ }
+
if (history_service) {
history_service_observer_.Add(history_service);
}
@@ -285,6 +291,19 @@ void ContentSuggestionsService::OnSuggestionInvalidated(
}
}
+// SigninManagerBase::Observer implementation
+void ContentSuggestionsService::GoogleSigninSucceeded(
+ const std::string& account_id,
+ const std::string& username,
+ const std::string& password) {
+ OnSignInStateChanged();
+}
+
+void ContentSuggestionsService::GoogleSignedOut(const std::string& account_id,
+ const std::string& username) {
+ OnSignInStateChanged();
+}
+
// history::HistoryServiceObserver implementation.
void ContentSuggestionsService::OnURLsDeleted(
history::HistoryService* history_service,
@@ -415,6 +434,19 @@ void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) {
}
}
+void ContentSuggestionsService::OnSignInStateChanged() {
+ // First notify the providers, so they can make the required changes.
+ for (const auto& provider : providers_) {
+ provider->OnSignInStateChanged();
+ }
+
+ // Finally notify the observers so they refresh only after the backend is
+ // ready.
+ for (Observer& observer : observers_) {
+ observer.OnFullRefreshRequired();
+ }
+}
+
void ContentSuggestionsService::SortCategories() {
std::sort(categories_.begin(), categories_.end(),
[this](const Category& left, const Category& right) {
« no previous file with comments | « components/ntp_snippets/content_suggestions_service.h ('k') | components/ntp_snippets/content_suggestions_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698