| OLD | NEW |
| 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; | 10 import android.os.AsyncTask; |
| 11 import android.os.IBinder; | 11 import android.os.IBinder; |
| 12 import android.os.Message; | 12 import android.os.Message; |
| 13 import android.os.Messenger; | 13 import android.os.Messenger; |
| 14 import android.text.TextUtils; | 14 import android.text.TextUtils; |
| 15 import android.util.Log; | 15 import android.util.Log; |
| 16 | 16 |
| 17 import org.chromium.base.ThreadUtils; | 17 import org.chromium.base.ThreadUtils; |
| 18 import org.chromium.base.annotations.SuppressFBWarnings; | 18 import org.chromium.base.annotations.SuppressFBWarnings; |
| 19 import org.chromium.base.library_loader.ProcessInitException; | 19 import org.chromium.base.library_loader.ProcessInitException; |
| 20 import org.chromium.chrome.R; | 20 import org.chromium.chrome.R; |
| 21 import org.chromium.chrome.browser.ApplicationInitialization; | 21 import org.chromium.chrome.browser.ApplicationInitialization; |
| 22 import org.chromium.chrome.browser.ChromeApplication; |
| 22 import org.chromium.chrome.browser.ChromeVersionInfo; | 23 import org.chromium.chrome.browser.ChromeVersionInfo; |
| 23 import org.chromium.chrome.browser.WarmupManager; | 24 import org.chromium.chrome.browser.WarmupManager; |
| 24 import org.chromium.chrome.browser.externalauth.ExternalAuthUtils; | 25 import org.chromium.chrome.browser.externalauth.ExternalAuthUtils; |
| 25 import org.chromium.chrome.browser.externalauth.VerifiedHandler; | 26 import org.chromium.chrome.browser.externalauth.VerifiedHandler; |
| 26 import org.chromium.chrome.browser.init.ChromeBrowserInitializer; | 27 import org.chromium.chrome.browser.init.ChromeBrowserInitializer; |
| 27 import org.chromium.content.browser.ChildProcessLauncher; | 28 import org.chromium.content.browser.ChildProcessLauncher; |
| 28 | 29 |
| 29 /** | 30 /** |
| 30 * A bound service that warms up Chrome and performs actions related with preren
dering urls. | 31 * A bound service that warms up Chrome and performs actions related with preren
dering urls. |
| 31 */ | 32 */ |
| 32 public class ChromePrerenderService extends Service { | 33 public class ChromePrerenderService extends Service { |
| 33 public static final int MSG_PRERENDER_URL = 1; | 34 public static final int MSG_PRERENDER_URL = 1; |
| 34 public static final int MSG_CANCEL_PRERENDER = 2; | 35 public static final int MSG_CANCEL_PRERENDER = 2; |
| 35 public static final String KEY_PRERENDERED_URL = "url_to_prerender"; | 36 public static final String KEY_PRERENDERED_URL = "url_to_prerender"; |
| 36 public static final String KEY_PRERENDER_WIDTH = "prerender_width"; | 37 public static final String KEY_PRERENDER_WIDTH = "prerender_width"; |
| 37 public static final String KEY_PRERENDER_HEIGHT = "prerender_height"; | 38 public static final String KEY_PRERENDER_HEIGHT = "prerender_height"; |
| 38 public static final String KEY_REFERRER = "referrer"; | 39 public static final String KEY_REFERRER = "referrer"; |
| 39 | 40 |
| 40 private static class LauncherWarmUpTask extends AsyncTask<Context, Void, Voi
d> { | 41 private static class LauncherWarmUpTaskParams { |
| 42 final Context mContext; |
| 43 final ChildProcessLauncher.ChildProcessCreationParams mParams; |
| 44 |
| 45 LauncherWarmUpTaskParams( |
| 46 Context context, ChildProcessLauncher.ChildProcessCreationParams
params) { |
| 47 mContext = context; |
| 48 mParams = params; |
| 49 } |
| 50 } |
| 51 |
| 52 private static class LauncherWarmUpTask |
| 53 extends AsyncTask<LauncherWarmUpTaskParams, Void, Void> { |
| 41 @Override | 54 @Override |
| 42 protected Void doInBackground(Context... args) { | 55 protected Void doInBackground(LauncherWarmUpTaskParams... args) { |
| 43 ChildProcessLauncher.warmUp(args[0]); | 56 ChildProcessLauncher.warmUp(args[0].mContext, args[0].mParams); |
| 44 return null; | 57 return null; |
| 45 } | 58 } |
| 46 } | 59 } |
| 47 | 60 |
| 48 /** | 61 /** |
| 49 * Handler of incoming messages from clients. | 62 * Handler of incoming messages from clients. |
| 50 */ | 63 */ |
| 51 class IncomingHandler extends VerifiedHandler { | 64 class IncomingHandler extends VerifiedHandler { |
| 52 IncomingHandler(Context context) { | 65 IncomingHandler(Context context) { |
| 53 super(context, ChromeVersionInfo.isLocalBuild() | 66 super(context, ChromeVersionInfo.isLocalBuild() |
| (...skipping 14 matching lines...) Expand all Loading... |
| 68 /** | 81 /** |
| 69 * When binding to the service, we return an interface to our messenger | 82 * When binding to the service, we return an interface to our messenger |
| 70 * for sending messages to the service. | 83 * for sending messages to the service. |
| 71 */ | 84 */ |
| 72 @SuppressFBWarnings("DM_EXIT") | 85 @SuppressFBWarnings("DM_EXIT") |
| 73 @Override | 86 @Override |
| 74 public IBinder onBind(Intent intent) { | 87 public IBinder onBind(Intent intent) { |
| 75 mMessenger = new Messenger(new IncomingHandler(getApplicationContext()))
; | 88 mMessenger = new Messenger(new IncomingHandler(getApplicationContext()))
; |
| 76 | 89 |
| 77 try { | 90 try { |
| 78 new LauncherWarmUpTask().execute(getApplicationContext()); | 91 final Context context = getApplicationContext(); |
| 92 final ChromeApplication chrome = (ChromeApplication) context; |
| 93 new LauncherWarmUpTask().execute(new LauncherWarmUpTaskParams( |
| 94 context, chrome.getChildProcessCreationParams())); |
| 79 ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup(
); | 95 ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup(
); |
| 80 | 96 |
| 81 ApplicationInitialization.enableFullscreenFlags( | 97 ApplicationInitialization.enableFullscreenFlags( |
| 82 getApplicationContext().getResources(), | 98 getApplicationContext().getResources(), |
| 83 getApplicationContext(), R.dimen.control_container_height); | 99 getApplicationContext(), R.dimen.control_container_height); |
| 84 } catch (ProcessInitException e) { | 100 } catch (ProcessInitException e) { |
| 85 Log.e(this.getClass().toString(), | 101 Log.e(this.getClass().toString(), |
| 86 "ProcessInitException while starting the browser process"); | 102 "ProcessInitException while starting the browser process"); |
| 87 // Since the library failed to initialize nothing in the application | 103 // Since the library failed to initialize nothing in the application |
| 88 // can work, so kill the whole application not just the activity | 104 // can work, so kill the whole application not just the activity |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 break; | 138 break; |
| 123 default: | 139 default: |
| 124 break; | 140 break; |
| 125 } | 141 } |
| 126 } | 142 } |
| 127 | 143 |
| 128 private void prerenderUrl(String url, String referrer, int width, int height
) { | 144 private void prerenderUrl(String url, String referrer, int width, int height
) { |
| 129 WarmupManager.getInstance().prerenderUrl(url, referrer, width, height); | 145 WarmupManager.getInstance().prerenderUrl(url, referrer, width, height); |
| 130 } | 146 } |
| 131 } | 147 } |
| OLD | NEW |