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..2ba499083ecb3846405d8a50907f033c7b1bafdf 100644 |
| --- a/chrome/browser/android/ntp/content_suggestions_notification_helper.cc |
| +++ b/chrome/browser/android/ntp/content_suggestions_notification_helper.cc |
| @@ -8,20 +8,24 @@ |
| #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/ntp_snippets/ntp_snippets_prefs.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/profiles/profile_manager.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())); |
| -} |
| - |
| void ContentSuggestionsNotificationHelper::SendNotification( |
| const GURL& url, |
| const base::string16& title, |
| @@ -50,4 +54,63 @@ void ContentSuggestionsNotificationHelper::HideAllNotifications() { |
| Java_ContentSuggestionsNotificationHelper_hideAllNotifications(env); |
| } |
| +bool ContentSuggestionsNotificationHelper::IsDisabledForProfile( |
| + Profile* profile) { |
| + auto prefs = profile->GetPrefs(); |
| + int current = |
| + prefs->GetInteger(kContentSuggestionsConsecutiveIgnoredPrefName); |
| + int limit = variations::GetVariationParamByFeatureAsInt( |
| + kContentSuggestionsNotificationsFeature, |
| + kContentSuggestionsNotificationsIgnoredLimitParam, |
| + kContentSuggestionsNotificationsIgnoredDefaultLimit); |
| + return current >= limit; |
| +} |
| + |
| +// static |
| +bool ContentSuggestionsNotificationHelper::Register(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |
| + |
| } // namespace ntp_snippets |
| + |
| +static bool IsDisabledForProfile(Profile* profile) { |
| + return ntp_snippets::ContentSuggestionsNotificationHelper:: |
| + IsDisabledForProfile(profile); |
| +} |
| + |
| +static void NotificationTapped(JNIEnv* env, const JavaParamRef<jclass>&) { |
| + auto profile = ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); |
|
Bernhard Bauer
2017/01/11 15:21:49
Can you use the actual type here? Profile* isn't t
sfiera
2017/01/11 15:41:51
Done.
|
| + auto prefs = profile->GetPrefs(); |
|
Bernhard Bauer
2017/01/11 15:21:49
And I would say for PrefService* too.
sfiera
2017/01/11 15:41:51
Done.
|
| + prefs->SetInteger(kContentSuggestionsConsecutiveIgnoredPrefName, 0); |
| + RecordContentSuggestionsNotificationAction(CONTENT_SUGGESTIONS_TAP); |
| +} |
| + |
| +static void NotificationDismissed(JNIEnv* env, const JavaParamRef<jclass>&) { |
| + Profile* profile = ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); |
| + auto prefs = profile->GetPrefs(); |
| + const bool was_disabled = IsDisabledForProfile(profile); |
| + int ignored = |
| + prefs->GetInteger(kContentSuggestionsConsecutiveIgnoredPrefName); |
| + prefs->SetInteger(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>&) { |
| + Profile* profile = ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); |
| + auto prefs = profile->GetPrefs(); |
| + const bool was_disabled = IsDisabledForProfile(profile); |
| + int ignored = |
| + prefs->GetInteger(kContentSuggestionsConsecutiveIgnoredPrefName); |
| + prefs->SetInteger(kContentSuggestionsConsecutiveIgnoredPrefName, ignored + 1); |
| + RecordContentSuggestionsNotificationAction( |
| + CONTENT_SUGGESTIONS_HIDE_DEADLINE); |
| + const bool is_disabled = IsDisabledForProfile(profile); |
| + if (!was_disabled && is_disabled) { |
| + RecordContentSuggestionsNotificationOptOut(CONTENT_SUGGESTIONS_IMPLICIT); |
| + } |
| +} |