OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 10 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 uint32 id; | 71 uint32 id; |
72 }; | 72 }; |
73 | 73 |
74 // Base class for associating additional parameters with an event. Log | 74 // Base class for associating additional parameters with an event. Log |
75 // observers need to know what specific derivations of EventParameters a | 75 // observers need to know what specific derivations of EventParameters a |
76 // particular EventType uses, in order to get at the individual components. | 76 // particular EventType uses, in order to get at the individual components. |
77 class NET_EXPORT EventParameters | 77 class NET_EXPORT EventParameters |
78 : public base::RefCountedThreadSafe<EventParameters> { | 78 : public base::RefCountedThreadSafe<EventParameters> { |
79 public: | 79 public: |
80 EventParameters() {} | 80 EventParameters() {} |
81 virtual ~EventParameters() {} | |
82 | 81 |
83 // Serializes the parameters to a Value tree. This is intended to be a | 82 // Serializes the parameters to a Value tree. This is intended to be a |
84 // lossless conversion, which is used to serialize the parameters to JSON. | 83 // lossless conversion, which is used to serialize the parameters to JSON. |
85 // The caller takes ownership of the returned Value*. | 84 // The caller takes ownership of the returned Value*. |
86 virtual base::Value* ToValue() const = 0; | 85 virtual base::Value* ToValue() const = 0; |
87 | 86 |
| 87 protected: |
| 88 virtual ~EventParameters() {} |
| 89 |
88 private: | 90 private: |
| 91 friend class base::RefCountedThreadSafe<EventParameters>; |
| 92 |
89 DISALLOW_COPY_AND_ASSIGN(EventParameters); | 93 DISALLOW_COPY_AND_ASSIGN(EventParameters); |
90 }; | 94 }; |
91 | 95 |
92 // Specifies the granularity of events that should be emitted to the log. | 96 // Specifies the granularity of events that should be emitted to the log. |
93 enum LogLevel { | 97 enum LogLevel { |
94 // Log everything possible, even if it is slow and memory expensive. | 98 // Log everything possible, even if it is slow and memory expensive. |
95 // Includes logging of transferred bytes. | 99 // Includes logging of transferred bytes. |
96 LOG_ALL, | 100 LOG_ALL, |
97 | 101 |
98 // Log all events, but do not include the actual transferred bytes as | 102 // Log all events, but do not include the actual transferred bytes as |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 NetLog::Source source_; | 318 NetLog::Source source_; |
315 NetLog* net_log_; | 319 NetLog* net_log_; |
316 }; | 320 }; |
317 | 321 |
318 // NetLogStringParameter is a subclass of EventParameters that encapsulates a | 322 // NetLogStringParameter is a subclass of EventParameters that encapsulates a |
319 // single std::string parameter. | 323 // single std::string parameter. |
320 class NET_EXPORT NetLogStringParameter : public NetLog::EventParameters { | 324 class NET_EXPORT NetLogStringParameter : public NetLog::EventParameters { |
321 public: | 325 public: |
322 // |name| must be a string literal. | 326 // |name| must be a string literal. |
323 NetLogStringParameter(const char* name, const std::string& value); | 327 NetLogStringParameter(const char* name, const std::string& value); |
324 virtual ~NetLogStringParameter(); | |
325 | 328 |
326 const std::string& value() const { | 329 const std::string& value() const { |
327 return value_; | 330 return value_; |
328 } | 331 } |
329 | 332 |
330 virtual base::Value* ToValue() const OVERRIDE; | 333 virtual base::Value* ToValue() const OVERRIDE; |
331 | 334 |
332 private: | 335 private: |
| 336 virtual ~NetLogStringParameter(); |
| 337 |
333 const char* const name_; | 338 const char* const name_; |
334 const std::string value_; | 339 const std::string value_; |
335 }; | 340 }; |
336 | 341 |
337 // NetLogIntegerParameter is a subclass of EventParameters that encapsulates a | 342 // NetLogIntegerParameter is a subclass of EventParameters that encapsulates a |
338 // single integer parameter. | 343 // single integer parameter. |
339 class NET_EXPORT NetLogIntegerParameter : public NetLog::EventParameters { | 344 class NET_EXPORT NetLogIntegerParameter : public NetLog::EventParameters { |
340 public: | 345 public: |
341 // |name| must be a string literal. | 346 // |name| must be a string literal. |
342 NetLogIntegerParameter(const char* name, int value) | 347 NetLogIntegerParameter(const char* name, int value) |
343 : name_(name), value_(value) {} | 348 : name_(name), value_(value) {} |
344 | 349 |
345 int value() const { | 350 int value() const { |
346 return value_; | 351 return value_; |
347 } | 352 } |
348 | 353 |
349 virtual base::Value* ToValue() const OVERRIDE; | 354 virtual base::Value* ToValue() const OVERRIDE; |
350 | 355 |
351 private: | 356 private: |
| 357 virtual ~NetLogIntegerParameter() {} |
| 358 |
352 const char* name_; | 359 const char* name_; |
353 const int value_; | 360 const int value_; |
354 }; | 361 }; |
355 | 362 |
356 // NetLogSourceParameter is a subclass of EventParameters that encapsulates a | 363 // NetLogSourceParameter is a subclass of EventParameters that encapsulates a |
357 // single NetLog::Source parameter. | 364 // single NetLog::Source parameter. |
358 class NET_EXPORT NetLogSourceParameter : public NetLog::EventParameters { | 365 class NET_EXPORT NetLogSourceParameter : public NetLog::EventParameters { |
359 public: | 366 public: |
360 // |name| must be a string literal. | 367 // |name| must be a string literal. |
361 NetLogSourceParameter(const char* name, const NetLog::Source& value) | 368 NetLogSourceParameter(const char* name, const NetLog::Source& value) |
362 : name_(name), value_(value) {} | 369 : name_(name), value_(value) {} |
363 | 370 |
364 const NetLog::Source& value() const { | 371 const NetLog::Source& value() const { |
365 return value_; | 372 return value_; |
366 } | 373 } |
367 | 374 |
368 virtual base::Value* ToValue() const OVERRIDE; | 375 virtual base::Value* ToValue() const OVERRIDE; |
369 | 376 |
370 private: | 377 private: |
| 378 virtual ~NetLogSourceParameter() {} |
| 379 |
371 const char* name_; | 380 const char* name_; |
372 const NetLog::Source value_; | 381 const NetLog::Source value_; |
373 }; | 382 }; |
374 | 383 |
375 // ScopedNetLogEvent logs a begin event on creation, and the corresponding end | 384 // ScopedNetLogEvent logs a begin event on creation, and the corresponding end |
376 // event on destruction. | 385 // event on destruction. |
377 class NET_EXPORT_PRIVATE ScopedNetLogEvent { | 386 class NET_EXPORT_PRIVATE ScopedNetLogEvent { |
378 public: | 387 public: |
379 ScopedNetLogEvent(const BoundNetLog& net_log, | 388 ScopedNetLogEvent(const BoundNetLog& net_log, |
380 NetLog::EventType event_type, | 389 NetLog::EventType event_type, |
(...skipping 11 matching lines...) Expand all Loading... |
392 | 401 |
393 private: | 402 private: |
394 BoundNetLog net_log_; | 403 BoundNetLog net_log_; |
395 const NetLog::EventType event_type_; | 404 const NetLog::EventType event_type_; |
396 scoped_refptr<NetLog::EventParameters> end_event_params_; | 405 scoped_refptr<NetLog::EventParameters> end_event_params_; |
397 }; | 406 }; |
398 | 407 |
399 } // namespace net | 408 } // namespace net |
400 | 409 |
401 #endif // NET_BASE_NET_LOG_H_ | 410 #endif // NET_BASE_NET_LOG_H_ |
OLD | NEW |