| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef NET_BASE_NET_LOG_H_ | 5 #ifndef NET_BASE_NET_LOG_H_ |
| 6 #define NET_BASE_NET_LOG_H_ | 6 #define NET_BASE_NET_LOG_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "net/base/net_api.h" | 14 #include "net/base/net_api.h" |
| 15 | 15 |
| 16 namespace base { |
| 16 class Value; | 17 class Value; |
| 18 } |
| 17 | 19 |
| 18 namespace base { | 20 namespace base { |
| 19 class TimeTicks; | 21 class TimeTicks; |
| 20 } | 22 } |
| 21 | 23 |
| 22 namespace net { | 24 namespace net { |
| 23 | 25 |
| 24 // NetLog is the destination for log messages generated by the network stack. | 26 // NetLog is the destination for log messages generated by the network stack. |
| 25 // Each log message has a "source" field which identifies the specific entity | 27 // Each log message has a "source" field which identifies the specific entity |
| 26 // that generated the message (for example, which URLRequest or which | 28 // that generated the message (for example, which URLRequest or which |
| (...skipping 30 matching lines...) Expand all Loading... |
| 57 // uniquely identify the source, and is used by log observers to infer | 59 // uniquely identify the source, and is used by log observers to infer |
| 58 // message groupings. Can use NetLog::NextID() to create unique IDs. | 60 // message groupings. Can use NetLog::NextID() to create unique IDs. |
| 59 struct NET_API Source { | 61 struct NET_API Source { |
| 60 static const uint32 kInvalidId = 0; | 62 static const uint32 kInvalidId = 0; |
| 61 | 63 |
| 62 Source() : type(SOURCE_NONE), id(kInvalidId) {} | 64 Source() : type(SOURCE_NONE), id(kInvalidId) {} |
| 63 Source(SourceType type, uint32 id) : type(type), id(id) {} | 65 Source(SourceType type, uint32 id) : type(type), id(id) {} |
| 64 bool is_valid() const { return id != kInvalidId; } | 66 bool is_valid() const { return id != kInvalidId; } |
| 65 | 67 |
| 66 // The caller takes ownership of the returned Value*. | 68 // The caller takes ownership of the returned Value*. |
| 67 Value* ToValue() const; | 69 base::Value* ToValue() const; |
| 68 | 70 |
| 69 SourceType type; | 71 SourceType type; |
| 70 uint32 id; | 72 uint32 id; |
| 71 }; | 73 }; |
| 72 | 74 |
| 73 // Base class for associating additional parameters with an event. Log | 75 // Base class for associating additional parameters with an event. Log |
| 74 // observers need to know what specific derivations of EventParameters a | 76 // observers need to know what specific derivations of EventParameters a |
| 75 // particular EventType uses, in order to get at the individual components. | 77 // particular EventType uses, in order to get at the individual components. |
| 76 class NET_API EventParameters | 78 class NET_API EventParameters |
| 77 : public base::RefCountedThreadSafe<EventParameters> { | 79 : public base::RefCountedThreadSafe<EventParameters> { |
| 78 public: | 80 public: |
| 79 EventParameters() {} | 81 EventParameters() {} |
| 80 virtual ~EventParameters() {} | 82 virtual ~EventParameters() {} |
| 81 | 83 |
| 82 // Serializes the parameters to a Value tree. This is intended to be a | 84 // Serializes the parameters to a Value tree. This is intended to be a |
| 83 // lossless conversion, which is used to serialize the parameters to JSON. | 85 // lossless conversion, which is used to serialize the parameters to JSON. |
| 84 // The caller takes ownership of the returned Value*. | 86 // The caller takes ownership of the returned Value*. |
| 85 virtual Value* ToValue() const = 0; | 87 virtual base::Value* ToValue() const = 0; |
| 86 | 88 |
| 87 private: | 89 private: |
| 88 DISALLOW_COPY_AND_ASSIGN(EventParameters); | 90 DISALLOW_COPY_AND_ASSIGN(EventParameters); |
| 89 }; | 91 }; |
| 90 | 92 |
| 91 // Specifies the granularity of events that should be emitted to the log. | 93 // Specifies the granularity of events that should be emitted to the log. |
| 92 enum LogLevel { | 94 enum LogLevel { |
| 93 // Log everything possible, even if it is slow and memory expensive. | 95 // Log everything possible, even if it is slow and memory expensive. |
| 94 // Includes logging of transferred bytes. | 96 // Includes logging of transferred bytes. |
| 95 LOG_ALL, | 97 LOG_ALL, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 static std::vector<EventType> GetAllEventTypes(); | 141 static std::vector<EventType> GetAllEventTypes(); |
| 140 | 142 |
| 141 // Returns a C-String symbolic name for |source_type|. | 143 // Returns a C-String symbolic name for |source_type|. |
| 142 static const char* SourceTypeToString(SourceType source_type); | 144 static const char* SourceTypeToString(SourceType source_type); |
| 143 | 145 |
| 144 // Returns a C-String symbolic name for |event_phase|. | 146 // Returns a C-String symbolic name for |event_phase|. |
| 145 static const char* EventPhaseToString(EventPhase event_phase); | 147 static const char* EventPhaseToString(EventPhase event_phase); |
| 146 | 148 |
| 147 // Serializes the specified event to a DictionaryValue. | 149 // Serializes the specified event to a DictionaryValue. |
| 148 // If |use_strings| is true, uses strings rather than numeric ids. | 150 // If |use_strings| is true, uses strings rather than numeric ids. |
| 149 static Value* EntryToDictionaryValue(NetLog::EventType type, | 151 static base::Value* EntryToDictionaryValue(NetLog::EventType type, |
| 150 const base::TimeTicks& time, | 152 const base::TimeTicks& time, |
| 151 const NetLog::Source& source, | 153 const NetLog::Source& source, |
| 152 NetLog::EventPhase phase, | 154 NetLog::EventPhase phase, |
| 153 NetLog::EventParameters* params, | 155 NetLog::EventParameters* params, |
| 154 bool use_strings); | 156 bool use_strings); |
| 155 | 157 |
| 156 private: | 158 private: |
| 157 DISALLOW_COPY_AND_ASSIGN(NetLog); | 159 DISALLOW_COPY_AND_ASSIGN(NetLog); |
| 158 }; | 160 }; |
| 159 | 161 |
| 160 // Helper that binds a Source to a NetLog, and exposes convenience methods to | 162 // Helper that binds a Source to a NetLog, and exposes convenience methods to |
| 161 // output log messages without needing to pass in the source. | 163 // output log messages without needing to pass in the source. |
| 162 class NET_API BoundNetLog { | 164 class NET_API BoundNetLog { |
| 163 public: | 165 public: |
| 164 BoundNetLog() : net_log_(NULL) {} | 166 BoundNetLog() : net_log_(NULL) {} |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 class NetLogStringParameter : public NetLog::EventParameters { | 228 class NetLogStringParameter : public NetLog::EventParameters { |
| 227 public: | 229 public: |
| 228 // |name| must be a string literal. | 230 // |name| must be a string literal. |
| 229 NetLogStringParameter(const char* name, const std::string& value); | 231 NetLogStringParameter(const char* name, const std::string& value); |
| 230 virtual ~NetLogStringParameter(); | 232 virtual ~NetLogStringParameter(); |
| 231 | 233 |
| 232 const std::string& value() const { | 234 const std::string& value() const { |
| 233 return value_; | 235 return value_; |
| 234 } | 236 } |
| 235 | 237 |
| 236 virtual Value* ToValue() const; | 238 virtual base::Value* ToValue() const; |
| 237 | 239 |
| 238 private: | 240 private: |
| 239 const char* const name_; | 241 const char* const name_; |
| 240 const std::string value_; | 242 const std::string value_; |
| 241 }; | 243 }; |
| 242 | 244 |
| 243 // NetLogIntegerParameter is a subclass of EventParameters that encapsulates a | 245 // NetLogIntegerParameter is a subclass of EventParameters that encapsulates a |
| 244 // single integer parameter. | 246 // single integer parameter. |
| 245 class NetLogIntegerParameter : public NetLog::EventParameters { | 247 class NetLogIntegerParameter : public NetLog::EventParameters { |
| 246 public: | 248 public: |
| 247 // |name| must be a string literal. | 249 // |name| must be a string literal. |
| 248 NetLogIntegerParameter(const char* name, int value) | 250 NetLogIntegerParameter(const char* name, int value) |
| 249 : name_(name), value_(value) {} | 251 : name_(name), value_(value) {} |
| 250 | 252 |
| 251 int value() const { | 253 int value() const { |
| 252 return value_; | 254 return value_; |
| 253 } | 255 } |
| 254 | 256 |
| 255 virtual Value* ToValue() const; | 257 virtual base::Value* ToValue() const; |
| 256 | 258 |
| 257 private: | 259 private: |
| 258 const char* name_; | 260 const char* name_; |
| 259 const int value_; | 261 const int value_; |
| 260 }; | 262 }; |
| 261 | 263 |
| 262 // NetLogSourceParameter is a subclass of EventParameters that encapsulates a | 264 // NetLogSourceParameter is a subclass of EventParameters that encapsulates a |
| 263 // single NetLog::Source parameter. | 265 // single NetLog::Source parameter. |
| 264 class NET_API NetLogSourceParameter : public NetLog::EventParameters { | 266 class NET_API NetLogSourceParameter : public NetLog::EventParameters { |
| 265 public: | 267 public: |
| 266 // |name| must be a string literal. | 268 // |name| must be a string literal. |
| 267 NetLogSourceParameter(const char* name, const NetLog::Source& value) | 269 NetLogSourceParameter(const char* name, const NetLog::Source& value) |
| 268 : name_(name), value_(value) {} | 270 : name_(name), value_(value) {} |
| 269 | 271 |
| 270 const NetLog::Source& value() const { | 272 const NetLog::Source& value() const { |
| 271 return value_; | 273 return value_; |
| 272 } | 274 } |
| 273 | 275 |
| 274 virtual Value* ToValue() const; | 276 virtual base::Value* ToValue() const; |
| 275 | 277 |
| 276 private: | 278 private: |
| 277 const char* name_; | 279 const char* name_; |
| 278 const NetLog::Source value_; | 280 const NetLog::Source value_; |
| 279 }; | 281 }; |
| 280 | 282 |
| 281 // ScopedNetLogEvent logs a begin event on creation, and the corresponding end | 283 // ScopedNetLogEvent logs a begin event on creation, and the corresponding end |
| 282 // event on destruction. | 284 // event on destruction. |
| 283 class NET_TEST ScopedNetLogEvent { | 285 class NET_TEST ScopedNetLogEvent { |
| 284 public: | 286 public: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 298 | 300 |
| 299 private: | 301 private: |
| 300 BoundNetLog net_log_; | 302 BoundNetLog net_log_; |
| 301 const NetLog::EventType event_type_; | 303 const NetLog::EventType event_type_; |
| 302 scoped_refptr<NetLog::EventParameters> end_event_params_; | 304 scoped_refptr<NetLog::EventParameters> end_event_params_; |
| 303 }; | 305 }; |
| 304 | 306 |
| 305 } // namespace net | 307 } // namespace net |
| 306 | 308 |
| 307 #endif // NET_BASE_NET_LOG_H_ | 309 #endif // NET_BASE_NET_LOG_H_ |
| OLD | NEW |