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 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 // | 35 // |
36 // All methods are thread safe, with the exception that no NetLog or | 36 // All methods are thread safe, with the exception that no NetLog or |
37 // NetLog::ThreadSafeObserver functions may be called by an observer's | 37 // NetLog::ThreadSafeObserver functions may be called by an observer's |
38 // OnAddEntry() method. Doing so will result in a deadlock. | 38 // OnAddEntry() method. Doing so will result in a deadlock. |
39 // | 39 // |
40 // For a broader introduction see the design document: | 40 // For a broader introduction see the design document: |
41 // https://sites.google.com/a/chromium.org/dev/developers/design-documents/netwo
rk-stack/netlog | 41 // https://sites.google.com/a/chromium.org/dev/developers/design-documents/netwo
rk-stack/netlog |
42 class NET_EXPORT NetLog { | 42 class NET_EXPORT NetLog { |
43 public: | 43 public: |
44 enum EventType { | 44 enum EventType { |
45 #define EVENT_TYPE(label) TYPE_ ## label, | 45 #define EVENT_TYPE(label) TYPE_##label, |
46 #include "net/base/net_log_event_type_list.h" | 46 #include "net/base/net_log_event_type_list.h" |
47 #undef EVENT_TYPE | 47 #undef EVENT_TYPE |
48 EVENT_COUNT | 48 EVENT_COUNT |
49 }; | 49 }; |
50 | 50 |
51 // The 'phase' of an event trace (whether it marks the beginning or end | 51 // The 'phase' of an event trace (whether it marks the beginning or end |
52 // of an event.). | 52 // of an event.). |
53 enum EventPhase { | 53 enum EventPhase { |
54 PHASE_NONE, | 54 PHASE_NONE, |
55 PHASE_BEGIN, | 55 PHASE_BEGIN, |
56 PHASE_END, | 56 PHASE_END, |
57 }; | 57 }; |
58 | 58 |
59 // The "source" identifies the entity that generated the log message. | 59 // The "source" identifies the entity that generated the log message. |
60 enum SourceType { | 60 enum SourceType { |
61 #define SOURCE_TYPE(label) SOURCE_ ## label, | 61 #define SOURCE_TYPE(label) SOURCE_##label, |
62 #include "net/base/net_log_source_type_list.h" | 62 #include "net/base/net_log_source_type_list.h" |
63 #undef SOURCE_TYPE | 63 #undef SOURCE_TYPE |
64 SOURCE_COUNT | 64 SOURCE_COUNT |
65 }; | 65 }; |
66 | 66 |
67 // Specifies the granularity of events that should be emitted to the log. | 67 // Specifies the granularity of events that should be emitted to the log. |
68 // | 68 // |
69 // Since the LogLevel may be read and set on any thread without locking, it | 69 // Since the LogLevel may be read and set on any thread without locking, it |
70 // may be possible for an Observer to receive an event or parameters that | 70 // may be possible for an Observer to receive an event or parameters that |
71 // normally wouldn't be logged at the currently active log level. | 71 // normally wouldn't be logged at the currently active log level. |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 // Just like EndEvent, except |net_error| is a net error code. If it's | 371 // Just like EndEvent, except |net_error| is a net error code. If it's |
372 // negative, a parameter called "net_error" with a value of |net_error| is | 372 // negative, a parameter called "net_error" with a value of |net_error| is |
373 // associated with the event. Otherwise, the end event has no parameters. | 373 // associated with the event. Otherwise, the end event has no parameters. |
374 // |net_error| must not be ERR_IO_PENDING, as it's not a true error. | 374 // |net_error| must not be ERR_IO_PENDING, as it's not a true error. |
375 void EndEventWithNetErrorCode(NetLog::EventType event_type, | 375 void EndEventWithNetErrorCode(NetLog::EventType event_type, |
376 int net_error) const; | 376 int net_error) const; |
377 | 377 |
378 // Logs a byte transfer event to the NetLog. Determines whether to log the | 378 // Logs a byte transfer event to the NetLog. Determines whether to log the |
379 // received bytes or not based on the current logging level. | 379 // received bytes or not based on the current logging level. |
380 void AddByteTransferEvent(NetLog::EventType event_type, | 380 void AddByteTransferEvent(NetLog::EventType event_type, |
381 int byte_count, const char* bytes) const; | 381 int byte_count, |
| 382 const char* bytes) const; |
382 | 383 |
383 NetLog::LogLevel GetLogLevel() const; | 384 NetLog::LogLevel GetLogLevel() const; |
384 | 385 |
385 // Shortcut for NetLog::IsLoggingBytes(this->GetLogLevel()). | 386 // Shortcut for NetLog::IsLoggingBytes(this->GetLogLevel()). |
386 bool IsLoggingBytes() const; | 387 bool IsLoggingBytes() const; |
387 | 388 |
388 // Shortcut for NetLog::IsLogging(this->GetLogLevel()). | 389 // Shortcut for NetLog::IsLogging(this->GetLogLevel()). |
389 bool IsLogging() const; | 390 bool IsLogging() const; |
390 | 391 |
391 // Helper to create a BoundNetLog given a NetLog and a SourceType. Takes care | 392 // Helper to create a BoundNetLog given a NetLog and a SourceType. Takes care |
392 // of creating a unique source ID, and handles the case of NULL net_log. | 393 // of creating a unique source ID, and handles the case of NULL net_log. |
393 static BoundNetLog Make(NetLog* net_log, NetLog::SourceType source_type); | 394 static BoundNetLog Make(NetLog* net_log, NetLog::SourceType source_type); |
394 | 395 |
395 const NetLog::Source& source() const { return source_; } | 396 const NetLog::Source& source() const { return source_; } |
396 NetLog* net_log() const { return net_log_; } | 397 NetLog* net_log() const { return net_log_; } |
397 | 398 |
398 private: | 399 private: |
399 BoundNetLog(const NetLog::Source& source, NetLog* net_log) | 400 BoundNetLog(const NetLog::Source& source, NetLog* net_log) |
400 : source_(source), net_log_(net_log) { | 401 : source_(source), net_log_(net_log) {} |
401 } | |
402 | 402 |
403 NetLog::Source source_; | 403 NetLog::Source source_; |
404 NetLog* net_log_; | 404 NetLog* net_log_; |
405 }; | 405 }; |
406 | 406 |
407 } // namespace net | 407 } // namespace net |
408 | 408 |
409 #endif // NET_BASE_NET_LOG_H_ | 409 #endif // NET_BASE_NET_LOG_H_ |
OLD | NEW |