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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/services/gcm/GCMJobService.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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/services/gcm/GCMJobService.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/services/gcm/GCMJobService.java b/chrome/android/java/src/org/chromium/chrome/browser/services/gcm/GCMJobService.java
new file mode 100644
index 0000000000000000000000000000000000000000..afd0b0bb1b3f51f2f073b7a2dfab35246639fc7e
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/services/gcm/GCMJobService.java
@@ -0,0 +1,55 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.services.gcm;
+
+import android.annotation.TargetApi;
+import android.app.job.JobParameters;
+import android.app.job.JobService;
+import android.os.Build;
+import android.os.PersistableBundle;
+
+import org.chromium.base.Log;
+import org.chromium.components.gcm_driver.GCMMessage;
+
+/**
+ * Processes jobs that have been scheduled for delivering GCM messages to the native GCM Driver,
+ * processing for which may exceed the lifetime of the GcmListenerService.
+ */
+@TargetApi(Build.VERSION_CODES.N)
+public class GCMJobService extends JobService {
+ private static final String TAG = "GCMJobService";
+
+ /**
+ * Called when a GCM message is ready to be delivered to the GCM Driver consumer.
+ *
+ * @param params The parameters that define the job that is to be started.
+ * @return True if the service has remaining asynchronous work and will use {@link #jobFinished}
+ * when done. (So the system will hold a wakelock.) False otherwise.
+ */
+ @Override
+ public boolean onStartJob(JobParameters params) {
+ PersistableBundle extras = params.getExtras();
+ if (!GCMMessage.validatePersistableBundle(extras)) {
+ Log.e(TAG, "The received bundle containing message data could not be validated.");
+ return false;
+ }
+
+ ChromeGcmListenerService.dispatchMessageToDriver(this, new GCMMessage(params.getExtras()));
+ return false;
+ }
+
+ /**
+ * Called when the system has determined that processing the GCM message must be stopped.
+ *
+ * @param params The parameters that define the job that is to be stopped.
+ * @return True if the job has finished and the wakelock is ready to be released. False if there
+ * is remaining (asynchronous) work to be done.
+ */
+ @Override
+ public boolean onStopJob(JobParameters params) {
+ // The GCM Driver has no mechanism for aborting previously dispatched messages.
+ return false;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698