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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsLauncherService.java

Issue 1699143002: [NTP Snippets] Schedule periodic fetching (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@snippets_feature
Patch Set: Created 4 years, 10 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 2015 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.ntp.snippets;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 8
9 import com.google.android.gms.gcm.GcmNetworkManager; 9 import com.google.android.gms.gcm.GcmNetworkManager;
10 import com.google.android.gms.gcm.GcmTaskService; 10 import com.google.android.gms.gcm.GcmTaskService;
11 import com.google.android.gms.gcm.TaskParams; 11 import com.google.android.gms.gcm.TaskParams;
12 12
13 import org.chromium.base.Log; 13 import org.chromium.base.Log;
14 import org.chromium.base.ThreadUtils; 14 import org.chromium.base.ThreadUtils;
15 import org.chromium.base.VisibleForTesting;
16 import org.chromium.base.annotations.SuppressFBWarnings; 15 import org.chromium.base.annotations.SuppressFBWarnings;
17 import org.chromium.base.library_loader.LibraryProcessType; 16 import org.chromium.base.library_loader.LibraryProcessType;
18 import org.chromium.base.library_loader.ProcessInitException; 17 import org.chromium.base.library_loader.ProcessInitException;
19 import org.chromium.content.app.ContentApplication; 18 import org.chromium.content.app.ContentApplication;
20 import org.chromium.content.browser.BrowserStartupController; 19 import org.chromium.content.browser.BrowserStartupController;
21 20
22 /** 21 /**
23 * {@link BackgroundSyncLauncherService} is scheduled through the {@link GcmNetw orkManager} 22 * {@link SnippetsLauncherService} is scheduled through the {@link GcmNetworkMan ager} when the
24 * when the browser needs to be launched in response to changing network or powe r conditions. 23 * browser needs to be launched to fetch new snippets.
25 */ 24 */
26 public class BackgroundSyncLauncherService extends GcmTaskService { 25 public class SnippetsLauncherService extends GcmTaskService {
Marc Treib 2016/02/16 15:03:25 So, as you can see, this class is currently almost
Bernhard Bauer 2016/02/16 16:19:08 Hm... I think there are a couple of things in here
Marc Treib 2016/02/16 16:54:27 Hm, I guess that might make sense longer-term. It
Bernhard Bauer 2016/02/17 16:53:00 OK, thanks! Even if we don't want to do coalescing
Marc Treib 2016/02/18 10:21:47 Done. Also added some tests.
27 private static final String TAG = "BgSyncLauncher"; 26 private static final String TAG = "SnippetsLauncherSvc";
Marc Treib 2016/02/16 15:03:25 Weirdly abbreviated because tags apparently must b
Bernhard Bauer 2016/02/16 16:19:08 Eh, I'd be fine with just "SnippetsLauncher".
Marc Treib 2016/02/16 16:54:27 There is another class called SnippetsLauncher, I'
Bernhard Bauer 2016/02/17 16:53:00 So, in general that is not a requirement; it's tot
Marc Treib 2016/02/18 10:21:47 Acknowledged (but obsolete now that this has been
28 27
29 @Override 28 @Override
30 @VisibleForTesting
31 public int onRunTask(TaskParams params) { 29 public int onRunTask(TaskParams params) {
32 // Start the browser. The browser's BackgroundSyncManager (for the activ e profile) will 30 Log.i(TAG, "Woken up at " + new java.util.Date().toString());
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; 31 final Context context = this;
38 ThreadUtils.runOnUiThread(new Runnable() { 32 ThreadUtils.runOnUiThread(new Runnable() {
39 @Override 33 @Override
40 public void run() { 34 public void run() {
41 if (!BackgroundSyncLauncher.hasInstance()) { 35 if (!SnippetsLauncher.hasInstance()) {
36 Log.i(TAG, "Launching browser");
42 launchBrowser(context); 37 launchBrowser(context);
43 } 38 }
39 SnippetsController.get(context).fetchSnippets(true);
44 } 40 }
45 }); 41 });
46 return GcmNetworkManager.RESULT_SUCCESS; 42 return GcmNetworkManager.RESULT_SUCCESS;
47 } 43 }
48 44
49 @VisibleForTesting
50 @SuppressFBWarnings("DM_EXIT") 45 @SuppressFBWarnings("DM_EXIT")
51 protected void launchBrowser(Context context) { 46 protected void launchBrowser(Context context) {
52 ContentApplication.initCommandLine(context); 47 ContentApplication.initCommandLine(context);
53 try { 48 try {
54 BrowserStartupController.get(context, LibraryProcessType.PROCESS_BRO WSER) 49 BrowserStartupController.get(context, LibraryProcessType.PROCESS_BRO WSER)
55 .startBrowserProcessesSync(false); 50 .startBrowserProcessesSync(false);
56 } catch (ProcessInitException e) { 51 } catch (ProcessInitException e) {
57 Log.e(TAG, "ProcessInitException while starting the browser process" ); 52 Log.e(TAG, "ProcessInitException while starting the browser process" );
58 // Since the library failed to initialize nothing in the application 53 // Since the library failed to initialize nothing in the application
59 // can work, so kill the whole application not just the activity. 54 // can work, so kill the whole application not just the activity.
60 System.exit(-1); 55 System.exit(-1);
61 } 56 }
62 } 57 }
58 }
63 59
64 @Override
65 @VisibleForTesting
66 public void onInitializeTasks() {
67 BackgroundSyncLauncher.rescheduleTasksOnUpgrade(this);
68 }
69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698