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

Unified Diff: components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerFactory.java

Issue 2714463002: [android] Add JobScheduler-based BackgroundTaskScheduler. (Closed)
Patch Set: FindBugs wants the real Pi, but I won't give it. 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: components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerFactory.java
diff --git a/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerFactory.java b/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerFactory.java
new file mode 100644
index 0000000000000000000000000000000000000000..239e855f777003e2a7f456f6bd502646bdd757b2
--- /dev/null
+++ b/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerFactory.java
@@ -0,0 +1,39 @@
+// 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.components.background_task_scheduler;
+
+import android.annotation.TargetApi;
+import android.os.Build;
+
+import org.chromium.base.ThreadUtils;
+
+/**
+ * A factory for {@link BackgroundTaskScheduler} that ensures there is only ever a single instance.
+ */
+public final class BackgroundTaskSchedulerFactory {
+ private static BackgroundTaskScheduler sInstance;
+
+ @TargetApi(Build.VERSION_CODES.M)
+ private static BackgroundTaskSchedulerDelegate getSchedulerDelegate() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ return new BackgroundTaskSchedulerJobService();
+ } else {
+ throw new RuntimeException("Not able to schedule through GCM yet.");
+ }
+ }
+
+ /**
+ * @return the current instance of the {@link BackgroundTaskScheduler}. Creates one if none
+ * exist.
+ */
+ public static BackgroundTaskScheduler getScheduler() {
+ ThreadUtils.assertOnUiThread();
+ if (sInstance == null) sInstance = new BackgroundTaskScheduler(getSchedulerDelegate());
+ return sInstance;
+ }
+
+ // Do not instantiate.
+ private BackgroundTaskSchedulerFactory() {}
+}

Powered by Google App Engine
This is Rietveld 408576698