Skip to content

Instantly share code, notes, and snippets.

@pasko
Last active November 22, 2016 14:45
Show Gist options
  • Save pasko/25c5024176faf07477983e2da7022ebb to your computer and use it in GitHub Desktop.
Save pasko/25c5024176faf07477983e2da7022ebb to your computer and use it in GitHub Desktop.
ThreadUtils.postOnUiThread(new Runnable() {
@Override
public void run() {
try {
TraceEvent.begin("CustomTabsConnection.warmupInternal");
// Warmup is done in several steps, some of them can happen only once.
// Step 1: Only once: Initialize the browser.
if (!initialized) initializeBrowser(mApplication);
// Step 2: Can happen more than once: Create a spare renderer. It takes time,
// other threads and processes, so start it sooner rather than later.
if (mayCreateSpareWebContents && mSpeculation == null
&& !SysUtils.isLowEndDevice()) {
WarmupManager.getInstance().createSpareWebContents();
}
if (!initialized) {
// Step 3: Only once: Create the ResourcePrefetchPredictor. It triggers work
// on other threads, start early.
Profile profile = Profile.getLastUsedProfile();
new ResourcePrefetchPredictor(profile).startInitialization();
// Step 4: Only once: Access the shared preferences for the first time. The
// throttling database uses shared preferences, that can cause a StrictMode
// violation on the first access. Make sure that this access is not in
// mayLauchUrl.
RequestThrottler.getForUid(mApplication, uid);
}
} finally {
TraceEvent.end("CustomTabsConnection.warmupInternal");
}
mWarmupHasBeenFinished.set(true);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment