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

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

Issue 2779753002: [Android] Adding scheduling through GcmNetworkManager (Closed)
Patch Set: Ensuring task is called on UI thread Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.components.background_task_scheduler; 5 package org.chromium.components.background_task_scheduler;
6 6
7 import android.annotation.TargetApi; 7 import android.annotation.TargetApi;
8 import android.os.Build; 8 import android.os.Build;
9 9
10 import org.chromium.base.ThreadUtils; 10 import org.chromium.base.ThreadUtils;
11 11
12 /** 12 /**
13 * A factory for {@link BackgroundTaskScheduler} that ensures there is only ever a single instance. 13 * A factory for {@link BackgroundTaskScheduler} that ensures there is only ever a single instance.
14 */ 14 */
15 public final class BackgroundTaskSchedulerFactory { 15 public final class BackgroundTaskSchedulerFactory {
16 private static BackgroundTaskScheduler sInstance; 16 private static BackgroundTaskScheduler sInstance;
17 17
18 @TargetApi(Build.VERSION_CODES.M) 18 @TargetApi(Build.VERSION_CODES.M)
19 private static BackgroundTaskSchedulerDelegate getSchedulerDelegate() { 19 private static BackgroundTaskSchedulerDelegate getSchedulerDelegate() {
20 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 20 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
21 return new BackgroundTaskSchedulerJobService(); 21 return new BackgroundTaskSchedulerJobService();
22 } else { 22 } else {
23 throw new RuntimeException("Not able to schedule through GCM yet."); 23 return new BackgroundTaskSchedulerGcmNetworkManager();
24 } 24 }
25 } 25 }
26 26
27 /** 27 /**
28 * @return the current instance of the {@link BackgroundTaskScheduler}. Crea tes one if none 28 * @return the current instance of the {@link BackgroundTaskScheduler}. Crea tes one if none
29 * exist. 29 * exist.
30 */ 30 */
31 public static BackgroundTaskScheduler getScheduler() { 31 public static BackgroundTaskScheduler getScheduler() {
32 ThreadUtils.assertOnUiThread(); 32 ThreadUtils.assertOnUiThread();
33 if (sInstance == null) sInstance = new BackgroundTaskScheduler(getSchedu lerDelegate()); 33 if (sInstance == null) sInstance = new BackgroundTaskScheduler(getSchedu lerDelegate());
34 return sInstance; 34 return sInstance;
35 } 35 }
36 36
37 // Do not instantiate. 37 // Do not instantiate.
38 private BackgroundTaskSchedulerFactory() {} 38 private BackgroundTaskSchedulerFactory() {}
39 } 39 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698