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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 64 |
65 void LoadTimingObserver::OnAddEntry(net::NetLog::EventType type, | 65 void LoadTimingObserver::OnAddEntry(net::NetLog::EventType type, |
66 const base::TimeTicks& time, | 66 const base::TimeTicks& time, |
67 const net::NetLog::Source& source, | 67 const net::NetLog::Source& source, |
68 net::NetLog::EventPhase phase, | 68 net::NetLog::EventPhase phase, |
69 net::NetLog::EventParameters* params) { | 69 net::NetLog::EventParameters* params) { |
70 if (source.type == net::NetLog::SOURCE_URL_REQUEST) | 70 if (source.type == net::NetLog::SOURCE_URL_REQUEST) |
71 OnAddURLRequestEntry(type, time, source, phase, params); | 71 OnAddURLRequestEntry(type, time, source, phase, params); |
72 else if (source.type == net::NetLog::SOURCE_CONNECT_JOB) | 72 else if (source.type == net::NetLog::SOURCE_CONNECT_JOB) |
73 OnAddConnectJobEntry(type, time, source, phase, params); | 73 OnAddConnectJobEntry(type, time, source, phase, params); |
| 74 else if (source.type == net::NetLog::SOURCE_SOCKET) |
| 75 OnAddSocketEntry(type, time, source, phase, params); |
74 } | 76 } |
75 | 77 |
76 void LoadTimingObserver::OnAddURLRequestEntry( | 78 void LoadTimingObserver::OnAddURLRequestEntry( |
77 net::NetLog::EventType type, | 79 net::NetLog::EventType type, |
78 const base::TimeTicks& time, | 80 const base::TimeTicks& time, |
79 const net::NetLog::Source& source, | 81 const net::NetLog::Source& source, |
80 net::NetLog::EventPhase phase, | 82 net::NetLog::EventPhase phase, |
81 net::NetLog::EventParameters* params) { | 83 net::NetLog::EventParameters* params) { |
82 bool is_begin = phase == net::NetLog::PHASE_BEGIN; | 84 bool is_begin = phase == net::NetLog::PHASE_BEGIN; |
83 bool is_end = phase == net::NetLog::PHASE_END; | 85 bool is_end = phase == net::NetLog::PHASE_END; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 timing.dns_end = TimeTicksToOffset(it->second.dns_end, record); | 143 timing.dns_end = TimeTicksToOffset(it->second.dns_end, record); |
142 } | 144 } |
143 } | 145 } |
144 break; | 146 break; |
145 case net::NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET: | 147 case net::NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET: |
146 record->socket_reused = true; | 148 record->socket_reused = true; |
147 break; | 149 break; |
148 case net::NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET: | 150 case net::NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET: |
149 record->socket_log_id = static_cast<net::NetLogSourceParameter*>( | 151 record->socket_log_id = static_cast<net::NetLogSourceParameter*>( |
150 params)->value().id; | 152 params)->value().id; |
| 153 if (!record->socket_reused) { |
| 154 SocketToRecordMap::iterator it = |
| 155 socket_to_record_.find(record->socket_log_id); |
| 156 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_end = TimeTicksToOffset(it->second.ssl_end, record); |
| 159 } |
| 160 } |
151 break; | 161 break; |
152 case net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST: | 162 case net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST: |
153 case net::NetLog::TYPE_SPDY_TRANSACTION_SEND_REQUEST: | 163 case net::NetLog::TYPE_SPDY_TRANSACTION_SEND_REQUEST: |
154 if (is_begin) | 164 if (is_begin) |
155 timing.send_start = TimeTicksToOffset(time, record); | 165 timing.send_start = TimeTicksToOffset(time, record); |
156 else if (is_end) | 166 else if (is_end) |
157 timing.send_end = TimeTicksToOffset(time, record); | 167 timing.send_end = TimeTicksToOffset(time, record); |
158 break; | 168 break; |
159 case net::NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS: | 169 case net::NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS: |
160 case net::NetLog::TYPE_SPDY_TRANSACTION_READ_HEADERS: | 170 case net::NetLog::TYPE_SPDY_TRANSACTION_READ_HEADERS: |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 ConnectJobToRecordMap::iterator it = | 207 ConnectJobToRecordMap::iterator it = |
198 connect_job_to_record_.find(source.id); | 208 connect_job_to_record_.find(source.id); |
199 if (it != connect_job_to_record_.end()) { | 209 if (it != connect_job_to_record_.end()) { |
200 if (is_begin) | 210 if (is_begin) |
201 it->second.dns_start = time; | 211 it->second.dns_start = time; |
202 else if (is_end) | 212 else if (is_end) |
203 it->second.dns_end = time; | 213 it->second.dns_end = time; |
204 } | 214 } |
205 } | 215 } |
206 } | 216 } |
| 217 |
| 218 void LoadTimingObserver::OnAddSocketEntry( |
| 219 net::NetLog::EventType type, |
| 220 const base::TimeTicks& time, |
| 221 const net::NetLog::Source& source, |
| 222 net::NetLog::EventPhase phase, |
| 223 net::NetLog::EventParameters* params) { |
| 224 bool is_begin = phase == net::NetLog::PHASE_BEGIN; |
| 225 bool is_end = phase == net::NetLog::PHASE_END; |
| 226 |
| 227 // Manage record lifetime based on the SOCKET_ALIVE entry. |
| 228 if (type == net::NetLog::TYPE_SOCKET_ALIVE) { |
| 229 if (is_begin) { |
| 230 // Prevents us from passively growing the memory memory unbounded in case |
| 231 // something went wrong. Should not happen. |
| 232 if (socket_to_record_.size() > kMaxNumEntries) { |
| 233 LOG(WARNING) << "The load timing observer socket count has grown " |
| 234 "larger than expected, resetting"; |
| 235 socket_to_record_.clear(); |
| 236 } |
| 237 |
| 238 socket_to_record_.insert( |
| 239 std::make_pair(source.id, SocketRecord())); |
| 240 } else if (is_end) { |
| 241 socket_to_record_.erase(source.id); |
| 242 } |
| 243 return; |
| 244 } |
| 245 SocketToRecordMap::iterator it = socket_to_record_.find(source.id); |
| 246 if (it == socket_to_record_.end()) |
| 247 return; |
| 248 |
| 249 if (type == net::NetLog::TYPE_SSL_CONNECT) { |
| 250 if (is_begin) |
| 251 it->second.ssl_start = time; |
| 252 else if (is_end) |
| 253 it->second.ssl_end = time; |
| 254 } |
| 255 } |
OLD | NEW |