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

Unified Diff: components/ntp_snippets/content_suggestions_service.cc

Issue 2519053002: 📰 Let the backend trigger sign in related refreshes (Closed)
Patch Set: 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 42890a7e6afb4d416fbc15452641a2b84d81cce1..c35808dd1f0f8fa4b85cee83d8fcc1800add493a 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);
@@ -269,6 +275,18 @@ void ContentSuggestionsService::OnSuggestionInvalidated(
observer.OnSuggestionInvalidated(suggestion_id);
}
+// SigninManagerBase::Observer implementation
+void ContentSuggestionsService::GoogleSigninSucceeded(
+ const std::string& account_id,
+ const std::string& username,
+ const std::string& password) {
+ OnSignInStateChanged();
+};
Bernhard Bauer 2016/11/21 15:48:15 Nit: empty line between method bodies.
dgn 2016/11/21 16:22:08 Done.
+void ContentSuggestionsService::GoogleSignedOut(const std::string& account_id,
Marc Treib 2016/11/21 15:48:53 nit: empty line before
dgn 2016/11/21 16:22:08 Done.
+ const std::string& username) {
+ OnSignInStateChanged();
+}
+
// history::HistoryServiceObserver implementation.
void ContentSuggestionsService::OnURLsDeleted(
history::HistoryService* history_service,
@@ -393,6 +411,19 @@ void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) {
observer.OnCategoryStatusChanged(category, GetCategoryStatus(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) {

Powered by Google App Engine
This is Rietveld 408576698