OLD | NEW |
(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.components.background_task_scheduler; |
| 6 |
| 7 import android.annotation.TargetApi; |
| 8 import android.os.Build; |
| 9 |
| 10 import org.chromium.base.ThreadUtils; |
| 11 |
| 12 /** |
| 13 * A factory for {@link BackgroundTaskScheduler} that ensures there is only ever
a single instance. |
| 14 */ |
| 15 public final class BackgroundTaskSchedulerFactory { |
| 16 private static BackgroundTaskScheduler sInstance; |
| 17 |
| 18 @TargetApi(Build.VERSION_CODES.M) |
| 19 private static BackgroundTaskSchedulerDelegate getSchedulerDelegate() { |
| 20 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
| 21 return new BackgroundTaskSchedulerJobService(); |
| 22 } else { |
| 23 throw new RuntimeException("Not able to schedule through GCM yet."); |
| 24 } |
| 25 } |
| 26 |
| 27 /** |
| 28 * @return the current instance of the {@link BackgroundTaskScheduler}. Crea
tes one if none |
| 29 * exist. |
| 30 */ |
| 31 public static BackgroundTaskScheduler getScheduler() { |
| 32 ThreadUtils.assertOnUiThread(); |
| 33 if (sInstance == null) sInstance = new BackgroundTaskScheduler(getSchedu
lerDelegate()); |
| 34 return sInstance; |
| 35 } |
| 36 |
| 37 // Do not instantiate. |
| 38 private BackgroundTaskSchedulerFactory() {} |
| 39 } |
OLD | NEW |