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