| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.notifications; | 5 package org.chromium.chrome.browser.notifications; |
| 6 | 6 |
| 7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
| 8 import android.app.NotificationManager; | 8 import android.app.NotificationManager; |
| 9 import android.content.SharedPreferences; | 9 import android.content.SharedPreferences; |
| 10 import android.support.annotation.IntDef; | 10 import android.support.annotation.IntDef; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 import java.lang.reflect.Method; | 23 import java.lang.reflect.Method; |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * Helper class to make tracking notification UMA stats easier for various featu
res. Having a | 26 * Helper class to make tracking notification UMA stats easier for various featu
res. Having a |
| 27 * single entry point here to make more complex tracking easier to add in the fu
ture. | 27 * single entry point here to make more complex tracking easier to add in the fu
ture. |
| 28 */ | 28 */ |
| 29 public class NotificationUmaTracker { | 29 public class NotificationUmaTracker { |
| 30 private static final String TAG = "NotifsUMATracker"; | 30 private static final String TAG = "NotifsUMATracker"; |
| 31 @Retention(RetentionPolicy.SOURCE) | 31 @Retention(RetentionPolicy.SOURCE) |
| 32 @IntDef({DOWNLOAD_FILES, DOWNLOAD_PAGES, CLOSE_INCOGNITO, CONTENT_SUGGESTION
, MEDIA_CAPTURE, | 32 @IntDef({DOWNLOAD_FILES, DOWNLOAD_PAGES, CLOSE_INCOGNITO, CONTENT_SUGGESTION
, MEDIA_CAPTURE, |
| 33 PHYSICAL_WEB, MEDIA, SITES, SYNC, SYSTEM_NOTIFICATION_TYPE_BOUNDARY}
) | 33 PHYSICAL_WEB, MEDIA, SITES, SYNC, BROWSER_ACTIONS, SYSTEM_NOTIFICATI
ON_TYPE_BOUNDARY}) |
| 34 public @interface SystemNotificationType {} | 34 public @interface SystemNotificationType {} |
| 35 | 35 |
| 36 /* | 36 /* |
| 37 * A list of notification types. To add a type to this list please update | 37 * A list of notification types. To add a type to this list please update |
| 38 * SystemNotificationType in histograms.xml and make sure to keep this list
in sync. Additions | 38 * SystemNotificationType in histograms.xml and make sure to keep this list
in sync. Additions |
| 39 * should be treated as APPEND ONLY to keep the UMA metric semantics the sam
e over time. | 39 * should be treated as APPEND ONLY to keep the UMA metric semantics the sam
e over time. |
| 40 * | 40 * |
| 41 * A SystemNotificationType value can also be saved in shared preferences. | 41 * A SystemNotificationType value can also be saved in shared preferences. |
| 42 */ | 42 */ |
| 43 public static final int DOWNLOAD_FILES = 0; | 43 public static final int DOWNLOAD_FILES = 0; |
| 44 | 44 |
| 45 public static final int DOWNLOAD_PAGES = 1; | 45 public static final int DOWNLOAD_PAGES = 1; |
| 46 | 46 |
| 47 public static final int CLOSE_INCOGNITO = 2; | 47 public static final int CLOSE_INCOGNITO = 2; |
| 48 | 48 |
| 49 public static final int CONTENT_SUGGESTION = 3; | 49 public static final int CONTENT_SUGGESTION = 3; |
| 50 public static final int MEDIA_CAPTURE = 4; | 50 public static final int MEDIA_CAPTURE = 4; |
| 51 public static final int PHYSICAL_WEB = 5; | 51 public static final int PHYSICAL_WEB = 5; |
| 52 public static final int MEDIA = 6; | 52 public static final int MEDIA = 6; |
| 53 public static final int SITES = 7; | 53 public static final int SITES = 7; |
| 54 public static final int SYNC = 8; | 54 public static final int SYNC = 8; |
| 55 public static final int BROWSER_ACTIONS = 9; |
| 55 | 56 |
| 56 private static final int SYSTEM_NOTIFICATION_TYPE_BOUNDARY = 9; | 57 private static final int SYSTEM_NOTIFICATION_TYPE_BOUNDARY = 10; |
| 57 | 58 |
| 58 private static final String LAST_SHOWN_NOTIFICATION_TYPE_KEY = | 59 private static final String LAST_SHOWN_NOTIFICATION_TYPE_KEY = |
| 59 "NotificationUmaTracker.LastShownNotificationType"; | 60 "NotificationUmaTracker.LastShownNotificationType"; |
| 60 | 61 |
| 61 private static class LazyHolder { | 62 private static class LazyHolder { |
| 62 private static final NotificationUmaTracker INSTANCE = new NotificationU
maTracker(); | 63 private static final NotificationUmaTracker INSTANCE = new NotificationU
maTracker(); |
| 63 } | 64 } |
| 64 | 65 |
| 65 /** Cached objects. */ | 66 /** Cached objects. */ |
| 66 private final SharedPreferences mSharedPreferences; | 67 private final SharedPreferences mSharedPreferences; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 mSharedPreferences.edit().remove(LAST_SHOWN_NOTIFICATION_TYPE_KEY).apply
(); | 135 mSharedPreferences.edit().remove(LAST_SHOWN_NOTIFICATION_TYPE_KEY).apply
(); |
| 135 | 136 |
| 136 recordHistogram("Mobile.SystemNotification.BlockedAfterShown", lastType)
; | 137 recordHistogram("Mobile.SystemNotification.BlockedAfterShown", lastType)
; |
| 137 } | 138 } |
| 138 | 139 |
| 139 private static void recordHistogram(String name, @SystemNotificationType int
type) { | 140 private static void recordHistogram(String name, @SystemNotificationType int
type) { |
| 140 if (!LibraryLoader.isInitialized()) return; | 141 if (!LibraryLoader.isInitialized()) return; |
| 141 RecordHistogram.recordEnumeratedHistogram(name, type, SYSTEM_NOTIFICATIO
N_TYPE_BOUNDARY); | 142 RecordHistogram.recordEnumeratedHistogram(name, type, SYSTEM_NOTIFICATIO
N_TYPE_BOUNDARY); |
| 142 } | 143 } |
| 143 } | 144 } |
| OLD | NEW |