Chromium Code Reviews| Index: net/base/net_log.h |
| =================================================================== |
| --- net/base/net_log.h (revision 137673) |
| +++ net/base/net_log.h (working copy) |
| @@ -9,11 +9,14 @@ |
| #include <string> |
| #include "base/basictypes.h" |
| +#include "base/callback_forward.h" |
| #include "base/compiler_specific.h" |
| #include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| #include "net/base/net_export.h" |
| namespace base { |
| +class DictionaryValue; |
| class TimeTicks; |
| class Value; |
| } |
| @@ -65,8 +68,18 @@ |
| bool is_valid() const { return id != kInvalidId; } |
| // The caller takes ownership of the returned Value*. |
| + // TODO(mmenke): Remove this. |
| base::Value* ToValue() const; |
| + // Adds the source to a DictionaryValue containing event parameters, |
| + // using the name "source_dependency". |
| + void AddToEventParameters(base::DictionaryValue* event_params) const; |
| + |
| + // Attempts to extract a Source from a set of event parameters. Returns |
| + // true and writes the result to |source| on success. Returns false and |
| + // makes |source| an invalid source on failure. |
| + static bool FromEventParameters(base::Value* event_params, Source* source); |
| + |
| SourceType type; |
| uint32 id; |
| }; |
| @@ -107,6 +120,45 @@ |
| LOG_BASIC, |
| }; |
| + // A callback function that return a Value representation of the parameters |
| + // associated with an event. If called, it will be called synchonously, |
| + // so it need not have owning references. May be called more than once, or |
| + // not at all. |
| + typedef base::Callback<base::Value*(LogLevel)> ParametersCallback; |
| + |
| + class NET_EXPORT Entry { |
| + public: |
| + Entry(EventType type, |
| + Source source, |
| + EventPhase phase, |
| + const ParametersCallback* parameters_callback, |
| + LogLevel log_level); |
| + ~Entry(); |
| + |
| + EventType type() const { return type_; } |
| + Source source() const { return source_; } |
| + EventPhase phase() const { return phase_; } |
| + |
| + // Serializes the specified event to a Value. The Value also includes the |
| + // current time. Caller takes ownership of returned Value. |
| + base::Value* ToValue() const; |
| + |
| + // Returns the parameters as a Value. Returns NULL if there are no such |
| + // objects. Caller takes ownership of returned Value. |
| + base::Value* ParametersToValue() const; |
| + |
| + private: |
| + const EventType type_; |
| + const Source source_; |
| + const EventPhase phase_; |
| + const ParametersCallback* parameters_callback_; |
| + |
| + // Log level when the event occurred. |
| + const LogLevel log_level_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Entry); |
|
eroman
2012/05/22 22:08:06
I suggest leaving a comment warning not to enable
|
| + }; |
| + |
| // An observer, that must ensure its own thread safety, for events |
| // being added to a NetLog. |
| class NET_EXPORT ThreadSafeObserver { |
| @@ -147,11 +199,7 @@ |
| // The specific subclass of EventParameters is defined |
| // by the contract for events of this |type|. |
| // TODO(eroman): Take a scoped_refptr<EventParameters> instead. |
|
eroman
2012/05/22 22:08:06
Please delete this comment.
|
| - virtual void OnAddEntry(EventType type, |
| - const base::TimeTicks& time, |
| - const Source& source, |
| - EventPhase phase, |
| - EventParameters* params) = 0; |
| + virtual void OnAddEntry(const Entry& entry) = 0; |
| private: |
| friend class NetLog; |
| @@ -224,22 +272,12 @@ |
| // Returns a C-String symbolic name for |event_phase|. |
| static const char* EventPhaseToString(EventPhase event_phase); |
| - // Serializes the specified event to a DictionaryValue. |
| - // If |use_strings| is true, uses strings rather than numeric ids. |
| - static base::Value* EntryToDictionaryValue(NetLog::EventType type, |
| - const base::TimeTicks& time, |
| - const NetLog::Source& source, |
| - NetLog::EventPhase phase, |
| - NetLog::EventParameters* params, |
| - bool use_strings); |
| + static Source GetSourceFromEventParameters(base::Value* event_params); |
| protected: |
| - // This is the internal function used by AddGlobalEntry and BoundNetLogs. |
| - virtual void AddEntry( |
| - EventType type, |
| - const Source& source, |
| - EventPhase phase, |
| - const scoped_refptr<NetLog::EventParameters>& params) = 0; |
| + // Child classes should respond to the new entry here. This includes |
| + // creating the Entry object and alerting their observers. |
| + virtual void OnAddEntry(const Entry& entry) = 0; |
| // Subclasses must call these in the corresponding functions to set an |
| // observer's |net_log_| and |log_level_| values. |
| @@ -251,6 +289,11 @@ |
| private: |
| friend class BoundNetLog; |
| + void AddEntry(EventType type, |
| + const Source& source, |
| + EventPhase phase, |
| + const NetLog::ParametersCallback* parameters_callback); |
| + |
| DISALLOW_COPY_AND_ASSIGN(NetLog); |
| }; |
| @@ -260,10 +303,25 @@ |
| public: |
| BoundNetLog() : net_log_(NULL) {} |
| - // Convenience methods that call through to the NetLog, passing in the |
| - // currently bound source. |
| + void AddEntry(NetLog::EventType type, NetLog::EventPhase phase); |
| void AddEntry(NetLog::EventType type, |
| NetLog::EventPhase phase, |
| + const NetLog::ParametersCallback& get_parameters); |
| + |
| + void AddEvent(NetLog::EventType type); |
| + void AddEvent(NetLog::EventType type, |
| + const NetLog::ParametersCallback& get_parameters); |
| + |
| + void BeginEvent(NetLog::EventType type); |
| + void BeginEvent(NetLog::EventType type, |
| + const NetLog::ParametersCallback& get_parameters); |
| + |
| + void EndEvent(NetLog::EventType type); |
| + void EndEvent(NetLog::EventType type, |
| + const NetLog::ParametersCallback& get_parameters); |
| + |
| + void AddEntry(NetLog::EventType type, |
| + NetLog::EventPhase phase, |
| const scoped_refptr<NetLog::EventParameters>& params) const; |
| // Convenience methods that call through to the NetLog, passing in the |