load_timing_info.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef NET_BASE_LOAD_TIMING_INFO_H_ 6#define NET_BASE_LOAD_TIMING_INFO_H_ 7 8#include "base/basictypes.h" 9#include "base/time.h" 10#include "net/base/net_export.h" 11 12namespace net { 13 14// Structure containing timing information for a request. 15// It addresses the needs of 16// http://groups.google.com/group/http-archive-specification/web/har-1-1-spec, 17// http://dev.w3.org/2006/webapi/WebTiming/, and 18// http://www.w3.org/TR/resource-timing/. 19// 20// All events that do not apply to a request have null times. For non-HTTP 21// requests, all times other than the request_start times are null. 22// 23// Requests with connection errors generally only have request start times as 24// well, since they never received an established socket. 25// 26// The general order for events is: 27// request_start 28// proxy_start 29// proxy_end 30// *dns_start 31// *dns_end 32// *connect_start 33// *ssl_start 34// *ssl_end 35// *connect_end 36// send_start 37// send_end 38// receive_headers_end 39// 40// Those times without an asterisk are computed by the URLRequest, or by objects 41// it directly creates and always owns. Those with an asterisk are computed 42// by the connection attempt itself. Since the connection attempt may be 43// started before a URLRequest, the starred times may occur before, during, or 44// after the request_start and proxy events. 45// 46// DNS and SSL times are both times for the host, not the proxy, so DNS times 47// when using proxies are null, and only requests to HTTPS hosts (Not proxies) 48// have SSL times. One exception to this is when a proxy server itself returns 49// a redirect response. In this case, the connect times treat the proxy as the 50// host. The send and receive times will all be null, however. 51// See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. 52// TODO(mmenke): Is this worth fixing? 53struct NET_EXPORT LoadTimingInfo { 54 // Contains the LoadTimingInfo events related to establishing a connection. 55 // These are all set by ConnectJobs. 56 struct NET_EXPORT_PRIVATE ConnectTiming { 57 ConnectTiming(); 58 ~ConnectTiming(); 59 60 // The time spent looking up the host's DNS address. Null for requests that 61 // used proxies to look up the DNS address. Also null for SOCKS4 proxies, 62 // since the DNS address is only looked up after the connection is 63 // established, which results in unexpected event ordering. 64 // TODO(mmenke): The SOCKS4 event ordering could be refactored to allow 65 // these times to be non-null. 66 base::TimeTicks dns_start; 67 base::TimeTicks dns_end; 68 69 // The time spent establishing the connection. Connect time includes proxy 70 // connect times (Though not proxy_resolve times), DNS lookup times, time 71 // spent waiting in certain queues, TCP, and SSL time. 72 // TODO(mmenke): For proxies, this includes time spent blocking on higher 73 // level socket pools. Fix this. 74 // TODO(mmenke): Retried connections to the same server should apparently 75 // be included in this time. Consider supporting that. 76 // Since the network stack has multiple notions of a "retry", 77 // handled at different levels, this may not be worth 78 // worrying about - backup jobs, reused socket failure, 79 // multiple round authentication. 80 base::TimeTicks connect_start; 81 base::TimeTicks connect_end; 82 83 // The time when the SSL handshake started / completed. For non-HTTPS 84 // requests these are null. These times are only for the SSL connection to 85 // the final destination server, not an SSL/SPDY proxy. 86 base::TimeTicks ssl_start; 87 base::TimeTicks ssl_end; 88 }; 89 90 LoadTimingInfo(); 91 ~LoadTimingInfo(); 92 93 // True if the socket was reused. When true, DNS, connect, and SSL times 94 // will all be null. When false, those times may be null, too, for non-HTTP 95 // requests, or when they don't apply to a request. 96 // 97 // For requests that are sent again after an AUTH challenge, this will be true 98 // if the original socket is reused, and false if a new socket is used. 99 // Responding to a proxy AUTH challenge is never considered to be reusing a 100 // socket, since a connection to the host wasn't established when the 101 // challenge was received. 102 bool socket_reused; 103 104 // Unique socket ID, can be used to identify requests served by the same 105 // socket. For connections tunnelled over SPDY proxies, this is the ID of 106 // the virtual connection (The SpdyProxyClientSocket), not the ID of the 107 // actual socket. HTTP requests handled by the SPDY proxy itself all use the 108 // actual socket's ID. 109 // 110 // 0 when there is no socket associated with the request, or it's not an HTTP 111 // request. 112 uint32 socket_log_id; 113 114 // Start time as a base::Time, so times can be coverted into actual times. 115 // Other times are recorded as TimeTicks so they are not affected by clock 116 // changes. 117 base::Time request_start_time; 118 119 base::TimeTicks request_start; 120 121 // The time spent determing which proxy to use. Null when there is no PAC. 122 base::TimeTicks proxy_resolve_start; 123 base::TimeTicks proxy_resolve_end; 124 125 ConnectTiming connect_timing; 126 127 // The time that sending HTTP request started / ended. 128 base::TimeTicks send_start; 129 base::TimeTicks send_end; 130 131 // The time at which the end of the HTTP headers were received. 132 base::TimeTicks receive_headers_end; 133}; 134 135} // namespace net 136 137#endif // NET_BASE_LOAD_TIMING_INFO_H_ 138