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

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

Issue 6592027: Update NetLog in preparation for late binding of HttpStream jobs to requests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address nits. Created 9 years, 9 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) 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/passive_log_collector.h" 5 #include "chrome/browser/net/passive_log_collector.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "net/url_request/url_request_netlog_params.h" 10 #include "net/url_request/url_request_netlog_params.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace { 13 namespace {
14 14
15 typedef PassiveLogCollector::RequestTracker RequestTracker; 15 typedef PassiveLogCollector::RequestTracker RequestTracker;
16 typedef PassiveLogCollector::SourceInfoList SourceInfoList; 16 typedef PassiveLogCollector::SourceInfoList SourceInfoList;
17 typedef PassiveLogCollector::SocketTracker SocketTracker; 17 typedef PassiveLogCollector::SocketTracker SocketTracker;
18 typedef PassiveLogCollector::HttpStreamJobTracker HttpStreamJobTracker;
18 using net::NetLog; 19 using net::NetLog;
19 20
20 const NetLog::SourceType kSourceType = NetLog::SOURCE_NONE; 21 const NetLog::SourceType kSourceType = NetLog::SOURCE_NONE;
21 22
22 ChromeNetLog::Entry MakeStartLogEntryWithURL(int source_id, 23 ChromeNetLog::Entry MakeStartLogEntryWithURL(int source_id,
23 const std::string& url) { 24 const std::string& url) {
24 return ChromeNetLog::Entry( 25 return ChromeNetLog::Entry(
25 0, 26 0,
26 NetLog::TYPE_URL_REQUEST_START_JOB, 27 NetLog::TYPE_URL_REQUEST_START_JOB,
27 base::TimeTicks(), 28 base::TimeTicks(),
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 base::TimeTicks(), 195 base::TimeTicks(),
195 NetLog::Source(NetLog::SOURCE_SPDY_SESSION, 1), 196 NetLog::Source(NetLog::SOURCE_SPDY_SESSION, 1),
196 NetLog::PHASE_END, 197 NetLog::PHASE_END,
197 NULL); 198 NULL);
198 199
199 tracker.OnAddEntry(end); 200 tracker.OnAddEntry(end);
200 EXPECT_EQ(0u, GetLiveSources(tracker).size()); 201 EXPECT_EQ(0u, GetLiveSources(tracker).size());
201 EXPECT_EQ(1u, GetDeadSources(tracker).size()); 202 EXPECT_EQ(1u, GetDeadSources(tracker).size());
202 } 203 }
203 204
204 // Test that when a SOURCE_SOCKET is connected to a SOURCE_URL_REQUEST 205 // Test that when a SOURCE_HTTP_STREAM_JOB is connected to a SOURCE_URL_REQUEST
205 // (via the TYPE_SOCKET_POOL_BOUND_TO_SOCKET event), it holds a reference 206 // (via the TYPE_HTTP_STREAM_REQUEST_BOUND_TO_JOB event), it holds a reference
206 // to the SOURCE_SOCKET preventing it from getting deleted as long as the 207 // to the SOURCE_HTTP_STREAM_JOB preventing it from getting deleted as long as
207 // SOURCE_URL_REQUEST is still around. 208 // the SOURCE_URL_REQUEST is still around.
208 TEST(PassiveLogCollectorTest, HoldReferenceToDependentSource) { 209 TEST(PassiveLogCollectorTest, HoldReferenceToDependentSource) {
209 PassiveLogCollector log; 210 PassiveLogCollector log;
210 211
211 EXPECT_EQ(0u, GetLiveSources(log.url_request_tracker_).size()); 212 EXPECT_EQ(0u, GetLiveSources(log.url_request_tracker_).size());
212 EXPECT_EQ(0u, GetLiveSources(log.socket_tracker_).size()); 213 EXPECT_EQ(0u, GetLiveSources(log.http_stream_job_tracker_).size());
213 214
214 uint32 next_id = 0; 215 uint32 next_id = 0;
215 NetLog::Source socket_source(NetLog::SOURCE_SOCKET, next_id++); 216 NetLog::Source stream_job_source(NetLog::SOURCE_HTTP_STREAM_JOB, next_id++);
216 NetLog::Source url_request_source(NetLog::SOURCE_URL_REQUEST, next_id++); 217 NetLog::Source url_request_source(NetLog::SOURCE_URL_REQUEST, next_id++);
217 218
218 // Start a SOURCE_SOCKET. 219 // Start a SOURCE_HTTP_STREAM_JOB.
219 log.OnAddEntry(NetLog::TYPE_SOCKET_ALIVE, 220 log.OnAddEntry(NetLog::TYPE_HTTP_STREAM_JOB,
220 base::TimeTicks(), 221 base::TimeTicks(),
221 socket_source, 222 stream_job_source,
222 NetLog::PHASE_BEGIN, 223 NetLog::PHASE_BEGIN,
223 NULL); 224 NULL);
224 225
225 EXPECT_EQ(0u, GetLiveSources(log.url_request_tracker_).size()); 226 EXPECT_EQ(0u, GetLiveSources(log.url_request_tracker_).size());
226 EXPECT_EQ(1u, GetLiveSources(log.socket_tracker_).size()); 227 EXPECT_EQ(1u, GetLiveSources(log.http_stream_job_tracker_).size());
227 228
228 // Start a SOURCE_URL_REQUEST. 229 // Start a SOURCE_URL_REQUEST.
229 log.OnAddEntry(NetLog::TYPE_REQUEST_ALIVE, 230 log.OnAddEntry(NetLog::TYPE_REQUEST_ALIVE,
230 base::TimeTicks(), 231 base::TimeTicks(),
231 url_request_source, 232 url_request_source,
232 NetLog::PHASE_BEGIN, 233 NetLog::PHASE_BEGIN,
233 NULL); 234 NULL);
234 235
235 // Check that there is no association between the SOURCE_URL_REQUEST and the 236 // Check that there is no association between the SOURCE_URL_REQUEST and the
236 // SOURCE_SOCKET yet. 237 // SOURCE_HTTP_STREAM_JOB yet.
237 ASSERT_EQ(1u, GetLiveSources(log.url_request_tracker_).size()); 238 ASSERT_EQ(1u, GetLiveSources(log.url_request_tracker_).size());
238 { 239 {
239 PassiveLogCollector::SourceInfo info = 240 PassiveLogCollector::SourceInfo info =
240 GetLiveSources(log.url_request_tracker_)[0]; 241 GetLiveSources(log.url_request_tracker_)[0];
241 EXPECT_EQ(0, info.reference_count); 242 EXPECT_EQ(0, info.reference_count);
242 EXPECT_EQ(0u, info.dependencies.size()); 243 EXPECT_EQ(0u, info.dependencies.size());
243 } 244 }
244 ASSERT_EQ(1u, GetLiveSources(log.socket_tracker_).size()); 245 ASSERT_EQ(1u, GetLiveSources(log.http_stream_job_tracker_).size());
245 { 246 {
246 PassiveLogCollector::SourceInfo info = 247 PassiveLogCollector::SourceInfo info =
247 GetLiveSources(log.socket_tracker_)[0]; 248 GetLiveSources(log.http_stream_job_tracker_)[0];
248 EXPECT_EQ(0, info.reference_count); 249 EXPECT_EQ(0, info.reference_count);
249 EXPECT_EQ(0u, info.dependencies.size()); 250 EXPECT_EQ(0u, info.dependencies.size());
250 } 251 }
251 252
252 // Associate the SOURCE_SOCKET with the SOURCE_URL_REQUEST. 253 // Associate the SOURCE_HTTP_STREAM_JOB with the SOURCE_URL_REQUEST.
253 log.OnAddEntry(NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, 254 log.OnAddEntry(NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_JOB,
254 base::TimeTicks(), 255 base::TimeTicks(),
255 url_request_source, 256 url_request_source,
256 NetLog::PHASE_NONE, 257 NetLog::PHASE_NONE,
257 new net::NetLogSourceParameter("x", socket_source)); 258 new net::NetLogSourceParameter("x", stream_job_source));
258 259
259 // Check that an associate was made -- the SOURCE_URL_REQUEST should have 260 // Check that an associate was made -- the SOURCE_URL_REQUEST should have
260 // added a reference to the SOURCE_SOCKET. 261 // added a reference to the SOURCE_HTTP_STREAM_JOB.
261 ASSERT_EQ(1u, GetLiveSources(log.url_request_tracker_).size()); 262 ASSERT_EQ(1u, GetLiveSources(log.url_request_tracker_).size());
262 { 263 {
263 PassiveLogCollector::SourceInfo info = 264 PassiveLogCollector::SourceInfo info =
264 GetLiveSources(log.url_request_tracker_)[0]; 265 GetLiveSources(log.url_request_tracker_)[0];
265 EXPECT_EQ(0, info.reference_count); 266 EXPECT_EQ(0, info.reference_count);
266 EXPECT_EQ(1u, info.dependencies.size()); 267 EXPECT_EQ(1u, info.dependencies.size());
267 EXPECT_EQ(socket_source.id, info.dependencies[0].id); 268 EXPECT_EQ(stream_job_source.id, info.dependencies[0].id);
268 } 269 }
269 ASSERT_EQ(1u, GetLiveSources(log.socket_tracker_).size()); 270 ASSERT_EQ(1u, GetLiveSources(log.http_stream_job_tracker_).size());
270 { 271 {
271 PassiveLogCollector::SourceInfo info = 272 PassiveLogCollector::SourceInfo info =
272 GetLiveSources(log.socket_tracker_)[0]; 273 GetLiveSources(log.http_stream_job_tracker_)[0];
273 EXPECT_EQ(1, info.reference_count); 274 EXPECT_EQ(1, info.reference_count);
274 EXPECT_EQ(0u, info.dependencies.size()); 275 EXPECT_EQ(0u, info.dependencies.size());
275 } 276 }
276 277
277 // Now end both |source_socket| and |source_url_request|. This sends them 278 // Now end both |stream_job_source| and |url_request_source|. This sends them
278 // to deletion queue, and they will be deleted once space runs out. 279 // to deletion queue, and they will be deleted once space runs out.
279 280
280 log.OnAddEntry(NetLog::TYPE_REQUEST_ALIVE, 281 log.OnAddEntry(NetLog::TYPE_REQUEST_ALIVE,
281 base::TimeTicks(), 282 base::TimeTicks(),
282 url_request_source, 283 url_request_source,
283 NetLog::PHASE_END, 284 NetLog::PHASE_END,
284 NULL); 285 NULL);
285 286
286 log.OnAddEntry(NetLog::TYPE_SOCKET_ALIVE, 287 log.OnAddEntry(NetLog::TYPE_HTTP_STREAM_JOB,
287 base::TimeTicks(), 288 base::TimeTicks(),
288 socket_source, 289 stream_job_source,
289 NetLog::PHASE_END, 290 NetLog::PHASE_END,
290 NULL); 291 NULL);
291 292
292 // Verify that both sources are in fact dead, and that |source_url_request| 293 // Verify that both sources are in fact dead, and that |url_request_source|
293 // still holds a reference to |source_socket|. 294 // still holds a reference to |stream_job_source|.
294 ASSERT_EQ(0u, GetLiveSources(log.url_request_tracker_).size()); 295 ASSERT_EQ(0u, GetLiveSources(log.url_request_tracker_).size());
295 ASSERT_EQ(1u, GetDeadSources(log.url_request_tracker_).size()); 296 ASSERT_EQ(1u, GetDeadSources(log.url_request_tracker_).size());
296 { 297 {
297 PassiveLogCollector::SourceInfo info = 298 PassiveLogCollector::SourceInfo info =
298 GetDeadSources(log.url_request_tracker_)[0]; 299 GetDeadSources(log.url_request_tracker_)[0];
299 EXPECT_EQ(0, info.reference_count); 300 EXPECT_EQ(0, info.reference_count);
300 EXPECT_EQ(1u, info.dependencies.size()); 301 EXPECT_EQ(1u, info.dependencies.size());
301 EXPECT_EQ(socket_source.id, info.dependencies[0].id); 302 EXPECT_EQ(stream_job_source.id, info.dependencies[0].id);
302 } 303 }
303 EXPECT_EQ(0u, GetLiveSources(log.socket_tracker_).size()); 304 EXPECT_EQ(0u, GetLiveSources(log.http_stream_job_tracker_).size());
304 ASSERT_EQ(1u, GetDeadSources(log.socket_tracker_).size()); 305 ASSERT_EQ(1u, GetDeadSources(log.http_stream_job_tracker_).size());
305 { 306 {
306 PassiveLogCollector::SourceInfo info = 307 PassiveLogCollector::SourceInfo info =
307 GetDeadSources(log.socket_tracker_)[0]; 308 GetDeadSources(log.http_stream_job_tracker_)[0];
308 EXPECT_EQ(1, info.reference_count); 309 EXPECT_EQ(1, info.reference_count);
309 EXPECT_EQ(0u, info.dependencies.size()); 310 EXPECT_EQ(0u, info.dependencies.size());
310 } 311 }
311 312
312 // Cycle through a bunch of SOURCE_SOCKET -- if it were not referenced, this 313 // Cycle through a bunch of SOURCE_HTTP_STREAM_JOB -- if it were not
313 // loop will have deleted it. 314 // referenced, this loop will have deleted it.
314 for (size_t i = 0; i < SocketTracker::kMaxGraveyardSize; ++i) { 315 for (size_t i = 0; i < HttpStreamJobTracker::kMaxGraveyardSize; ++i) {
315 log.OnAddEntry(NetLog::TYPE_SOCKET_ALIVE, 316 log.OnAddEntry(NetLog::TYPE_HTTP_STREAM_JOB,
316 base::TimeTicks(), 317 base::TimeTicks(),
317 NetLog::Source(NetLog::SOURCE_SOCKET, next_id++), 318 NetLog::Source(NetLog::SOURCE_HTTP_STREAM_JOB, next_id++),
318 NetLog::PHASE_END, 319 NetLog::PHASE_END,
319 NULL); 320 NULL);
320 } 321 }
321 322
322 EXPECT_EQ(0u, GetLiveSources(log.socket_tracker_).size()); 323 EXPECT_EQ(0u, GetLiveSources(log.http_stream_job_tracker_).size());
323 ASSERT_EQ(SocketTracker::kMaxGraveyardSize + 1, 324 ASSERT_EQ(HttpStreamJobTracker::kMaxGraveyardSize + 1,
324 GetDeadSources(log.socket_tracker_).size()); 325 GetDeadSources(log.http_stream_job_tracker_).size());
325 { 326 {
326 PassiveLogCollector::SourceInfo info = 327 PassiveLogCollector::SourceInfo info =
327 GetDeadSources(log.socket_tracker_)[0]; 328 GetDeadSources(log.http_stream_job_tracker_)[0];
328 EXPECT_EQ(socket_source.id, info.source_id); 329 EXPECT_EQ(stream_job_source.id, info.source_id);
329 EXPECT_EQ(1, info.reference_count); 330 EXPECT_EQ(1, info.reference_count);
330 EXPECT_EQ(0u, info.dependencies.size()); 331 EXPECT_EQ(0u, info.dependencies.size());
331 } 332 }
332 333
333 // Cycle through a bunch of SOURCE_URL_REQUEST -- this will cause 334 // Cycle through a bunch of SOURCE_URL_REQUEST -- this will cause
334 // |source_url_request| to be freed, which in turn should release the final 335 // |url_request_source| to be freed, which in turn should release the final
335 // reference to |source_socket| cause it to be freed as well. 336 // reference to |stream_job_source| cause it to be freed as well.
336 for (size_t i = 0; i < RequestTracker::kMaxGraveyardSize; ++i) { 337 for (size_t i = 0; i < RequestTracker::kMaxGraveyardSize; ++i) {
337 log.OnAddEntry(NetLog::TYPE_REQUEST_ALIVE, 338 log.OnAddEntry(NetLog::TYPE_REQUEST_ALIVE,
338 base::TimeTicks(), 339 base::TimeTicks(),
339 NetLog::Source(NetLog::SOURCE_URL_REQUEST, next_id++), 340 NetLog::Source(NetLog::SOURCE_URL_REQUEST, next_id++),
340 NetLog::PHASE_END, 341 NetLog::PHASE_END,
341 NULL); 342 NULL);
342 } 343 }
343 344
344 EXPECT_EQ(0u, GetLiveSources(log.url_request_tracker_).size()); 345 EXPECT_EQ(0u, GetLiveSources(log.url_request_tracker_).size());
345 EXPECT_EQ(RequestTracker::kMaxGraveyardSize, 346 EXPECT_EQ(RequestTracker::kMaxGraveyardSize,
346 GetDeadSources(log.url_request_tracker_).size()); 347 GetDeadSources(log.url_request_tracker_).size());
347 348
348 EXPECT_EQ(0u, GetLiveSources(log.socket_tracker_).size()); 349 EXPECT_EQ(0u, GetLiveSources(log.http_stream_job_tracker_).size());
349 EXPECT_EQ(SocketTracker::kMaxGraveyardSize, 350 EXPECT_EQ(HttpStreamJobTracker::kMaxGraveyardSize,
350 GetDeadSources(log.socket_tracker_).size()); 351 GetDeadSources(log.http_stream_job_tracker_).size());
351 } 352 }
352 353
353 // Have a URL_REQUEST hold a reference to a SOCKET. Then cause the SOCKET to 354 // Have a HTTP_STREAM_JOB hold a reference to a SOCKET. Then cause the SOCKET to
354 // get evicted (by exceeding maximum sources limit). Now the URL_REQUEST is 355 // get evicted (by exceeding maximum sources limit). Now the HTTP_STREAM_JOB is
355 // referencing a non-existant SOCKET. Lastly, evict the URL_REQUEST so it 356 // referencing a non-existant SOCKET. Lastly, evict the HTTP_STREAM_JOB so it
356 // tries to drop all of its references. Make sure that in releasing its 357 // tries to drop all of its references. Make sure that in releasing its
357 // non-existant reference it doesn't trip any DCHECKs. 358 // non-existant reference it doesn't trip any DCHECKs.
358 TEST(PassiveLogCollectorTest, HoldReferenceToDeletedSource) { 359 TEST(PassiveLogCollectorTest, HoldReferenceToDeletedSource) {
359 PassiveLogCollector log; 360 PassiveLogCollector log;
360 361
361 EXPECT_EQ(0u, GetLiveSources(log.url_request_tracker_).size()); 362 EXPECT_EQ(0u, GetLiveSources(log.http_stream_job_tracker_).size());
362 EXPECT_EQ(0u, GetLiveSources(log.socket_tracker_).size()); 363 EXPECT_EQ(0u, GetLiveSources(log.socket_tracker_).size());
363 364
364 uint32 next_id = 0; 365 uint32 next_id = 0;
365 NetLog::Source socket_source(NetLog::SOURCE_SOCKET, next_id++); 366 NetLog::Source socket_source(NetLog::SOURCE_SOCKET, next_id++);
366 NetLog::Source url_request_source(NetLog::SOURCE_URL_REQUEST, next_id++); 367 NetLog::Source stream_job_source(NetLog::SOURCE_HTTP_STREAM_JOB, next_id++);
367 368
368 // Start a SOURCE_SOCKET. 369 // Start a SOURCE_SOCKET.
369 log.OnAddEntry(NetLog::TYPE_SOCKET_ALIVE, 370 log.OnAddEntry(NetLog::TYPE_SOCKET_ALIVE,
370 base::TimeTicks(), 371 base::TimeTicks(),
371 socket_source, 372 socket_source,
372 NetLog::PHASE_BEGIN, 373 NetLog::PHASE_BEGIN,
373 NULL); 374 NULL);
374 375
375 EXPECT_EQ(0u, GetLiveSources(log.url_request_tracker_).size()); 376 EXPECT_EQ(0u, GetLiveSources(log.http_stream_job_tracker_).size());
376 EXPECT_EQ(1u, GetLiveSources(log.socket_tracker_).size()); 377 EXPECT_EQ(1u, GetLiveSources(log.socket_tracker_).size());
377 378
378 // Start a SOURCE_URL_REQUEST. 379 // Start a SOURCE_HTTP_STREAM_JOB.
379 log.OnAddEntry(NetLog::TYPE_REQUEST_ALIVE, 380 log.OnAddEntry(NetLog::TYPE_HTTP_STREAM_JOB,
380 base::TimeTicks(), 381 base::TimeTicks(),
381 url_request_source, 382 stream_job_source,
382 NetLog::PHASE_BEGIN, 383 NetLog::PHASE_BEGIN,
383 NULL); 384 NULL);
384 385
385 // Associate the SOURCE_SOCKET with the SOURCE_URL_REQUEST. 386 // Associate the SOURCE_SOCKET with the SOURCE_HTTP_STREAM_JOB.
386 log.OnAddEntry(NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, 387 log.OnAddEntry(NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET,
387 base::TimeTicks(), 388 base::TimeTicks(),
388 url_request_source, 389 stream_job_source,
389 NetLog::PHASE_NONE, 390 NetLog::PHASE_NONE,
390 new net::NetLogSourceParameter("x", socket_source)); 391 new net::NetLogSourceParameter("x", socket_source));
391 392
392 // Check that an associate was made -- the SOURCE_URL_REQUEST should have 393 // Check that an associate was made -- the SOURCE_HTTP_STREAM_JOB should have
393 // added a reference to the SOURCE_SOCKET. 394 // added a reference to the SOURCE_SOCKET.
394 ASSERT_EQ(1u, GetLiveSources(log.url_request_tracker_).size()); 395 ASSERT_EQ(1u, GetLiveSources(log.http_stream_job_tracker_).size());
395 { 396 {
396 PassiveLogCollector::SourceInfo info = 397 PassiveLogCollector::SourceInfo info =
397 GetLiveSources(log.url_request_tracker_)[0]; 398 GetLiveSources(log.http_stream_job_tracker_)[0];
398 EXPECT_EQ(0, info.reference_count); 399 EXPECT_EQ(0, info.reference_count);
399 EXPECT_EQ(1u, info.dependencies.size()); 400 EXPECT_EQ(1u, info.dependencies.size());
400 EXPECT_EQ(socket_source.id, info.dependencies[0].id); 401 EXPECT_EQ(socket_source.id, info.dependencies[0].id);
401 } 402 }
402 ASSERT_EQ(1u, GetLiveSources(log.socket_tracker_).size()); 403 ASSERT_EQ(1u, GetLiveSources(log.socket_tracker_).size());
403 { 404 {
404 PassiveLogCollector::SourceInfo info = 405 PassiveLogCollector::SourceInfo info =
405 GetLiveSources(log.socket_tracker_)[0]; 406 GetLiveSources(log.socket_tracker_)[0];
406 EXPECT_EQ(1, info.reference_count); 407 EXPECT_EQ(1, info.reference_count);
407 EXPECT_EQ(0u, info.dependencies.size()); 408 EXPECT_EQ(0u, info.dependencies.size());
408 } 409 }
409 410
410 // Add lots of sources to the socket tracker. This is just enough to cause 411 // Add lots of sources to the socket tracker. This is just enough to cause
411 // the tracker to reach its peak, and reset all of its data as a safeguard. 412 // the tracker to reach its peak, and reset all of its data as a safeguard.
412 for (size_t i = 0; i < SocketTracker::kMaxNumSources; ++i) { 413 for (size_t i = 0; i < SocketTracker::kMaxNumSources; ++i) {
413 log.OnAddEntry(NetLog::TYPE_SOCKET_ALIVE, 414 log.OnAddEntry(NetLog::TYPE_SOCKET_ALIVE,
414 base::TimeTicks(), 415 base::TimeTicks(),
415 NetLog::Source(NetLog::SOURCE_SOCKET, next_id++), 416 NetLog::Source(NetLog::SOURCE_SOCKET, next_id++),
416 NetLog::PHASE_BEGIN, 417 NetLog::PHASE_BEGIN,
417 NULL); 418 NULL);
418 } 419 }
419 ASSERT_EQ(1u, GetLiveSources(log.socket_tracker_).size()); 420 ASSERT_EQ(1u, GetLiveSources(log.socket_tracker_).size());
420 421
421 // End the original request. Then saturate the graveyard with enough other 422 // End the original request. Then saturate the graveyard with enough other
422 // requests to cause it to be deleted. Once that source is deleted, it will 423 // requests to cause it to be deleted. Once that source is deleted, it will
423 // try to give up its reference to the SOCKET. However that socket_id no 424 // try to give up its reference to the SOCKET. However that socket_id no
424 // longer exists -- should not DCHECK(). 425 // longer exists -- should not DCHECK().
425 log.OnAddEntry(NetLog::TYPE_REQUEST_ALIVE, 426 log.OnAddEntry(NetLog::TYPE_HTTP_STREAM_JOB,
426 base::TimeTicks(), 427 base::TimeTicks(),
427 url_request_source, 428 stream_job_source,
428 NetLog::PHASE_END, 429 NetLog::PHASE_END,
429 NULL); 430 NULL);
430 for (size_t i = 0; i < RequestTracker::kMaxGraveyardSize; ++i) { 431 for (size_t i = 0; i < HttpStreamJobTracker::kMaxGraveyardSize; ++i) {
431 log.OnAddEntry(NetLog::TYPE_REQUEST_ALIVE, 432 log.OnAddEntry(NetLog::TYPE_HTTP_STREAM_JOB,
432 base::TimeTicks(), 433 base::TimeTicks(),
433 NetLog::Source(NetLog::SOURCE_URL_REQUEST, next_id++), 434 NetLog::Source(NetLog::SOURCE_HTTP_STREAM_JOB, next_id++),
434 NetLog::PHASE_END, 435 NetLog::PHASE_END,
435 NULL); 436 NULL);
436 } 437 }
437 EXPECT_EQ(RequestTracker::kMaxGraveyardSize, 438 EXPECT_EQ(HttpStreamJobTracker::kMaxGraveyardSize,
438 GetDeadSources(log.url_request_tracker_).size()); 439 GetDeadSources(log.http_stream_job_tracker_).size());
439 } 440 }
440 441
441 // Regression test for http://crbug.com/58847 442 // Regression test for http://crbug.com/58847
442 TEST(PassiveLogCollectorTest, ReleaseDependencyToUnreferencedSource) { 443 TEST(PassiveLogCollectorTest, ReleaseDependencyToUnreferencedSource) {
443 PassiveLogCollector log; 444 PassiveLogCollector log;
444 445
445 // If these constants are weird, the test won't be testing the right thing. 446 // If these constants are weird, the test won't be testing the right thing.
446 EXPECT_LT(PassiveLogCollector::RequestTracker::kMaxGraveyardSize, 447 EXPECT_LT(PassiveLogCollector::HttpStreamJobTracker::kMaxGraveyardSize,
447 PassiveLogCollector::RequestTracker::kMaxNumSources); 448 PassiveLogCollector::HttpStreamJobTracker::kMaxNumSources);
448 449
449 // Add a "reference" to a non-existant source (sourceID=1706 does not exist). 450 // Add a "reference" to a non-existant source (sourceID=1263 does not exist).
450 scoped_refptr<net::NetLog::EventParameters> params = 451 scoped_refptr<net::NetLog::EventParameters> params =
451 new net::NetLogSourceParameter( 452 new net::NetLogSourceParameter(
452 "source_dependency", 453 "source_dependency",
453 net::NetLog::Source(net::NetLog::SOURCE_SOCKET, 1263)); 454 net::NetLog::Source(net::NetLog::SOURCE_SOCKET, 1263));
454 log.OnAddEntry(net::NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, 455 log.OnAddEntry(net::NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET,
455 base::TimeTicks(), 456 base::TimeTicks(),
456 net::NetLog::Source(net::NetLog::SOURCE_URL_REQUEST, 1706), 457 net::NetLog::Source(net::NetLog::SOURCE_HTTP_STREAM_JOB, 1706),
457 net::NetLog::PHASE_NONE, 458 net::NetLog::PHASE_NONE,
458 params); 459 params);
459 460
460 // At this point source 1706 has noted 1263 as a dependency. However the 461 // At this point source 1706 has noted 1263 as a dependency. However the
461 // reference count for 1263 was not adjusted since it doesn't actually exist. 462 // reference count for 1263 was not adjusted since it doesn't actually exist.
462 463
463 // Move source 1706 to the graveyard. 464 // Move source 1706 to the graveyard.
464 log.OnAddEntry(net::NetLog::TYPE_REQUEST_ALIVE, 465 log.OnAddEntry(net::NetLog::TYPE_HTTP_STREAM_JOB,
465 base::TimeTicks(), 466 base::TimeTicks(),
466 net::NetLog::Source(net::NetLog::SOURCE_URL_REQUEST, 1706), 467 net::NetLog::Source(net::NetLog::SOURCE_HTTP_STREAM_JOB, 1706),
467 net::NetLog::PHASE_END, 468 net::NetLog::PHASE_END,
468 NULL); 469 NULL);
469 470
470 // Now create a source entry for 1263, such that it is unreferenced and 471 // Now create a source entry for 1263, such that it is unreferenced and
471 // waiting to be garbage collected. 472 // waiting to be garbage collected.
472 log.OnAddEntry(net::NetLog::TYPE_SOCKET_ALIVE, 473 log.OnAddEntry(net::NetLog::TYPE_SOCKET_ALIVE,
473 base::TimeTicks(), 474 base::TimeTicks(),
474 net::NetLog::Source(net::NetLog::SOURCE_SOCKET, 1263), 475 net::NetLog::Source(net::NetLog::SOURCE_SOCKET, 1263),
475 net::NetLog::PHASE_END, NULL); 476 net::NetLog::PHASE_END, NULL);
476 477
477 // Add kMaxGraveyardSize unreferenced URL_REQUESTS, so the circular buffer 478 // Add kMaxGraveyardSize unreferenced HTTP_STREAM_JOBS, so the circular
478 // containing source 1706. After adding kMaxGraveyardSize - 1 the buffer 479 // buffer containing source 1706. After adding kMaxGraveyardSize - 1 the
479 // will be full. Now when we add one more more source it will now evict the 480 // buffer will be full. Now when we add one more more source it will now evict
480 // oldest item, which is 1706. In doing so, 1706 will try to release the 481 // the oldest item, which is 1706. In doing so, 1706 will try to release the
481 // reference it *thinks* it has on 1263. However 1263 has a reference count 482 // reference it *thinks* it has on 1263. However 1263 has a reference count
482 // of 0 and is already in a graveyard. 483 // of 0 and is already in a graveyard.
483 for (size_t i = 0; 484 for (size_t i = 0;
484 i < PassiveLogCollector::RequestTracker::kMaxGraveyardSize; ++i) { 485 i < PassiveLogCollector::HttpStreamJobTracker::kMaxGraveyardSize; ++i) {
485 log.OnAddEntry(net::NetLog::TYPE_REQUEST_ALIVE, 486 log.OnAddEntry(net::NetLog::TYPE_HTTP_STREAM_JOB,
486 base::TimeTicks(), 487 base::TimeTicks(),
487 net::NetLog::Source(net::NetLog::SOURCE_URL_REQUEST, i), 488 net::NetLog::Source(net::NetLog::SOURCE_HTTP_STREAM_JOB, i),
488 net::NetLog::PHASE_END, 489 net::NetLog::PHASE_END,
489 NULL); 490 NULL);
490 } 491 }
491 492
492 // To pass, this should simply not have DCHECK-ed above. 493 // To pass, this should simply not have DCHECK-ed above.
493 } 494 }
494
OLDNEW
« no previous file with comments | « chrome/browser/net/passive_log_collector.cc ('k') | chrome/browser/resources/net_internals/sourceentry.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698