diff options
Diffstat (limited to 'net/base/net_log.h')
-rw-r--r-- | net/base/net_log.h | 66 |
1 files changed, 25 insertions, 41 deletions
diff --git a/net/base/net_log.h b/net/base/net_log.h index cb2b3a6..c847b0e 100644 --- a/net/base/net_log.h +++ b/net/base/net_log.h @@ -14,6 +14,8 @@ #include "base/time.h" #include "net/base/net_log.h" +class Value; + namespace net { // NetLog is the destination for log messages generated by the network stack. @@ -30,11 +32,6 @@ namespace net { // ******** The NetLog (and associated logging) is a work in progress ******** // // TODO(eroman): Remove the 'const' qualitifer from the BoundNetLog methods. -// TODO(eroman): Remove the AddString() and AddStringLiteral() methods. -// These are a carry-over from old approach. Really, consumers -// should be calling AddEventWithParameters(), and passing a -// custom EventParameters* object that encapsulates all of the -// interesting state. // 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 @@ -92,9 +89,10 @@ class NetLog { EventParameters() {} virtual ~EventParameters() {} - // Serializes the parameters to a string representation (this should be a - // lossless conversion). - virtual std::string ToString() const = 0; + // Serializes the parameters to a Value tree. This is intended to be a + // lossless conversion, which is used to serialize the parameters to JSON. + // The caller takes ownership of the returned Value*. + virtual Value* ToValue() const = 0; private: DISALLOW_COPY_AND_ASSIGN(EventParameters); @@ -170,18 +168,18 @@ class BoundNetLog { void BeginEventWithParameters(NetLog::EventType event_type, NetLog::EventParameters* params) const; void BeginEventWithString(NetLog::EventType event_type, - const std::string& string) const; - void BeginEventWithInteger(NetLog::EventType event_type, int integer) const; - void AddEventWithInteger(NetLog::EventType event_type, int integer) const; + 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, int integer) const; - - // Deprecated: Don't add new dependencies that use these methods. Instead, use - // AddEventWithParameters(). - void AddString(const std::string& string) const; - void AddStringLiteral(const char* literal) 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. @@ -199,53 +197,39 @@ class BoundNetLog { // single std::string parameter. class NetLogStringParameter : public NetLog::EventParameters { public: - explicit NetLogStringParameter(const std::string& value); + // |name| must be a string literal. + NetLogStringParameter(const char* name, const std::string& value); const std::string& value() const { return value_; } - virtual std::string ToString() const { - return value_; - } + virtual Value* ToValue() const; private: - std::string value_; + const char* const name_; + const std::string value_; }; // NetLogIntegerParameter is a subclass of EventParameters that encapsulates a // single integer parameter. class NetLogIntegerParameter : public NetLog::EventParameters { public: - explicit NetLogIntegerParameter(int value) : value_(value) {} + // |name| must be a string literal. + NetLogIntegerParameter(const char* name, int value) + : name_(name), value_(value) {} int value() const { return value_; } - virtual std::string ToString() const; + virtual Value* ToValue() const; private: + const char* name_; const int value_; }; -// NetLogStringLiteralParameter is a subclass of EventParameters that -// encapsulates a single string literal parameter. -class NetLogStringLiteralParameter : public NetLog::EventParameters { - public: - explicit NetLogStringLiteralParameter(const char* value) : value_(value) {} - - const char* const value() const { - return value_; - } - - virtual std::string ToString() const; - - private: - const char* const value_; -}; - - // CapturingNetLog is an implementation of NetLog that saves messages to a // bounded buffer. class CapturingNetLog : public NetLog { |