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;
17 * Wrapper for the steps needed to initialize the java and native sides of webview chromium.
19 public abstract class AwBrowserProcess {
20 private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "webview";
21 private static final String TAG = "AwBrowserProcess";
24 * Loads the native library, and performs basic static construction of objects needed
25 * to run webview in this process. Does not create threads; safe to call from zygote.
26 * Note: it is up to the caller to ensure this is only called once.
28 public static void loadLibrary() {
29 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
31 LibraryLoader.loadNow();
32 } catch (ProcessInitException e) {
33 throw new RuntimeException("Cannot load WebView", e);
38 * Starts the chromium browser process running within this process. Creates threads
39 * and performs other per-app resource allocations; must not be called from zygote.
40 * Note: it is up to the caller to ensure this is only called once.
41 * @param context The Android application context
43 public static void start(final Context context) {
44 // We must post to the UI thread to cover the case that the user
45 // has invoked Chromium startup by using the (thread-safe)
46 // CookieManager rather than creating a WebView.
47 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
51 BrowserStartupController.get(context).startBrowserProcessesSync(
52 BrowserStartupController.MAX_RENDERERS_SINGLE_PROCESS);
53 } catch (ProcessInitException e) {
54 throw new RuntimeException("Cannot initialize WebView", e);