Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(317)

Side by Side Diff: chrome/browser/net/load_timing_observer.cc

Issue 10399083: Make NetLog take in callbacks that return Values (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix net-internals Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/time.h" 7 #include "base/time.h"
8 #include "chrome/browser/net/chrome_net_log.h" 8 #include "chrome/browser/net/chrome_net_log.h"
9 #include "content/public/common/resource_response.h" 9 #include "content/public/common/resource_response.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 LoadTimingObserver::URLRequestRecord* 76 LoadTimingObserver::URLRequestRecord*
77 LoadTimingObserver::GetURLRequestRecord(uint32 source_id) { 77 LoadTimingObserver::GetURLRequestRecord(uint32 source_id) {
78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
79 79
80 URLRequestToRecordMap::iterator it = url_request_to_record_.find(source_id); 80 URLRequestToRecordMap::iterator it = url_request_to_record_.find(source_id);
81 if (it != url_request_to_record_.end()) 81 if (it != url_request_to_record_.end())
82 return &it->second; 82 return &it->second;
83 return NULL; 83 return NULL;
84 } 84 }
85 85
86 void LoadTimingObserver::OnAddEntry(net::NetLog::EventType type, 86 void LoadTimingObserver::OnAddEntry(const net::NetLog::Entry& entry) {
87 const base::TimeTicks& time,
88 const net::NetLog::Source& source,
89 net::NetLog::EventPhase phase,
90 net::NetLog::EventParameters* params) {
91 // The events that the Observer is interested in only occur on the IO thread. 87 // The events that the Observer is interested in only occur on the IO thread.
92 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) 88 if (!BrowserThread::CurrentlyOn(BrowserThread::IO))
93 return; 89 return;
94 if (source.type == net::NetLog::SOURCE_URL_REQUEST) 90 if (entry.source().type == net::NetLog::SOURCE_URL_REQUEST)
95 OnAddURLRequestEntry(type, time, source, phase, params); 91 OnAddURLRequestEntry(entry);
96 else if (source.type == net::NetLog::SOURCE_HTTP_STREAM_JOB) 92 else if (entry.source().type == net::NetLog::SOURCE_HTTP_STREAM_JOB)
97 OnAddHTTPStreamJobEntry(type, time, source, phase, params); 93 OnAddHTTPStreamJobEntry(entry);
98 else if (source.type == net::NetLog::SOURCE_CONNECT_JOB) 94 else if (entry.source().type == net::NetLog::SOURCE_CONNECT_JOB)
99 OnAddConnectJobEntry(type, time, source, phase, params); 95 OnAddConnectJobEntry(entry);
100 else if (source.type == net::NetLog::SOURCE_SOCKET) 96 else if (entry.source().type == net::NetLog::SOURCE_SOCKET)
101 OnAddSocketEntry(type, time, source, phase, params); 97 OnAddSocketEntry(entry);
102 } 98 }
103 99
104 // static 100 // static
105 void LoadTimingObserver::PopulateTimingInfo( 101 void LoadTimingObserver::PopulateTimingInfo(
106 net::URLRequest* request, 102 net::URLRequest* request,
107 content::ResourceResponse* response) { 103 content::ResourceResponse* response) {
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
109 if (!(request->load_flags() & net::LOAD_ENABLE_LOAD_TIMING)) 105 if (!(request->load_flags() & net::LOAD_ENABLE_LOAD_TIMING))
110 return; 106 return;
111 107
112 ChromeNetLog* chrome_net_log = static_cast<ChromeNetLog*>( 108 ChromeNetLog* chrome_net_log = static_cast<ChromeNetLog*>(
113 request->net_log().net_log()); 109 request->net_log().net_log());
114 if (chrome_net_log == NULL) 110 if (chrome_net_log == NULL)
115 return; 111 return;
116 112
117 uint32 source_id = request->net_log().source().id; 113 uint32 source_id = request->net_log().source().id;
118 LoadTimingObserver* observer = chrome_net_log->load_timing_observer(); 114 LoadTimingObserver* observer = chrome_net_log->load_timing_observer();
119 LoadTimingObserver::URLRequestRecord* record = 115 LoadTimingObserver::URLRequestRecord* record =
120 observer->GetURLRequestRecord(source_id); 116 observer->GetURLRequestRecord(source_id);
121 if (record) { 117 if (record) {
122 response->connection_id = record->socket_log_id; 118 response->connection_id = record->socket_log_id;
123 response->connection_reused = record->socket_reused; 119 response->connection_reused = record->socket_reused;
124 response->load_timing = record->timing; 120 response->load_timing = record->timing;
125 } 121 }
126 } 122 }
127 123
128 void LoadTimingObserver::OnAddURLRequestEntry( 124 void LoadTimingObserver::OnAddURLRequestEntry(const net::NetLog::Entry& entry) {
129 net::NetLog::EventType type,
130 const base::TimeTicks& time,
131 const net::NetLog::Source& source,
132 net::NetLog::EventPhase phase,
133 net::NetLog::EventParameters* params) {
134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
135 126
136 bool is_begin = phase == net::NetLog::PHASE_BEGIN; 127 bool is_begin = entry.phase() == net::NetLog::PHASE_BEGIN;
137 bool is_end = phase == net::NetLog::PHASE_END; 128 bool is_end = entry.phase() == net::NetLog::PHASE_END;
138 129
139 if (type == net::NetLog::TYPE_URL_REQUEST_START_JOB) { 130 if (entry.type() == net::NetLog::TYPE_URL_REQUEST_START_JOB) {
140 if (is_begin) { 131 if (is_begin) {
141 // Only record timing for entries with corresponding flag. 132 // Only record timing for entries with corresponding flag.
142 int load_flags = 133 int load_flags;
143 static_cast<net::URLRequestStartEventParameters*>(params)-> 134 scoped_ptr<Value> event_parameters(entry.ParametersToValue());
144 load_flags(); 135 if (!net::StartEventLoadFlagsFromEventParameters(
136 event_parameters.get(),
137 &load_flags)) {
138 NOTREACHED();
139 return;
140 }
141
145 if (!(load_flags & net::LOAD_ENABLE_LOAD_TIMING)) 142 if (!(load_flags & net::LOAD_ENABLE_LOAD_TIMING))
146 return; 143 return;
147 144
148 // Prevents us from passively growing the memory unbounded in case 145 // Prevents us from passively growing the memory unbounded in case
149 // something went wrong. Should not happen. 146 // something went wrong. Should not happen.
150 if (url_request_to_record_.size() > kMaxNumEntries) { 147 if (url_request_to_record_.size() > kMaxNumEntries) {
151 LOG(WARNING) << "The load timing observer url request count has grown " 148 LOG(WARNING) << "The load timing observer url request count has grown "
152 "larger than expected, resetting"; 149 "larger than expected, resetting";
153 url_request_to_record_.clear(); 150 url_request_to_record_.clear();
154 } 151 }
155 152
156 URLRequestRecord& record = url_request_to_record_[source.id]; 153 URLRequestRecord& record = url_request_to_record_[entry.source().id];
157 record.base_ticks = time; 154 base::TimeTicks now = base::TimeTicks::Now();
155
156 record.base_ticks = now;
158 record.timing = ResourceLoadTimingInfo(); 157 record.timing = ResourceLoadTimingInfo();
159 record.timing.base_ticks = time; 158 record.timing.base_ticks = now;
160 record.timing.base_time = TimeTicksToTime(time); 159 record.timing.base_time = TimeTicksToTime(now);
161 } 160 }
162 return; 161 return;
163 } else if (type == net::NetLog::TYPE_REQUEST_ALIVE) { 162 } else if (entry.type() == net::NetLog::TYPE_REQUEST_ALIVE) {
164 // Cleanup records based on the TYPE_REQUEST_ALIVE entry. 163 // Cleanup records based on the TYPE_REQUEST_ALIVE entry.
165 if (is_end) 164 if (is_end)
166 url_request_to_record_.erase(source.id); 165 url_request_to_record_.erase(entry.source().id);
167 return; 166 return;
168 } 167 }
169 168
170 URLRequestRecord* record = GetURLRequestRecord(source.id); 169 URLRequestRecord* record = GetURLRequestRecord(entry.source().id);
171 if (!record) 170 if (!record)
172 return; 171 return;
173 172
174 ResourceLoadTimingInfo& timing = record->timing; 173 ResourceLoadTimingInfo& timing = record->timing;
175 174
176 switch (type) { 175 switch (entry.type()) {
177 case net::NetLog::TYPE_PROXY_SERVICE: 176 case net::NetLog::TYPE_PROXY_SERVICE:
178 if (is_begin) 177 if (is_begin)
179 timing.proxy_start = TimeTicksToOffset(time, record); 178 timing.proxy_start = TimeTicksToOffset(base::TimeTicks::Now(), record);
180 else if (is_end) 179 else if (is_end)
181 timing.proxy_end = TimeTicksToOffset(time, record); 180 timing.proxy_end = TimeTicksToOffset(base::TimeTicks::Now(), record);
182 break; 181 break;
183 case net::NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_JOB: { 182 case net::NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_JOB: {
184 uint32 http_stream_job_id = static_cast<net::NetLogSourceParameter*>( 183 net::NetLog::Source http_stream_job_source;
185 params)->value().id; 184 scoped_ptr<Value> event_parameters(entry.ParametersToValue());
185 if (!net::NetLog::Source::FromEventParameters(
186 event_parameters.get(),
187 &http_stream_job_source)) {
188 NOTREACHED();
189 return;
190 }
191 DCHECK_EQ(net::NetLog::SOURCE_HTTP_STREAM_JOB,
192 http_stream_job_source.type);
193
186 HTTPStreamJobToRecordMap::iterator it = 194 HTTPStreamJobToRecordMap::iterator it =
187 http_stream_job_to_record_.find(http_stream_job_id); 195 http_stream_job_to_record_.find(http_stream_job_source.id);
188 if (it == http_stream_job_to_record_.end()) 196 if (it == http_stream_job_to_record_.end())
189 return; 197 return;
190 if (!it->second.connect_start.is_null()) { 198 if (!it->second.connect_start.is_null()) {
191 timing.connect_start = TimeTicksToOffset(it->second.connect_start, 199 timing.connect_start = TimeTicksToOffset(it->second.connect_start,
192 record); 200 record);
193 } 201 }
194 if (!it->second.connect_end.is_null()) 202 if (!it->second.connect_end.is_null())
195 timing.connect_end = TimeTicksToOffset(it->second.connect_end, record); 203 timing.connect_end = TimeTicksToOffset(it->second.connect_end, record);
196 if (!it->second.dns_start.is_null()) 204 if (!it->second.dns_start.is_null())
197 timing.dns_start = TimeTicksToOffset(it->second.dns_start, record); 205 timing.dns_start = TimeTicksToOffset(it->second.dns_start, record);
198 if (!it->second.dns_end.is_null()) 206 if (!it->second.dns_end.is_null())
199 timing.dns_end = TimeTicksToOffset(it->second.dns_end, record); 207 timing.dns_end = TimeTicksToOffset(it->second.dns_end, record);
200 if (!it->second.ssl_start.is_null()) 208 if (!it->second.ssl_start.is_null())
201 timing.ssl_start = TimeTicksToOffset(it->second.ssl_start, record); 209 timing.ssl_start = TimeTicksToOffset(it->second.ssl_start, record);
202 if (!it->second.ssl_end.is_null()) 210 if (!it->second.ssl_end.is_null())
203 timing.ssl_end = TimeTicksToOffset(it->second.ssl_end, record); 211 timing.ssl_end = TimeTicksToOffset(it->second.ssl_end, record);
204 record->socket_reused = it->second.socket_reused; 212 record->socket_reused = it->second.socket_reused;
205 record->socket_log_id = it->second.socket_log_id; 213 record->socket_log_id = it->second.socket_log_id;
206 break; 214 break;
207 } 215 }
208 case net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST: 216 case net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST:
209 if (is_begin) 217 if (is_begin)
210 timing.send_start = TimeTicksToOffset(time, record); 218 timing.send_start = TimeTicksToOffset(base::TimeTicks::Now(), record);
211 else if (is_end) 219 else if (is_end)
212 timing.send_end = TimeTicksToOffset(time, record); 220 timing.send_end = TimeTicksToOffset(base::TimeTicks::Now(), record);
213 break; 221 break;
214 case net::NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS: 222 case net::NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS:
215 if (is_begin) 223 if (is_begin) {
216 timing.receive_headers_start = TimeTicksToOffset(time, record); 224 timing.receive_headers_start =
217 else if (is_end) 225 TimeTicksToOffset(base::TimeTicks::Now(), record);
218 timing.receive_headers_end = TimeTicksToOffset(time, record); 226 } else if (is_end) {
227 timing.receive_headers_end =
228 TimeTicksToOffset(base::TimeTicks::Now(), record);
229 }
219 break; 230 break;
220 default: 231 default:
221 break; 232 break;
222 } 233 }
223 } 234 }
224 235
225 void LoadTimingObserver::OnAddHTTPStreamJobEntry( 236 void LoadTimingObserver::OnAddHTTPStreamJobEntry(
226 net::NetLog::EventType type, 237 const net::NetLog::Entry& entry) {
227 const base::TimeTicks& time,
228 const net::NetLog::Source& source,
229 net::NetLog::EventPhase phase,
230 net::NetLog::EventParameters* params) {
231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
232 239
233 bool is_begin = phase == net::NetLog::PHASE_BEGIN; 240 bool is_begin = entry.phase() == net::NetLog::PHASE_BEGIN;
234 bool is_end = phase == net::NetLog::PHASE_END; 241 bool is_end = entry.phase() == net::NetLog::PHASE_END;
235 242
236 if (type == net::NetLog::TYPE_HTTP_STREAM_JOB) { 243 if (entry.type() == net::NetLog::TYPE_HTTP_STREAM_JOB) {
237 if (is_begin) { 244 if (is_begin) {
238 // Prevents us from passively growing the memory unbounded in 245 // Prevents us from passively growing the memory unbounded in
239 // case something went wrong. Should not happen. 246 // case something went wrong. Should not happen.
240 if (http_stream_job_to_record_.size() > kMaxNumEntries) { 247 if (http_stream_job_to_record_.size() > kMaxNumEntries) {
241 LOG(WARNING) << "The load timing observer http stream job count " 248 LOG(WARNING) << "The load timing observer http stream job count "
242 "has grown larger than expected, resetting"; 249 "has grown larger than expected, resetting";
243 http_stream_job_to_record_.clear(); 250 http_stream_job_to_record_.clear();
244 } 251 }
245 252
246 http_stream_job_to_record_.insert( 253 http_stream_job_to_record_.insert(
247 std::make_pair(source.id, HTTPStreamJobRecord())); 254 std::make_pair(entry.source().id, HTTPStreamJobRecord()));
248 } else if (is_end) { 255 } else if (is_end) {
249 http_stream_job_to_record_.erase(source.id); 256 http_stream_job_to_record_.erase(entry.source().id);
250 } 257 }
251 return; 258 return;
252 } 259 }
253 260
254 HTTPStreamJobToRecordMap::iterator it = 261 HTTPStreamJobToRecordMap::iterator it =
255 http_stream_job_to_record_.find(source.id); 262 http_stream_job_to_record_.find(entry.source().id);
256 if (it == http_stream_job_to_record_.end()) 263 if (it == http_stream_job_to_record_.end())
257 return; 264 return;
258 265
259 switch (type) { 266 switch (entry.type()) {
260 case net::NetLog::TYPE_SOCKET_POOL: 267 case net::NetLog::TYPE_SOCKET_POOL:
261 if (is_begin) 268 if (is_begin)
262 it->second.connect_start = time; 269 it->second.connect_start = base::TimeTicks::Now();
263 else if (is_end) 270 else if (is_end)
264 it->second.connect_end = time; 271 it->second.connect_end = base::TimeTicks::Now();
265 break; 272 break;
266 case net::NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB: { 273 case net::NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB: {
267 uint32 connect_job_id = static_cast<net::NetLogSourceParameter*>( 274 net::NetLog::Source connect_job_source;
268 params)->value().id; 275 scoped_ptr<Value> event_parameters(entry.ParametersToValue());
269 if (last_connect_job_id_ == connect_job_id && 276 if (!net::NetLog::Source::FromEventParameters(
277 event_parameters.get(),
278 &connect_job_source)) {
279 NOTREACHED();
280 return;
281 }
282 DCHECK_EQ(net::NetLog::SOURCE_CONNECT_JOB, connect_job_source.type);
283
284 if (last_connect_job_id_ == connect_job_source.id &&
270 !last_connect_job_record_.dns_start.is_null()) { 285 !last_connect_job_record_.dns_start.is_null()) {
271 it->second.dns_start = last_connect_job_record_.dns_start; 286 it->second.dns_start = last_connect_job_record_.dns_start;
272 it->second.dns_end = last_connect_job_record_.dns_end; 287 it->second.dns_end = last_connect_job_record_.dns_end;
273 } 288 }
274 break; 289 break;
275 } 290 }
276 case net::NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET: 291 case net::NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET:
277 it->second.socket_reused = true; 292 it->second.socket_reused = true;
278 break; 293 break;
279 case net::NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET: 294 case net::NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET: {
280 it->second.socket_log_id = static_cast<net::NetLogSourceParameter*>( 295 net::NetLog::Source socket_source;
281 params)->value().id; 296 scoped_ptr<Value> event_parameters(entry.ParametersToValue());
297 if (!net::NetLog::Source::FromEventParameters(
298 event_parameters.get(),
299 &socket_source)) {
300 NOTREACHED();
301 return;
302 }
303 DCHECK_EQ(net::NetLog::SOURCE_SOCKET, socket_source.type);
304
305 it->second.socket_log_id = socket_source.id;
282 if (!it->second.socket_reused) { 306 if (!it->second.socket_reused) {
283 SocketToRecordMap::iterator socket_it = 307 SocketToRecordMap::iterator socket_it =
284 socket_to_record_.find(it->second.socket_log_id); 308 socket_to_record_.find(it->second.socket_log_id);
285 if (socket_it != socket_to_record_.end() && 309 if (socket_it != socket_to_record_.end() &&
286 !socket_it->second.ssl_start.is_null()) { 310 !socket_it->second.ssl_start.is_null()) {
287 it->second.ssl_start = socket_it->second.ssl_start; 311 it->second.ssl_start = socket_it->second.ssl_start;
288 it->second.ssl_end = socket_it->second.ssl_end; 312 it->second.ssl_end = socket_it->second.ssl_end;
289 } 313 }
290 } 314 }
291 break; 315 break;
316 }
292 default: 317 default:
293 break; 318 break;
294 } 319 }
295 } 320 }
296 321
297 void LoadTimingObserver::OnAddConnectJobEntry( 322 void LoadTimingObserver::OnAddConnectJobEntry(const net::NetLog::Entry& entry) {
298 net::NetLog::EventType type,
299 const base::TimeTicks& time,
300 const net::NetLog::Source& source,
301 net::NetLog::EventPhase phase,
302 net::NetLog::EventParameters* params) {
303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 323 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
304 324
305 bool is_begin = phase == net::NetLog::PHASE_BEGIN; 325 bool is_begin = entry.phase() == net::NetLog::PHASE_BEGIN;
306 bool is_end = phase == net::NetLog::PHASE_END; 326 bool is_end = entry.phase() == net::NetLog::PHASE_END;
307 327
308 // Manage record lifetime based on the SOCKET_POOL_CONNECT_JOB entry. 328 // Manage record lifetime based on the SOCKET_POOL_CONNECT_JOB entry.
309 if (type == net::NetLog::TYPE_SOCKET_POOL_CONNECT_JOB) { 329 if (entry.type() == net::NetLog::TYPE_SOCKET_POOL_CONNECT_JOB) {
310 if (is_begin) { 330 if (is_begin) {
311 // Prevents us from passively growing the memory unbounded in case 331 // Prevents us from passively growing the memory unbounded in case
312 // something went wrong. Should not happen. 332 // something went wrong. Should not happen.
313 if (connect_job_to_record_.size() > kMaxNumEntries) { 333 if (connect_job_to_record_.size() > kMaxNumEntries) {
314 LOG(WARNING) << "The load timing observer connect job count has grown " 334 LOG(WARNING) << "The load timing observer connect job count has grown "
315 "larger than expected, resetting"; 335 "larger than expected, resetting";
316 connect_job_to_record_.clear(); 336 connect_job_to_record_.clear();
317 } 337 }
318 338
319 connect_job_to_record_.insert( 339 connect_job_to_record_.insert(
320 std::make_pair(source.id, ConnectJobRecord())); 340 std::make_pair(entry.source().id, ConnectJobRecord()));
321 } else if (is_end) { 341 } else if (is_end) {
322 ConnectJobToRecordMap::iterator it = 342 ConnectJobToRecordMap::iterator it =
323 connect_job_to_record_.find(source.id); 343 connect_job_to_record_.find(entry.source().id);
324 if (it != connect_job_to_record_.end()) { 344 if (it != connect_job_to_record_.end()) {
325 last_connect_job_id_ = it->first; 345 last_connect_job_id_ = it->first;
326 last_connect_job_record_ = it->second; 346 last_connect_job_record_ = it->second;
327 connect_job_to_record_.erase(it); 347 connect_job_to_record_.erase(it);
328 } 348 }
329 } 349 }
330 } else if (type == net::NetLog::TYPE_HOST_RESOLVER_IMPL) { 350 } else if (entry.type() == net::NetLog::TYPE_HOST_RESOLVER_IMPL) {
331 ConnectJobToRecordMap::iterator it = 351 ConnectJobToRecordMap::iterator it =
332 connect_job_to_record_.find(source.id); 352 connect_job_to_record_.find(entry.source().id);
333 if (it != connect_job_to_record_.end()) { 353 if (it != connect_job_to_record_.end()) {
334 if (is_begin) 354 if (is_begin)
335 it->second.dns_start = time; 355 it->second.dns_start = base::TimeTicks::Now();
336 else if (is_end) 356 else if (is_end)
337 it->second.dns_end = time; 357 it->second.dns_end = base::TimeTicks::Now();
338 } 358 }
339 } 359 }
340 } 360 }
341 361
342 void LoadTimingObserver::OnAddSocketEntry( 362 void LoadTimingObserver::OnAddSocketEntry(const net::NetLog::Entry& entry) {
343 net::NetLog::EventType type,
344 const base::TimeTicks& time,
345 const net::NetLog::Source& source,
346 net::NetLog::EventPhase phase,
347 net::NetLog::EventParameters* params) {
348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 363 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
349 364
350 bool is_begin = phase == net::NetLog::PHASE_BEGIN; 365 bool is_begin = entry.phase() == net::NetLog::PHASE_BEGIN;
351 bool is_end = phase == net::NetLog::PHASE_END; 366 bool is_end = entry.phase() == net::NetLog::PHASE_END;
352 367
353 // Manage record lifetime based on the SOCKET_ALIVE entry. 368 // Manage record lifetime based on the SOCKET_ALIVE entry.
354 if (type == net::NetLog::TYPE_SOCKET_ALIVE) { 369 if (entry.type() == net::NetLog::TYPE_SOCKET_ALIVE) {
355 if (is_begin) { 370 if (is_begin) {
356 // Prevents us from passively growing the memory unbounded in case 371 // Prevents us from passively growing the memory unbounded in case
357 // something went wrong. Should not happen. 372 // something went wrong. Should not happen.
358 if (socket_to_record_.size() > kMaxNumEntries) { 373 if (socket_to_record_.size() > kMaxNumEntries) {
359 LOG(WARNING) << "The load timing observer socket count has grown " 374 LOG(WARNING) << "The load timing observer socket count has grown "
360 "larger than expected, resetting"; 375 "larger than expected, resetting";
361 socket_to_record_.clear(); 376 socket_to_record_.clear();
362 } 377 }
363 378
364 socket_to_record_.insert( 379 socket_to_record_.insert(
365 std::make_pair(source.id, SocketRecord())); 380 std::make_pair(entry.source().id, SocketRecord()));
366 } else if (is_end) { 381 } else if (is_end) {
367 socket_to_record_.erase(source.id); 382 socket_to_record_.erase(entry.source().id);
368 } 383 }
369 return; 384 return;
370 } 385 }
371 SocketToRecordMap::iterator it = socket_to_record_.find(source.id); 386 SocketToRecordMap::iterator it = socket_to_record_.find(entry.source().id);
372 if (it == socket_to_record_.end()) 387 if (it == socket_to_record_.end())
373 return; 388 return;
374 389
375 if (type == net::NetLog::TYPE_SSL_CONNECT) { 390 if (entry.type() == net::NetLog::TYPE_SSL_CONNECT) {
376 if (is_begin) 391 if (is_begin)
377 it->second.ssl_start = time; 392 it->second.ssl_start = base::TimeTicks::Now();
378 else if (is_end) 393 else if (is_end)
379 it->second.ssl_end = time; 394 it->second.ssl_end = base::TimeTicks::Now();
380 } 395 }
381 } 396 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698