Index: chrome/android/java/src/org/chromium/chrome/browser/ChromeBackgroundService.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/BackgroundSyncLauncherService.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromeBackgroundService.java |
similarity index 47% |
rename from chrome/android/java/src/org/chromium/chrome/browser/BackgroundSyncLauncherService.java |
rename to chrome/android/java/src/org/chromium/chrome/browser/ChromeBackgroundService.java |
index a6219fd1868d9300af1d642f605d95b7f93b4152..7828402c83dd6c7bc34685759953359eff50b6d0 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/BackgroundSyncLauncherService.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeBackgroundService.java |
@@ -1,4 +1,4 @@ |
-// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Copyright 2016 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. |
@@ -16,39 +16,72 @@ 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.chrome.browser.ntp.snippets.SnippetsController; |
+import org.chromium.chrome.browser.ntp.snippets.SnippetsLauncher; |
import org.chromium.content.app.ContentApplication; |
import org.chromium.content.browser.BrowserStartupController; |
/** |
- * {@link BackgroundSyncLauncherService} is scheduled through the {@link GcmNetworkManager} |
- * when the browser needs to be launched in response to changing network or power conditions. |
+ * {@link ChromeBackgroundService} is scheduled through the {@link GcmNetworkManager} when the |
+ * browser needs to be launched for scheduled tasks, or in response to changing network or power |
+ * conditions. |
*/ |
-public class BackgroundSyncLauncherService extends GcmTaskService { |
- private static final String TAG = "BgSyncLauncher"; |
+public class ChromeBackgroundService extends GcmTaskService { |
+ private static final String TAG = "BackgroundService"; |
@Override |
- @VisibleForTesting |
public int onRunTask(TaskParams params) { |
- // Start the browser. The browser's BackgroundSyncManager (for the active profile) will |
- // start, check the network, and run any necessary sync events. This task runs with a wake |
- // lock, but has a three minute timeout, so we need to start the browser in its own task. |
- // TODO(jkarlin): Protect the browser sync event with a wake lock. See crbug.com/486020. |
- Log.v(TAG, "Starting Browser after coming online"); |
+ Log.i(TAG, "Woken up at " + new java.util.Date().toString()); |
+ handleRunTask(params.getTag()); |
+ return GcmNetworkManager.RESULT_SUCCESS; |
+ } |
+ |
+ @VisibleForTesting |
+ public void handleRunTask(final String tag) { |
final Context context = this; |
ThreadUtils.runOnUiThread(new Runnable() { |
@Override |
public void run() { |
- if (!BackgroundSyncLauncher.hasInstance()) { |
- launchBrowser(context); |
+ switch(tag) { |
+ case BackgroundSyncLauncher.TASK_TAG: |
+ handleBackgroundSyncEvent(context); |
+ break; |
+ |
+ case SnippetsLauncher.TASK_TAG: |
+ handleFetchSnippets(context); |
+ break; |
+ |
+ default: |
+ Log.i(TAG, "Unknown task tag " + tag); |
+ break; |
} |
} |
}); |
- return GcmNetworkManager.RESULT_SUCCESS; |
+ } |
+ |
+ private void handleBackgroundSyncEvent(Context context) { |
+ if (!BackgroundSyncLauncher.hasInstance()) { |
+ // Start the browser. The browser's BackgroundSyncManager (for the active profile) will |
+ // start, check the network, and run any necessary sync events. This task runs with a |
+ // wake lock, but has a three minute timeout, so we need to start the browser in its |
+ // own task. |
+ // TODO(jkarlin): Protect the browser sync event with a wake lock. |
+ // See crbug.com/486020. |
+ launchBrowser(context); |
+ } |
+ } |
+ |
+ private void handleFetchSnippets(Context context) { |
+ if (!SnippetsLauncher.hasInstance()) { |
+ launchBrowser(context); |
+ } |
+ SnippetsController.get(context).fetchSnippets(true); |
} |
@VisibleForTesting |
@SuppressFBWarnings("DM_EXIT") |
protected void launchBrowser(Context context) { |
+ Log.i(TAG, "Launching browser"); |
ContentApplication.initCommandLine(context); |
try { |
BrowserStartupController.get(context, LibraryProcessType.PROCESS_BROWSER) |
@@ -62,7 +95,6 @@ public class BackgroundSyncLauncherService extends GcmTaskService { |
} |
@Override |
- @VisibleForTesting |
public void onInitializeTasks() { |
BackgroundSyncLauncher.rescheduleTasksOnUpgrade(this); |
} |