mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame^] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef NET_LOG_NET_LOG_ENTRY_H_ |
| 6 | #define NET_LOG_NET_LOG_ENTRY_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | |
| 10 | #include "base/macros.h" |
| 11 | #include "base/time/time.h" |
| 12 | #include "net/base/net_export.h" |
| 13 | #include "net/log/net_log_capture_mode.h" |
| 14 | #include "net/log/net_log_event_type.h" |
| 15 | #include "net/log/net_log_parameters_callback.h" |
| 16 | #include "net/log/net_log_source.h" |
| 17 | |
| 18 | namespace base { |
| 19 | class Value; |
| 20 | } |
| 21 | |
| 22 | namespace net { |
| 23 | |
| 24 | struct NET_EXPORT NetLogEntryData { |
| 25 | NetLogEntryData(NetLogEventType type, |
| 26 | NetLogSource source, |
| 27 | NetLogEventPhase phase, |
| 28 | base::TimeTicks time, |
| 29 | const NetLogParametersCallback* parameters_callback); |
| 30 | ~NetLogEntryData(); |
| 31 | |
| 32 | const NetLogEventType type; |
| 33 | const NetLogSource source; |
| 34 | const NetLogEventPhase phase; |
| 35 | const base::TimeTicks time; |
| 36 | const NetLogParametersCallback* const parameters_callback; |
| 37 | }; |
| 38 | |
| 39 | // A NetLogEntry pre-binds NetLogEntryData to a capture mode, so observers will |
| 40 | // observe the output of ToValue() and ParametersToValue() at their log |
| 41 | // capture mode rather than the current maximum. |
| 42 | class NET_EXPORT NetLogEntry { |
| 43 | public: |
| 44 | NetLogEntry(const NetLogEntryData* data, NetLogCaptureMode capture_mode); |
| 45 | ~NetLogEntry(); |
| 46 | |
| 47 | NetLogEventType type() const { return data_->type; } |
| 48 | NetLogSource source() const { return data_->source; } |
| 49 | NetLogEventPhase phase() const { return data_->phase; } |
| 50 | |
| 51 | // Serializes the specified event to a Value. The Value also includes the |
| 52 | // current time. Takes in a time to allow back-dating entries. |
| 53 | std::unique_ptr<base::Value> ToValue() const; |
| 54 | |
| 55 | // Returns the parameters as a Value. Returns nullptr if there are no |
| 56 | // parameters. |
| 57 | std::unique_ptr<base::Value> ParametersToValue() const; |
| 58 | |
| 59 | private: |
| 60 | const NetLogEntryData* const data_; |
| 61 | |
| 62 | // Log capture mode when the event occurred. |
| 63 | const NetLogCaptureMode capture_mode_; |
| 64 | |
| 65 | // It is not safe to copy this class, since |parameters_callback_| may |
| 66 | // include pointers that become stale immediately after the event is added, |
| 67 | // even if the code were modified to keep its own copy of the callback. |
| 68 | DISALLOW_COPY_AND_ASSIGN(NetLogEntry); |
| 69 | }; |
| 70 | |
| 71 | } // namespace net |
| 72 | |
| 73 | #endif // NET_LOG_NET_LOG_ENTRY_H_ |