summaryrefslogtreecommitdiffstats
path: root/net/base
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-28 19:28:09 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-28 19:28:09 +0000
commitec11be60eaf6e832219328ea18656c558dec3040 (patch)
tree1d8a6710f277a55b4743fbc54c8554abf3164669 /net/base
parent9bb75ccc56cdb94a9778dcef26be3de97808f3ce (diff)
downloadchromium_src-ec11be60eaf6e832219328ea18656c558dec3040.zip
chromium_src-ec11be60eaf6e832219328ea18656c558dec3040.tar.gz
chromium_src-ec11be60eaf6e832219328ea18656c558dec3040.tar.bz2
More cleanup to address TODOs in net_log.h.
* Removes 9 methods: AddEventWithParameters, BeginEventWithParameters, EndEventWithParameters, BeginEventWithString, BeginEventWithInteger, AddEventWithString, AddEventWithInteger, EndEventWithParameters, EndEventWithInteger. This was becoming ridiculous, instead made the EventParameters* a required parameter. * Moves CapturingBoundNetLog / CapturingNetLog to its own file. BUG=37421 Review URL: http://codereview.chromium.org/1746012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45843 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r--net/base/capturing_net_log.cc43
-rw-r--r--net/base/capturing_net_log.h109
-rw-r--r--net/base/host_resolver_impl.cc20
-rw-r--r--net/base/host_resolver_impl.h1
-rw-r--r--net/base/net_log.cc109
-rw-r--r--net/base/net_log.h135
-rw-r--r--net/base/net_log_unittest.h2
-rw-r--r--net/base/net_log_util.h2
8 files changed, 195 insertions, 226 deletions
diff --git a/net/base/capturing_net_log.cc b/net/base/capturing_net_log.cc
new file mode 100644
index 0000000..08f3b8d
--- /dev/null
+++ b/net/base/capturing_net_log.cc
@@ -0,0 +1,43 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/base/capturing_net_log.h"
+
+namespace net {
+
+CapturingNetLog::CapturingNetLog(size_t max_num_entries)
+ : next_id_(0), max_num_entries_(max_num_entries) {
+}
+
+void CapturingNetLog::AddEntry(EventType type,
+ const base::TimeTicks& time,
+ const Source& source,
+ EventPhase phase,
+ EventParameters* extra_parameters) {
+ Entry entry(type, time, source, phase, extra_parameters);
+ if (entries_.size() + 1 < max_num_entries_)
+ entries_.push_back(entry);
+}
+
+uint32 CapturingNetLog::NextID() {
+ return next_id_++;
+}
+
+void CapturingNetLog::Clear() {
+ entries_.clear();
+}
+
+void CapturingBoundNetLog::Clear() {
+ capturing_net_log_->Clear();
+}
+
+void CapturingBoundNetLog::AppendTo(const BoundNetLog& net_log) const {
+ for (size_t i = 0; i < entries().size(); ++i) {
+ const CapturingNetLog::Entry& entry = entries()[i];
+ net_log.AddEntryWithTime(entry.type, entry.time, entry.phase,
+ entry.extra_parameters);
+ }
+}
+
+} // namespace net
diff --git a/net/base/capturing_net_log.h b/net/base/capturing_net_log.h
new file mode 100644
index 0000000..2f95f7c
--- /dev/null
+++ b/net/base/capturing_net_log.h
@@ -0,0 +1,109 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_BASE_CAPTURING_NET_LOG_H_
+#define NET_BASE_CAPTURING_NET_LOG_H_
+
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/ref_counted.h"
+#include "base/scoped_ptr.h"
+#include "net/base/net_log.h"
+
+namespace net {
+
+// CapturingNetLog is an implementation of NetLog that saves messages to a
+// bounded buffer.
+class CapturingNetLog : public NetLog {
+ public:
+ struct Entry {
+ Entry(EventType type,
+ const base::TimeTicks& time,
+ Source source,
+ EventPhase phase,
+ EventParameters* extra_parameters)
+ : type(type), time(time), source(source), phase(phase),
+ extra_parameters(extra_parameters) {
+ }
+
+ EventType type;
+ base::TimeTicks time;
+ Source source;
+ EventPhase phase;
+ scoped_refptr<EventParameters> extra_parameters;
+ };
+
+ // Ordered set of entries that were logged.
+ typedef std::vector<Entry> EntryList;
+
+ enum { kUnbounded = -1 };
+
+ // Creates a CapturingNetLog that logs a maximum of |max_num_entries|
+ // messages.
+ explicit CapturingNetLog(size_t max_num_entries);
+
+ // NetLog implementation:
+ virtual void AddEntry(EventType type,
+ const base::TimeTicks& time,
+ const Source& source,
+ EventPhase phase,
+ EventParameters* extra_parameters);
+ virtual uint32 NextID();
+ virtual bool HasListener() const { return true; }
+
+ // Returns the list of all entries in the log.
+ const EntryList& entries() const { return entries_; }
+
+ void Clear();
+
+ private:
+ uint32 next_id_;
+ size_t max_num_entries_;
+ EntryList entries_;
+
+ DISALLOW_COPY_AND_ASSIGN(CapturingNetLog);
+};
+
+// Helper class that exposes a similar API as BoundNetLog, but uses a
+// CapturingNetLog rather than the more generic NetLog.
+//
+// CapturingBoundNetLog can easily be converted to a BoundNetLog using the
+// bound() method.
+class CapturingBoundNetLog {
+ public:
+ CapturingBoundNetLog(const NetLog::Source& source, CapturingNetLog* net_log)
+ : source_(source), capturing_net_log_(net_log) {
+ }
+
+ explicit CapturingBoundNetLog(size_t max_num_entries)
+ : capturing_net_log_(new CapturingNetLog(max_num_entries)) {}
+
+ // The returned BoundNetLog is only valid while |this| is alive.
+ BoundNetLog bound() const {
+ return BoundNetLog(source_, capturing_net_log_.get());
+ }
+
+ // Returns the list of all entries in the log.
+ const CapturingNetLog::EntryList& entries() const {
+ return capturing_net_log_->entries();
+ }
+
+ void Clear();
+
+ // Sends all of captured messages to |net_log|, using the same source ID
+ // as |net_log|.
+ void AppendTo(const BoundNetLog& net_log) const;
+
+ private:
+ NetLog::Source source_;
+ scoped_ptr<CapturingNetLog> capturing_net_log_;
+
+ DISALLOW_COPY_AND_ASSIGN(CapturingBoundNetLog);
+};
+
+} // namespace net
+
+#endif // NET_BASE_CAPTURING_NET_LOG_H_
+
diff --git a/net/base/host_resolver_impl.cc b/net/base/host_resolver_impl.cc
index f1b57f6..1c97f22 100644
--- a/net/base/host_resolver_impl.cc
+++ b/net/base/host_resolver_impl.cc
@@ -1003,7 +1003,7 @@ void HostResolverImpl::OnJobComplete(Job* job,
void HostResolverImpl::OnStartRequest(const BoundNetLog& net_log,
int request_id,
const RequestInfo& info) {
- net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL);
+ net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL, NULL);
if (requests_trace_) {
requests_trace_->Add(StringPrintf(
@@ -1021,14 +1021,14 @@ void HostResolverImpl::OnStartRequest(const BoundNetLog& net_log,
// Notify the observers of the start.
if (!observers_.empty()) {
- net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART);
+ net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART, NULL);
for (ObserversList::iterator it = observers_.begin();
it != observers_.end(); ++it) {
(*it)->OnStartResolution(request_id, info);
}
- net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART);
+ net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART, NULL);
}
}
@@ -1043,7 +1043,7 @@ void HostResolverImpl::OnFinishRequest(const BoundNetLog& net_log,
// Notify the observers of the completion.
if (!observers_.empty()) {
- net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONFINISH);
+ net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONFINISH, NULL);
bool was_resolved = error == OK;
for (ObserversList::iterator it = observers_.begin();
@@ -1051,33 +1051,33 @@ void HostResolverImpl::OnFinishRequest(const BoundNetLog& net_log,
(*it)->OnFinishResolutionWithStatus(request_id, was_resolved, info);
}
- net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONFINISH);
+ net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONFINISH, NULL);
}
- net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL);
+ net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL, NULL);
}
void HostResolverImpl::OnCancelRequest(const BoundNetLog& net_log,
int request_id,
const RequestInfo& info) {
- net_log.AddEvent(NetLog::TYPE_CANCELLED);
+ net_log.AddEvent(NetLog::TYPE_CANCELLED, NULL);
if (requests_trace_)
requests_trace_->Add(StringPrintf("Cancelled request r%d", request_id));
// Notify the observers of the cancellation.
if (!observers_.empty()) {
- net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL);
+ net_log.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL, NULL);
for (ObserversList::iterator it = observers_.begin();
it != observers_.end(); ++it) {
(*it)->OnCancelResolution(request_id, info);
}
- net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL);
+ net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL, NULL);
}
- net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL);
+ net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL, NULL);
}
void HostResolverImpl::OnIPAddressChanged() {
diff --git a/net/base/host_resolver_impl.h b/net/base/host_resolver_impl.h
index 1a182b3..80ca2ca 100644
--- a/net/base/host_resolver_impl.h
+++ b/net/base/host_resolver_impl.h
@@ -9,6 +9,7 @@
#include <vector>
#include "base/scoped_ptr.h"
+#include "net/base/capturing_net_log.h"
#include "net/base/host_cache.h"
#include "net/base/host_resolver.h"
#include "net/base/host_resolver_proc.h"
diff --git a/net/base/net_log.cc b/net/base/net_log.cc
index c46214f..02b6bbd 100644
--- a/net/base/net_log.cc
+++ b/net/base/net_log.cc
@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include "net/base/net_log.h"
-#include "base/logging.h"
#include "base/string_util.h"
#include "base/values.h"
@@ -28,12 +27,12 @@ std::vector<NetLog::EventType> NetLog::GetAllEventTypes() {
return types;
}
-void BoundNetLog::AddEntry(NetLog::EventType type,
- NetLog::EventPhase phase,
- NetLog::EventParameters* extra_parameters) const {
+void BoundNetLog::AddEntry(
+ NetLog::EventType type,
+ NetLog::EventPhase phase,
+ const scoped_refptr<NetLog::EventParameters>& params) const {
if (net_log_) {
- net_log_->AddEntry(type, base::TimeTicks::Now(), source_, phase,
- extra_parameters);
+ net_log_->AddEntry(type, base::TimeTicks::Now(), source_, phase, params);
}
}
@@ -41,9 +40,9 @@ void BoundNetLog::AddEntryWithTime(
NetLog::EventType type,
const base::TimeTicks& time,
NetLog::EventPhase phase,
- NetLog::EventParameters* extra_parameters) const {
+ const scoped_refptr<NetLog::EventParameters>& params) const {
if (net_log_) {
- net_log_->AddEntry(type, time, source_, phase, extra_parameters);
+ net_log_->AddEntry(type, time, source_, phase, params);
}
}
@@ -53,76 +52,24 @@ bool BoundNetLog::HasListener() const {
return false;
}
-void BoundNetLog::AddEvent(NetLog::EventType event_type) const {
- AddEventWithParameters(event_type, NULL);
-}
-
-void BoundNetLog::AddEventWithParameters(
+void BoundNetLog::AddEvent(
NetLog::EventType event_type,
- NetLog::EventParameters* params) const {
+ const scoped_refptr<NetLog::EventParameters>& params) const {
AddEntry(event_type, NetLog::PHASE_NONE, params);
}
-void BoundNetLog::AddEventWithInteger(NetLog::EventType event_type,
- const char* name,
- int value) const {
- scoped_refptr<NetLog::EventParameters> params =
- new NetLogIntegerParameter(name, value);
- AddEventWithParameters(event_type, params);
-}
-
-void BoundNetLog::AddEventWithString(NetLog::EventType event_type,
- const char* name,
- const std::string& value) const {
- scoped_refptr<NetLog::EventParameters> params =
- new NetLogStringParameter(name, value);
- AddEventWithParameters(event_type, params);
-}
-
-void BoundNetLog::BeginEvent(NetLog::EventType event_type) const {
- BeginEventWithParameters(event_type, NULL);
-}
-
-void BoundNetLog::BeginEventWithParameters(
+void BoundNetLog::BeginEvent(
NetLog::EventType event_type,
- NetLog::EventParameters* params) const {
+ const scoped_refptr<NetLog::EventParameters>& params) const {
AddEntry(event_type, NetLog::PHASE_BEGIN, params);
}
-void BoundNetLog::BeginEventWithString(NetLog::EventType event_type,
- const char* name,
- const std::string& value) const {
- scoped_refptr<NetLog::EventParameters> params =
- new NetLogStringParameter(name, value);
- BeginEventWithParameters(event_type, params);
-}
-
-void BoundNetLog::BeginEventWithInteger(NetLog::EventType event_type,
- const char* name,
- int value) const {
- scoped_refptr<NetLog::EventParameters> params =
- new NetLogIntegerParameter(name, value);
- BeginEventWithParameters(event_type, params);
-}
-
-void BoundNetLog::EndEvent(NetLog::EventType event_type) const {
- EndEventWithParameters(event_type, NULL);
-}
-
-void BoundNetLog::EndEventWithParameters(
+void BoundNetLog::EndEvent(
NetLog::EventType event_type,
- NetLog::EventParameters* params) const {
+ const scoped_refptr<NetLog::EventParameters>& params) const {
AddEntry(event_type, NetLog::PHASE_END, params);
}
-void BoundNetLog::EndEventWithInteger(NetLog::EventType event_type,
- const char* name,
- int value) const {
- scoped_refptr<NetLog::EventParameters> params =
- new NetLogIntegerParameter(name, value);
- EndEventWithParameters(event_type, params);
-}
-
// static
BoundNetLog BoundNetLog::Make(NetLog* net_log,
NetLog::SourceType source_type) {
@@ -150,34 +97,4 @@ Value* NetLogStringParameter::ToValue() const {
return dict;
}
-void CapturingNetLog::AddEntry(EventType type,
- const base::TimeTicks& time,
- const Source& source,
- EventPhase phase,
- EventParameters* extra_parameters) {
- Entry entry(type, time, source, phase, extra_parameters);
- if (entries_.size() + 1 < max_num_entries_)
- entries_.push_back(entry);
-}
-
-uint32 CapturingNetLog::NextID() {
- return next_id_++;
-}
-
-void CapturingNetLog::Clear() {
- entries_.clear();
-}
-
-void CapturingBoundNetLog::Clear() {
- capturing_net_log_->Clear();
-}
-
-void CapturingBoundNetLog::AppendTo(const BoundNetLog& net_log) const {
- for (size_t i = 0; i < entries().size(); ++i) {
- const CapturingNetLog::Entry& entry = entries()[i];
- net_log.AddEntryWithTime(entry.type, entry.time, entry.phase,
- entry.extra_parameters);
- }
-}
-
} // namespace net
diff --git a/net/base/net_log.h b/net/base/net_log.h
index c847b0e..6bef13c 100644
--- a/net/base/net_log.h
+++ b/net/base/net_log.h
@@ -12,7 +12,6 @@
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
#include "base/time.h"
-#include "net/base/net_log.h"
class Value;
@@ -34,8 +33,6 @@ namespace net {
// TODO(eroman): Remove the 'const' qualitifer from the BoundNetLog methods.
// TODO(eroman): Remove NetLogUtil. Pretty printing should only be done from
// javascript, and should be very context-aware.
-// TODO(eroman): Move Capturing*NetLog to its own file. (And eventually remove
-// all the consumers of it).
// TODO(eroman): Make the DNS jobs emit directly into the NetLog.
// TODO(eroman): Start a new Source each time URLRequest redirects
// (simpler to reason about each as a separate entity).
@@ -149,37 +146,29 @@ class BoundNetLog {
: source_(source), net_log_(net_log) {
}
+ // Convenience methods that call through to the NetLog, passing in the
+ // currently bound source.
void AddEntry(NetLog::EventType type,
NetLog::EventPhase phase,
- NetLog::EventParameters* extra_parameters) const;
+ const scoped_refptr<NetLog::EventParameters>& params) const;
- void AddEntryWithTime(NetLog::EventType type,
- const base::TimeTicks& time,
- NetLog::EventPhase phase,
- NetLog::EventParameters* extra_parameters) const;
+ void AddEntryWithTime(
+ NetLog::EventType type,
+ const base::TimeTicks& time,
+ NetLog::EventPhase phase,
+ const scoped_refptr<NetLog::EventParameters>& params) const;
// Convenience methods that call through to the NetLog, passing in the
- // currently bound source.
- void AddEvent(NetLog::EventType event_type) const;
- void AddEventWithParameters(NetLog::EventType event_type,
- NetLog::EventParameters* params) const;
+ // currently bound source, current time, and a fixed "capture phase"
+ // (begin, end, or none).
+ void AddEvent(NetLog::EventType event_type,
+ const scoped_refptr<NetLog::EventParameters>& params) const;
+ void BeginEvent(NetLog::EventType event_type,
+ const scoped_refptr<NetLog::EventParameters>& params) const;
+ void EndEvent(NetLog::EventType event_type,
+ const scoped_refptr<NetLog::EventParameters>& params) const;
+
bool HasListener() const;
- void BeginEvent(NetLog::EventType event_type) const;
- void BeginEventWithParameters(NetLog::EventType event_type,
- NetLog::EventParameters* params) const;
- void BeginEventWithString(NetLog::EventType event_type,
- const char* name, const std::string& value) const;
- void BeginEventWithInteger(NetLog::EventType event_type,
- const char* name, int value) const;
- void AddEventWithInteger(NetLog::EventType event_type,
- const char* name, int value) const;
- void AddEventWithString(NetLog::EventType event_type,
- const char* name, const std::string& value) const;
- void EndEvent(NetLog::EventType event_type) const;
- void EndEventWithParameters(NetLog::EventType event_type,
- NetLog::EventParameters* params) const;
- void EndEventWithInteger(NetLog::EventType event_type,
- const char* name, int value) const;
// Helper to create a BoundNetLog given a NetLog and a SourceType. Takes care
// of creating a unique source ID, and handles the case of NULL net_log.
@@ -230,96 +219,6 @@ class NetLogIntegerParameter : public NetLog::EventParameters {
const int value_;
};
-// CapturingNetLog is an implementation of NetLog that saves messages to a
-// bounded buffer.
-class CapturingNetLog : public NetLog {
- public:
- struct Entry {
- Entry(EventType type,
- const base::TimeTicks& time,
- Source source,
- EventPhase phase,
- EventParameters* extra_parameters)
- : type(type), time(time), source(source), phase(phase),
- extra_parameters(extra_parameters) {
- }
-
- EventType type;
- base::TimeTicks time;
- Source source;
- EventPhase phase;
- scoped_refptr<EventParameters> extra_parameters;
- };
-
- // Ordered set of entries that were logged.
- typedef std::vector<Entry> EntryList;
-
- enum { kUnbounded = -1 };
-
- // Creates a CapturingNetLog that logs a maximum of |max_num_entries|
- // messages.
- explicit CapturingNetLog(size_t max_num_entries)
- : next_id_(0), max_num_entries_(max_num_entries) {}
-
- // NetLog implementation:
- virtual void AddEntry(EventType type,
- const base::TimeTicks& time,
- const Source& source,
- EventPhase phase,
- EventParameters* extra_parameters);
- virtual uint32 NextID();
- virtual bool HasListener() const { return true; }
-
- // Returns the list of all entries in the log.
- const EntryList& entries() const { return entries_; }
-
- void Clear();
-
- private:
- uint32 next_id_;
- size_t max_num_entries_;
- EntryList entries_;
-
- DISALLOW_COPY_AND_ASSIGN(CapturingNetLog);
-};
-
-// Helper class that exposes a similar API as BoundNetLog, but uses a
-// CapturingNetLog rather than the more generic NetLog.
-//
-// CapturingBoundNetLog can easily be converted to a BoundNetLog using the
-// bound() method.
-class CapturingBoundNetLog {
- public:
- CapturingBoundNetLog(const NetLog::Source& source, CapturingNetLog* net_log)
- : source_(source), capturing_net_log_(net_log) {
- }
-
- explicit CapturingBoundNetLog(size_t max_num_entries)
- : capturing_net_log_(new CapturingNetLog(max_num_entries)) {}
-
- // The returned BoundNetLog is only valid while |this| is alive.
- BoundNetLog bound() const {
- return BoundNetLog(source_, capturing_net_log_.get());
- }
-
- // Returns the list of all entries in the log.
- const CapturingNetLog::EntryList& entries() const {
- return capturing_net_log_->entries();
- }
-
- void Clear();
-
- // Sends all of captured messages to |net_log|, using the same source ID
- // as |net_log|.
- void AppendTo(const BoundNetLog& net_log) const;
-
- private:
- NetLog::Source source_;
- scoped_ptr<CapturingNetLog> capturing_net_log_;
-
- DISALLOW_COPY_AND_ASSIGN(CapturingBoundNetLog);
-};
-
} // namespace net
#endif // NET_BASE_NET_LOG_H_
diff --git a/net/base/net_log_unittest.h b/net/base/net_log_unittest.h
index b7a6147..376ceac 100644
--- a/net/base/net_log_unittest.h
+++ b/net/base/net_log_unittest.h
@@ -7,7 +7,7 @@
#include <cstddef>
#include <vector>
-#include "net/base/net_log.h"
+#include "net/base/capturing_net_log.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
diff --git a/net/base/net_log_util.h b/net/base/net_log_util.h
index 7ca5e65..0d603e8 100644
--- a/net/base/net_log_util.h
+++ b/net/base/net_log_util.h
@@ -9,7 +9,7 @@
#include <vector>
#include "base/basictypes.h"
-#include "net/base/net_log.h"
+#include "net/base/capturing_net_log.h"
namespace net {