Chromium Code Reviews| 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..abc96f4e7d12f9c0d6d744fd8dbb95b5dc77a5fc |
| --- /dev/null |
| +++ b/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerFactory.java |
| @@ -0,0 +1,37 @@ |
| +// 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.os.Build; |
| + |
| +import org.chromium.base.ThreadUtils; |
| + |
| +/** |
| + * A factory for {@link BackgroundTaskScheduler} that ensures there is only ever a single instance. |
|
David Trainor- moved to gerrit
2017/02/24 07:19:49
Do we really ensure this? Should we make the task
Peter Beverloo
2017/02/24 18:07:09
The BackgroundTaskScheduler's constructor already
nyquist
2017/02/24 23:41:11
I guess since the constructor is package protected
|
| + */ |
| +public final class BackgroundTaskSchedulerFactory { |
| + private static BackgroundTaskScheduler sInstance; |
| + |
| + private static BackgroundTaskSchedulerDelegate getSchedulerDelegate() { |
|
Peter Beverloo
2017/02/24 18:07:09
Wild idea: should we mark this with @TargetApi on
nyquist
2017/02/24 23:41:12
Good call. I'll do that for now until we have GcmN
|
| + 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() {} |
| +} |