Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Life of a URLRequest | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:30
Suggestion: There's enough in this doc that a tabl
mmenke
2015/07/13 19:57:23
It doesn't look to me like markdown has a way to a
Randy Smith (Not in Mondays)
2015/07/14 16:35:50
Yeah, if there's no way to do it automatically, it
| |
| 2 | |
| 3 This document is intended as an overview of the core layers of the network | |
| 4 stack, their basic responsibilities, how they fit together, and where some of | |
| 5 the pain points are, without going into too much detail. Though it touches a | |
| 6 bit on child processes and the content/loader stack, the focus is on net/ | |
| 7 itself. | |
| 8 | |
| 9 It's particularly targeted at people new to the Chrome network stack, but | |
| 10 should also be useful for team members who may be experts at some parts of the | |
| 11 stack, but are largely unfamiliar with other components. It starts by walking | |
| 12 through how a basic request issued by Blink works its way through the network | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:30
I'd suggest scrubbing mention of "Blink" from this
mmenke
2015/07/13 19:57:24
Done.
| |
| 13 stack, and then moves on to discuss how various components plug in. | |
| 14 | |
| 15 | |
| 16 # Anatomy of the Network Stack | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:31
From my perspective, *the* most important object i
mmenke
2015/07/13 19:57:24
I've added a paragraph about it (After I discuss t
Randy Smith (Not in Mondays)
2015/07/14 16:35:50
What you have looks good to me, though I'd also ad
mmenke
2015/07/14 16:47:47
Done.
| |
| 17 | |
| 18 The main top-level network stack object is the URLRequextContext. The context | |
| 19 has non-owning pointers to everything needed to create and issue a URLRequest. | |
| 20 The context must outlive all requests that use it. Creating a context is a | |
| 21 rather complicated process, and it's recommended that most embedders use | |
| 22 URLRequestContextBuilder to do this. Chrome itself has several request | |
| 23 contexts that the network stack team owns: | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:31
Random idea: I think the breakdown of the differen
xunjieli
2015/07/13 18:23:57
I will vote to keep this breakdown of URLRequestCo
mmenke
2015/07/13 19:57:24
Acknowledged.
mmenke
2015/07/13 19:57:24
I'll keep it as-is for now, though happy to talk f
| |
| 24 | |
| 25 * The proxy URLRequestContext, owned by the IOThread and used to get PAC | |
| 26 scripts while avoiding re-entrancy. | |
| 27 * The system URLRequestContext, also owned by the IOThread, used for requests | |
| 28 that aren't associated with a profile. | |
| 29 * Each profile, including incognito profiles, has a number of URLRequestContexts | |
| 30 that are created as needed: | |
| 31 * The main URLRequestContext is mostly created in ProfileIOData, though it | |
| 32 has a couple components that are passed in from content's StoragePartition | |
| 33 code. Several other components are shared with the system URLRequestContext, | |
| 34 like the HostResolver. | |
| 35 * Each non-incognito profile also has a media request context, which uses a | |
| 36 different on-disk cache than the main request context. This prevents a | |
| 37 single huge media file from evicting everything else in the cache. | |
| 38 * On desktop platforms, each profile has a request context for extensions. | |
| 39 * Each profile has two contexts for each isolated app (One for media, one | |
| 40 for everything else). | |
| 41 | |
| 42 The HttpNetworkSession is another major network stack object. It has | |
| 43 pointers to the network stack objects that more directly deal with sockets, and | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:31
nit: owning of non-owning pointers? Construction/
mmenke
2015/07/13 19:57:24
I've updated it to be clearer here (Owns what I ca
| |
| 44 their dependendencies. Its main objects are the HttpStreamFactory, the socket | |
| 45 pools, and the SPDY/QUIC session pools. | |
| 46 | |
| 47 This document does not mention either of these objects much, but at layers | |
| 48 above the HttpStreamFactory, objects often grab their dependencies from the | |
| 49 URLRequestContext, while the HttpStreamFactory and layers below it generally | |
| 50 get their dependencies from the HttpNetworkSession. | |
| 51 | |
| 52 | |
| 53 # How many "Delegates"? | |
| 54 | |
| 55 The network stack informs the embedder of important events for a request using | |
| 56 two main interfaces: the URLRequest::Delegate interface and the NetworkDelegate | |
| 57 interface. | |
| 58 | |
| 59 The URLRequest::Delegate interface consists of small set of callbacks needed to | |
|
xunjieli
2015/07/13 18:23:57
nit: Do we need an article here? s/"small set"/"a
mmenke
2015/07/13 19:57:23
Done.
| |
| 60 let the embedder drive a request forward. URLRequest::Delegates generally own | |
| 61 the URLRequest. | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:30
This mention adds to the weirdness of not having y
mmenke
2015/07/13 19:57:23
Acknowledged.
| |
| 62 | |
| 63 The NetworkDelegate is a single object shared by all requests, and includes | |
| 64 callbacks corresponding to most of the URLRequest::Delegate's callbacks, as well | |
| 65 as an assortment of other methods. The NetworkDelegate is optional, while the | |
| 66 URLRequest::Delegate is not. | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:31
Worthwhile indicating how the NetworkDelegate is s
mmenke
2015/07/13 19:57:24
Done.
| |
| 67 | |
| 68 | |
| 69 # Overview | |
| 70 | |
| 71 A request for data is normally dispatched from a child to the browser process. | |
| 72 There a URLRequest is created to drive the request. A protocol-specific job | |
| 73 (e.g. HTTP, data, file) is attached to the request. That job first checks the | |
| 74 cache, and then creates a network connection, if necessary, to actually fetch | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:30
nit, suggestion: "network connection" -> "network
mmenke
2015/07/13 19:57:24
Done.
| |
| 75 the data. That connection object interacts with network socket pools to | |
| 76 potentially re-use sockets; the socket pools create and connect a socket if | |
| 77 there is no appropriate existing socket. Once that socket exists, the HTTP | |
| 78 request is dispatched, the response read and parsed, and the result returned | |
| 79 back up the stack and sent over to the child process. | |
| 80 | |
| 81 Of course, it's not quite that simple :-}. | |
| 82 | |
| 83 Consider a simple request issued by a child process. Suppose it's an HTTP | |
| 84 request, the response is uncompressed, and no matching entry in the cache. | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:30
I like this method of indicating the conditional a
Randy Smith (Not in Mondays)
2015/07/13 15:39:31
nit, suggestion: For completeness, this sentence s
mmenke
2015/07/13 19:57:23
Done.
mmenke
2015/07/13 19:57:23
Acknowledged.
| |
| 85 | |
| 86 ### Request starts in a child process | |
| 87 | |
| 88 * ResourceDispatcher creates an IPCResourceLoaderBridge. | |
| 89 * The IPCResourceLoaderBridge asks ResourceDispatcher to start the request. | |
| 90 * ResourceDispatcher sends an IPC to the ResourceDispatcherHost in the | |
| 91 browser process. | |
| 92 | |
| 93 ### ResourceDispatcherHost sets up the request in the Browser Process | |
|
xunjieli
2015/07/13 18:23:57
nit: browser process should be lowercase.
mmenke
2015/07/13 19:57:24
Done.
| |
| 94 | |
| 95 * ResourceDispatcherHost uses the URLRequestContext to create the URLRequest. | |
| 96 * ResourceDispatcherHost creates a ResourceLoader and a chain of | |
| 97 ResourceHandlers to manage the URLRequest. | |
| 98 * ResourceLoader starts the URLRequest. | |
| 99 | |
| 100 ### Check the cache, request an HttpStream | |
| 101 | |
| 102 * The URLRequest asks the URLRequestJobFactory to create a URLRequestJob, | |
| 103 usually a URLRequestHttpJob for HTTP/HTTPS requests. | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:30
nit, suggestion: Given last sentence of overview,
mmenke
2015/07/13 19:57:24
Done.
| |
| 104 * The URLRequestHttpJob asks the HttpCache to create an HttpTransaction | |
| 105 (always an HttpCache::Transaction). | |
| 106 * The HttpCache::Transaction sees there's no cache entry for the request, | |
| 107 and creates an HttpNetworkTransaction. | |
| 108 * The HttpNetworkTransaction calls into the HttpStreamFactory to request an | |
| 109 HttpStream. | |
| 110 | |
| 111 ### Create an HttpStream | |
| 112 * HttpStreamFactory creates an HttpStreamFactoryImpl::Job. | |
| 113 * HttpStreamFactoryImpl::Job calls into the TransportClientSocketPool to | |
| 114 populate an ClientSocketHandle. | |
| 115 * TransportClientSocketPool has no idle sockets, so it creates a | |
| 116 TransportConnectJob and starts it. | |
| 117 * TransportConnectJob creates a StreamSocket and establishes a connection. | |
| 118 * TransportClientSocketPool puts the StreamSocket in the ClientSocketHandle, | |
| 119 and calls into HttpStreamFactoryImpl::Job. | |
| 120 * HttpStreamFactoryImpl::Job creates an HttpBasicStream, which takes | |
| 121 ownership of the ClientSocketHandle. | |
| 122 * It returns the HttpBasicStream to the HttpNetworkTransaction. | |
| 123 | |
| 124 ### Send request and read the response headers | |
| 125 | |
| 126 * HttpNetworkTransaction gives the request headers to the HttpBasicStream, | |
| 127 and tells it to start the request. | |
| 128 * HttpBasicStream sends the request, and waits for the response. | |
| 129 * The HttpBasicStream sends the response headers back to the | |
| 130 HttpNetworkTransaction. | |
| 131 * The response headers are sent up to the URLRequest, to the ResourceLoader, | |
| 132 through the ResourceHandler chain. | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:30
nit: ", *and* through the ResourceHandler chain".
mmenke
2015/07/13 19:57:23
Done.
| |
| 133 * They're then sent by the the last ResourceHandler in the chain (the | |
| 134 AsyncResourceHandler) to the ResourceDispatcher, with an IPC. | |
| 135 | |
| 136 ### Response body is read | |
| 137 | |
| 138 * AsyncResourceHandler allocates a 512k ring buffer of shared memory to read | |
| 139 the body of the request. | |
| 140 * AsyncResourceHandler tells the ResourceLoader to read the response body to | |
| 141 the buffer, 32kB at a time. | |
| 142 * AsyncResourceHandler informs the ResourceDispatcher of each read using IPCs. | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:30
nit, suggestion: "using cross-process IPCs" (redun
mmenke
2015/07/13 19:57:23
Done.
| |
| 143 * ResourceDispatcher tells the AsyncResourceHandler when it's done with the | |
| 144 data with each read, so it knows when parts of the buffer can be reused. | |
| 145 | |
| 146 ### URLRequest is destroyed | |
| 147 | |
| 148 * When complete, the RDH deletes the ResourceLoader, which deletes the | |
| 149 URLRequest and the ResourceHandler chain. | |
| 150 * During destruction, the HttpNetworkTransaction determines if the socket is | |
| 151 reusable, and if so, tells the HttpBasicStream to return it to the socket pool. | |
| 152 | |
| 153 # Details | |
| 154 | |
| 155 Continuing with a "simple" URLRequest, here's a bit more detail on how things | |
| 156 work. | |
| 157 | |
| 158 ### Request starts in a child process | |
| 159 | |
| 160 Chrome has a single browser process, which handles network requests and tab | |
| 161 management, among other things, and multiple child processes, which are | |
| 162 generally sandboxed so can't send out network requests directly. There are | |
| 163 multiple types of child processes (renderer, GPU, plugin, etc). The renderer | |
| 164 processes are the ones that layout webpages and run HTML. | |
| 165 | |
| 166 Each child process has at most one ResourceDispatcher, which is responsible for | |
| 167 all URL request-related communication with the browser process. When something | |
| 168 in another process needs to issue a resource request, it calls into the | |
| 169 ResourceDispatcher, which returns an IPCResourceLoaderBridge to the caller. | |
| 170 The caller uses the bridge to start a request. When started, the | |
| 171 ResourceDispatcher assigns the request a per-renderer ID, and then sends the | |
| 172 ID, along with all information needed to issue the request, to the | |
| 173 ResourceDispatcherHost in the browser process. | |
| 174 | |
| 175 ### ResourceDispatcherHost sets up the request in the browser process | |
| 176 | |
| 177 The ResourceDispatcherHost (RDH), along with most of the network stack, lives | |
| 178 on the browser process's IO thread. The browser process only has one RDH, | |
| 179 which is responsible for handling all network requests initiated by | |
| 180 ResourceDispatchers in all child processes, not just renderer process. | |
| 181 Requests initiated in the browser process don't go through the RDH, with some | |
| 182 exceptions. | |
| 183 | |
| 184 When the RDH sees the request, it calls into a URLRequestContext to create the | |
| 185 URLRequest. The URLRequestContext has pointers to all the network stack | |
| 186 objects needed to issue the request over the network, such as the cache, cookie | |
| 187 store, and host resolver. The RDH then creates a chain of ResourceHandlers | |
| 188 each of which can monitor/modify/delay/cancel the URLRequest and the | |
| 189 information it returns. The only one of these I'll talk about here is the | |
| 190 AsyncResourceHandler, which is the last ResourceHandler in the chain. The RDH | |
| 191 then creates a ResourceLoader (Which is the URLRequest::Delegate), passes | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:30
nit: lower-case "w" on "Which".
mmenke
2015/07/13 19:57:24
Done.
| |
| 192 ownership of the URLRequest and the ResourceHandler chain to it, and then starts | |
| 193 the ResourceLoader. | |
| 194 | |
| 195 The ResourceLoader checks that none of the ResourceHandlers want to cancel, | |
| 196 modify, or delay the request, and then finally starts the URLRequest. | |
| 197 | |
| 198 ### Check the cache, request an HttpStream | |
| 199 | |
| 200 The URLRequest then calls into the URLRequestJobFactory to create a | |
| 201 URLRequestJob and then starts it. In the case of an HTTP or HTTPS request, this | |
| 202 will be a URLRequestHttpJob. The URLRequestHttpJob attaches cookies to the | |
| 203 request, if needed. | |
| 204 | |
| 205 The URLRequestHttpJob calls into the HttpCache to create an | |
| 206 HttpCache::Transaction. If there's no matching entry in the cache, the | |
| 207 HttpCache::Transaction will just call into the HttpNetworkLayer to create an | |
| 208 HttpNetworkTransaction, and transparently wrap it. The HttpNetworkTransaction | |
| 209 then calls into the HttpStreamFactory to request an HttpStream to the server. | |
| 210 | |
| 211 ### Create an HttpStream | |
| 212 | |
| 213 The HttpStreamFactoryImpl::Job creates a ClientSocketHandle to hold a socket, | |
| 214 once connected, and passes it into the ClientSocketPoolManager. The | |
| 215 ClientSocketPoolManager assembles the TransportSocketParams needed to | |
| 216 establish the connection and creates a group name ("host:port") used to | |
| 217 identify sockets that can be used interchangeably. | |
| 218 | |
| 219 The ClientSocketPoolManager directs the request to the | |
| 220 TransportClientSocketPool, since there's no proxy and it's an HTTP request. The | |
| 221 request is forwarded to the pool's ClientSocketPoolBase<TransportSocketParams>'s | |
| 222 ClientSocketPoolBaseHelper. If there isn't already an idle connection, and there | |
| 223 are available socket slots, the ClientSocketPoolBaseHelper will create a new | |
| 224 TransportConnectJob using the aforementioned params object. This Job will do the | |
| 225 actual DNS lookup by calling into the HostResolverImpl, if needed, and then | |
| 226 finally establishes a connection. | |
| 227 | |
| 228 Once the socket is connected, ownership of the socket is passed to the | |
| 229 ClientSocketHandle. The HttpStreamFactoryImpl::Job is then informed the | |
| 230 connection attempt succeeded, and it then creates an HttpBasicStream, which | |
| 231 takes ownership of the ClientSocketHandle. It then passes ownership of the | |
| 232 HttpBasicStream back to the HttpNetworkTransaction. | |
| 233 | |
| 234 ### Send request and read the response headers | |
| 235 | |
| 236 The HttpNetworkTransaction passes the request headers to the HttpBasicStream, | |
| 237 which uses an HttpStreamParser to (finally) format the request headers and body | |
| 238 (if present) and send them to the server. | |
| 239 | |
| 240 The HttpStreamParser waits to receive the response and then parses the HTTP/1.x | |
| 241 response headers, and then passes them up through both the | |
| 242 HttpNetworkTransaction and HttpCache::Transaction to the URLRequestHttpJob. The | |
| 243 URLRequestHttpJob saves any cookies, if needed, and then passes the headers up | |
| 244 to the URLRequest and on to the ResourceLoader. | |
| 245 | |
| 246 The ResourceLoader passes them through the chain of ResourceHandlers, and then | |
| 247 they make their way to the AsyncResourceHandler. The AsyncResourceHandler uses | |
| 248 the renderer process ID ("child ID") to figure out which process the request | |
| 249 was associated with, and then sends the headers along with the request ID to | |
| 250 that process's ResourceDispatcher. The ResourceDispatcher uses the ID to | |
| 251 figure out which IPCResourceLoaderBridge the headers should be sent to, which | |
| 252 sends them on to whatever created the IPCResourceLoaderBridge in the first | |
| 253 place. | |
| 254 | |
| 255 ### Response body is read | |
| 256 | |
| 257 Without waiting to hear back from the ResourceDispatcher, the ResourceLoader | |
| 258 tells its ResourceHandler chain to allocate memory to receive the response | |
| 259 body. The AsyncResourceHandler creates a 512KB ring buffer of shared memory, | |
| 260 and then passes the first 32KB of it to the ResourceLoader for the first read. | |
| 261 The ResourceLoader then passes a 32KB body read request down through the | |
| 262 URLRequest all the way down to the HttpResponseParser. Once some data is read, | |
| 263 possibly less than 32KB, the number of bytes read makes its way back to the | |
| 264 AsyncResourceHandler, which passes the shared memory buffer and the offset and | |
| 265 amount of data read to the renderer process. | |
| 266 | |
| 267 The AsyncResourceHandler relies on ACKs from the renderer to prevent it from | |
| 268 overwriting data that the renderer has yet to consume. This process repeats | |
| 269 until the response body is completely read. | |
| 270 | |
| 271 ### URLRequest is destroyed | |
| 272 | |
| 273 When the URLRequest informs the ResourceLoader it's complete, the | |
| 274 ResourceLoader tells the ResourceHandlers, and the AsyncResourceHandler tells | |
| 275 the ResourceDispatcher the request is complete. The RDH then deletes | |
| 276 ResourceLoader, which deletes the URLRequest and ResourceHandler chain. | |
| 277 | |
| 278 When the HttpNetworkTransaction is being torn down, it figures out if the | |
| 279 socket is reusable. If not, it tells the HttpBasicStream to close the socket. | |
| 280 Either way, the ClientSocketHandle returns the socket is then returned to the | |
| 281 socket pool, either for reuse or so the socket pool knows it has another free | |
| 282 socket slot. | |
| 283 | |
| 284 | |
| 285 # Additional Topics | |
| 286 | |
| 287 ## HTTP Cache | |
| 288 | |
| 289 The HttpCache::Transaction sits between the URLRequestHttpJob and the | |
| 290 HttpNetworkTransaction, and implements the HttpTransaction interface, just like | |
| 291 the HttpNetworkTransaction. The HttpCache::Transaction checks if a request can | |
| 292 be served out of the cache. If a request needs to be revalidated, it handles | |
| 293 sending a 204 revalidation request over the network. It may also break a range | |
| 294 request into multiple cached and non-cached contiguous chunks, and may issue | |
| 295 multiple network requests for a single range URLRequest. | |
| 296 | |
| 297 One important detail is that it has a read/write lock for each URL. The lock | |
| 298 technically allows multiple reads at once, but since an HttpCache::Transaction | |
| 299 always grabs the lock for writing and reading before downgrading it to a read | |
| 300 only lock, all requests for the same URL are effectively done serially. Blink | |
| 301 merges requests for the same URL in many cases, which mitigates this problem to | |
| 302 some extent. | |
| 303 | |
| 304 The HttpCache::Transaction uses one of three disk_cache::Backends to actually | |
| 305 store the cache's index and files: The in memory backend, the blockfile cache | |
| 306 backend, and the simple cache backend. The first is used in incognito. The | |
| 307 latter two are both stored on disk, and are used on different platforms. | |
| 308 | |
| 309 ## Cancellation | |
| 310 | |
| 311 A request can be cancelled by the child process, by any of the | |
| 312 ResourceHandlers in the chain, or by the ResourceDispatcherHost itself. When the | |
| 313 cancellation message reaches the URLRequest, it passes on the fact it's been | |
| 314 cancelled back to the ResourceLoader, which then sends the message down the | |
| 315 ResourceHandler chain. | |
| 316 | |
| 317 When an HttpNetworkTransaction for a cancelled request is being torn down, it | |
| 318 figures out if the socket the HttpStream owns can potentially be reused, based | |
| 319 on the protocol (HTTP / SPDY / QUIC) and any received headers. If the socket | |
| 320 potentially can be reused, an HttpResponseBodyDrainer is created to try and | |
| 321 read any remaining body bytes of the HttpStream, if any, before returning the | |
| 322 socket to the SocketPool. If this takes too long, or there's an error, the | |
| 323 socket is closed instead. Since this all happens at the layer below the cache, | |
| 324 any drained bytes are not written to the cache, and as far as the cache layer is | |
| 325 concerned, it only has a partial response. | |
| 326 | |
| 327 ## Redirects | |
| 328 | |
| 329 The URLRequestHttpJob checks if headers indicate a redirect when it receives | |
| 330 them from the next layer down (Typically the HttpCache::Transaction). If they | |
| 331 indicate a redirect, it tells the cache the response is complete, ignoring the | |
| 332 body, so the cache only has the headers. The cache then treats it as a complete | |
| 333 entry, even if the headers indicated there will be a body. | |
| 334 | |
| 335 The URLRequestHttpJob then checks if the URLRequest if the request should be | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:31
"checks if"?
mmenke
2015/07/13 19:57:24
Done.
| |
| 336 followed. First it checks the scheme. Then it informs the ResourceLoader | |
| 337 about the redirect, to give it a chance to cancel the request. The information | |
| 338 makes its way down through the AsyncResourceHandler to the ResourceDispatcher | |
| 339 and on into Blink, which checks if the redirect should be followed. | |
| 340 | |
| 341 The ResourceDispatcher then asynchronously sends a message back to either | |
| 342 follow the redirect or cancel the request. In either case, the old | |
| 343 HttpTransaction is destroyed, and the HttpNetworkTransaction attempts to drain | |
| 344 the socket for reuse, just as in the cancellation case. If the redirect is | |
| 345 followed, the URLRequest calls into the URLRequestJobFactory to create a new | |
| 346 URLRequestJob, and then starts it. | |
| 347 | |
| 348 ## Filters (gzip, SDCH, etc) | |
| 349 | |
| 350 When the URLRequestHttpJob receives headers, it sends a list of all | |
| 351 Content-Encoding values to Filter::Factory, which creates a (possibly empty) | |
| 352 chain of filters. As body bytes are received, they're passed through the | |
| 353 filters at the URLRequestJob layer and the decoded bytes are passed back to the | |
| 354 embedder. | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:31
You haven't really used the language of "embedder"
mmenke
2015/07/13 19:57:23
Done (Used "URLRequest::Delegate" instead)
| |
| 355 | |
| 356 Since this is done above the cache layer, the cache stores the responses prior | |
| 357 to decompression. As a result, if files aren't compressed over the wire, they | |
| 358 aren't compressed in the cache, either. This behavior can also create problems | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:31
nit, suggestion: Remove "also"; I don't think this
mmenke
2015/07/13 19:57:24
Done (Though the fact the cache isn't compressed d
Randy Smith (Not in Mondays)
2015/07/14 16:35:50
It totally is, and if you want to modify this sect
mmenke
2015/07/14 16:47:47
Left it as-is.
| |
| 359 when responses are SDCH compressed, as a dictionary and a cached file encoded | |
| 360 using it may have different lifetimes. | |
| 361 | |
| 362 ## Socket Pools | |
| 363 | |
| 364 The ClientSocketPoolManager is responsible for assembling the parameters needed | |
| 365 to connect a socket, and then sending the request to the right socket pool. | |
| 366 Each socket request sent to a socket pool comes with a socket params object, a | |
| 367 ClientSocketHandle, and a "group name". The params object contains all the | |
| 368 information a ConnectJob needs to create a connection of a given type, and | |
| 369 different types of socket pools take different params types. The | |
| 370 ClientSocketHandle will take temporary ownership of the socket, once connected | |
| 371 socket, and return it to the socket pool when done. All connections with the | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:31
I don't understand what you mean by ", once connec
mmenke
2015/07/13 19:57:24
Oops...Should be "once connected". Reworded sligh
| |
| 372 same group name in the same pool can be used to service the same connection | |
| 373 request, so it consists of host, port, protocol, and whether "privacy mode" is | |
| 374 used for requests using the socket or not. | |
| 375 | |
| 376 All socket pool classes derive from the ClientSocketPoolBase<SocketParamType>. | |
| 377 The ClientSocketPoolBase handles managing sockets - which requests to create | |
| 378 sockets for, which requests get connected sockets first, which sockets belong | |
| 379 to which groups, connection limits per group, keeping track of and closing idle | |
| 380 sockets, etc. Each ClientSocketPoolBase subclass has its own ConnectJob type, | |
| 381 which establishes a connection using the socket params, before the pool hands | |
| 382 out the connected socket. | |
| 383 | |
| 384 ## Socket Pool Layering | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:31
nit, suggestion: Subsection of Socket Pools?
mmenke
2015/07/13 19:57:23
Done.
| |
| 385 | |
| 386 Some socket pools are layered on top other socket pools. This is done when a | |
| 387 "socket" in a higher layer needs to establish a connection in a lower level | |
| 388 pool and then take ownership of it as part of its connection process. See later | |
| 389 sections for examples. There are a couple additional complexities here. | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:31
I'd include a parenthetical example right here--I
mmenke
2015/07/13 19:57:24
Done.
| |
| 390 | |
| 391 From the perspective of the lower layer pool, all of its sockets that a higher | |
| 392 layer pools owns are actively in use, even when the higher layer pool considers | |
| 393 them idle. As a result, when a lower layer pool is at its connection limit and | |
| 394 needs to make a new connection, it will ask any higher layer pools pools to | |
| 395 close an idle connection if they have one, so it can make a new connection. | |
| 396 | |
| 397 Since sockets in the higher layer pool are also in a group in the lower layer | |
| 398 pool, have their own distinct group name. This is needed so that, for instance, | |
|
xunjieli
2015/07/13 18:23:57
nit: The second part of the first sentence does no
mmenke
2015/07/13 19:57:24
Done.
| |
| 399 SSL and HTTP connections won't be group together in the TcpClientSocketPool, | |
|
xunjieli
2015/07/13 18:23:57
nit: grouped.
mmenke
2015/07/13 19:57:24
Done.
| |
| 400 which the SSLClientSocketPool sits on top of. | |
| 401 | |
| 402 ## SSL | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:30
nit, suggestion: Subsection of Socket Pool Layerin
mmenke
2015/07/13 19:57:23
Done.
| |
| 403 | |
| 404 When an SSL connection is needed, the ClientSocketPoolManager assembles the | |
| 405 parameters needed both to connect the TCP socket and establish an SSL | |
| 406 connection. It then passes them to the SSLClientSocketPool, which creates | |
| 407 an SSLConnectJob using them. The SSLConnectJob's first step is to call into the | |
| 408 TransportSocketPool to establish a TCP connection. | |
| 409 | |
| 410 Once a connection is established by the lower layered pool, the SSLConnectJob | |
| 411 then starts SSL negotiation. Once that's done, the SSL socket is passed back to | |
| 412 the HttpStreamFactoryImpl::Job that initiated the request, and things proceed | |
| 413 just as with HTTP. When complete, the socket is returned to the | |
| 414 SSLClientSocketPool. | |
| 415 | |
| 416 ## Proxies | |
| 417 | |
| 418 The first step the HttpStreamFactoryImpl::Job performs, just before calling | |
| 419 into the ClientSocketPoolManager to create a socket, is to check with the | |
| 420 ProxyService to see if a proxy is needed for the URL it's been given. The | |
| 421 ClientSocketPoolManager then uses this information to find the correct proxy | |
| 422 socket pool to send the request to. | |
| 423 | |
| 424 TODO(mmenke): Discuss proxy configurations, WPAD, tracing proxy resolver. | |
| 425 | |
| 426 ## Proxy Socket Pools | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:30
Suggestion: I'd combine this section with the prev
mmenke
2015/07/13 19:57:24
I've merged the sections, and flipped the order (M
| |
| 427 | |
| 428 Each SOCKS or HTTP proxy has its own completely independent set of socket | |
| 429 pools. They have their own exclusive TransportSocketPool, their own protocol- | |
| 430 specific pool above it, and their own SSLSocketPool above that. HTTPS proxies | |
| 431 also have a second SSLSocketPool between the the HttpProxyClientSocketPool and | |
| 432 the TransportSocketPool, since they can talk SSL to both the proxy and the | |
| 433 destination server, layered on top of each other. | |
| 434 | |
| 435 ## SPDY | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:31
nit, suggestion: Subsection of SSL? Alternatively
mmenke
2015/07/13 19:57:24
I've combined QUIC and SPDY into a section (And sw
| |
| 436 | |
| 437 Once an SSL connection is established, the HttpStreamFactoryImpl::Job checks if | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:31
This suggests that SSL connection establishment ha
mmenke
2015/07/13 19:57:24
I don't think you're not reading it quite right -
| |
| 438 SPDY was negotiated over the socket. If so, it creates a SpdySession using the | |
| 439 socket, and a SpdyHttpStream. The SpdyHttpStream will be passed to the | |
| 440 HttpNetworkTransaction, which drives the stream as usual. | |
| 441 | |
| 442 The SpdySession will be shared with other Jobs connecting to the same server, | |
| 443 and future Jobs will find the SpdySession before they try to create a | |
| 444 connection. HttpServerProperties also tracks which servers supported SPDY when | |
| 445 we last talked to them. We only try to establish a single connection to servers | |
| 446 we think speak SPDY when multiple HttpStreamFactoryImpl::Jobs are trying to | |
| 447 connect to them, to avoid wasting resources. | |
| 448 | |
| 449 ## QUIC | |
| 450 | |
| 451 HttpServerProperties also tracks which servers have advertised QUIC support in | |
| 452 the past. If a server has advertised QUIC support, a second | |
| 453 HttpStreamFactoryImpl::Job will be created for SPDY, and will be raced against | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:31
Did you mean QUIC in this sentence?
mmenke
2015/07/13 19:57:23
Done.
| |
| 454 the one for HTTP/HTTPS connection. Whichever connects first will be used. | |
| 455 Existing QUIC sessions will be reused if available. | |
| 456 | |
| 457 TODO(mmenke): Discuss SPDY/QUIC proxies? | |
|
Randy Smith (Not in Mondays)
2015/07/13 15:39:31
FWIW, I don't think that's necessary in this docum
mmenke
2015/07/13 19:57:23
Removed.
| |
| 458 | |
| 459 ## Prioritization | |
| 460 | |
| 461 URLRequests are assigned a priority on creation. It only comes into play in | |
| 462 a couple places: | |
| 463 | |
| 464 * The ResourceScheduler lives outside net/, and in some cases, delays starting | |
| 465 low priority requests on a per-tab basis. | |
| 466 * DNS lookups are initiated based on the highest priority request for a lookup. | |
| 467 * Socket pools hand out and create sockets based on prioritization. However, | |
| 468 when a socket becomes idle, it will be assigned to the highest priority request | |
| 469 for the server its connected to, even if there's a higher priority request to | |
| 470 another server that's waiting on a free socket slot. | |
| 471 * SPDY and QUIC both support sending priorities over-the-wire. | |
| 472 | |
| 473 At the socket pool layer, sockets are only assigned to socket requests once the | |
| 474 socket is connected and SSL is negotiated, if needed. This is done so that if | |
| 475 a higher priority request for a group reaches the socket pool before a | |
| 476 connection is established, the first usable connection goes to the highest | |
| 477 priority socket request. | |
| 478 | |
| 479 ## Non-HTTP schemes | |
| 480 | |
| 481 The URLRequestJobFactory has a ProtocolHander for each supported scheme. | |
| 482 Non-HTTP URLRequests have their own ProtocolHandlers. Some are implemented in | |
| 483 net/, (like FTP, file, and data, though blink handles some data URLs | |
| 484 internally), and others are implemented in content/ or chrome (like blob, | |
| 485 chrome, and chrome-extension). | |
| OLD | NEW |