1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.android_webview;
7 import android.content.Context;
9 import org.chromium.base.PathUtils;
10 import org.chromium.base.ThreadUtils;
11 import org.chromium.base.library_loader.LibraryLoader;
12 import org.chromium.base.library_loader.ProcessInitException;
13 import org.chromium.content.browser.BrowserStartupController;
16 * Wrapper for the steps needed to initialize the java and native sides of webview chromium.
18 public abstract class AwBrowserProcess {
19 private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "webview";
22 * Loads the native library, and performs basic static construction of objects needed
23 * to run webview in this process. Does not create threads; safe to call from zygote.
24 * Note: it is up to the caller to ensure this is only called once.
26 public static void loadLibrary() {
27 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
29 LibraryLoader.loadNow();
30 } catch (ProcessInitException e) {
31 throw new RuntimeException("Cannot load WebView", e);
36 * Starts the chromium browser process running within this process. Creates threads
37 * and performs other per-app resource allocations; must not be called from zygote.
38 * Note: it is up to the caller to ensure this is only called once.
39 * @param context The Android application context
41 public static void start(final Context context) {
42 // We must post to the UI thread to cover the case that the user
43 // has invoked Chromium startup by using the (thread-safe)
44 // CookieManager rather than creating a WebView.
45 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
49 BrowserStartupController.get(context).startBrowserProcessesSync(
50 BrowserStartupController.MAX_RENDERERS_SINGLE_PROCESS);
51 } catch (ProcessInitException e) {
52 throw new RuntimeException("Cannot initialize WebView", e);