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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/services/gcm/GCMBackgroundTask.java

Issue 2722503004: Route through the BGTaskScheduler when receiving a message for the GCM Driver (Closed)
Patch Set: Route through the BGTaskScheduler when receiving a message for the GCM Driver Created 3 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.services.gcm;
6
7 import android.annotation.TargetApi;
8 import android.content.Context;
9 import android.os.Build;
10 import android.os.Bundle;
11 import android.support.annotation.MainThread;
12
13 import org.chromium.base.Log;
14 import org.chromium.components.background_task_scheduler.BackgroundTask;
15 import org.chromium.components.background_task_scheduler.TaskParameters;
16 import org.chromium.components.gcm_driver.GCMMessage;
17
18 /**
19 * Processes jobs that have been scheduled for delivering GCM messages to the na tive GCM Driver,
20 * processing for which may exceed the lifetime of the GcmListenerService.
21 */
22 @TargetApi(Build.VERSION_CODES.N)
23 public class GCMBackgroundTask implements BackgroundTask {
24 private static final String TAG = "GCMBackgroundTask";
25
26 /**
27 * Called when a GCM message is ready to be delivered to the GCM Driver cons umer. Because we
28 * don't yet know when a message has been fully processed, the task returns that processing has
29 * been completed, and we hope that the system keeps us alive long enough to finish processing.
30 *
31 * @return Boolean indicating whether the WakeLock for this task must be mai ntained.
32 */
33 @MainThread
34 @Override
35 public boolean onStartTask(
36 Context context, TaskParameters taskParameters, TaskFinishedCallback callback) {
37 Bundle extras = taskParameters.getExtras();
38 if (!GCMMessage.validateBundle(extras)) {
39 Log.e(TAG, "The received bundle containing message data could not be validated.");
40 return false;
41 }
42
43 ChromeGcmListenerService.dispatchMessageToDriver(context, new GCMMessage (extras));
44 return false;
45 }
46
47 /**
48 * Called when the system has determined that processing the GCM message mus t be stopped.
49 *
50 * @return Boolean indicating whether the task has to be rescheduled.
51 */
52 @MainThread
53 @Override
54 public boolean onStopTask(Context context, TaskParameters taskParameters) {
55 // The GCM Driver has no mechanism for aborting previously dispatched me ssages.
56 return false;
57 }
58 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698