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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/BackgroundSyncLauncherService.java

Issue 1699143002: [NTP Snippets] Schedule periodic fetching (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@snippets_feature
Patch Set: fix bots Created 4 years, 9 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
(Empty)
1 // Copyright 2015 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.chrome.browser;
6
7 import android.content.Context;
8
9 import com.google.android.gms.gcm.GcmNetworkManager;
10 import com.google.android.gms.gcm.GcmTaskService;
11 import com.google.android.gms.gcm.TaskParams;
12
13 import org.chromium.base.Log;
14 import org.chromium.base.ThreadUtils;
15 import org.chromium.base.VisibleForTesting;
16 import org.chromium.base.annotations.SuppressFBWarnings;
17 import org.chromium.base.library_loader.LibraryProcessType;
18 import org.chromium.base.library_loader.ProcessInitException;
19 import org.chromium.content.app.ContentApplication;
20 import org.chromium.content.browser.BrowserStartupController;
21
22 /**
23 * {@link BackgroundSyncLauncherService} is scheduled through the {@link GcmNetw orkManager}
24 * when the browser needs to be launched in response to changing network or powe r conditions.
25 */
26 public class BackgroundSyncLauncherService extends GcmTaskService {
27 private static final String TAG = "BgSyncLauncher";
28
29 @Override
30 @VisibleForTesting
31 public int onRunTask(TaskParams params) {
32 // Start the browser. The browser's BackgroundSyncManager (for the activ e profile) will
33 // start, check the network, and run any necessary sync events. This tas k runs with a wake
34 // lock, but has a three minute timeout, so we need to start the browser in its own task.
35 // TODO(jkarlin): Protect the browser sync event with a wake lock. See c rbug.com/486020.
36 Log.v(TAG, "Starting Browser after coming online");
37 final Context context = this;
38 ThreadUtils.runOnUiThread(new Runnable() {
39 @Override
40 public void run() {
41 if (!BackgroundSyncLauncher.hasInstance()) {
42 launchBrowser(context);
43 }
44 }
45 });
46 return GcmNetworkManager.RESULT_SUCCESS;
47 }
48
49 @VisibleForTesting
50 @SuppressFBWarnings("DM_EXIT")
51 protected void launchBrowser(Context context) {
52 ContentApplication.initCommandLine(context);
53 try {
54 BrowserStartupController.get(context, LibraryProcessType.PROCESS_BRO WSER)
55 .startBrowserProcessesSync(false);
56 } catch (ProcessInitException e) {
57 Log.e(TAG, "ProcessInitException while starting the browser process" );
58 // Since the library failed to initialize nothing in the application
59 // can work, so kill the whole application not just the activity.
60 System.exit(-1);
61 }
62 }
63
64 @Override
65 @VisibleForTesting
66 public void onInitializeTasks() {
67 BackgroundSyncLauncher.rescheduleTasksOnUpgrade(this);
68 }
69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698