Index: chrome/browser/android/ntp/content_suggestions_notifier_service.cc |
diff --git a/chrome/browser/android/ntp/content_suggestions_notifier_service.cc b/chrome/browser/android/ntp/content_suggestions_notifier_service.cc |
index 07f305e977bb5db8ed0fb830f14f7e07319817d7..606e5a4fac38325398df37ebbe4d98171ec90bd1 100644 |
--- a/chrome/browser/android/ntp/content_suggestions_notifier_service.cc |
+++ b/chrome/browser/android/ntp/content_suggestions_notifier_service.cc |
@@ -53,19 +53,16 @@ class ContentSuggestionsNotifierService::NotifyingObserver |
: service_(service), prefs_(prefs), weak_ptr_factory_(this) {} |
void OnNewSuggestions(Category category) override { |
- if (!category.IsKnownCategory(KnownCategories::ARTICLES)) { |
+ const ContentSuggestion* suggestion = GetSuggestionToNotifyAbout(category); |
+ if (!suggestion) { |
return; |
} |
- const auto& suggestions = service_->GetSuggestionsForCategory(category); |
- if (!suggestions.empty()) { |
- const auto& suggestion = suggestions[0]; |
- service_->FetchSuggestionImage( |
- suggestions[0].id(), |
- base::Bind(&NotifyingObserver::ImageFetched, |
- weak_ptr_factory_.GetWeakPtr(), suggestion.id(), |
- suggestion.url(), suggestion.title(), |
- suggestion.publisher_name())); |
- } |
+ service_->FetchSuggestionImage( |
+ suggestion->id(), |
+ base::Bind(&NotifyingObserver::ImageFetched, |
+ weak_ptr_factory_.GetWeakPtr(), suggestion->id(), |
+ suggestion->url(), suggestion->title(), |
+ suggestion->publisher_name())); |
} |
void OnCategoryStatusChanged(Category category, |
@@ -106,6 +103,24 @@ class ContentSuggestionsNotifierService::NotifyingObserver |
} |
private: |
+ const ContentSuggestion* GetSuggestionToNotifyAbout(Category category) { |
+ const auto& suggestions = service_->GetSuggestionsForCategory(category); |
+ if (false /* DO_NOT_SUBMIT: always_notify after crrev.com/2613863003 */) { |
Bernhard Bauer
2017/01/05 17:31:17
So, if the feature is enabled, we will always noti
sfiera
2017/01/05 19:14:37
This condition will use AlwaysNotifyAboutContentSu
Bernhard Bauer
2017/01/06 13:26:59
Yes, but my point was, in the third case (if the a
sfiera
2017/01/06 15:39:52
Oh, I see. Yes, this is the intended behavior. The
|
+ if (category.IsKnownCategory(KnownCategories::ARTICLES) && |
+ suggestions.size()) { |
Bernhard Bauer
2017/01/05 17:31:17
Maybe use !suggestions.empty()?
sfiera
2017/01/05 19:14:37
Done.
|
+ return &suggestions[0]; |
+ } |
+ return nullptr; |
+ } |
+ |
+ for (const ContentSuggestion& suggestion : suggestions) { |
+ if (suggestion.notification_extra()) { |
+ return &suggestion; |
+ } |
+ } |
+ return nullptr; |
+ } |
+ |
void ImageFetched(const ContentSuggestion::ID& id, |
const GURL& url, |
const base::string16& title, |