Java Code Examples for org.chromium.chrome.browser.WarmupManager#createSpareWebContents()

The following examples show how to use org.chromium.chrome.browser.WarmupManager#createSpareWebContents() . 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: CustomTabsConnection.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * High confidence mayLaunchUrl() call, that is:
 * - Tries to prerender if possible.
 * - An empty URL cancels the current prerender if any.
 * - If prerendering is not possible, makes sure that there is a spare renderer.
 */
private void highConfidenceMayLaunchUrl(CustomTabsSessionToken session,
        int uid, String url, Bundle extras, List<Bundle> otherLikelyBundles) {
    ThreadUtils.assertOnUiThread();
    if (TextUtils.isEmpty(url)) {
        cancelPrerender(session);
        return;
    }

    WarmupManager warmupManager = WarmupManager.getInstance();
    Profile profile = Profile.getLastUsedProfile();

    url = DataReductionProxySettings.getInstance().maybeRewriteWebliteUrl(url);
    int debugOverrideValue = NO_OVERRIDE;
    if (extras != null) debugOverrideValue = extras.getInt(DEBUG_OVERRIDE_KEY, NO_OVERRIDE);

    boolean didStartPrerender = false, didStartPrefetch = false;
    boolean mayPrerender = mayPrerender(session);
    if (mayPrerender) {
        if (debugOverrideValue == PREFETCH_ONLY) {
            didStartPrefetch = new ResourcePrefetchPredictor(profile).startPrefetching(url);
            if (didStartPrefetch) mSpeculation = SpeculationParams.forPrefetch(session, url);
        } else if (debugOverrideValue != NO_PRERENDERING) {
            didStartPrerender = prerenderUrl(session, url, extras, uid);
        }
    }
    preconnectUrls(otherLikelyBundles);
    if (!didStartPrefetch) warmupManager.maybePreconnectUrlAndSubResources(profile, url);
    if (!didStartPrerender) warmupManager.createSpareWebContents();
}
 
Example 2
Source File: CustomTabsConnection.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void startSpeculation(CustomTabsSessionToken session, String url, int speculationMode,
        Bundle extras, int uid) {
    WarmupManager warmupManager = WarmupManager.getInstance();
    Profile profile = Profile.getLastUsedProfile();
    boolean preconnect = true, createSpareWebContents = true;
    if (speculationMode == SpeculationParams.HIDDEN_TAB
            && !ChromeFeatureList.isEnabled(ChromeFeatureList.CCT_BACKGROUND_TAB)) {
        speculationMode = SpeculationParams.PRERENDER;
    }
    switch (speculationMode) {
        case SpeculationParams.PREFETCH:
            boolean didPrefetch = new LoadingPredictor(profile).prepareForPageLoad(url);
            if (didPrefetch) mSpeculation = SpeculationParams.forPrefetch(session, url);
            preconnect = !didPrefetch;
            break;
        case SpeculationParams.PRERENDER:
            boolean didPrerender = prerenderUrl(session, url, extras, uid);
            createSpareWebContents = !didPrerender;
            break;
        case SpeculationParams.HIDDEN_TAB:
            launchUrlInHiddenTab(session, url, extras);
            break;
        default:
            break;
    }
    if (preconnect) warmupManager.maybePreconnectUrlAndSubResources(profile, url);
    if (createSpareWebContents) warmupManager.createSpareWebContents();
}