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

Unified Diff: content/public/android/java/src/org/chromium/content/browser/BackgroundSyncLauncherService.java

Issue 1324173002: [Background Sync] Use GcmNetworkManager to start the browser for sync events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@bgsync-fix-background5
Patch Set: Addressing comments from PS#25 Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: content/public/android/java/src/org/chromium/content/browser/BackgroundSyncLauncherService.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/BackgroundSyncLauncherService.java b/content/public/android/java/src/org/chromium/content/browser/BackgroundSyncLauncherService.java
deleted file mode 100644
index fd92e55d2472212edefede449996a7359c56d661..0000000000000000000000000000000000000000
--- a/content/public/android/java/src/org/chromium/content/browser/BackgroundSyncLauncherService.java
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright 2015 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.content.browser;
-
-import android.app.IntentService;
-import android.content.Context;
-import android.content.Intent;
-import android.net.ConnectivityManager;
-import android.net.NetworkInfo;
-import android.support.v4.content.WakefulBroadcastReceiver;
-
-import org.chromium.base.Log;
-import org.chromium.base.ThreadUtils;
-import org.chromium.base.VisibleForTesting;
-import org.chromium.base.annotations.SuppressFBWarnings;
-import org.chromium.base.library_loader.LibraryProcessType;
-import org.chromium.base.library_loader.ProcessInitException;
-import org.chromium.content.app.ContentApplication;
-
-/**
- * {@link BackgroundSyncLauncherService} monitors network connectivity and launches
- * the browser when it goes online if the {@link BackgroundSyncLauncher} requested it.
- */
-public class BackgroundSyncLauncherService extends IntentService {
- private static final String TAG = "cr.BgSyncLauncher";
-
- /**
- * Receiver for network connection change broadcasts. If the device is online
- * and the browser isn't running it starts the BackgroundSyncLauncherService.
- * The service will then launch the browser if necessary.
- *
- * This class is public so that it can be instantiated by the Android runtime.
- */
- public static class Receiver extends WakefulBroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- // If online, the browser isn't running, and the browser has requested
- // it be launched the next time the device is online, start the browser.
- if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())
- && isOnline(context) && !BackgroundSyncLauncher.hasInstance()) {
- startService(context);
- }
- }
-
- @VisibleForTesting
- protected void startService(Context context) {
- Intent serviceIntent = new Intent(context, BackgroundSyncLauncherService.class);
- startWakefulService(context, serviceIntent);
- }
-
- @VisibleForTesting
- protected boolean isOnline(Context context) {
- ConnectivityManager connectivityManager =
- (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
- NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
- return networkInfo != null && networkInfo.isConnected();
- }
- }
-
- public BackgroundSyncLauncherService() {
- super("BackgroundSyncLauncherService");
- }
-
- @Override
- public void onHandleIntent(Intent intent) {
- try {
- ThreadUtils.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- onOnline(getApplicationContext());
- }
- });
- } finally {
- WakefulBroadcastReceiver.completeWakefulIntent(intent);
- }
- }
-
- private void onOnline(final Context context) {
- ThreadUtils.assertOnUiThread();
-
- BackgroundSyncLauncher.ShouldLaunchCallback callback =
- new BackgroundSyncLauncher.ShouldLaunchCallback() {
- @Override
- public void run(Boolean shouldLaunch) {
- if (!shouldLaunch) return;
- // Start the browser. The browser's BackgroundSyncManager (for the active
- // profile) will start, check the network, and run any necessary sync
- // events. It runs without a wake lock.
- // TODO(jkarlin): Protect the browser sync event with a wake lock. See
- // crbug.com/486020.
- Log.v(TAG, "Starting Browser after coming online");
- launchBrowser(context);
- }
- };
- BackgroundSyncLauncher.shouldLaunchWhenNextOnline(context, callback);
- }
-
- @SuppressFBWarnings("DM_EXIT")
- private void launchBrowser(Context context) {
- ContentApplication.initCommandLine(context);
- try {
- BrowserStartupController.get(context, LibraryProcessType.PROCESS_BROWSER)
- .startBrowserProcessesSync(false);
- } catch (ProcessInitException e) {
- Log.e(TAG, "ProcessInitException while starting the browser process");
- // Since the library failed to initialize nothing in the application
- // can work, so kill the whole application not just the activity.
- System.exit(-1);
- }
- }
-}

Powered by Google App Engine
This is Rietveld 408576698