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

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

Issue 2086483004: Remove ChromePrerenderService, keeping only its skeleton behind. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Explain why the service is staying. 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 2015 The Chromium Authors. All rights reserved. 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 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.prerender; 5 package org.chromium.chrome.browser.prerender;
6 6
7 import android.app.Service; 7 import android.app.Service;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.os.AsyncTask;
11 import android.os.IBinder; 10 import android.os.IBinder;
12 import android.os.Message; 11 import android.os.Message;
13 import android.os.Messenger; 12 import android.os.Messenger;
14 import android.text.TextUtils;
15 import android.util.Log;
16 13
17 import org.chromium.base.ThreadUtils;
18 import org.chromium.base.annotations.SuppressFBWarnings;
19 import org.chromium.base.library_loader.ProcessInitException;
20 import org.chromium.chrome.R;
21 import org.chromium.chrome.browser.ApplicationInitialization;
22 import org.chromium.chrome.browser.ChromeApplication;
23 import org.chromium.chrome.browser.ChromeVersionInfo; 14 import org.chromium.chrome.browser.ChromeVersionInfo;
24 import org.chromium.chrome.browser.WarmupManager;
25 import org.chromium.chrome.browser.externalauth.ExternalAuthUtils; 15 import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
26 import org.chromium.chrome.browser.externalauth.VerifiedHandler; 16 import org.chromium.chrome.browser.externalauth.VerifiedHandler;
27 import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
28 import org.chromium.content.browser.ChildProcessCreationParams;
29 import org.chromium.content.browser.ChildProcessLauncher;
30 17
31 /** 18 /**
32 * A bound service that warms up Chrome and performs actions related with preren dering urls. 19 * A bound service that does nothing. Kept here to prevent old clients relying o n it being
20 * available from crashing.
33 */ 21 */
34 public class ChromePrerenderService extends Service { 22 public class ChromePrerenderService extends Service {
35 public static final int MSG_PRERENDER_URL = 1;
36 public static final int MSG_CANCEL_PRERENDER = 2;
37 public static final String KEY_PRERENDERED_URL = "url_to_prerender";
38 public static final String KEY_PRERENDER_WIDTH = "prerender_width";
39 public static final String KEY_PRERENDER_HEIGHT = "prerender_height";
40 public static final String KEY_REFERRER = "referrer";
41
42 /** 23 /**
43 * Handler of incoming messages from clients. 24 * Handler of incoming messages from clients.
44 */ 25 */
45 class IncomingHandler extends VerifiedHandler { 26 static class IncomingHandler extends VerifiedHandler {
46 IncomingHandler(Context context) { 27 IncomingHandler(Context context) {
47 super(context, ChromeVersionInfo.isLocalBuild() 28 super(context, ChromeVersionInfo.isLocalBuild()
48 ? 0 : ExternalAuthUtils.FLAG_SHOULD_BE_GOOGLE_SIGNED); 29 ? 0 : ExternalAuthUtils.FLAG_SHOULD_BE_GOOGLE_SIGNED);
49 } 30 }
50 31
51 @Override 32 @Override
52 public void handleMessage(Message msg) { 33 public void handleMessage(Message msg) {}
53 ChromePrerenderService.this.handleMessage(msg);
54 }
55 } 34 }
56 35
57 /**
58 * Target we publish for clients to send messages to IncomingHandler.
59 */
60 private Messenger mMessenger; 36 private Messenger mMessenger;
61 37
62 /**
63 * When binding to the service, we return an interface to our messenger
64 * for sending messages to the service.
65 */
66 @SuppressFBWarnings("DM_EXIT")
67 @Override 38 @Override
68 public IBinder onBind(Intent intent) { 39 public IBinder onBind(Intent intent) {
69 mMessenger = new Messenger(new IncomingHandler(getApplicationContext())) ; 40 mMessenger = new Messenger(new IncomingHandler(getApplicationContext())) ;
70
71 try {
72 final Context context = getApplicationContext();
73 final ChromeApplication chrome = (ChromeApplication) context;
74 ChildProcessCreationParams.set(chrome.getChildProcessCreationParams( ));
75 new AsyncTask<Context, Void, Void>() {
76 @Override
77 protected Void doInBackground(Context... params) {
78 ChildProcessLauncher.warmUp(params[0]);
79 return null;
80 }
81 }.execute(context);
82 ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup( );
83
84 ApplicationInitialization.enableFullscreenFlags(
85 getApplicationContext().getResources(),
86 getApplicationContext(), R.dimen.control_container_height);
87 } catch (ProcessInitException e) {
88 Log.e(this.getClass().toString(),
89 "ProcessInitException while starting the browser process");
90 // Since the library failed to initialize nothing in the application
91 // can work, so kill the whole application not just the activity
92 System.exit(-1);
93 }
94 return mMessenger.getBinder(); 41 return mMessenger.getBinder();
95 } 42 }
96
97 /**
98 * Handle and incoming message from the messenger. Child classes adding new messages
99 * should extend this call and handle them separately.
100 * @param msg The message to be handled.
101 */
102 protected void handleMessage(Message msg) {
103 switch (msg.what) {
104 case MSG_PRERENDER_URL:
105 final String url = msg.getData().getString(KEY_PRERENDERED_URL);
106 final String referrer = msg.getData().getString(KEY_REFERRER, "" );
107 final int width = msg.getData().getInt(KEY_PRERENDER_WIDTH, 0);
108 final int height = msg.getData().getInt(KEY_PRERENDER_HEIGHT, 0) ;
109 if (!TextUtils.isEmpty(url)) {
110 ThreadUtils.runOnUiThread(new Runnable() {
111 @Override
112 public void run() {
113 prerenderUrl(url, referrer, width, height);
114 }
115 });
116 }
117 break;
118 case MSG_CANCEL_PRERENDER:
119 ThreadUtils.runOnUiThread(new Runnable() {
120 @Override
121 public void run() {
122 WarmupManager.getInstance().cancelCurrentPrerender();
123 }
124 });
125 break;
126 default:
127 break;
128 }
129 }
130
131 private void prerenderUrl(String url, String referrer, int width, int height ) {
132 WarmupManager.getInstance().prerenderUrl(url, referrer, width, height);
133 }
134 } 43 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698