| 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); | |
| 76 } | 74 } |
| 77 | 75 |
| 78 void LoadTimingObserver::OnAddURLRequestEntry( | 76 void LoadTimingObserver::OnAddURLRequestEntry( |
| 79 net::NetLog::EventType type, | 77 net::NetLog::EventType type, |
| 80 const base::TimeTicks& time, | 78 const base::TimeTicks& time, |
| 81 const net::NetLog::Source& source, | 79 const net::NetLog::Source& source, |
| 82 net::NetLog::EventPhase phase, | 80 net::NetLog::EventPhase phase, |
| 83 net::NetLog::EventParameters* params) { | 81 net::NetLog::EventParameters* params) { |
| 84 bool is_begin = phase == net::NetLog::PHASE_BEGIN; | 82 bool is_begin = phase == net::NetLog::PHASE_BEGIN; |
| 85 bool is_end = phase == net::NetLog::PHASE_END; | 83 bool is_end = phase == net::NetLog::PHASE_END; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 timing.dns_end = TimeTicksToOffset(it->second.dns_end, record); | 141 timing.dns_end = TimeTicksToOffset(it->second.dns_end, record); |
| 144 } | 142 } |
| 145 } | 143 } |
| 146 break; | 144 break; |
| 147 case net::NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET: | 145 case net::NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET: |
| 148 record->socket_reused = true; | 146 record->socket_reused = true; |
| 149 break; | 147 break; |
| 150 case net::NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET: | 148 case net::NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET: |
| 151 record->socket_log_id = static_cast<net::NetLogSourceParameter*>( | 149 record->socket_log_id = static_cast<net::NetLogSourceParameter*>( |
| 152 params)->value().id; | 150 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 } | |
| 161 break; | 151 break; |
| 162 case net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST: | 152 case net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST: |
| 163 case net::NetLog::TYPE_SPDY_TRANSACTION_SEND_REQUEST: | 153 case net::NetLog::TYPE_SPDY_TRANSACTION_SEND_REQUEST: |
| 164 if (is_begin) | 154 if (is_begin) |
| 165 timing.send_start = TimeTicksToOffset(time, record); | 155 timing.send_start = TimeTicksToOffset(time, record); |
| 166 else if (is_end) | 156 else if (is_end) |
| 167 timing.send_end = TimeTicksToOffset(time, record); | 157 timing.send_end = TimeTicksToOffset(time, record); |
| 168 break; | 158 break; |
| 169 case net::NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS: | 159 case net::NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS: |
| 170 case net::NetLog::TYPE_SPDY_TRANSACTION_READ_HEADERS: | 160 case net::NetLog::TYPE_SPDY_TRANSACTION_READ_HEADERS: |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 ConnectJobToRecordMap::iterator it = | 197 ConnectJobToRecordMap::iterator it = |
| 208 connect_job_to_record_.find(source.id); | 198 connect_job_to_record_.find(source.id); |
| 209 if (it != connect_job_to_record_.end()) { | 199 if (it != connect_job_to_record_.end()) { |
| 210 if (is_begin) | 200 if (is_begin) |
| 211 it->second.dns_start = time; | 201 it->second.dns_start = time; |
| 212 else if (is_end) | 202 else if (is_end) |
| 213 it->second.dns_end = time; | 203 it->second.dns_end = time; |
| 214 } | 204 } |
| 215 } | 205 } |
| 216 } | 206 } |
| 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 |