Chromium Code Reviews| Index: chrome/browser/android/ntp/content_suggestions_notification_helper.cc |
| diff --git a/chrome/browser/android/ntp/content_suggestions_notification_helper.cc b/chrome/browser/android/ntp/content_suggestions_notification_helper.cc |
| index db5abdd3b659d21147ce6a302283ebbb834b695f..0544f7c38d1b62ecaccb2f8c0447c29dd3a79009 100644 |
| --- a/chrome/browser/android/ntp/content_suggestions_notification_helper.cc |
| +++ b/chrome/browser/android/ntp/content_suggestions_notification_helper.cc |
| @@ -8,20 +8,39 @@ |
| #include "base/android/jni_android.h" |
| #include "base/android/jni_string.h" |
| +#include "base/metrics/histogram_macros.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "chrome/browser/ntp_snippets/ntp_snippets_features.h" |
| +#include "chrome/browser/ntp_snippets/ntp_snippets_metrics.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/profiles/profile_manager.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "components/prefs/pref_service.h" |
| +#include "components/variations/variations_associated_data.h" |
| #include "jni/ContentSuggestionsNotificationHelper_jni.h" |
| #include "ui/gfx/android/java_bitmap.h" |
| #include "ui/gfx/image/image.h" |
| #include "ui/gfx/image/image_skia.h" |
| +using base::android::JavaParamRef; |
| + |
| namespace ntp_snippets { |
| -void ContentSuggestionsNotificationHelper::OpenURL(const GURL& url) { |
| - JNIEnv* env = base::android::AttachCurrentThread(); |
| - Java_ContentSuggestionsNotificationHelper_openUrl( |
| - env, base::android::ConvertUTF8ToJavaString(env, url.spec())); |
| +namespace { |
| + |
| +bool IsDisabledForProfile(Profile* profile) { |
| + PrefService* prefs = profile->GetPrefs(); |
| + int current = |
| + prefs->GetInteger(prefs::kContentSuggestionsConsecutiveIgnoredPrefName); |
| + int limit = variations::GetVariationParamByFeatureAsInt( |
| + kContentSuggestionsNotificationsFeature, |
| + kContentSuggestionsNotificationsIgnoredLimitParam, |
| + kContentSuggestionsNotificationsIgnoredDefaultLimit); |
| + return current >= limit; |
| } |
| +} // namespace |
| + |
| void ContentSuggestionsNotificationHelper::SendNotification( |
| const GURL& url, |
| const base::string16& title, |
| @@ -50,4 +69,56 @@ void ContentSuggestionsNotificationHelper::HideAllNotifications() { |
| Java_ContentSuggestionsNotificationHelper_hideAllNotifications(env); |
| } |
| +bool ContentSuggestionsNotificationHelper::IsDisabledForProfile( |
| + Profile* profile) { |
| + return ntp_snippets::IsDisabledForProfile(profile); |
| +} |
| + |
| +// static |
| +bool ContentSuggestionsNotificationHelper::Register(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |
| + |
| +static void NotificationTapped(JNIEnv* env, |
| + const JavaParamRef<jclass> /* class_object */&) { |
| + Profile* profile = ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); |
| + PrefService* prefs = profile->GetPrefs(); |
| + prefs->SetInteger(prefs::kContentSuggestionsConsecutiveIgnoredPrefName, 0); |
| + RecordContentSuggestionsNotificationAction(CONTENT_SUGGESTIONS_TAP); |
| +} |
| + |
| +static void NotificationDismissed( |
| + JNIEnv* env, |
| + const JavaParamRef<jclass> /* class_object */&) { |
|
Bernhard Bauer
2017/01/12 12:13:52
Put the ampersand before the variable name?
|
| + Profile* profile = ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); |
| + PrefService* prefs = profile->GetPrefs(); |
| + const bool was_disabled = IsDisabledForProfile(profile); |
| + int ignored = |
| + prefs->GetInteger(prefs::kContentSuggestionsConsecutiveIgnoredPrefName); |
| + prefs->SetInteger(prefs::kContentSuggestionsConsecutiveIgnoredPrefName, |
| + ignored + 1); |
| + RecordContentSuggestionsNotificationAction(CONTENT_SUGGESTIONS_DISMISSAL); |
| + const bool is_disabled = IsDisabledForProfile(profile); |
| + if (!was_disabled && is_disabled) { |
| + RecordContentSuggestionsNotificationOptOut(CONTENT_SUGGESTIONS_IMPLICIT); |
| + } |
| +} |
| + |
| +static void NotificationExpired( |
| + JNIEnv* env, |
| + const JavaParamRef<jclass>& /* class_object */) { |
| + Profile* profile = ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); |
| + PrefService* prefs = profile->GetPrefs(); |
| + const bool was_disabled = IsDisabledForProfile(profile); |
| + int ignored = |
| + prefs->GetInteger(prefs::kContentSuggestionsConsecutiveIgnoredPrefName); |
| + prefs->SetInteger(prefs::kContentSuggestionsConsecutiveIgnoredPrefName, |
| + ignored + 1); |
| + RecordContentSuggestionsNotificationAction(CONTENT_SUGGESTIONS_HIDE_DEADLINE); |
| + const bool is_disabled = IsDisabledForProfile(profile); |
| + if (!was_disabled && is_disabled) { |
| + RecordContentSuggestionsNotificationOptOut(CONTENT_SUGGESTIONS_IMPLICIT); |
| + } |
| +} |
| + |
| } // namespace ntp_snippets |