OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/net/load_timing_observer.h" | 5 #include "chrome/browser/net/load_timing_observer.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "net/base/load_flags.h" | 9 #include "net/base/load_flags.h" |
10 #include "net/url_request/url_request_netlog_params.h" | 10 #include "net/url_request/url_request_netlog_params.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 } | 41 } |
42 | 42 |
43 } | 43 } |
44 | 44 |
45 LoadTimingObserver::URLRequestRecord::URLRequestRecord() | 45 LoadTimingObserver::URLRequestRecord::URLRequestRecord() |
46 : connect_job_id(net::NetLog::Source::kInvalidId), | 46 : connect_job_id(net::NetLog::Source::kInvalidId), |
47 socket_log_id(net::NetLog::Source::kInvalidId), | 47 socket_log_id(net::NetLog::Source::kInvalidId), |
48 socket_reused(false) { | 48 socket_reused(false) { |
49 } | 49 } |
50 | 50 |
51 LoadTimingObserver::LoadTimingObserver() { | 51 LoadTimingObserver::LoadTimingObserver() |
| 52 : last_connect_job_id_(net::NetLog::Source::kInvalidId) { |
52 } | 53 } |
53 | 54 |
54 LoadTimingObserver::~LoadTimingObserver() { | 55 LoadTimingObserver::~LoadTimingObserver() { |
55 } | 56 } |
56 | 57 |
57 LoadTimingObserver::URLRequestRecord* | 58 LoadTimingObserver::URLRequestRecord* |
58 LoadTimingObserver::GetURLRequestRecord(uint32 source_id) { | 59 LoadTimingObserver::GetURLRequestRecord(uint32 source_id) { |
59 URLRequestToRecordMap::iterator it = url_request_to_record_.find(source_id); | 60 URLRequestToRecordMap::iterator it = url_request_to_record_.find(source_id); |
60 if (it != url_request_to_record_.end()) | 61 if (it != url_request_to_record_.end()) |
61 return &it->second; | 62 return &it->second; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 url_request_to_record_.erase(source.id); | 112 url_request_to_record_.erase(source.id); |
112 return; | 113 return; |
113 } | 114 } |
114 | 115 |
115 URLRequestRecord* record = GetURLRequestRecord(source.id); | 116 URLRequestRecord* record = GetURLRequestRecord(source.id); |
116 if (!record) | 117 if (!record) |
117 return; | 118 return; |
118 | 119 |
119 ResourceLoaderBridge::LoadTimingInfo& timing = record->timing; | 120 ResourceLoaderBridge::LoadTimingInfo& timing = record->timing; |
120 | 121 |
121 switch(type) { | 122 switch (type) { |
122 case net::NetLog::TYPE_PROXY_SERVICE: | 123 case net::NetLog::TYPE_PROXY_SERVICE: |
123 if (is_begin) | 124 if (is_begin) |
124 timing.proxy_start = TimeTicksToOffset(time, record); | 125 timing.proxy_start = TimeTicksToOffset(time, record); |
125 else if (is_end) | 126 else if (is_end) |
126 timing.proxy_end = TimeTicksToOffset(time, record); | 127 timing.proxy_end = TimeTicksToOffset(time, record); |
127 break; | 128 break; |
128 case net::NetLog::TYPE_SOCKET_POOL: | 129 case net::NetLog::TYPE_SOCKET_POOL: |
129 if (is_begin) | 130 if (is_begin) |
130 timing.connect_start = TimeTicksToOffset(time, record); | 131 timing.connect_start = TimeTicksToOffset(time, record); |
131 else if (is_end) | 132 else if (is_end) |
132 timing.connect_end = TimeTicksToOffset(time, record); | 133 timing.connect_end = TimeTicksToOffset(time, record); |
133 break; | 134 break; |
134 case net::NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB: | 135 case net::NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB: |
135 { | 136 { |
136 uint32 connect_job_id = static_cast<net::NetLogSourceParameter*>( | 137 uint32 connect_job_id = static_cast<net::NetLogSourceParameter*>( |
137 params)->value().id; | 138 params)->value().id; |
138 ConnectJobToRecordMap::iterator it = | 139 if (last_connect_job_id_ == connect_job_id && |
139 connect_job_to_record_.find(connect_job_id); | 140 !last_connect_job_record_.dns_start.is_null()) { |
140 if (it != connect_job_to_record_.end() && | 141 timing.dns_start = |
141 !it->second.dns_start.is_null()) { | 142 TimeTicksToOffset(last_connect_job_record_.dns_start, record); |
142 timing.dns_start = TimeTicksToOffset(it->second.dns_start, record); | 143 timing.dns_end = |
143 timing.dns_end = TimeTicksToOffset(it->second.dns_end, record); | 144 TimeTicksToOffset(last_connect_job_record_.dns_end, record); |
144 } | 145 } |
145 } | 146 } |
146 break; | 147 break; |
147 case net::NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET: | 148 case net::NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET: |
148 record->socket_reused = true; | 149 record->socket_reused = true; |
149 break; | 150 break; |
150 case net::NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET: | 151 case net::NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET: |
151 record->socket_log_id = static_cast<net::NetLogSourceParameter*>( | 152 record->socket_log_id = static_cast<net::NetLogSourceParameter*>( |
152 params)->value().id; | 153 params)->value().id; |
153 if (!record->socket_reused) { | 154 if (!record->socket_reused) { |
154 SocketToRecordMap::iterator it = | 155 SocketToRecordMap::iterator it = |
155 socket_to_record_.find(record->socket_log_id); | 156 socket_to_record_.find(record->socket_log_id); |
156 if (it != socket_to_record_.end() && !it->second.ssl_start.is_null()) { | 157 if (it != socket_to_record_.end() && !it->second.ssl_start.is_null()) { |
157 timing.ssl_start = TimeTicksToOffset(it->second.ssl_start, record); | 158 timing.ssl_start = TimeTicksToOffset(it->second.ssl_start, record); |
158 timing.ssl_end = TimeTicksToOffset(it->second.ssl_end, record); | 159 timing.ssl_end = TimeTicksToOffset(it->second.ssl_end, record); |
159 } | 160 } |
160 } | 161 } |
161 break; | 162 break; |
162 case net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST: | 163 case net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST: |
163 case net::NetLog::TYPE_SPDY_TRANSACTION_SEND_REQUEST: | 164 case net::NetLog::TYPE_SPDY_TRANSACTION_SEND_REQUEST: |
164 if (is_begin) | 165 if (is_begin) |
165 timing.send_start = TimeTicksToOffset(time, record); | 166 timing.send_start = TimeTicksToOffset(time, record); |
166 else if (is_end) | 167 else if (is_end) |
167 timing.send_end = TimeTicksToOffset(time, record); | 168 timing.send_end = TimeTicksToOffset(time, record); |
168 break; | 169 break; |
(...skipping 25 matching lines...) Expand all Loading... |
194 // something went wrong. Should not happen. | 195 // something went wrong. Should not happen. |
195 if (connect_job_to_record_.size() > kMaxNumEntries) { | 196 if (connect_job_to_record_.size() > kMaxNumEntries) { |
196 LOG(WARNING) << "The load timing observer connect job count has grown " | 197 LOG(WARNING) << "The load timing observer connect job count has grown " |
197 "larger than expected, resetting"; | 198 "larger than expected, resetting"; |
198 connect_job_to_record_.clear(); | 199 connect_job_to_record_.clear(); |
199 } | 200 } |
200 | 201 |
201 connect_job_to_record_.insert( | 202 connect_job_to_record_.insert( |
202 std::make_pair(source.id, ConnectJobRecord())); | 203 std::make_pair(source.id, ConnectJobRecord())); |
203 } else if (is_end) { | 204 } else if (is_end) { |
204 connect_job_to_record_.erase(source.id); | 205 ConnectJobToRecordMap::iterator it = |
| 206 connect_job_to_record_.find(source.id); |
| 207 if (it != connect_job_to_record_.end()) { |
| 208 last_connect_job_id_ = it->first; |
| 209 last_connect_job_record_ = it->second; |
| 210 connect_job_to_record_.erase(it); |
| 211 } |
205 } | 212 } |
206 } else if (type == net::NetLog::TYPE_HOST_RESOLVER_IMPL) { | 213 } else if (type == net::NetLog::TYPE_HOST_RESOLVER_IMPL) { |
207 ConnectJobToRecordMap::iterator it = | 214 ConnectJobToRecordMap::iterator it = |
208 connect_job_to_record_.find(source.id); | 215 connect_job_to_record_.find(source.id); |
209 if (it != connect_job_to_record_.end()) { | 216 if (it != connect_job_to_record_.end()) { |
210 if (is_begin) | 217 if (is_begin) |
211 it->second.dns_start = time; | 218 it->second.dns_start = time; |
212 else if (is_end) | 219 else if (is_end) |
213 it->second.dns_end = time; | 220 it->second.dns_end = time; |
214 } | 221 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 if (it == socket_to_record_.end()) | 253 if (it == socket_to_record_.end()) |
247 return; | 254 return; |
248 | 255 |
249 if (type == net::NetLog::TYPE_SSL_CONNECT) { | 256 if (type == net::NetLog::TYPE_SSL_CONNECT) { |
250 if (is_begin) | 257 if (is_begin) |
251 it->second.ssl_start = time; | 258 it->second.ssl_start = time; |
252 else if (is_end) | 259 else if (is_end) |
253 it->second.ssl_end = time; | 260 it->second.ssl_end = time; |
254 } | 261 } |
255 } | 262 } |
OLD | NEW |