| OLD | NEW |
| 1 # Quick Start Guide to Using Cronet | 1 # Quick Start Guide to Using Cronet |
| 2 Cronet is the networking stack of Chromium put into a library for use on | 2 Cronet is the networking stack of Chromium put into a library for use on |
| 3 mobile. This is the same networking stack that is used in the Chrome browser | 3 mobile. This is the same networking stack that is used in the Chrome browser |
| 4 by over a billion people. It offers an easy-to-use, high performance, | 4 by over a billion people. It offers an easy-to-use, high performance, |
| 5 standards-compliant, and secure way to perform HTTP requests. Cronet has support | 5 standards-compliant, and secure way to perform HTTP requests. Cronet has support |
| 6 for both Android and iOS. On Android, Cronet offers its own Java asynchronous | 6 for both Android and iOS. On Android, Cronet offers its own Java asynchronous |
| 7 API as well as support for the [java.net.HttpURLConnection] API. | 7 API as well as support for the [java.net.HttpURLConnection] API. |
| 8 This document gives a brief introduction to using these two Java APIs. | 8 This document gives a brief introduction to using these two Java APIs. |
| 9 | 9 |
| 10 ### Basics | 10 ### Basics |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // not resolved, connection to server refused, etc. | 65 // not resolved, connection to server refused, etc. |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 Make a request like this: | 69 Make a request like this: |
| 70 | 70 |
| 71 CronetEngine.Builder engineBuilder = new CronetEngine.Builder(getContext()); | 71 CronetEngine.Builder engineBuilder = new CronetEngine.Builder(getContext()); |
| 72 CronetEngine engine = engineBuilder.build(); | 72 CronetEngine engine = engineBuilder.build(); |
| 73 Executor executor = Executors.newSingleThreadExecutor(); | 73 Executor executor = Executors.newSingleThreadExecutor(); |
| 74 MyCallback callback = new MyCallback(); | 74 MyCallback callback = new MyCallback(); |
| 75 UrlRequest.Builder requestBuilder = new UrlRequest.Builder( | 75 UrlRequest.Builder requestBuilder = engine.newUrlRequestBuilder( |
| 76 "https://www.example.com", callback, executor, engine); | 76 "https://www.example.com", callback, executor); |
| 77 UrlRequest request = requestBuilder.build(); | 77 UrlRequest request = requestBuilder.build(); |
| 78 request.start(); | 78 request.start(); |
| 79 | 79 |
| 80 In the above example, `MyCallback` extends `UrlRequest.Callback`. The request | 80 In the above example, `MyCallback` extends `UrlRequest.Callback`. The request |
| 81 is started asynchronously. When the response is ready (fully or partially), and | 81 is started asynchronously. When the response is ready (fully or partially), and |
| 82 in the event of failures or redirects, `callback`'s methods will be invoked on | 82 in the event of failures or redirects, `callback`'s methods will be invoked on |
| 83 `executor`'s thread to inform the client of the request state and/or response | 83 `executor`'s thread to inform the client of the request state and/or response |
| 84 information. | 84 information. |
| 85 | 85 |
| 86 ### Downloading Data | 86 ### Downloading Data |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 see {@link org.chromium.net.CronetEngine#createURLStreamHandlerFactory} for | 160 see {@link org.chromium.net.CronetEngine#createURLStreamHandlerFactory} for |
| 161 more information). | 161 more information). |
| 162 You can configure Cronet and control caching through the | 162 You can configure Cronet and control caching through the |
| 163 `CronetEngine.Builder` instance, `engineBuilder` | 163 `CronetEngine.Builder` instance, `engineBuilder` |
| 164 (See [Configuring Cronet](#configuring-cronet) section), before you build the | 164 (See [Configuring Cronet](#configuring-cronet) section), before you build the |
| 165 `CronetEngine` and then call `CronetEngine.createURLStreamHandlerFactory()`. | 165 `CronetEngine` and then call `CronetEngine.createURLStreamHandlerFactory()`. |
| 166 | 166 |
| 167 [ByteBuffer]: https://developer.android.com/reference/java/nio/ByteBuffer.html | 167 [ByteBuffer]: https://developer.android.com/reference/java/nio/ByteBuffer.html |
| 168 [chrome://net-internals#import]: chrome://net-internals#import | 168 [chrome://net-internals#import]: chrome://net-internals#import |
| 169 [java.net.HttpURLConnection]: https://developer.android.com/reference/java/net/H
ttpURLConnection.html | 169 [java.net.HttpURLConnection]: https://developer.android.com/reference/java/net/H
ttpURLConnection.html |
| OLD | NEW |