OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 PHASE_END, | 60 PHASE_END, |
61 }; | 61 }; |
62 | 62 |
63 // The "source" identifies the entity that generated the log message. | 63 // The "source" identifies the entity that generated the log message. |
64 enum SourceType { | 64 enum SourceType { |
65 SOURCE_NONE, | 65 SOURCE_NONE, |
66 SOURCE_URL_REQUEST, | 66 SOURCE_URL_REQUEST, |
67 SOURCE_SOCKET_STREAM, | 67 SOURCE_SOCKET_STREAM, |
68 SOURCE_INIT_PROXY_RESOLVER, | 68 SOURCE_INIT_PROXY_RESOLVER, |
69 SOURCE_CONNECT_JOB, | 69 SOURCE_CONNECT_JOB, |
| 70 SOURCE_SOCKET, |
70 }; | 71 }; |
71 | 72 |
72 // Identifies the entity that generated this log. The |id| field should | 73 // Identifies the entity that generated this log. The |id| field should |
73 // uniquely identify the source, and is used by log observers to infer | 74 // uniquely identify the source, and is used by log observers to infer |
74 // message groupings. Can use NetLog::NextID() to create unique IDs. | 75 // message groupings. Can use NetLog::NextID() to create unique IDs. |
75 struct Source { | 76 struct Source { |
76 Source() : type(SOURCE_NONE), id(-1) {} | 77 static const uint32 kInvalidId = 0; |
77 Source(SourceType type, int id) : type(type), id(id) {} | 78 |
| 79 Source() : type(SOURCE_NONE), id(kInvalidId) {} |
| 80 Source(SourceType type, uint32 id) : type(type), id(id) {} |
| 81 bool is_valid() { return id != kInvalidId; } |
78 | 82 |
79 SourceType type; | 83 SourceType type; |
80 int id; | 84 uint32 id; |
81 }; | 85 }; |
82 | 86 |
83 // Base class for associating additional parameters with an event. Log | 87 // Base class for associating additional parameters with an event. Log |
84 // observers need to know what specific derivations of EventParameters a | 88 // observers need to know what specific derivations of EventParameters a |
85 // particular EventType uses, in order to get at the individual components. | 89 // particular EventType uses, in order to get at the individual components. |
86 class EventParameters : public base::RefCounted<EventParameters> { | 90 class EventParameters : public base::RefCounted<EventParameters> { |
87 public: | 91 public: |
88 EventParameters() {} | 92 EventParameters() {} |
89 virtual ~EventParameters() {} | 93 virtual ~EventParameters() {} |
90 | 94 |
(...skipping 17 matching lines...) Expand all Loading... |
108 // |extra_parameters| - Optional (may be NULL) parameters for this event. | 112 // |extra_parameters| - Optional (may be NULL) parameters for this event. |
109 // The specific subclass of EventParameters is defined | 113 // The specific subclass of EventParameters is defined |
110 // by the contract for events of this |type|. | 114 // by the contract for events of this |type|. |
111 virtual void AddEntry(EventType type, | 115 virtual void AddEntry(EventType type, |
112 const base::TimeTicks& time, | 116 const base::TimeTicks& time, |
113 const Source& source, | 117 const Source& source, |
114 EventPhase phase, | 118 EventPhase phase, |
115 EventParameters* extra_parameters) = 0; | 119 EventParameters* extra_parameters) = 0; |
116 | 120 |
117 // Returns a unique ID which can be used as a source ID. | 121 // Returns a unique ID which can be used as a source ID. |
118 virtual int NextID() = 0; | 122 virtual uint32 NextID() = 0; |
119 | 123 |
120 // Returns true if more complicated messages should be sent to the log. | 124 // Returns true if more complicated messages should be sent to the log. |
121 // TODO(eroman): This is a carry-over from refactoring; figure out | 125 // TODO(eroman): This is a carry-over from refactoring; figure out |
122 // something better. | 126 // something better. |
123 virtual bool HasListener() const = 0; | 127 virtual bool HasListener() const = 0; |
124 | 128 |
125 // Returns a C-String symbolic name for |event_type|. | 129 // Returns a C-String symbolic name for |event_type|. |
126 static const char* EventTypeToString(EventType event_type); | 130 static const char* EventTypeToString(EventType event_type); |
127 | 131 |
128 // Returns a list of all the available EventTypes. | 132 // Returns a list of all the available EventTypes. |
129 static std::vector<EventType> GetAllEventTypes(); | 133 static std::vector<EventType> GetAllEventTypes(); |
130 | 134 |
131 private: | 135 private: |
132 DISALLOW_COPY_AND_ASSIGN(NetLog); | 136 DISALLOW_COPY_AND_ASSIGN(NetLog); |
133 }; | 137 }; |
134 | 138 |
135 // Helper that binds a Source to a NetLog, and exposes convenience methods to | 139 // Helper that binds a Source to a NetLog, and exposes convenience methods to |
136 // output log messages without needing to pass in the source. | 140 // output log messages without needing to pass in the source. |
137 class BoundNetLog { | 141 class BoundNetLog { |
138 public: | 142 public: |
139 BoundNetLog() : net_log_(NULL) {} | 143 BoundNetLog() : net_log_(NULL) {} |
140 | 144 |
141 // TODO(eroman): This is a complete hack to allow passing in NULL in | 145 // TODO(eroman): This is a complete hack to allow passing in NULL in |
142 // place of a BoundNetLog. I added this while refactoring to simplify the | 146 // place of a BoundNetLog. I added this while refactoring to simplify the |
143 // task of updating all the callers. | 147 // task of updating all the callers. |
144 BoundNetLog(int) : net_log_(NULL) {} | 148 BoundNetLog(uint32) : net_log_(NULL) {} |
145 | 149 |
146 BoundNetLog(const NetLog::Source& source, NetLog* net_log) | 150 BoundNetLog(const NetLog::Source& source, NetLog* net_log) |
147 : source_(source), net_log_(net_log) { | 151 : source_(source), net_log_(net_log) { |
148 } | 152 } |
149 | 153 |
150 void AddEntry(NetLog::EventType type, | 154 void AddEntry(NetLog::EventType type, |
151 NetLog::EventPhase phase, | 155 NetLog::EventPhase phase, |
152 NetLog::EventParameters* extra_parameters) const; | 156 NetLog::EventParameters* extra_parameters) const; |
153 | 157 |
154 void AddEntryWithTime(NetLog::EventType type, | 158 void AddEntryWithTime(NetLog::EventType type, |
155 const base::TimeTicks& time, | 159 const base::TimeTicks& time, |
156 NetLog::EventPhase phase, | 160 NetLog::EventPhase phase, |
157 NetLog::EventParameters* extra_parameters) const; | 161 NetLog::EventParameters* extra_parameters) const; |
158 | 162 |
159 // Convenience methods that call through to the NetLog, passing in the | 163 // Convenience methods that call through to the NetLog, passing in the |
160 // currently bound source. | 164 // currently bound source. |
161 void AddEvent(NetLog::EventType event_type) const; | 165 void AddEvent(NetLog::EventType event_type) const; |
162 void AddEventWithParameters(NetLog::EventType event_type, | 166 void AddEventWithParameters(NetLog::EventType event_type, |
163 NetLog::EventParameters* params) const; | 167 NetLog::EventParameters* params) const; |
164 bool HasListener() const; | 168 bool HasListener() const; |
165 void BeginEvent(NetLog::EventType event_type) const; | 169 void BeginEvent(NetLog::EventType event_type) const; |
166 void BeginEventWithParameters(NetLog::EventType event_type, | 170 void BeginEventWithParameters(NetLog::EventType event_type, |
167 NetLog::EventParameters* params) const; | 171 NetLog::EventParameters* params) const; |
168 void BeginEventWithString(NetLog::EventType event_type, | 172 void BeginEventWithString(NetLog::EventType event_type, |
169 const std::string& string) const; | 173 const std::string& string) const; |
| 174 void BeginEventWithInteger(NetLog::EventType event_type, int integer) const; |
170 void AddEventWithInteger(NetLog::EventType event_type, int integer) const; | 175 void AddEventWithInteger(NetLog::EventType event_type, int integer) const; |
171 void EndEvent(NetLog::EventType event_type) const; | 176 void EndEvent(NetLog::EventType event_type) const; |
172 void EndEventWithParameters(NetLog::EventType event_type, | 177 void EndEventWithParameters(NetLog::EventType event_type, |
173 NetLog::EventParameters* params) const; | 178 NetLog::EventParameters* params) const; |
174 void EndEventWithInteger(NetLog::EventType event_type, int integer) const; | 179 void EndEventWithInteger(NetLog::EventType event_type, int integer) const; |
175 | 180 |
176 // Deprecated: Don't add new dependencies that use these methods. Instead, use | 181 // Deprecated: Don't add new dependencies that use these methods. Instead, use |
177 // AddEventWithParameters(). | 182 // AddEventWithParameters(). |
178 void AddString(const std::string& string) const; | 183 void AddString(const std::string& string) const; |
179 void AddStringLiteral(const char* literal) const; | 184 void AddStringLiteral(const char* literal) const; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 // messages. | 276 // messages. |
272 explicit CapturingNetLog(size_t max_num_entries) | 277 explicit CapturingNetLog(size_t max_num_entries) |
273 : next_id_(0), max_num_entries_(max_num_entries) {} | 278 : next_id_(0), max_num_entries_(max_num_entries) {} |
274 | 279 |
275 // NetLog implementation: | 280 // NetLog implementation: |
276 virtual void AddEntry(EventType type, | 281 virtual void AddEntry(EventType type, |
277 const base::TimeTicks& time, | 282 const base::TimeTicks& time, |
278 const Source& source, | 283 const Source& source, |
279 EventPhase phase, | 284 EventPhase phase, |
280 EventParameters* extra_parameters); | 285 EventParameters* extra_parameters); |
281 virtual int NextID(); | 286 virtual uint32 NextID(); |
282 virtual bool HasListener() const { return true; } | 287 virtual bool HasListener() const { return true; } |
283 | 288 |
284 // Returns the list of all entries in the log. | 289 // Returns the list of all entries in the log. |
285 const EntryList& entries() const { return entries_; } | 290 const EntryList& entries() const { return entries_; } |
286 | 291 |
287 void Clear(); | 292 void Clear(); |
288 | 293 |
289 private: | 294 private: |
290 int next_id_; | 295 uint32 next_id_; |
291 size_t max_num_entries_; | 296 size_t max_num_entries_; |
292 EntryList entries_; | 297 EntryList entries_; |
293 | 298 |
294 DISALLOW_COPY_AND_ASSIGN(CapturingNetLog); | 299 DISALLOW_COPY_AND_ASSIGN(CapturingNetLog); |
295 }; | 300 }; |
296 | 301 |
297 // Helper class that exposes a similar API as BoundNetLog, but uses a | 302 // Helper class that exposes a similar API as BoundNetLog, but uses a |
298 // CapturingNetLog rather than the more generic NetLog. | 303 // CapturingNetLog rather than the more generic NetLog. |
299 // | 304 // |
300 // CapturingBoundNetLog can easily be converted to a BoundNetLog using the | 305 // CapturingBoundNetLog can easily be converted to a BoundNetLog using the |
(...skipping 26 matching lines...) Expand all Loading... |
327 private: | 332 private: |
328 NetLog::Source source_; | 333 NetLog::Source source_; |
329 scoped_ptr<CapturingNetLog> capturing_net_log_; | 334 scoped_ptr<CapturingNetLog> capturing_net_log_; |
330 | 335 |
331 DISALLOW_COPY_AND_ASSIGN(CapturingBoundNetLog); | 336 DISALLOW_COPY_AND_ASSIGN(CapturingBoundNetLog); |
332 }; | 337 }; |
333 | 338 |
334 } // namespace net | 339 } // namespace net |
335 | 340 |
336 #endif // NET_BASE_NET_LOG_H_ | 341 #endif // NET_BASE_NET_LOG_H_ |
OLD | NEW |