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

Unified Diff: chrome/browser/android/ntp/content_suggestions_notifier_service.cc

Issue 2618703004: Use server signal to decide whether to notify (Closed)
Patch Set: rebase Created 3 years, 11 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 b4155d2c20842946bfa37f81ad5a3ae24eb35d26..61fe726928eff0775b13943c5b35024993aabed4 100644
--- a/chrome/browser/android/ntp/content_suggestions_notifier_service.cc
+++ b/chrome/browser/android/ntp/content_suggestions_notifier_service.cc
@@ -11,10 +11,12 @@
#include "chrome/browser/android/ntp/content_suggestions_notification_helper.h"
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_handler.h"
+#include "chrome/browser/ntp_snippets/ntp_snippets_features.h"
#include "chrome/browser/profiles/profile.h"
#include "components/ntp_snippets/content_suggestions_service.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
+#include "components/variations/variations_associated_data.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_operations.h"
@@ -72,20 +74,19 @@ class ContentSuggestionsNotifierService::NotifyingObserver
weak_ptr_factory_(this) {}
void OnNewSuggestions(Category category) override {
- if (!ShouldNotifyInState(app_status_listener_.GetState()) ||
- !category.IsKnownCategory(KnownCategories::ARTICLES)) {
+ if (!ShouldNotifyInState(app_status_listener_.GetState())) {
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()));
+ const ContentSuggestion* suggestion = GetSuggestionToNotifyAbout(category);
+ if (!suggestion) {
+ return;
}
+ 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,
@@ -126,6 +127,27 @@ class ContentSuggestionsNotifierService::NotifyingObserver
}
private:
+ const ContentSuggestion* GetSuggestionToNotifyAbout(Category category) {
+ const auto& suggestions = service_->GetSuggestionsForCategory(category);
+ // TODO(sfiera): replace with AlwaysNotifyAboutContentSuggestions().
+ if (variations::GetVariationParamByFeatureAsBool(
+ kContentSuggestionsNotificationsFeature,
+ kContentSuggestionsNotificationsAlwaysNotifyParam, false)) {
+ if (category.IsKnownCategory(KnownCategories::ARTICLES) &&
+ !suggestions.empty()) {
+ return &suggestions[0];
+ }
+ return nullptr;
+ }
+
+ for (const ContentSuggestion& suggestion : suggestions) {
+ if (suggestion.notification_extra()) {
+ return &suggestion;
+ }
+ }
+ return nullptr;
+ }
+
void AppStatusChanged(base::android::ApplicationState state) {
if (!ShouldNotifyInState(state)) {
ContentSuggestionsNotificationHelper::HideNotification();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698