diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-06 19:59:36 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-06 19:59:36 +0000 |
commit | 60c4c41ce3ed1fa0697daf274233d84febf6233c (patch) | |
tree | 7b6bfe29f7b6526b4c63ce49ab7a7ffcd20d3bbf /net | |
parent | 3203c5e35bba5266fe1d149875c3a9815ee9c214 (diff) | |
download | chromium_src-60c4c41ce3ed1fa0697daf274233d84febf6233c.zip chromium_src-60c4c41ce3ed1fa0697daf274233d84febf6233c.tar.gz chromium_src-60c4c41ce3ed1fa0697daf274233d84febf6233c.tar.bz2 |
Improve the display of LoadLogs when truncation occurs.
Rather than drop all subsequent entries, we now preserve the final entry that was appended to the log.
This way, even if entries have been dropped, we can still infer what the total time was, and what the exit condition was.
Also makes LoadLog take the bound as a required parameter.
BUG=none
TEST=LoadLogUtilTest.DisplayOfTruncated
Review URL: http://codereview.chromium.org/363025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31274 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
21 files changed, 180 insertions, 108 deletions
diff --git a/net/base/host_resolver_impl_unittest.cc b/net/base/host_resolver_impl_unittest.cc index 63e06a7..1ec38b2 100644 --- a/net/base/host_resolver_impl_unittest.cc +++ b/net/base/host_resolver_impl_unittest.cc @@ -30,8 +30,8 @@ namespace net { namespace { -static const int kMaxCacheEntries = 100; -static const int kMaxCacheAgeMs = 60000; +const int kMaxCacheEntries = 100; +const int kMaxCacheAgeMs = 60000; // A variant of WaitingHostResolverProc that pushes each host mapped into a // list. @@ -189,7 +189,7 @@ TEST_F(HostResolverImplTest, SynchronousLookup) { new HostResolverImpl(resolver_proc, kMaxCacheEntries, kMaxCacheAgeMs)); HostResolver::RequestInfo info("just.testing", kPortnum); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); int err = host_resolver->Resolve(info, &adrlist, NULL, NULL, log); EXPECT_EQ(OK, err); @@ -221,7 +221,7 @@ TEST_F(HostResolverImplTest, AsynchronousLookup) { new HostResolverImpl(resolver_proc, kMaxCacheEntries, kMaxCacheAgeMs)); HostResolver::RequestInfo info("just.testing", kPortnum); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); int err = host_resolver->Resolve(info, &adrlist, &callback_, NULL, log); EXPECT_EQ(ERR_IO_PENDING, err); @@ -252,7 +252,7 @@ TEST_F(HostResolverImplTest, CanceledAsynchronousLookup) { scoped_refptr<WaitingHostResolverProc> resolver_proc = new WaitingHostResolverProc(NULL); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); { scoped_refptr<HostResolver> host_resolver( new HostResolverImpl(resolver_proc, kMaxCacheEntries, kMaxCacheAgeMs)); @@ -822,7 +822,7 @@ TEST_F(HostResolverImplTest, Observers) { // Resolve "host1". HostResolver::RequestInfo info1("host1", 70); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); int rv = host_resolver->Resolve(info1, &addrlist, NULL, NULL, log); EXPECT_EQ(OK, rv); diff --git a/net/base/load_log.cc b/net/base/load_log.cc index 42b1b85f..451d4e3 100644 --- a/net/base/load_log.cc +++ b/net/base/load_log.cc @@ -3,10 +3,13 @@ // found in the LICENSE file. #include "net/base/load_log.h" +#include "base/logging.h" namespace net { -LoadLog::LoadLog() { +LoadLog::LoadLog(size_t max_num_entries) + : num_entries_truncated_(0), max_num_entries_(max_num_entries) { + DCHECK_GT(max_num_entries, 0u); } // static @@ -22,20 +25,24 @@ const char* LoadLog::EventTypeToString(EventType event) { void LoadLog::Add(const Event& event) { // Minor optimization. TODO(eroman): use StackVector instead. if (events_.empty()) - events_.reserve(kMaxNumEntries / 2); + events_.reserve(10); // It is likely we will have at least 10 entries. - // Enforce a bound of kMaxNumEntries -- when we reach it, make it so the - // final entry in the list is |TYPE_LOG_TRUNCATED|. + // Enforce a bound of |max_num_entries_| -- once we reach it, keep overwriting + // the final entry in the log. - if (events_.size() + 1 == kMaxNumEntries) - events_.push_back(Event(event.time, TYPE_LOG_TRUNCATED, PHASE_NONE)); - else if (events_.size() < kMaxNumEntries) + if (events_.size() + 1 <= max_num_entries_ || + max_num_entries_ == kUnbounded) { events_.push_back(event); + } else { + num_entries_truncated_ += 1; + events_[max_num_entries_ - 1] = event; + } } void LoadLog::Append(const LoadLog* log) { for (size_t i = 0; i < log->events().size(); ++i) Add(log->events()[i]); + num_entries_truncated_ += log->num_entries_truncated(); } } // namespace net diff --git a/net/base/load_log.h b/net/base/load_log.h index 7ee5185..3f433ac 100644 --- a/net/base/load_log.h +++ b/net/base/load_log.h @@ -19,7 +19,6 @@ namespace net { // that it can be AddRef() / Release() across threads. class LoadLog : public base::RefCountedThreadSafe<LoadLog> { public: - enum EventType { #define EVENT_TYPE(label) TYPE_ ## label, #include "net/base/load_log_event_type_list.h" @@ -48,18 +47,20 @@ class LoadLog : public base::RefCountedThreadSafe<LoadLog> { EventPhase phase; }; - // The maximum size of |events_|. - enum { kMaxNumEntries = 40 }; - // Ordered set of events that were logged. // TODO(eroman): use a StackVector or array to avoid allocations. typedef std::vector<Event> EventList; - // Create a log, which can hold up to |kMaxNumEntries| Events. + // Value for max_num_entries to indicate the LoadLog has no size limit. + static const size_t kUnbounded = static_cast<size_t>(-1); + + // Creates a log, which can hold up to |max_num_entries| Events. + // If |max_num_entries| is |kUnbounded|, then the log can grow arbitrarily + // large. // - // If events are dropped because the log has grown too large, the final - // entry will be of type kLogTruncated. - LoadLog(); + // If events are dropped because the log has grown too large, the final entry + // will be overwritten. + explicit LoadLog(size_t max_num_entries); // -------------------------------------------------------------------------- @@ -93,6 +94,17 @@ class LoadLog : public base::RefCountedThreadSafe<LoadLog> { return events_; } + // Returns the number of entries that were dropped from the log because the + // maximum size had been reached. + size_t num_entries_truncated() const { + return num_entries_truncated_; + } + + // Returns the bound on the size of the log. + size_t max_num_entries() const { + return max_num_entries_; + } + // Returns a C-String symbolic name for |event|. static const char* EventTypeToString(EventType event); @@ -111,6 +123,8 @@ class LoadLog : public base::RefCountedThreadSafe<LoadLog> { ~LoadLog() {} EventList events_; + size_t num_entries_truncated_; + size_t max_num_entries_;; }; } // namespace net diff --git a/net/base/load_log_event_type_list.h b/net/base/load_log_event_type_list.h index f17bfb9..2fcf294 100644 --- a/net/base/load_log_event_type_list.h +++ b/net/base/load_log_event_type_list.h @@ -9,10 +9,6 @@ // General pseudo-events // -------------------------------------------------------------------------- -// If a log is terminated by a kLogTruncated event, then it grew too large -// and any subsequent events logged to it were discarded. -EVENT_TYPE(LOG_TRUNCATED) - // Something got cancelled (we determine what is cancelled based on the // log context around it.) EVENT_TYPE(CANCELLED) diff --git a/net/base/load_log_unittest.cc b/net/base/load_log_unittest.cc index 81ccac9..a3db7bb 100644 --- a/net/base/load_log_unittest.cc +++ b/net/base/load_log_unittest.cc @@ -18,10 +18,11 @@ TEST(LoadLogTest, Nullable) { } TEST(LoadLogTest, Basic) { - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(10)); // Logs start off empty. EXPECT_EQ(0u, log->events().size()); + EXPECT_EQ(0u, log->num_entries_truncated()); // Add 3 entries. @@ -31,6 +32,7 @@ TEST(LoadLogTest, Basic) { LoadLog::PHASE_END); EXPECT_EQ(3u, log->events().size()); + EXPECT_EQ(0u, log->num_entries_truncated()); ExpectLogContains(log, 0, MakeTime(0), LoadLog::TYPE_HOST_RESOLVER_IMPL, LoadLog::PHASE_BEGIN); @@ -45,32 +47,39 @@ TEST(LoadLogTest, Basic) { // Test that the log's size is strictly bounded. TEST(LoadLogTest, Truncation) { - scoped_refptr<LoadLog> log(new LoadLog); + size_t kMaxNumEntries = 10; + scoped_refptr<LoadLog> log(new LoadLog(kMaxNumEntries)); - // Almost max it out. - for (size_t i = 0; i < LoadLog::kMaxNumEntries - 1; ++i) { - log->Add(MakeTime(0), LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE); + // Max it out. + for (size_t i = 0; i < kMaxNumEntries; ++i) { + log->Add(MakeTime(i), LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE); } - EXPECT_EQ(LoadLog::kMaxNumEntries - 1, - static_cast<int>(log->events().size())); - EXPECT_EQ(LoadLog::TYPE_CANCELLED, - log->events()[LoadLog::kMaxNumEntries - 2].type); - // Max it out (none of these get appended to the log). - log->Add(MakeTime(0), LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE); - log->Add(MakeTime(0), LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE); + EXPECT_EQ(kMaxNumEntries, log->events().size()); + EXPECT_EQ(0u, log->num_entries_truncated()); + + // Check the last entry. + ExpectLogContains(log, 9, MakeTime(9), + LoadLog::TYPE_CANCELLED, + LoadLog::PHASE_NONE); + + // Add three entries while maxed out (will cause truncation) log->Add(MakeTime(0), LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE); + log->Add(MakeTime(1), LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE); + log->Add(MakeTime(2), LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE); - EXPECT_EQ(LoadLog::kMaxNumEntries, log->events().size()); + EXPECT_EQ(kMaxNumEntries, log->events().size()); + EXPECT_EQ(3u, log->num_entries_truncated()); - // We terminated with a "truncation" event. - ExpectLogContains(log, LoadLog::kMaxNumEntries - 1, MakeTime(0), - LoadLog::TYPE_LOG_TRUNCATED, LoadLog::PHASE_NONE); + // Check the last entry -- it should be the final entry we added. + ExpectLogContains(log, 9, MakeTime(2), + LoadLog::TYPE_CANCELLED, + LoadLog::PHASE_NONE); } TEST(LoadLogTest, Append) { - scoped_refptr<LoadLog> log1(new LoadLog); - scoped_refptr<LoadLog> log2(new LoadLog); + scoped_refptr<LoadLog> log1(new LoadLog(10)); + scoped_refptr<LoadLog> log2(new LoadLog(10)); log1->Add(MakeTime(0), LoadLog::TYPE_HOST_RESOLVER_IMPL, LoadLog::PHASE_BEGIN); @@ -84,6 +93,7 @@ TEST(LoadLogTest, Append) { log2->Add(MakeTime(19), LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE); EXPECT_EQ(3u, log1->events().size()); + EXPECT_EQ(0u, log1->num_entries_truncated()); ExpectLogContains(log1, 0, MakeTime(0), LoadLog::TYPE_HOST_RESOLVER_IMPL, LoadLog::PHASE_BEGIN); @@ -99,22 +109,25 @@ TEST(LoadLogTest, AppendWithTruncation) { // Append() should also respect the maximum number of entries bound. // (This is basically the same test as LoadLogTest.Truncation). - // Create two load logs, which are 2/3 capcity. - scoped_refptr<LoadLog> log1(new LoadLog); - scoped_refptr<LoadLog> log2(new LoadLog); - for (size_t i = 0; i < 2 * LoadLog::kMaxNumEntries / 3; ++i) { - log1->Add(MakeTime(1), LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE); - log2->Add(MakeTime(2), LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE); + // Create two load logs, which both have 6 out of 10 entries filled. + size_t kMaxNumEntries = 10; + scoped_refptr<LoadLog> log1(new LoadLog(kMaxNumEntries)); + scoped_refptr<LoadLog> log2(new LoadLog(kMaxNumEntries)); + for (size_t i = 0; i < 6; ++i) { + log1->Add(MakeTime(i), LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE); + log2->Add(MakeTime(2 * i), LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE); } // Append log2 to log1. log1->Append(log2); - EXPECT_EQ(LoadLog::kMaxNumEntries, log1->events().size()); + // The combined log totalled 12 entries, so 2 must have been dropped. + EXPECT_EQ(10u, log1->events().size()); + EXPECT_EQ(2u, log1->num_entries_truncated()); - // We terminated with a "truncation" event. - ExpectLogContains(log1, LoadLog::kMaxNumEntries - 1, MakeTime(2), - LoadLog::TYPE_LOG_TRUNCATED, LoadLog::PHASE_NONE); + // Combined log should end with the final entry of log2. + ExpectLogContains(log1, 9, MakeTime(10), LoadLog::TYPE_CANCELLED, + LoadLog::PHASE_NONE); } TEST(LoadLogTest, EventTypeToString) { diff --git a/net/base/load_log_util.cc b/net/base/load_log_util.cc index 28304d0..c9de440f 100644 --- a/net/base/load_log_util.cc +++ b/net/base/load_log_util.cc @@ -33,6 +33,11 @@ class FormatHelper { if (i > 0) result += "\n"; + if (log->num_entries_truncated() > 0 && i + 1 == entries_.size()) { + result += StringPrintf(" ... Truncated %d entries ...\n", + log->num_entries_truncated()); + } + int indentation_spaces = entries_[i].indentation * kSpacesPerIndentation; std::string event_str = GetEventString(i); diff --git a/net/base/load_log_util_unittest.cc b/net/base/load_log_util_unittest.cc index fbaa77b..4766a86f 100644 --- a/net/base/load_log_util_unittest.cc +++ b/net/base/load_log_util_unittest.cc @@ -10,7 +10,7 @@ namespace net { namespace { TEST(LoadLogUtilTest, Basic) { - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(10)); log->Add(MakeTime(1), LoadLog::TYPE_HOST_RESOLVER_IMPL, LoadLog::PHASE_BEGIN); log->Add(MakeTime(5), LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART, @@ -30,7 +30,7 @@ TEST(LoadLogUtilTest, Basic) { } TEST(LoadLogUtilTest, UnmatchedOpen) { - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(10)); log->Add(MakeTime(3), LoadLog::TYPE_HOST_RESOLVER_IMPL, LoadLog::PHASE_BEGIN); // Note that there is no matching call to PHASE_END for all of the following. @@ -53,5 +53,26 @@ TEST(LoadLogUtilTest, UnmatchedOpen) { LoadLogUtil::PrettyPrintAsEventTree(log)); } +TEST(LoadLogUtilTest, DisplayOfTruncated) { + size_t kMaxNumEntries = 5; + scoped_refptr<LoadLog> log(new LoadLog(kMaxNumEntries)); + + // Add a total of 10 events. This means that 5 will be truncated. + log->Add(MakeTime(0), LoadLog::TYPE_TCP_CONNECT, LoadLog::PHASE_BEGIN); + for (size_t i = 1; i < 8; ++i) { + log->Add(MakeTime(i), LoadLog::TYPE_CANCELLED, LoadLog::PHASE_NONE); + } + log->Add(MakeTime(9), LoadLog::TYPE_TCP_CONNECT, LoadLog::PHASE_END); + + EXPECT_EQ( + "t=0: +TCP_CONNECT [dt=9]\n" + "t=1: CANCELLED\n" + "t=2: CANCELLED\n" + "t=3: CANCELLED\n" + " ... Truncated 4 entries ...\n" + "t=9: -TCP_CONNECT", + LoadLogUtil::PrettyPrintAsEventTree(log)); +} + } // namespace } // namespace net diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc index fd66e79..0378ca0 100644 --- a/net/http/http_cache_unittest.cc +++ b/net/http/http_cache_unittest.cc @@ -784,7 +784,7 @@ TEST(HttpCache, SimpleGETNoDiskCache) { cache.disk_cache()->set_fail_requests(); - scoped_refptr<net::LoadLog> log(new net::LoadLog); + scoped_refptr<net::LoadLog> log(new net::LoadLog(net::LoadLog::kUnbounded)); // Read from the network, and don't use the cache. RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, log); @@ -867,7 +867,7 @@ TEST(HttpCache, SimpleGETWithDiskFailures2) { TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) { MockHttpCache cache; - scoped_refptr<net::LoadLog> log(new net::LoadLog); + scoped_refptr<net::LoadLog> log(new net::LoadLog(net::LoadLog::kUnbounded)); // write to the cache RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction, log); @@ -891,7 +891,7 @@ TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) { MockTransaction transaction(kSimpleGET_Transaction); transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; - log = new net::LoadLog; + log = new net::LoadLog(net::LoadLog::kUnbounded); RunTransactionTestWithLog(cache.http_cache(), transaction, log); diff --git a/net/proxy/init_proxy_resolver_unittest.cc b/net/proxy/init_proxy_resolver_unittest.cc index e9d05a2..680a870 100644 --- a/net/proxy/init_proxy_resolver_unittest.cc +++ b/net/proxy/init_proxy_resolver_unittest.cc @@ -171,7 +171,7 @@ TEST(InitProxyResolverTest, CustomPacSucceeds) { Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); TestCompletionCallback callback; - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); InitProxyResolver init(&resolver, &fetcher); EXPECT_EQ(OK, init.Init(config, &callback, log)); EXPECT_EQ(rule.bytes(), resolver.pac_bytes()); @@ -204,7 +204,7 @@ TEST(InitProxyResolverTest, CustomPacFails1) { rules.AddFailDownloadRule("http://custom/proxy.pac"); TestCompletionCallback callback; - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); InitProxyResolver init(&resolver, &fetcher); EXPECT_EQ(kFailedDownloading, init.Init(config, &callback, log)); EXPECT_EQ("", resolver.pac_bytes()); @@ -288,7 +288,7 @@ TEST(InitProxyResolverTest, AutodetectFailCustomSuccess2) { Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); TestCompletionCallback callback; - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); InitProxyResolver init(&resolver, &fetcher); EXPECT_EQ(OK, init.Init(config, &callback, log)); EXPECT_EQ(rule.bytes(), resolver.pac_bytes()); diff --git a/net/proxy/proxy_resolver_v8_unittest.cc b/net/proxy/proxy_resolver_v8_unittest.cc index 550426a..54830bf 100644 --- a/net/proxy/proxy_resolver_v8_unittest.cc +++ b/net/proxy/proxy_resolver_v8_unittest.cc @@ -118,7 +118,7 @@ TEST(ProxyResolverV8Test, Direct) { EXPECT_EQ(OK, result); ProxyInfo proxy_info; - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, log); EXPECT_EQ(OK, result); @@ -423,7 +423,7 @@ TEST(ProxyResolverV8Test, LoadLog) { EXPECT_EQ(OK, result); ProxyInfo proxy_info; - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, log); EXPECT_EQ(OK, result); @@ -459,7 +459,7 @@ TEST(ProxyResolverV8Test, EndsWithCommentNoNewline) { EXPECT_EQ(OK, result); ProxyInfo proxy_info; - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, log); EXPECT_EQ(OK, result); @@ -478,7 +478,7 @@ TEST(ProxyResolverV8Test, EndsWithStatementNoNewline) { EXPECT_EQ(OK, result); ProxyInfo proxy_info; - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, log); EXPECT_EQ(OK, result); diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc index 91a6133..0177b75 100644 --- a/net/proxy/proxy_service.cc +++ b/net/proxy/proxy_service.cc @@ -36,6 +36,8 @@ using base::TimeTicks; namespace net { +static const size_t kMaxNumLoadLogEntries = 100; + // Config getter that fails every time. class ProxyConfigServiceNull : public ProxyConfigService { public: @@ -630,7 +632,7 @@ void ProxyService::SetConfig(const ProxyConfig& config) { init_proxy_resolver_.reset( new InitProxyResolver(resolver_.get(), proxy_script_fetcher_.get())); - init_proxy_resolver_log_ = new LoadLog; + init_proxy_resolver_log_ = new LoadLog(kMaxNumLoadLogEntries); int rv = init_proxy_resolver_->Init( config_, &init_proxy_resolver_callback_, init_proxy_resolver_log_); diff --git a/net/proxy/proxy_service_unittest.cc b/net/proxy/proxy_service_unittest.cc index a7500f4..72faf17 100644 --- a/net/proxy/proxy_service_unittest.cc +++ b/net/proxy/proxy_service_unittest.cc @@ -95,7 +95,7 @@ TEST(ProxyServiceTest, Direct) { ProxyInfo info; TestCompletionCallback callback; - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); int rv = service->ResolveProxy(url, &info, &callback, NULL, log); EXPECT_EQ(OK, rv); EXPECT_TRUE(resolver->pending_requests().empty()); @@ -122,7 +122,7 @@ TEST(ProxyServiceTest, PAC) { ProxyInfo info; TestCompletionCallback callback; - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); int rv = service->ResolveProxy(url, &info, &callback, NULL, log); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -1020,7 +1020,7 @@ TEST(ProxyServiceTest, CancelWhilePACFetching) { ProxyInfo info1; TestCompletionCallback callback1; ProxyService::PacRequest* request1; - scoped_refptr<LoadLog> log1(new LoadLog); + scoped_refptr<LoadLog> log1(new LoadLog(LoadLog::kUnbounded)); int rv = service->ResolveProxy( GURL("http://request1"), &info1, &callback1, &request1, log1); EXPECT_EQ(ERR_IO_PENDING, rv); diff --git a/net/proxy/single_threaded_proxy_resolver.cc b/net/proxy/single_threaded_proxy_resolver.cc index ad5fdba..5de2865 100644 --- a/net/proxy/single_threaded_proxy_resolver.cc +++ b/net/proxy/single_threaded_proxy_resolver.cc @@ -125,9 +125,12 @@ class SingleThreadedProxyResolver::Job void Start() { is_started_ = true; + size_t load_log_bound = load_log_ ? load_log_->max_num_entries() : 0; + coordinator_->thread()->message_loop()->PostTask( FROM_HERE, NewRunnableMethod(this, &Job::DoQuery, - coordinator_->resolver_.get())); + coordinator_->resolver_.get(), + load_log_bound)); } bool is_started() const { return is_started_; } @@ -149,9 +152,12 @@ class SingleThreadedProxyResolver::Job ~Job() {} // Runs on the worker thread. - void DoQuery(ProxyResolver* resolver) { - LoadLog* worker_log = new LoadLog; - worker_log->AddRef(); // Balanced in QueryComplete. + void DoQuery(ProxyResolver* resolver, size_t load_log_bound) { + LoadLog* worker_log = NULL; + if (load_log_bound > 0) { + worker_log = new LoadLog(load_log_bound); + worker_log->AddRef(); // Balanced in QueryComplete. + } int rv = resolver->GetProxyForURL(url_, &results_buf_, NULL, NULL, worker_log); @@ -165,9 +171,11 @@ class SingleThreadedProxyResolver::Job void QueryComplete(int result_code, LoadLog* worker_log) { // Merge the load log that was generated on the worker thread, into the // main log. - if (load_log_) - load_log_->Append(worker_log); - worker_log->Release(); + if (worker_log) { + if (load_log_) + load_log_->Append(worker_log); + worker_log->Release(); + } // The Job may have been cancelled after it was started. if (!was_cancelled()) { diff --git a/net/proxy/single_threaded_proxy_resolver_unittest.cc b/net/proxy/single_threaded_proxy_resolver_unittest.cc index 37bf14a..72cd8ee 100644 --- a/net/proxy/single_threaded_proxy_resolver_unittest.cc +++ b/net/proxy/single_threaded_proxy_resolver_unittest.cc @@ -155,7 +155,7 @@ TEST(SingleThreadedProxyResolverTest, Basic) { // Start request 0. TestCompletionCallback callback0; - scoped_refptr<LoadLog> log0(new LoadLog); + scoped_refptr<LoadLog> log0(new LoadLog(LoadLog::kUnbounded)); ProxyInfo results0; rv = resolver->GetProxyForURL( GURL("http://request0"), &results0, &callback0, NULL, log0); diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc index 1dc1180..9413005 100644 --- a/net/socket/client_socket_pool_base.cc +++ b/net/socket/client_socket_pool_base.cc @@ -24,6 +24,9 @@ namespace { // some conditions. See http://crbug.com/4606. const int kCleanupInterval = 10; // DO NOT INCREASE THIS TIMEOUT. +// The maximum size of the ConnectJob's LoadLog. +const int kMaxNumLoadLogEntries = 50; + } // namespace namespace net { @@ -199,7 +202,7 @@ int ClientSocketPoolBaseHelper::RequestSocket( // If we aren't using late binding, the job lines up with a request so // just write directly into the request's LoadLog. scoped_refptr<LoadLog> job_load_log = g_late_binding ? - new LoadLog : request->load_log(); + new LoadLog(kMaxNumLoadLogEntries) : request->load_log(); scoped_ptr<ConnectJob> connect_job( connect_job_factory_->NewConnectJob(group_name, *request, this, diff --git a/net/socket/client_socket_pool_base_unittest.cc b/net/socket/client_socket_pool_base_unittest.cc index 437db55..1aa25c2 100644 --- a/net/socket/client_socket_pool_base_unittest.cc +++ b/net/socket/client_socket_pool_base_unittest.cc @@ -470,7 +470,7 @@ TEST_F(ClientSocketPoolBaseTest, ConnectJob_NoTimeoutOnSynchronousCompletion) { TEST_F(ClientSocketPoolBaseTest, ConnectJob_TimedOut) { TestConnectJobDelegate delegate; ClientSocketHandle ignored; - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); TestClientSocketPoolBase::Request request( &ignored, NULL, kDefaultPriority, NULL, NULL); // Deleted by TestConnectJobDelegate. @@ -500,7 +500,7 @@ TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) { TestCompletionCallback callback; ClientSocketHandle handle; - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); EXPECT_EQ(OK, InitHandle(&handle, "a", kDefaultPriority, &callback, pool_.get(), log)); EXPECT_TRUE(handle.is_initialized()); @@ -520,7 +520,7 @@ TEST_F(ClientSocketPoolBaseTest, BasicAsynchronous) { CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); TestSocketRequest req(&request_order_, &completion_count_); int rv = InitHandle(req.handle(), "a", 0, &req, pool_.get(), log); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -543,7 +543,7 @@ TEST_F(ClientSocketPoolBaseTest, InitConnectionFailure) { CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); TestSocketRequest req(&request_order_, &completion_count_); EXPECT_EQ(ERR_CONNECTION_FAILED, InitHandle(req.handle(), "a", kDefaultPriority, &req, @@ -562,7 +562,7 @@ TEST_F(ClientSocketPoolBaseTest, InitConnectionAsynchronousFailure) { CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); TestSocketRequest req(&request_order_, &completion_count_); EXPECT_EQ(ERR_IO_PENDING, InitHandle(req.handle(), "a", kDefaultPriority, &req, @@ -1296,7 +1296,7 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, BasicSynchronous) { TestCompletionCallback callback; ClientSocketHandle handle; - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); EXPECT_EQ(OK, InitHandle(&handle, "a", kDefaultPriority, &callback, pool_.get(), log)); EXPECT_TRUE(handle.is_initialized()); @@ -1317,7 +1317,7 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, BasicAsynchronous) { connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); TestSocketRequest req(&request_order_, &completion_count_); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); int rv = InitHandle(req.handle(), "a", 0, &req, pool_.get(), log); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle())); @@ -1344,7 +1344,7 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, InitConnectionFailure) { connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); TestSocketRequest req(&request_order_, &completion_count_); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); EXPECT_EQ(ERR_CONNECTION_FAILED, InitHandle(req.handle(), "a", kDefaultPriority, &req, pool_.get(), log)); @@ -1364,7 +1364,7 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); TestSocketRequest req(&request_order_, &completion_count_); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); EXPECT_EQ(ERR_IO_PENDING, InitHandle(req.handle(), "a", kDefaultPriority, &req, pool_.get(), log)); @@ -1455,11 +1455,11 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, TwoRequestsCancelOne) { TestSocketRequest req(&request_order_, &completion_count_); TestSocketRequest req2(&request_order_, &completion_count_); - scoped_refptr<LoadLog> log1(new LoadLog); + scoped_refptr<LoadLog> log1(new LoadLog(LoadLog::kUnbounded)); EXPECT_EQ(ERR_IO_PENDING, InitHandle(req.handle(), "a", kDefaultPriority, &req, pool_.get(), log1)); - scoped_refptr<LoadLog> log2(new LoadLog); + scoped_refptr<LoadLog> log2(new LoadLog(LoadLog::kUnbounded)); EXPECT_EQ(ERR_IO_PENDING, InitHandle(req2.handle(), "a", kDefaultPriority, &req2, pool_.get(), log2)); diff --git a/net/socket/socks5_client_socket_unittest.cc b/net/socket/socks5_client_socket_unittest.cc index 1b079e7..8981ab8 100644 --- a/net/socket/socks5_client_socket_unittest.cc +++ b/net/socket/socks5_client_socket_unittest.cc @@ -114,7 +114,7 @@ TEST_F(SOCKS5ClientSocketTest, CompleteHandshake) { EXPECT_TRUE(tcp_sock_->IsConnected()); EXPECT_FALSE(user_sock_->IsConnected()); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); int rv = user_sock_->Connect(&callback_, log); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(user_sock_->IsConnected()); @@ -171,7 +171,7 @@ TEST_F(SOCKS5ClientSocketTest, FailedDNS) { user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80)); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); int rv = user_sock_->Connect(&callback_, log); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_TRUE(LogContains( @@ -208,7 +208,7 @@ TEST_F(SOCKS5ClientSocketTest, IPv6Domain) { user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80)); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); int rv = user_sock_->Connect(&callback_, log); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_TRUE(LogContains( @@ -237,7 +237,7 @@ TEST_F(SOCKS5ClientSocketTest, PartialReadWrites) { MockRead(true, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), MockRead(true, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)) }; user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80)); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); int rv = user_sock_->Connect(&callback_, log); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_TRUE(LogContains( @@ -261,7 +261,7 @@ TEST_F(SOCKS5ClientSocketTest, PartialReadWrites) { MockRead(true, partial2, arraysize(partial2)), MockRead(true, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)) }; user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80)); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); int rv = user_sock_->Connect(&callback_, log); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_TRUE(LogContains( @@ -285,7 +285,7 @@ TEST_F(SOCKS5ClientSocketTest, PartialReadWrites) { MockRead(true, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), MockRead(true, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)) }; user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80)); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); int rv = user_sock_->Connect(&callback_, log); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_TRUE(LogContains( @@ -309,7 +309,7 @@ TEST_F(SOCKS5ClientSocketTest, PartialReadWrites) { MockRead(true, partial1, arraysize(partial1)), MockRead(true, partial2, arraysize(partial2)) }; user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80)); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); int rv = user_sock_->Connect(&callback_, log); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_TRUE(LogContains( diff --git a/net/socket/socks_client_socket_unittest.cc b/net/socket/socks_client_socket_unittest.cc index 56d84a8..6b5c0fb 100644 --- a/net/socket/socks_client_socket_unittest.cc +++ b/net/socket/socks_client_socket_unittest.cc @@ -93,7 +93,7 @@ TEST_F(SOCKSClientSocketTest, CompleteHandshake) { EXPECT_TRUE(tcp_sock_->IsConnected()); EXPECT_FALSE(user_sock_->IsConnected()); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); int rv = user_sock_->Connect(&callback_, log); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_TRUE( @@ -154,7 +154,7 @@ TEST_F(SOCKSClientSocketTest, HandshakeFailures) { MockRead(false, tests[i].fail_reply, arraysize(tests[i].fail_reply)) }; user_sock_.reset(BuildMockSocket(data_reads, data_writes, "localhost", 80)); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); int rv = user_sock_->Connect(&callback_, log); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -182,7 +182,7 @@ TEST_F(SOCKSClientSocketTest, PartialServerReads) { MockRead(true, kSOCKSPartialReply2, arraysize(kSOCKSPartialReply2)) }; user_sock_.reset(BuildMockSocket(data_reads, data_writes, "localhost", 80)); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); int rv = user_sock_->Connect(&callback_, log); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -212,7 +212,7 @@ TEST_F(SOCKSClientSocketTest, PartialClientWrites) { MockRead(true, kSOCKSOkReply, arraysize(kSOCKSOkReply)) }; user_sock_.reset(BuildMockSocket(data_reads, data_writes, "localhost", 80)); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); int rv = user_sock_->Connect(&callback_, log); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -236,7 +236,7 @@ TEST_F(SOCKSClientSocketTest, FailedSocketRead) { MockRead(false, 0) }; user_sock_.reset(BuildMockSocket(data_reads, data_writes, "localhost", 80)); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); int rv = user_sock_->Connect(&callback_, log); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -265,7 +265,7 @@ TEST_F(SOCKSClientSocketTest, SOCKS4AFailedDNS) { MockRead(false, kSOCKSOkReply, arraysize(kSOCKSOkReply)) }; user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80)); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); int rv = user_sock_->Connect(&callback_, log); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -296,7 +296,7 @@ TEST_F(SOCKSClientSocketTest, SOCKS4AIfDomainInIPv6) { MockRead(false, kSOCKSOkReply, arraysize(kSOCKSOkReply)) }; user_sock_.reset(BuildMockSocket(data_reads, data_writes, hostname, 80)); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); int rv = user_sock_->Connect(&callback_, log); EXPECT_EQ(ERR_IO_PENDING, rv); diff --git a/net/socket/ssl_client_socket_unittest.cc b/net/socket/ssl_client_socket_unittest.cc index 611a604..e360136 100644 --- a/net/socket/ssl_client_socket_unittest.cc +++ b/net/socket/ssl_client_socket_unittest.cc @@ -80,7 +80,7 @@ TEST_F(SSLClientSocketTest, Connect) { EXPECT_FALSE(sock->IsConnected()); - scoped_refptr<net::LoadLog> log(new net::LoadLog); + scoped_refptr<net::LoadLog> log(new net::LoadLog(net::LoadLog::kUnbounded)); rv = sock->Connect(&callback, log); EXPECT_TRUE(net::LogContains( *log, 0, net::LoadLog::TYPE_SSL_CONNECT, net::LoadLog::PHASE_BEGIN)); @@ -124,7 +124,7 @@ TEST_F(SSLClientSocketTest, ConnectExpired) { EXPECT_FALSE(sock->IsConnected()); - scoped_refptr<net::LoadLog> log(new net::LoadLog); + scoped_refptr<net::LoadLog> log(new net::LoadLog(net::LoadLog::kUnbounded)); rv = sock->Connect(&callback, log); EXPECT_TRUE(net::LogContains( *log, 0, net::LoadLog::TYPE_SSL_CONNECT, net::LoadLog::PHASE_BEGIN)); @@ -169,7 +169,7 @@ TEST_F(SSLClientSocketTest, ConnectMismatched) { EXPECT_FALSE(sock->IsConnected()); - scoped_refptr<net::LoadLog> log(new net::LoadLog); + scoped_refptr<net::LoadLog> log(new net::LoadLog(net::LoadLog::kUnbounded)); rv = sock->Connect(&callback, log); EXPECT_TRUE(net::LogContains( *log, 0, net::LoadLog::TYPE_SSL_CONNECT, net::LoadLog::PHASE_BEGIN)); diff --git a/net/socket/tcp_client_socket_unittest.cc b/net/socket/tcp_client_socket_unittest.cc index 80b0496..d797e05 100644 --- a/net/socket/tcp_client_socket_unittest.cc +++ b/net/socket/tcp_client_socket_unittest.cc @@ -99,7 +99,7 @@ TEST_F(TCPClientSocketTest, Connect) { TestCompletionCallback callback; EXPECT_FALSE(sock_->IsConnected()); - scoped_refptr<LoadLog> log(new LoadLog); + scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); int rv = sock_->Connect(&callback, log); EXPECT_TRUE(net::LogContains( *log, 0, net::LoadLog::TYPE_TCP_CONNECT, net::LoadLog::PHASE_BEGIN)); diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc index ad13b6f..96fb051 100644 --- a/net/url_request/url_request.cc +++ b/net/url_request/url_request.cc @@ -27,6 +27,9 @@ using std::wstring; // Max number of http redirects to follow. Same number as gecko. static const int kMaxRedirects = 20; +// The maximum size of the passive LoadLog associated with each request. +static const int kMaxNumLoadLogEntries = 50; + static URLRequestJobManager* GetJobManager() { return Singleton<URLRequestJobManager>::get(); } @@ -35,7 +38,7 @@ static URLRequestJobManager* GetJobManager() { // URLRequest URLRequest::URLRequest(const GURL& url, Delegate* delegate) - : load_log_(new net::LoadLog), + : load_log_(new net::LoadLog(kMaxNumLoadLogEntries)), url_(url), original_url_(url), method_("GET"), |