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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/ContentSuggestionsNotificationHelper.java

Issue 2792583002: 📱 Simplify naming of generated java enums IntDefs (Closed)
Patch Set: rebase Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.ntp; 5 package org.chromium.chrome.browser.ntp;
6 6
7 import android.app.AlarmManager; 7 import android.app.AlarmManager;
8 import android.app.Notification; 8 import android.app.Notification;
9 import android.app.NotificationManager; 9 import android.app.NotificationManager;
10 import android.app.PendingIntent; 10 import android.app.PendingIntent;
(...skipping 12 matching lines...) Expand all
23 import org.chromium.chrome.R; 23 import org.chromium.chrome.R;
24 import org.chromium.chrome.browser.ChromeFeatureList; 24 import org.chromium.chrome.browser.ChromeFeatureList;
25 import org.chromium.chrome.browser.IntentHandler; 25 import org.chromium.chrome.browser.IntentHandler;
26 import org.chromium.chrome.browser.ShortcutHelper; 26 import org.chromium.chrome.browser.ShortcutHelper;
27 import org.chromium.chrome.browser.document.ChromeLauncherActivity; 27 import org.chromium.chrome.browser.document.ChromeLauncherActivity;
28 import org.chromium.chrome.browser.notifications.ChromeNotificationBuilder; 28 import org.chromium.chrome.browser.notifications.ChromeNotificationBuilder;
29 import org.chromium.chrome.browser.notifications.NotificationBuilderFactory; 29 import org.chromium.chrome.browser.notifications.NotificationBuilderFactory;
30 import org.chromium.chrome.browser.notifications.NotificationConstants; 30 import org.chromium.chrome.browser.notifications.NotificationConstants;
31 import org.chromium.chrome.browser.notifications.NotificationUmaTracker; 31 import org.chromium.chrome.browser.notifications.NotificationUmaTracker;
32 import org.chromium.chrome.browser.ntp.snippets.ContentSuggestionsNotificationAc tion; 32 import org.chromium.chrome.browser.ntp.snippets.ContentSuggestionsNotificationAc tion;
33 import org.chromium.chrome.browser.ntp.snippets.ContentSuggestionsNotificationAc tion.ContentSuggestionsNotificationActionEnum; 33 import org.chromium.chrome.browser.ntp.snippets.ContentSuggestionsNotificationOp tOut;
34 import org.chromium.chrome.browser.ntp.snippets.ContentSuggestionsNotificationOp tOut.ContentSuggestionsNotificationOptOutEnum;
35 import org.chromium.chrome.browser.preferences.ContentSuggestionsPreferences; 34 import org.chromium.chrome.browser.preferences.ContentSuggestionsPreferences;
36 35
37 import java.util.Collection; 36 import java.util.Collection;
38 import java.util.Collections; 37 import java.util.Collections;
39 import java.util.HashSet; 38 import java.util.HashSet;
40 import java.util.Set; 39 import java.util.Set;
41 40
42 /** 41 /**
43 * Provides functionality needed for content suggestion notifications. 42 * Provides functionality needed for content suggestion notifications.
44 * 43 *
(...skipping 24 matching lines...) Expand all
69 "ntp.content_suggestions.notification.cached_consecutive_ignored"; 68 "ntp.content_suggestions.notification.cached_consecutive_ignored";
70 69
71 // Tracks which URIs there is an active notification for. 70 // Tracks which URIs there is an active notification for.
72 private static final String PREF_ACTIVE_NOTIFICATIONS = 71 private static final String PREF_ACTIVE_NOTIFICATIONS =
73 "ntp.content_suggestions.notification.active"; 72 "ntp.content_suggestions.notification.active";
74 73
75 private ContentSuggestionsNotificationHelper() {} // Prevent instantiation 74 private ContentSuggestionsNotificationHelper() {} // Prevent instantiation
76 75
77 /** 76 /**
78 * Records the reason why Content Suggestions notifications have been opted out. 77 * Records the reason why Content Suggestions notifications have been opted out.
79 * @see ContentSuggestionsNotificationOptOutEnum; 78 * @see ContentSuggestionsNotificationOptOut;
80 */ 79 */
81 public static void recordNotificationOptOut( 80 public static void recordNotificationOptOut(@ContentSuggestionsNotificationO ptOut int reason) {
82 @ContentSuggestionsNotificationOptOutEnum int reason) {
83 nativeRecordNotificationOptOut(reason); 81 nativeRecordNotificationOptOut(reason);
84 } 82 }
85 83
86 /** 84 /**
87 * Records an action performed on a Content Suggestions notification. 85 * Records an action performed on a Content Suggestions notification.
88 * @see ContentSuggestionsNotificationActionEnum; 86 * @see ContentSuggestionsNotificationAction;
89 */ 87 */
90 public static void recordNotificationAction( 88 public static void recordNotificationAction(@ContentSuggestionsNotificationA ction int action) {
91 @ContentSuggestionsNotificationActionEnum int action) {
92 nativeRecordNotificationAction(action); 89 nativeRecordNotificationAction(action);
93 } 90 }
94 91
95 /** 92 /**
96 * Opens the content suggestion when notification is tapped. 93 * Opens the content suggestion when notification is tapped.
97 */ 94 */
98 public static final class OpenUrlReceiver extends BroadcastReceiver { 95 public static final class OpenUrlReceiver extends BroadcastReceiver {
99 @Override 96 @Override
100 public void onReceive(Context context, Intent intent) { 97 public void onReceive(Context context, Intent intent) {
101 int category = intent.getIntExtra(NOTIFICATION_CATEGORY_EXTRA, -1); 98 int category = intent.getIntExtra(NOTIFICATION_CATEGORY_EXTRA, -1);
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 Uri notificationUri = Uri.parse(serialized); 357 Uri notificationUri = Uri.parse(serialized);
361 ActiveNotification activeNotification = ActiveNotification.fromUri(n otificationUri); 358 ActiveNotification activeNotification = ActiveNotification.fromUri(n otificationUri);
362 if ((activeNotification != null) && (activeNotification.mId >= nextI d)) { 359 if ((activeNotification != null) && (activeNotification.mId >= nextI d)) {
363 nextId = activeNotification.mId + 1; 360 nextId = activeNotification.mId + 1;
364 } 361 }
365 } 362 }
366 return nextId; 363 return nextId;
367 } 364 }
368 365
369 private static String cachedMetricNameForAction( 366 private static String cachedMetricNameForAction(
370 @ContentSuggestionsNotificationActionEnum int action) { 367 @ContentSuggestionsNotificationAction int action) {
371 switch (action) { 368 switch (action) {
372 case ContentSuggestionsNotificationAction.TAP: 369 case ContentSuggestionsNotificationAction.TAP:
373 return PREF_CACHED_ACTION_TAP; 370 return PREF_CACHED_ACTION_TAP;
374 case ContentSuggestionsNotificationAction.DISMISSAL: 371 case ContentSuggestionsNotificationAction.DISMISSAL:
375 return PREF_CACHED_ACTION_DISMISSAL; 372 return PREF_CACHED_ACTION_DISMISSAL;
376 case ContentSuggestionsNotificationAction.HIDE_DEADLINE: 373 case ContentSuggestionsNotificationAction.HIDE_DEADLINE:
377 return PREF_CACHED_ACTION_HIDE_DEADLINE; 374 return PREF_CACHED_ACTION_HIDE_DEADLINE;
378 case ContentSuggestionsNotificationAction.HIDE_EXPIRY: 375 case ContentSuggestionsNotificationAction.HIDE_EXPIRY:
379 return PREF_CACHED_ACTION_HIDE_EXPIRY; 376 return PREF_CACHED_ACTION_HIDE_EXPIRY;
380 case ContentSuggestionsNotificationAction.HIDE_FRONTMOST: 377 case ContentSuggestionsNotificationAction.HIDE_FRONTMOST:
(...skipping 11 matching lines...) Expand all
392 * 389 *
393 * Also tracks the number of consecutively-ignored notifications, resetting it on a tap or 390 * Also tracks the number of consecutively-ignored notifications, resetting it on a tap or
394 * otherwise incrementing it. 391 * otherwise incrementing it.
395 * 392 *
396 * This method may be called when the native library is not loaded. If it is loaded, the metrics 393 * This method may be called when the native library is not loaded. If it is loaded, the metrics
397 * will immediately be sent to C++. If not, it will cache them for a later c all to 394 * will immediately be sent to C++. If not, it will cache them for a later c all to
398 * flushCachedMetrics(). 395 * flushCachedMetrics().
399 * 396 *
400 * @param action The action to update the pref for. 397 * @param action The action to update the pref for.
401 */ 398 */
402 private static void recordCachedActionMetric( 399 private static void recordCachedActionMetric(@ContentSuggestionsNotification Action int action) {
403 @ContentSuggestionsNotificationActionEnum int action) {
404 String prefName = cachedMetricNameForAction(action); 400 String prefName = cachedMetricNameForAction(action);
405 assert !prefName.isEmpty(); 401 assert !prefName.isEmpty();
406 402
407 SharedPreferences prefs = ContextUtils.getAppSharedPreferences(); 403 SharedPreferences prefs = ContextUtils.getAppSharedPreferences();
408 int currentValue = prefs.getInt(prefName, 0); 404 int currentValue = prefs.getInt(prefName, 0);
409 405
410 int consecutiveIgnored = prefs.getInt(PREF_CACHED_CONSECUTIVE_IGNORED, 0 ); 406 int consecutiveIgnored = prefs.getInt(PREF_CACHED_CONSECUTIVE_IGNORED, 0 );
411 switch (action) { 407 switch (action) {
412 case ContentSuggestionsNotificationAction.TAP: 408 case ContentSuggestionsNotificationAction.TAP:
413 consecutiveIgnored = 0; 409 consecutiveIgnored = 0;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 .remove(PREF_CACHED_ACTION_HIDE_SHUTDOWN) 463 .remove(PREF_CACHED_ACTION_HIDE_SHUTDOWN)
468 .remove(PREF_CACHED_CONSECUTIVE_IGNORED) 464 .remove(PREF_CACHED_CONSECUTIVE_IGNORED)
469 .apply(); 465 .apply();
470 } 466 }
471 } 467 }
472 468
473 private static native void nativeReceiveFlushedMetrics(int tapCount, int dis missalCount, 469 private static native void nativeReceiveFlushedMetrics(int tapCount, int dis missalCount,
474 int hideDeadlineCount, int hideExpiryCount, int hideFrontmostCount, 470 int hideDeadlineCount, int hideExpiryCount, int hideFrontmostCount,
475 int hideDisabledCount, int hideShutdownCount, int consecutiveIgnored ); 471 int hideDisabledCount, int hideShutdownCount, int consecutiveIgnored );
476 private static native void nativeRecordNotificationOptOut( 472 private static native void nativeRecordNotificationOptOut(
477 @ContentSuggestionsNotificationOptOutEnum int reason); 473 @ContentSuggestionsNotificationOptOut int reason);
478 private static native void nativeRecordNotificationAction( 474 private static native void nativeRecordNotificationAction(
479 @ContentSuggestionsNotificationActionEnum int action); 475 @ContentSuggestionsNotificationAction int action);
480 } 476 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698