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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationService.java

Issue 2690163008: Route through a JobService when receiving a message for the GCM Driver (Closed)
Patch Set: Route through a JobService when receiving a message for the GCM Driver Created 3 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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.app.IntentService; 7 import android.app.IntentService;
8 import android.app.job.JobInfo; 8 import android.app.job.JobInfo;
9 import android.app.job.JobScheduler; 9 import android.app.job.JobScheduler;
10 import android.content.BroadcastReceiver; 10 import android.content.BroadcastReceiver;
11 import android.content.ComponentName; 11 import android.content.ComponentName;
12 import android.content.Context; 12 import android.content.Context;
13 import android.content.Intent; 13 import android.content.Intent;
14 import android.os.Build; 14 import android.os.Build;
15 import android.os.PersistableBundle; 15 import android.os.PersistableBundle;
16 import android.os.StrictMode; 16 import android.os.StrictMode;
17 import android.util.Log; 17 import android.util.Log;
18 18
19 import org.chromium.base.ThreadUtils; 19 import org.chromium.base.ThreadUtils;
20 import org.chromium.base.annotations.SuppressFBWarnings; 20 import org.chromium.base.annotations.SuppressFBWarnings;
21 import org.chromium.base.library_loader.ProcessInitException; 21 import org.chromium.base.library_loader.ProcessInitException;
22 import org.chromium.chrome.browser.JobSchedulerConstants;
22 import org.chromium.chrome.browser.init.ChromeBrowserInitializer; 23 import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
23 import org.chromium.chrome.browser.webapps.WebappRegistry; 24 import org.chromium.chrome.browser.webapps.WebappRegistry;
24 25
25 /** 26 /**
26 * The Notification service receives intents fired as responses to user actions issued on Android 27 * The Notification service receives intents fired as responses to user actions issued on Android
27 * notifications displayed in the notification tray. 28 * notifications displayed in the notification tray.
28 */ 29 */
29 public class NotificationService extends IntentService { 30 public class NotificationService extends IntentService {
30 private static final String TAG = NotificationService.class.getSimpleName(); 31 private static final String TAG = NotificationService.class.getSimpleName();
31 32
32 /** 33 /**
33 * The class which receives the intents from the Android framework. It initi alizes the 34 * The class which receives the intents from the Android framework. It initi alizes the
34 * Notification service, and forward the intents there. Declared public as i t needs to be 35 * Notification service, and forward the intents there. Declared public as i t needs to be
35 * initialized by the Android framework. 36 * initialized by the Android framework.
36 */ 37 */
37 public static class Receiver extends BroadcastReceiver { 38 public static class Receiver extends BroadcastReceiver {
38 @Override 39 @Override
39 public void onReceive(Context context, Intent intent) { 40 public void onReceive(Context context, Intent intent) {
40 Log.i(TAG, "Received a notification intent in the NotificationServic e's receiver."); 41 Log.i(TAG, "Received a notification intent in the NotificationServic e's receiver.");
41 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 42 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
42 // Android encourages us not to start services directly on N+, s o instead we 43 // Android encourages us not to start services directly on N+, s o instead we
43 // schedule a job to handle the notification intent. We use the Android JobScheduler 44 // schedule a job to handle the notification intent. We use the Android JobScheduler
44 // rather than GcmNetworkManager or FirebaseJobDispatcher since the JobScheduler 45 // rather than GcmNetworkManager or FirebaseJobDispatcher since the JobScheduler
45 // allows us to execute immediately by setting an override deadl ine of zero 46 // allows us to execute immediately by setting an override deadl ine of zero
46 // milliseconds. 47 // milliseconds.
47 // TODO(crbug.com/685210): UMA to check this does not introduce noticeable latency. 48 // TODO(crbug.com/685210): UMA to check this does not introduce noticeable latency.
48 PersistableBundle extras = NotificationJobService.getJobExtrasFr omIntent(intent); 49 PersistableBundle extras = NotificationJobService.getJobExtrasFr omIntent(intent);
49 JobInfo job = 50 JobInfo job =
50 new JobInfo 51 new JobInfo
51 .Builder(NotificationJobService.JOB_ID, 52 .Builder(JobSchedulerConstants.NOTIFICATION_SERV ICE_JOB_ID,
52 new ComponentName(context, NotificationJ obService.class)) 53 new ComponentName(context, NotificationJ obService.class))
53 .setExtras(extras) 54 .setExtras(extras)
54 .setOverrideDeadline(0) 55 .setOverrideDeadline(0)
55 .build(); 56 .build();
56 JobScheduler scheduler = 57 JobScheduler scheduler =
57 (JobScheduler) context.getSystemService(Context.JOB_SCHE DULER_SERVICE); 58 (JobScheduler) context.getSystemService(Context.JOB_SCHE DULER_SERVICE);
58 scheduler.schedule(job); 59 scheduler.schedule(job);
59 } else { 60 } else {
60 // TODO(peter): Do we need to acquire a wake lock here? 61 // TODO(peter): Do we need to acquire a wake lock here?
61 62
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 123
123 // TODO(peter): Verify that the lifetime of the NotificationService is sufficient 124 // TODO(peter): Verify that the lifetime of the NotificationService is sufficient
124 // when a notification event could be dispatched successfully. 125 // when a notification event could be dispatched successfully.
125 126
126 } catch (ProcessInitException e) { 127 } catch (ProcessInitException e) {
127 Log.e(TAG, "Unable to start the browser process.", e); 128 Log.e(TAG, "Unable to start the browser process.", e);
128 System.exit(-1); 129 System.exit(-1);
129 } 130 }
130 } 131 }
131 } 132 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698