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

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

Issue 2030773002: Add unit tests for the Background Scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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.chrome.browser; 5 package org.chromium.chrome.browser;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.os.Bundle; 8 import android.os.Bundle;
9 9
10 import com.google.android.gms.gcm.GcmNetworkManager; 10 import com.google.android.gms.gcm.GcmNetworkManager;
11 import com.google.android.gms.gcm.GcmTaskService; 11 import com.google.android.gms.gcm.GcmTaskService;
12 import com.google.android.gms.gcm.TaskParams; 12 import com.google.android.gms.gcm.TaskParams;
13 13
14 import org.chromium.base.Log; 14 import org.chromium.base.Log;
15 import org.chromium.base.ThreadUtils; 15 import org.chromium.base.ThreadUtils;
16 import org.chromium.base.VisibleForTesting; 16 import org.chromium.base.VisibleForTesting;
17 import org.chromium.base.annotations.SuppressFBWarnings; 17 import org.chromium.base.annotations.SuppressFBWarnings;
18 import org.chromium.base.library_loader.ProcessInitException; 18 import org.chromium.base.library_loader.ProcessInitException;
19 import org.chromium.chrome.browser.init.ChromeBrowserInitializer; 19 import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
20 import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge; 20 import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge;
21 import org.chromium.chrome.browser.ntp.snippets.SnippetsLauncher; 21 import org.chromium.chrome.browser.ntp.snippets.SnippetsLauncher;
22 import org.chromium.chrome.browser.offlinepages.BackgroundOfflinerTask; 22 import org.chromium.chrome.browser.offlinepages.BackgroundOfflinerTask;
23 import org.chromium.chrome.browser.offlinepages.OfflinePageUtils; 23 import org.chromium.chrome.browser.offlinepages.OfflinePageUtils;
24 import org.chromium.chrome.browser.offlinepages.SchedulerBridge;
24 import org.chromium.chrome.browser.precache.PrecacheController; 25 import org.chromium.chrome.browser.precache.PrecacheController;
25 26
26 /** 27 /**
27 * {@link ChromeBackgroundService} is scheduled through the {@link GcmNetworkMan ager} when the 28 * {@link ChromeBackgroundService} is scheduled through the {@link GcmNetworkMan ager} when the
28 * browser needs to be launched for scheduled tasks, or in response to changing network or power 29 * browser needs to be launched for scheduled tasks, or in response to changing network or power
29 * conditions. 30 * conditions.
30 */ 31 */
31 public class ChromeBackgroundService extends GcmTaskService { 32 public class ChromeBackgroundService extends GcmTaskService {
32 private static final String TAG = "BackgroundService"; 33 private static final String TAG = "BackgroundService";
33 34
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 @VisibleForTesting 119 @VisibleForTesting
119 protected boolean hasPrecacheInstance() { 120 protected boolean hasPrecacheInstance() {
120 return PrecacheController.hasInstance(); 121 return PrecacheController.hasInstance();
121 } 122 }
122 123
123 @VisibleForTesting 124 @VisibleForTesting
124 protected void precache(Context context, String tag) { 125 protected void precache(Context context, String tag) {
125 PrecacheController.get(context).precache(tag); 126 PrecacheController.get(context).precache(tag);
126 } 127 }
127 128
129 @VisibleForTesting
dougarnett 2016/06/02 00:14:45 ? but the following method is private so confused
Pete Williamson 2016/06/02 00:42:06 I meant to mark it as testable since the test now
128 private void handleOfflinePageBackgroundLoad(Context context, Bundle bundle) { 130 private void handleOfflinePageBackgroundLoad(Context context, Bundle bundle) {
129 if (!hasPrecacheInstance()) { 131 if (!hasPrecacheInstance()) {
130 launchBrowser(context); 132 launchBrowser(context);
131 } 133 }
132 134
133 // Call BackgroundTask, provide context. 135 // Call BackgroundTask, provide context.
134 BackgroundOfflinerTask.startBackgroundRequests(context, bundle); 136 BackgroundOfflinerTask task = new BackgroundOfflinerTask(new SchedulerBr idge());
137 task.startBackgroundRequests(context, bundle);
135 // TODO(petewil) if processBackgroundRequest returns false, return RESTA RT_RESCHEDULE 138 // TODO(petewil) if processBackgroundRequest returns false, return RESTA RT_RESCHEDULE
136 // to the GcmNetworkManager 139 // to the GcmNetworkManager
137 } 140 }
138 141
139 @VisibleForTesting 142 @VisibleForTesting
140 @SuppressFBWarnings("DM_EXIT") 143 @SuppressFBWarnings("DM_EXIT")
141 protected void launchBrowser(Context context) { 144 protected void launchBrowser(Context context) {
142 Log.i(TAG, "Launching browser"); 145 Log.i(TAG, "Launching browser");
143 try { 146 try {
144 ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup( ); 147 ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup( );
145 } catch (ProcessInitException e) { 148 } catch (ProcessInitException e) {
146 Log.e(TAG, "ProcessInitException while starting the browser process" ); 149 Log.e(TAG, "ProcessInitException while starting the browser process" );
147 // Since the library failed to initialize nothing in the application 150 // Since the library failed to initialize nothing in the application
148 // can work, so kill the whole application not just the activity. 151 // can work, so kill the whole application not just the activity.
149 System.exit(-1); 152 System.exit(-1);
150 } 153 }
151 } 154 }
152 155
153 @Override 156 @Override
154 public void onInitializeTasks() { 157 public void onInitializeTasks() {
155 BackgroundSyncLauncher.rescheduleTasksOnUpgrade(this); 158 BackgroundSyncLauncher.rescheduleTasksOnUpgrade(this);
156 PrecacheController.rescheduleTasksOnUpgrade(this); 159 PrecacheController.rescheduleTasksOnUpgrade(this);
157 } 160 }
158 } 161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698