org.chromium.content.browser.ChildProcessLauncher Java Examples

The following examples show how to use org.chromium.content.browser.ChildProcessLauncher. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChromeApplication.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Called when a top-level Chrome activity (ChromeTabbedActivity, FullscreenActivity) is
 * started in foreground. It will not be called again when other Chrome activities take over
 * (see onStart()), that is, when correct activity calls startActivity() for another Chrome
 * activity.
 */
private void onForegroundSessionStart() {
    ChildProcessLauncher.onBroughtToForeground();
    mBackgroundProcessing.startTimers();
    updatePasswordEchoState();
    FontSizePrefs.getInstance(this).onSystemFontScaleChanged();
    updateAcceptLanguages();
    mVariationsSession.start(getApplicationContext());
    mPowerBroadcastReceiver.onForegroundSessionStart();

    // Track the ratio of Chrome startups that are caused by notification clicks.
    // TODO(johnme): Add other reasons (and switch to recordEnumeratedHistogram).
    RecordHistogram.recordBooleanHistogram(
            "Startup.BringToForegroundReason",
            NotificationPlatformBridge.wasNotificationRecentlyClicked());
}
 
Example #2
Source File: CustomTabsConnection.java    From delion with Apache License 2.0 6 votes vote down vote up
/** Warmup activities that should only happen once. */
@SuppressFBWarnings("DM_EXIT")
private static void initializeBrowser(final Application app) {
    ThreadUtils.assertOnUiThread();
    try {
        ChromeBrowserInitializer.getInstance(app).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "ProcessInitException while starting the browser process.");
        // Cannot do anything without the native library, and cannot show a
        // dialog to the user.
        System.exit(-1);
    }
    final Context context = app.getApplicationContext();
    final ChromeApplication chrome = (ChromeApplication) context;
    ChildProcessCreationParams.set(chrome.getChildProcessCreationParams());
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            ChildProcessLauncher.warmUp(context);
            return null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    ChromeBrowserInitializer.initNetworkChangeNotifier(context);
    WarmupManager.getInstance().initializeViewHierarchy(
            context, R.layout.custom_tabs_control_container);
}
 
Example #3
Source File: CustomTabsConnection.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/** Warmup activities that should only happen once. */
@SuppressFBWarnings("DM_EXIT")
private static void initializeBrowser(final Application app) {
    ThreadUtils.assertOnUiThread();
    try {
        ChromeBrowserInitializer.getInstance(app).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "ProcessInitException while starting the browser process.");
        // Cannot do anything without the native library, and cannot show a
        // dialog to the user.
        System.exit(-1);
    }
    final Context context = app.getApplicationContext();
    final ChromeApplication chrome = (ChromeApplication) context;
    ChildProcessCreationParams.set(chrome.getChildProcessCreationParams());
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            ChildProcessLauncher.warmUp(context);
            return null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    ChromeBrowserInitializer.initNetworkChangeNotifier(context);
    WarmupManager.getInstance().initializeViewHierarchy(
            context, R.layout.custom_tabs_control_container, R.layout.custom_tabs_toolbar);
}
 
Example #4
Source File: ChromeActivitySessionTracker.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Called when a top-level Chrome activity (ChromeTabbedActivity, FullscreenActivity) is
 * started in foreground. It will not be called again when other Chrome activities take over
 * (see onStart()), that is, when correct activity calls startActivity() for another Chrome
 * activity.
 */
private void onForegroundSessionStart() {
    UmaUtils.recordForegroundStartTime();
    ChildProcessLauncher.onBroughtToForeground();
    updatePasswordEchoState();
    FontSizePrefs.getInstance(mApplication).onSystemFontScaleChanged();
    updateAcceptLanguages();
    mVariationsSession.start(mApplication);
    mPowerBroadcastReceiver.onForegroundSessionStart();

    // Track the ratio of Chrome startups that are caused by notification clicks.
    // TODO(johnme): Add other reasons (and switch to recordEnumeratedHistogram).
    RecordHistogram.recordBooleanHistogram(
            "Startup.BringToForegroundReason",
            NotificationPlatformBridge.wasNotificationRecentlyClicked());
}
 
Example #5
Source File: ChromeActivitySessionTracker.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Called when last of Chrome activities is stopped, ending the foreground session. This will
 * not be called when a Chrome activity is stopped because another Chrome activity takes over.
 * This is ensured by ActivityStatus, which switches to track new activity when its started and
 * will not report the old one being stopped (see createStateListener() below).
 */
private void onForegroundSessionEnd() {
    if (!mIsStarted) return;
    ChromeApplication.flushPersistentData();
    mIsStarted = false;
    mPowerBroadcastReceiver.onForegroundSessionEnd();

    ChildProcessLauncher.onSentToBackground();
    IntentHandler.clearPendingReferrer();
    IntentHandler.clearPendingIncognitoUrl();

    int totalTabCount = 0;
    for (WeakReference<Activity> reference : ApplicationStatus.getRunningActivities()) {
        Activity activity = reference.get();
        if (activity instanceof ChromeActivity) {
            TabModelSelector tabModelSelector =
                    ((ChromeActivity) activity).getTabModelSelector();
            if (tabModelSelector != null) {
                totalTabCount += tabModelSelector.getTotalTabCount();
            }
        }
    }
    RecordHistogram.recordCountHistogram(
            "Tab.TotalTabCount.BeforeLeavingApp", totalTabCount);
}
 
Example #6
Source File: CustomTabsConnection.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/** Warmup activities that should only happen once. */
@SuppressFBWarnings("DM_EXIT")
private static void initializeBrowser(final Application app) {
    ThreadUtils.assertOnUiThread();
    try {
        ChromeBrowserInitializer.getInstance(app).handleSynchronousStartupWithGpuWarmUp();
    } catch (ProcessInitException e) {
        Log.e(TAG, "ProcessInitException while starting the browser process.");
        // Cannot do anything without the native library, and cannot show a
        // dialog to the user.
        System.exit(-1);
    }
    final Context context = app.getApplicationContext();
    ChildProcessLauncher.warmUp(context);
    ChromeBrowserInitializer.initNetworkChangeNotifier(context);
    WarmupManager.getInstance().initializeViewHierarchy(
            context, R.layout.custom_tabs_control_container, R.layout.custom_tabs_toolbar);
}
 
Example #7
Source File: ChromeActivitySessionTracker.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Called when a top-level Chrome activity (ChromeTabbedActivity, FullscreenActivity) is
 * started in foreground. It will not be called again when other Chrome activities take over
 * (see onStart()), that is, when correct activity calls startActivity() for another Chrome
 * activity.
 */
private void onForegroundSessionStart() {
    UmaUtils.recordForegroundStartTime();
    ChildProcessLauncher.onBroughtToForeground();
    updatePasswordEchoState();
    FontSizePrefs.getInstance(mApplication).onSystemFontScaleChanged();
    updateAcceptLanguages();
    mVariationsSession.start(mApplication);
    mPowerBroadcastReceiver.onForegroundSessionStart();

    // Track the ratio of Chrome startups that are caused by notification clicks.
    // TODO(johnme): Add other reasons (and switch to recordEnumeratedHistogram).
    RecordHistogram.recordBooleanHistogram(
            "Startup.BringToForegroundReason",
            NotificationPlatformBridge.wasNotificationRecentlyClicked());
}
 
Example #8
Source File: ChromeActivitySessionTracker.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Called when last of Chrome activities is stopped, ending the foreground session. This will
 * not be called when a Chrome activity is stopped because another Chrome activity takes over.
 * This is ensured by ActivityStatus, which switches to track new activity when its started and
 * will not report the old one being stopped (see createStateListener() below).
 */
private void onForegroundSessionEnd() {
    if (!mIsStarted) return;
    UmaUtils.recordBackgroundTime();
    ChromeApplication.flushPersistentData();
    mIsStarted = false;
    mPowerBroadcastReceiver.onForegroundSessionEnd();

    ChildProcessLauncher.onSentToBackground();
    IntentHandler.clearPendingReferrer();
    IntentHandler.clearPendingIncognitoUrl();

    int totalTabCount = 0;
    for (WeakReference<Activity> reference : ApplicationStatus.getRunningActivities()) {
        Activity activity = reference.get();
        if (activity instanceof ChromeActivity) {
            TabModelSelector tabModelSelector =
                    ((ChromeActivity) activity).getTabModelSelector();
            if (tabModelSelector != null) {
                totalTabCount += tabModelSelector.getTotalTabCount();
            }
        }
    }
    RecordHistogram.recordCountHistogram(
            "Tab.TotalTabCount.BeforeLeavingApp", totalTabCount);
}
 
Example #9
Source File: NativeInitializationController.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Start loading the native library in the background. This kicks off the native initialization
 * process.
 *
 * @param allocateChildConnection Whether a spare child connection should be allocated. Set to
 *                                false if you know that no new renderer is needed.
 */
public void startBackgroundTasks(final boolean allocateChildConnection) {
    // TODO(yusufo) : Investigate using an AsyncTask for this.
    new Thread() {
        @Override
        public void run() {
            try {
                LibraryLoader libraryLoader =
                        LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER);
                libraryLoader.ensureInitialized(mContext.getApplicationContext());
                // The prefetch is done after the library load for two reasons:
                // - It is easier to know the library location after it has
                //   been loaded.
                // - Testing has shown that this gives the best compromise,
                //   by avoiding performance regression on any tested
                //   device, and providing performance improvement on
                //   some. Doing it earlier delays UI inflation and more
                //   generally startup on some devices, most likely by
                //   competing for IO.
                // For experimental results, see http://crbug.com/460438.
                libraryLoader.asyncPrefetchLibrariesToMemory();
            } catch (ProcessInitException e) {
                Log.e(TAG, "Unable to load native library.", e);
                mActivityDelegate.onStartupFailure();
                return;
            }
            if (allocateChildConnection) ChildProcessLauncher.warmUp(mContext);
            ThreadUtils.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    onLibraryLoaded();
                }
            });
        }
    }.start();
}
 
Example #10
Source File: DeferredStartupHandler.java    From delion with Apache License 2.0 5 votes vote down vote up
private void startModerateBindingManagementIfNeeded() {
    // Moderate binding doesn't apply to low end devices.
    if (SysUtils.isLowEndDevice()) return;

    boolean moderateBindingTillBackgrounded =
            FieldTrialList.findFullName("ModerateBindingOnBackgroundTabCreation")
                    .equals("Enabled");
    ChildProcessLauncher.startModerateBindingManagement(
            mAppContext, moderateBindingTillBackgrounded);
}
 
Example #11
Source File: ChromeApplication.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Called when last of Chrome activities is stopped, ending the foreground session. This will
 * not be called when a Chrome activity is stopped because another Chrome activity takes over.
 * This is ensured by ActivityStatus, which switches to track new activity when its started and
 * will not report the old one being stopped (see createStateListener() below).
 */
private void onForegroundSessionEnd() {
    if (!mIsStarted) return;
    mBackgroundProcessing.suspendTimers();
    flushPersistentData();
    mIsStarted = false;
    mPowerBroadcastReceiver.onForegroundSessionEnd();

    ChildProcessLauncher.onSentToBackground();
    IntentHandler.clearPendingReferrer();

    if (FeatureUtilities.isDocumentMode(this)) {
        if (sDocumentTabModelSelector != null) {
            RecordHistogram.recordCountHistogram("Tab.TotalTabCount.BeforeLeavingApp",
                    sDocumentTabModelSelector.getTotalTabCount());
        }
    } else {
        int totalTabCount = 0;
        for (WeakReference<Activity> reference : ApplicationStatus.getRunningActivities()) {
            Activity activity = reference.get();
            if (activity instanceof ChromeActivity) {
                TabModelSelector tabModelSelector =
                        ((ChromeActivity) activity).getTabModelSelector();
                if (tabModelSelector != null) {
                    totalTabCount += tabModelSelector.getTotalTabCount();
                }
            }
        }
        RecordHistogram.recordCountHistogram(
                "Tab.TotalTabCount.BeforeLeavingApp", totalTabCount);
    }
}
 
Example #12
Source File: Tab.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Called to swap out the current view with the one passed in.
 *
 * @param newContentViewCore The content view that should be swapped into the tab.
 * @param deleteOldNativeWebContents Whether to delete the native web
 *         contents of old view.
 * @param didStartLoad Whether
 *         WebContentsObserver::DidStartProvisionalLoadForFrame() has
 *         already been called.
 * @param didFinishLoad Whether WebContentsObserver::DidFinishLoad() has
 *         already been called.
 */
public void swapContentViewCore(ContentViewCore newContentViewCore,
        boolean deleteOldNativeWebContents, boolean didStartLoad, boolean didFinishLoad) {
    int originalWidth = 0;
    int originalHeight = 0;
    if (mContentViewCore != null) {
        originalWidth = mContentViewCore.getViewportWidthPix();
        originalHeight = mContentViewCore.getViewportHeightPix();
        mContentViewCore.onHide();
    }
    destroyContentViewCore(deleteOldNativeWebContents);
    NativePage previousNativePage = mNativePage;
    mNativePage = null;
    setContentViewCore(newContentViewCore);
    // Size of the new ContentViewCore is zero at this point. If we don't call onSizeChanged(),
    // next onShow() call would send a resize message with the current ContentViewCore size
    // (zero) to the renderer process, although the new size will be set soon.
    // However, this size fluttering may confuse Blink and rendered result can be broken
    // (see http://crbug.com/340987).
    mContentViewCore.onSizeChanged(originalWidth, originalHeight, 0, 0);
    mContentViewCore.onShow();
    mContentViewCore.attachImeAdapter();

    // If the URL has already committed (e.g. prerendering), tell process management logic that
    // it can rely on the process visibility signal for binding management.
    // TODO: Call ChildProcessLauncher#determinedVisibility() at a more intuitive time.
    // See crbug.com/537671
    if (!mContentViewCore.getWebContents().getLastCommittedUrl().equals("")) {
        ChildProcessLauncher.determinedVisibility(mContentViewCore.getCurrentRenderProcessId());
    }

    destroyNativePageInternal(previousNativePage);
    for (TabObserver observer : mObservers) {
        observer.onWebContentsSwapped(this, didStartLoad, didFinishLoad);
    }
}
 
Example #13
Source File: DeferredStartupHandler.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void startModerateBindingManagementIfNeeded() {
    // Moderate binding doesn't apply to low end devices.
    if (SysUtils.isLowEndDevice()) return;

    boolean moderateBindingTillBackgrounded =
            FieldTrialList.findFullName("ModerateBindingOnBackgroundTabCreation")
                    .equals("Enabled");
    ChildProcessLauncher.startModerateBindingManagement(
            mAppContext, moderateBindingTillBackgrounded);
}
 
Example #14
Source File: Tab.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Called to swap out the current view with the one passed in.
 *
 * @param newContentViewCore The content view that should be swapped into the tab.
 * @param deleteOldNativeWebContents Whether to delete the native web
 *         contents of old view.
 * @param didStartLoad Whether
 *         WebContentsObserver::DidStartProvisionalLoadForFrame() has
 *         already been called.
 * @param didFinishLoad Whether WebContentsObserver::DidFinishLoad() has
 *         already been called.
 */
public void swapContentViewCore(ContentViewCore newContentViewCore,
        boolean deleteOldNativeWebContents, boolean didStartLoad, boolean didFinishLoad) {
    int originalWidth = 0;
    int originalHeight = 0;
    if (mContentViewCore != null) {
        originalWidth = mContentViewCore.getViewportWidthPix();
        originalHeight = mContentViewCore.getViewportHeightPix();
        mContentViewCore.onHide();
    }

    Rect bounds = new Rect();
    if (originalWidth == 0 && originalHeight == 0) {
        bounds = ExternalPrerenderHandler.estimateContentSize(
                (Application) getApplicationContext(), false);
        originalWidth = bounds.right - bounds.left;
        originalHeight = bounds.bottom - bounds.top;
    }

    destroyContentViewCore(deleteOldNativeWebContents);
    NativePage previousNativePage = mNativePage;
    mNativePage = null;
    // Size of the new ContentViewCore is zero at this point. If we don't call onSizeChanged(),
    // next onShow() call would send a resize message with the current ContentViewCore size
    // (zero) to the renderer process, although the new size will be set soon.
    // However, this size fluttering may confuse Blink and rendered result can be broken
    // (see http://crbug.com/340987).
    newContentViewCore.onSizeChanged(originalWidth, originalHeight, 0, 0);
    if (!bounds.isEmpty()) {
        newContentViewCore.onPhysicalBackingSizeChanged(bounds.right, bounds.bottom);
    }
    newContentViewCore.onShow();
    setContentViewCore(newContentViewCore);

    mContentViewCore.attachImeAdapter();

    // If the URL has already committed (e.g. prerendering), tell process management logic that
    // it can rely on the process visibility signal for binding management.
    // TODO: Call ChildProcessLauncher#determinedVisibility() at a more intuitive time.
    // See crbug.com/537671
    if (!mContentViewCore.getWebContents().getLastCommittedUrl().equals("")) {
        ChildProcessLauncher.determinedVisibility(mContentViewCore.getCurrentRenderProcessId());
    }

    destroyNativePageInternal(previousNativePage);
    for (TabObserver observer : mObservers) {
        observer.onWebContentsSwapped(this, didStartLoad, didFinishLoad);
    }
}
 
Example #15
Source File: ProcessInitializationHandler.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private void startModerateBindingManagementIfNeeded(Context context) {
    // Moderate binding doesn't apply to low end devices.
    if (SysUtils.isLowEndDevice()) return;
    ChildProcessLauncher.startModerateBindingManagement(context);
}