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

The following examples show how to use org.chromium.chrome.browser.WarmupManager#maybePreconnectUrlAndSubResources() . 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 delion with Apache License 2.0 6 votes vote down vote up
private boolean preconnectUrls(List<Bundle> likelyBundles) {
    boolean atLeastOneUrl = false;
    if (likelyBundles == null) return false;
    WarmupManager warmupManager = WarmupManager.getInstance();
    Profile profile = Profile.getLastUsedProfile();
    for (Bundle bundle : likelyBundles) {
        Uri uri;
        try {
            uri = IntentUtils.safeGetParcelable(bundle, CustomTabsService.KEY_URL);
        } catch (ClassCastException e) {
            continue;
        }
        String url = checkAndConvertUri(uri);
        if (url != null) {
            warmupManager.maybePreconnectUrlAndSubResources(profile, url);
            atLeastOneUrl = true;
        }
    }
    return atLeastOneUrl;
}
 
Example 2
Source File: CustomTabsConnection.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private boolean preconnectUrls(List<Bundle> likelyBundles) {
    boolean atLeastOneUrl = false;
    if (likelyBundles == null) return false;
    WarmupManager warmupManager = WarmupManager.getInstance();
    Profile profile = Profile.getLastUsedProfile();
    for (Bundle bundle : likelyBundles) {
        Uri uri;
        try {
            uri = IntentUtils.safeGetParcelable(bundle, CustomTabsService.KEY_URL);
        } catch (ClassCastException e) {
            continue;
        }
        String url = checkAndConvertUri(uri);
        if (url != null) {
            warmupManager.maybePreconnectUrlAndSubResources(profile, url);
            atLeastOneUrl = true;
        }
    }
    return atLeastOneUrl;
}
 
Example 3
Source File: CustomTabsConnection.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private boolean preconnectUrls(List<Bundle> likelyBundles) {
    boolean atLeastOneUrl = false;
    if (likelyBundles == null) return false;
    WarmupManager warmupManager = WarmupManager.getInstance();
    Profile profile = Profile.getLastUsedProfile();
    for (Bundle bundle : likelyBundles) {
        Uri uri;
        try {
            uri = IntentUtils.safeGetParcelable(bundle, CustomTabsService.KEY_URL);
        } catch (ClassCastException e) {
            continue;
        }
        String url = checkAndConvertUri(uri);
        if (url != null) {
            warmupManager.maybePreconnectUrlAndSubResources(profile, url);
            atLeastOneUrl = true;
        }
    }
    return atLeastOneUrl;
}
 
Example 4
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 5
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();
}