| OLD | NEW |
| 1 # Life of a URLRequest | 1 # Life of a URLRequest |
| 2 | 2 |
| 3 This document is intended as an overview of the core layers of the network | 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 | 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 | 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/ | 6 bit on child processes and the content/loader stack, the focus is on net/ |
| 7 itself. | 7 itself. |
| 8 | 8 |
| 9 It's particularly targeted at people new to the Chrome network stack, but | 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 | 10 should also be useful for team members who may be experts at some parts of the |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 request, the response is uncompressed, no matching entry in the cache, and there | 96 request, the response is uncompressed, no matching entry in the cache, and there |
| 97 are no idle sockets connected to the server in the socket pool. | 97 are no idle sockets connected to the server in the socket pool. |
| 98 | 98 |
| 99 Continuing with a "simple" URLRequest, here's a bit more detail on how things | 99 Continuing with a "simple" URLRequest, here's a bit more detail on how things |
| 100 work. | 100 work. |
| 101 | 101 |
| 102 ### Request starts in a child process | 102 ### Request starts in a child process |
| 103 | 103 |
| 104 Summary: | 104 Summary: |
| 105 | 105 |
| 106 * ResourceDispatcher creates an IPCResourceLoaderBridge. | 106 * Network consumers in child processes interact with ResourceDispatcher to |
| 107 * The IPCResourceLoaderBridge asks ResourceDispatcher to start the request. | 107 start/cancel/read/write network requests. |
| 108 * ResourceDispatcher sends an IPC to the ResourceDispatcherHost in the | 108 * ResourceDispatcher acts as a proxy to the browser process (where the |
| 109 browser process. | 109 networking is actually carried out). |
| 110 | 110 |
| 111 Chrome has a single browser process, which handles network requests and tab | 111 Chrome has a single browser process, which handles network requests and tab |
| 112 management, among other things, and multiple child processes, which are | 112 management, among other things, and multiple child processes, which are |
| 113 generally sandboxed so can't send out network requests directly. There are | 113 generally sandboxed so can't send out network requests directly. There are |
| 114 multiple types of child processes (renderer, GPU, plugin, etc). The renderer | 114 multiple types of child processes (renderer, GPU, plugin, etc). The renderer |
| 115 processes are the ones that layout webpages and run HTML. | 115 processes are the ones that layout webpages and run HTML. |
| 116 | 116 |
| 117 Each child process has at most one ResourceDispatcher, which is responsible for | 117 Each child process has at most one ResourceDispatcher, which is responsible for |
| 118 all URL request-related communication with the browser process. When something | 118 all URL request-related communication with the browser process. When something |
| 119 in another process needs to issue a resource request, it calls into the | 119 in another process needs to issue a resource request, it calls into the |
| 120 ResourceDispatcher, which returns an IPCResourceLoaderBridge to the caller. | 120 ResourceDispatcher to start either a synchronous or asynchronous request. |
| 121 The caller uses the bridge to start a request. When started, the | 121 |
| 122 ResourceDispatcher assigns the request a per-renderer ID, and then sends the | 122 ResourceDispatcher assigns the request a per-renderer ID, and then sends the |
| 123 ID, along with all information needed to issue the request, to the | 123 ID, along with all information needed to issue the request, to the |
| 124 ResourceDispatcherHost in the browser process. | 124 ResourceDispatcherHost in the browser process. |
| 125 | 125 |
| 126 When starting asynchronous requests, callers provide a RequestPeer which acts |
| 127 much like a URLRequest::Delegate does in the browser process (receives |
| 128 notifications of progress/completion for the network request). |
| 129 |
| 126 ### ResourceDispatcherHost sets up the request in the browser process | 130 ### ResourceDispatcherHost sets up the request in the browser process |
| 127 | 131 |
| 128 Summary: | 132 Summary: |
| 129 | 133 |
| 130 * ResourceDispatcherHost uses the URLRequestContext to create the URLRequest. | 134 * ResourceDispatcherHost uses the URLRequestContext to create the URLRequest. |
| 131 * ResourceDispatcherHost creates a ResourceLoader and a chain of | 135 * ResourceDispatcherHost creates a ResourceLoader and a chain of |
| 132 ResourceHandlers to manage the URLRequest. | 136 ResourceHandlers to manage the URLRequest. |
| 133 * ResourceLoader starts the URLRequest. | 137 * ResourceLoader starts the URLRequest. |
| 134 | 138 |
| 135 The ResourceDispatcherHost (RDH), along with most of the network stack, lives | 139 The ResourceDispatcherHost (RDH), along with most of the network stack, lives |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 | 238 |
| 235 The HttpStreamParser waits to receive the response and then parses the HTTP/1.x | 239 The HttpStreamParser waits to receive the response and then parses the HTTP/1.x |
| 236 response headers, and then passes them up through both the | 240 response headers, and then passes them up through both the |
| 237 HttpNetworkTransaction and HttpCache::Transaction to the URLRequestHttpJob. The | 241 HttpNetworkTransaction and HttpCache::Transaction to the URLRequestHttpJob. The |
| 238 URLRequestHttpJob saves any cookies, if needed, and then passes the headers up | 242 URLRequestHttpJob saves any cookies, if needed, and then passes the headers up |
| 239 to the URLRequest and on to the ResourceLoader. | 243 to the URLRequest and on to the ResourceLoader. |
| 240 | 244 |
| 241 The ResourceLoader passes them through the chain of ResourceHandlers, and then | 245 The ResourceLoader passes them through the chain of ResourceHandlers, and then |
| 242 they make their way to the AsyncResourceHandler. The AsyncResourceHandler uses | 246 they make their way to the AsyncResourceHandler. The AsyncResourceHandler uses |
| 243 the renderer process ID ("child ID") to figure out which process the request | 247 the renderer process ID ("child ID") to figure out which process the request |
| 244 was associated with, and then sends the headers along with the request ID to | 248 originated from, and then sends the headers along with the request ID to |
| 245 that process's ResourceDispatcher. The ResourceDispatcher uses the ID to | 249 that process's ResourceDispatcher. The ResourceDispatcher then forwards the |
| 246 figure out which IPCResourceLoaderBridge the headers should be sent to, which | 250 response to the RequestPeer that was attached to the request. |
| 247 sends them on to whatever created the IPCResourceLoaderBridge in the first | |
| 248 place. | |
| 249 | 251 |
| 250 ### Response body is read | 252 ### Response body is read |
| 251 | 253 |
| 252 Summary: | 254 Summary: |
| 253 | 255 |
| 254 * AsyncResourceHandler allocates a 512k ring buffer of shared memory to read | 256 * AsyncResourceHandler allocates a 512k ring buffer of shared memory to read |
| 255 the body of the request. | 257 the body of the request. |
| 256 * AsyncResourceHandler tells the ResourceLoader to read the response body to | 258 * AsyncResourceHandler tells the ResourceLoader to read the response body to |
| 257 the buffer, 32kB at a time. | 259 the buffer, 32kB at a time. |
| 258 * AsyncResourceHandler informs the ResourceDispatcher of each read using | 260 * AsyncResourceHandler informs the ResourceDispatcher of each read using |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 connection is established, the first usable connection goes to the highest | 505 connection is established, the first usable connection goes to the highest |
| 504 priority socket request. | 506 priority socket request. |
| 505 | 507 |
| 506 ## Non-HTTP Schemes | 508 ## Non-HTTP Schemes |
| 507 | 509 |
| 508 The URLRequestJobFactory has a ProtocolHander for each supported scheme. | 510 The URLRequestJobFactory has a ProtocolHander for each supported scheme. |
| 509 Non-HTTP URLRequests have their own ProtocolHandlers. Some are implemented in | 511 Non-HTTP URLRequests have their own ProtocolHandlers. Some are implemented in |
| 510 net/, (like FTP, file, and data, though the renderer handles some data URLs | 512 net/, (like FTP, file, and data, though the renderer handles some data URLs |
| 511 internally), and others are implemented in content/ or chrome (like blob, | 513 internally), and others are implemented in content/ or chrome (like blob, |
| 512 chrome, and chrome-extension). | 514 chrome, and chrome-extension). |
| OLD | NEW |