Discover Cronet

Chiara Chiappini
Aug 22, 2016 · 5 min read

Networking today

Chromium Network stack

Other Cronet features

HTTP/2 and QUIC support

HTTP/2

QUIC

Usage

CronetEngine

engineBuilder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_IN_MEMORY, 100 * 1024)
engineBuilder.setStoragePath(storagePathString);
engineBuilder.enableHttpCache(CronetEngine.Builder.HttpCache.DISK,
1024 * 1024);
 engineBuilder.enableHttp2(true)
engineBuilder.enableQuic(true)
engineBuilder.addQuicHint(...)
cronetBuilder.setStoragePath(...)cronetBuilder.enableHttpCache(
CronetEngine.Builder.HTTP_CACHE_DISK_NO_HTTP, 1024 * 1024)

UrlRequest

onRedirectReceived(...)onResponseStarted(...)onReadCompleted(...)onSucceeded(...)
// Create an executor to execute the requestExecutor executor = Executors.newSingleThreadExecutor();UrlRequest.Callback callback = new SimpleUrlRequestCallback(holder.imageViewCronet);UrlRequest.Builder builder = new UrlRequest.Builder(ImageRepository.getImage(position), callback, executor, cronetEngine);// Start the requestbuilder.build().start();

Priorities

builder.setPriority(UrlRequest.Builder.REQUEST_PRIORITY_HIGHEST);

HTTPURLConnection

HttpURLConnection connection = (HttpURLConnection)engine.openConnection(url);URL.setURLStreamHandlerFactory(engine.createURLStreamHandlerFactory());

Debugging

Library

Conclusion

Sources

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade