| 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() {}
|
| +}
|
|
|