Search in sources :

Example 1 with ChildProcessCreationParams

use of org.chromium.content.browser.ChildProcessCreationParams in project AndroidChromium by JackyAndroid.

the class WebApkActivity method initializeChildProcessCreationParams.

/**
 * Initializes {@link ChildProcessCreationParams} as a WebAPK's renderer process if
 * {@link isForWebApk}} is true; as Chrome's child process otherwise.
 * @param isForWebApk: Whether the {@link ChildProcessCreationParams} is initialized as a
 *                     WebAPK renderer process.
 */
private void initializeChildProcessCreationParams(boolean isForWebApk) {
    // TODO(hanxi): crbug.com/664530. WebAPKs shouldn't use a global ChildProcessCreationParams.
    ChromeApplication chrome = (ChromeApplication) ContextUtils.getApplicationContext();
    ChildProcessCreationParams params = chrome.getChildProcessCreationParams();
    if (isForWebApk) {
        boolean isExternalService = false;
        params = new ChildProcessCreationParams(getWebappInfo().webApkPackageName(), isExternalService, LibraryProcessType.PROCESS_CHILD);
    }
    ChildProcessCreationParams.set(params);
}
Also used : ChromeApplication(org.chromium.chrome.browser.ChromeApplication) ChildProcessCreationParams(org.chromium.content.browser.ChildProcessCreationParams)

Example 2 with ChildProcessCreationParams

use of org.chromium.content.browser.ChildProcessCreationParams in project AndroidChromium by JackyAndroid.

the class ChromeBrowserInitializer method handlePostNativeStartup.

/**
 * Execute startup tasks that require native libraries to be loaded. See {@link BrowserParts}
 * for a list of calls to be implemented.
 * @param isAsync Whether this call should synchronously wait for the browser process to be
 *                fully initialized before returning to the caller.
 * @param delegate The delegate for the {@link ChromeBrowserInitializer} to communicate
 *                 initialization tasks.
 */
public void handlePostNativeStartup(final boolean isAsync, final BrowserParts delegate) throws ProcessInitException {
    assert ThreadUtils.runningOnUiThread() : "Tried to start the browser on the wrong thread";
    final LinkedList<Runnable> initQueue = new LinkedList<>();
    abstract class NativeInitTask implements Runnable {

        @Override
        public final void run() {
            // Run the current task then put a request for the next one onto the
            // back of the UI message queue. This lets Chrome handle input events
            // between tasks.
            initFunction();
            if (!initQueue.isEmpty()) {
                Runnable nextTask = initQueue.pop();
                if (isAsync) {
                    mHandler.post(nextTask);
                } else {
                    nextTask.run();
                }
            }
        }

        public abstract void initFunction();
    }
    initQueue.add(new NativeInitTask() {

        @Override
        public void initFunction() {
            ProcessInitializationHandler.getInstance().initializePostNative();
        }
    });
    initQueue.add(new NativeInitTask() {

        @Override
        public void initFunction() {
            initNetworkChangeNotifier(mApplication.getApplicationContext());
        }
    });
    initQueue.add(new NativeInitTask() {

        @Override
        public void initFunction() {
            // This is not broken down as a separate task, since this:
            // 1. Should happen as early as possible
            // 2. Only submits asynchronous work
            // 3. Is thus very cheap (profiled at 0.18ms on a Nexus 5 with Lollipop)
            // It should also be in a separate task (and after) initNetworkChangeNotifier, as
            // this posts a task to the UI thread that would interfere with preconneciton
            // otherwise. By preconnecting afterwards, we make sure that this task has run.
            delegate.maybePreconnect();
            onStartNativeInitialization();
        }
    });
    initQueue.add(new NativeInitTask() {

        @Override
        public void initFunction() {
            if (delegate.isActivityDestroyed())
                return;
            delegate.initializeCompositor();
        }
    });
    initQueue.add(new NativeInitTask() {

        @Override
        public void initFunction() {
            if (delegate.isActivityDestroyed())
                return;
            delegate.initializeState();
        }
    });
    initQueue.add(new NativeInitTask() {

        @Override
        public void initFunction() {
            onFinishNativeInitialization();
        }
    });
    initQueue.add(new NativeInitTask() {

        @Override
        public void initFunction() {
            if (delegate.isActivityDestroyed())
                return;
            delegate.finishNativeInitialization();
        }
    });
    // See crbug.com/593250. This can be removed after N SDK is released, crbug.com/592722.
    ChildProcessCreationParams creationParams = mApplication.getChildProcessCreationParams();
    // N SDK is released, since it breaks WebAPKs on N+.
    if (creationParams != null && ChildProcessCreationParams.get() != null) {
        ChildProcessCreationParams.set(creationParams);
    }
    if (isAsync) {
        // We want to start this queue once the C++ startup tasks have run; allow the
        // C++ startup to run asynchonously, and set it up to start the Java queue once
        // it has finished.
        startChromeBrowserProcessesAsync(delegate.shouldStartGpuProcess(), new BrowserStartupController.StartupCallback() {

            @Override
            public void onFailure() {
                delegate.onStartupFailure();
            }

            @Override
            public void onSuccess(boolean success) {
                mHandler.post(initQueue.pop());
            }
        });
    } else {
        startChromeBrowserProcessesSync();
        initQueue.pop().run();
        assert initQueue.isEmpty();
    }
}
Also used : ChildProcessCreationParams(org.chromium.content.browser.ChildProcessCreationParams) BrowserStartupController(org.chromium.content.browser.BrowserStartupController) LinkedList(java.util.LinkedList)

Aggregations

ChildProcessCreationParams (org.chromium.content.browser.ChildProcessCreationParams)2 LinkedList (java.util.LinkedList)1 ChromeApplication (org.chromium.chrome.browser.ChromeApplication)1 BrowserStartupController (org.chromium.content.browser.BrowserStartupController)1