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/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" |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
431 log.OnAddEntry(NetLog::TYPE_REQUEST_ALIVE, | 431 log.OnAddEntry(NetLog::TYPE_REQUEST_ALIVE, |
432 base::TimeTicks(), | 432 base::TimeTicks(), |
433 NetLog::Source(NetLog::SOURCE_URL_REQUEST, next_id++), | 433 NetLog::Source(NetLog::SOURCE_URL_REQUEST, next_id++), |
434 NetLog::PHASE_END, | 434 NetLog::PHASE_END, |
435 NULL); | 435 NULL); |
436 } | 436 } |
437 EXPECT_EQ(RequestTracker::kMaxGraveyardSize, | 437 EXPECT_EQ(RequestTracker::kMaxGraveyardSize, |
438 GetDeadSources(log.url_request_tracker_).size()); | 438 GetDeadSources(log.url_request_tracker_).size()); |
439 } | 439 } |
440 | 440 |
441 // Regression test for http://crbug.com/58847 | |
442 TEST(PassiveLogCollectorTest, ReleaseDependencyToUnreferencedSource) { | |
443 PassiveLogCollector x; | |
mmenke
2010/11/15 16:21:52
nit: You're undoubtedly more familiar with Google
eroman
2010/11/15 19:28:10
Done.
You are right, |x| is a bad name. (carry ov
| |
444 | |
445 // If these constants are weird, the test won't be testing the right thing. | |
446 EXPECT_LT(PassiveLogCollector::RequestTracker::kMaxGraveyardSize, | |
447 PassiveLogCollector::RequestTracker::kMaxNumSources); | |
448 | |
449 // Add a "reference" to a non-existant source (sourceID=1706 does not exist). | |
450 scoped_refptr<net::NetLog::EventParameters> params = | |
451 new net::NetLogSourceParameter( | |
452 "source_dependency", | |
453 net::NetLog::Source(net::NetLog::SOURCE_SOCKET, 1263)); | |
454 x.OnAddEntry(net::NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, | |
455 base::TimeTicks(), | |
456 net::NetLog::Source(net::NetLog::SOURCE_URL_REQUEST, 1706), | |
457 net::NetLog::PHASE_NONE, | |
458 params); | |
459 | |
460 // 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 | |
463 // Move source 1706 to the graveyard. | |
464 x.OnAddEntry(net::NetLog::TYPE_REQUEST_ALIVE, | |
465 base::TimeTicks(), | |
466 net::NetLog::Source(net::NetLog::SOURCE_URL_REQUEST, 1706), | |
467 net::NetLog::PHASE_END, | |
468 NULL); | |
469 | |
470 // Now create a source entry for 1263, such that it is unreferenced and | |
471 // waiting to be garbage collected. | |
472 x.OnAddEntry(net::NetLog::TYPE_SOCKET_ALIVE, | |
473 base::TimeTicks(), | |
474 net::NetLog::Source(net::NetLog::SOURCE_SOCKET, 1263), | |
475 net::NetLog::PHASE_END, NULL); | |
476 | |
477 // Add kMaxGraveyardSize unreferenced URL_REQUESTS, so the circular buffer | |
478 // containing source 1706. After adding kMaxGraveyardSize - 1 the buffer | |
479 // will be full. Now when we add one more more source it will now evict the | |
480 // 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 // of 0 and is already in a graveyard. | |
483 for (size_t i = 0; | |
484 i < PassiveLogCollector::RequestTracker::kMaxGraveyardSize; ++i) { | |
485 x.OnAddEntry(net::NetLog::TYPE_REQUEST_ALIVE, | |
486 base::TimeTicks(), | |
487 net::NetLog::Source(net::NetLog::SOURCE_URL_REQUEST, i), | |
488 net::NetLog::PHASE_END, | |
489 NULL); | |
490 } | |
491 | |
492 // To pass, this should simply not have DCHECK-ed above. | |
493 } | |
494 | |
OLD | NEW |