Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: net/base/net_log.h

Issue 1716007: Cleanup: Address some of the todos in net_log.h... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Address willchan's comments Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/host_resolver_impl.cc ('k') | net/base/net_log.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/ref_counted.h" 12 #include "base/ref_counted.h"
13 #include "base/scoped_ptr.h" 13 #include "base/scoped_ptr.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "net/base/net_log.h" 15 #include "net/base/net_log.h"
16 16
17 class Value;
18
17 namespace net { 19 namespace net {
18 20
19 // NetLog is the destination for log messages generated by the network stack. 21 // NetLog is the destination for log messages generated by the network stack.
20 // Each log message has a "source" field which identifies the specific entity 22 // Each log message has a "source" field which identifies the specific entity
21 // that generated the message (for example, which URLRequest or which 23 // that generated the message (for example, which URLRequest or which
22 // SocketStream). 24 // SocketStream).
23 // 25 //
24 // To avoid needing to pass in the "source id" to the logging functions, NetLog 26 // To avoid needing to pass in the "source id" to the logging functions, NetLog
25 // is usually accessed through a BoundNetLog, which will always pass in a 27 // is usually accessed through a BoundNetLog, which will always pass in a
26 // specific source ID. 28 // specific source ID.
27 // 29 //
28 // Note that NetLog is NOT THREADSAFE. 30 // Note that NetLog is NOT THREADSAFE.
29 // 31 //
30 // ******** The NetLog (and associated logging) is a work in progress ******** 32 // ******** The NetLog (and associated logging) is a work in progress ********
31 // 33 //
32 // TODO(eroman): Remove the 'const' qualitifer from the BoundNetLog methods. 34 // TODO(eroman): Remove the 'const' qualitifer from the BoundNetLog methods.
33 // TODO(eroman): Remove the AddString() and AddStringLiteral() methods.
34 // These are a carry-over from old approach. Really, consumers
35 // should be calling AddEventWithParameters(), and passing a
36 // custom EventParameters* object that encapsulates all of the
37 // interesting state.
38 // TODO(eroman): Remove NetLogUtil. Pretty printing should only be done from 35 // TODO(eroman): Remove NetLogUtil. Pretty printing should only be done from
39 // javascript, and should be very context-aware. 36 // javascript, and should be very context-aware.
40 // TODO(eroman): Move Capturing*NetLog to its own file. (And eventually remove 37 // TODO(eroman): Move Capturing*NetLog to its own file. (And eventually remove
41 // all the consumers of it). 38 // all the consumers of it).
42 // TODO(eroman): Make the DNS jobs emit directly into the NetLog. 39 // TODO(eroman): Make the DNS jobs emit directly into the NetLog.
43 // TODO(eroman): Start a new Source each time URLRequest redirects 40 // TODO(eroman): Start a new Source each time URLRequest redirects
44 // (simpler to reason about each as a separate entity). 41 // (simpler to reason about each as a separate entity).
45 // TODO(eroman): Add the URLRequest load flags to the start entry. 42 // TODO(eroman): Add the URLRequest load flags to the start entry.
46 43
47 class NetLog { 44 class NetLog {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 }; 82 };
86 83
87 // Base class for associating additional parameters with an event. Log 84 // Base class for associating additional parameters with an event. Log
88 // observers need to know what specific derivations of EventParameters a 85 // observers need to know what specific derivations of EventParameters a
89 // particular EventType uses, in order to get at the individual components. 86 // particular EventType uses, in order to get at the individual components.
90 class EventParameters : public base::RefCounted<EventParameters> { 87 class EventParameters : public base::RefCounted<EventParameters> {
91 public: 88 public:
92 EventParameters() {} 89 EventParameters() {}
93 virtual ~EventParameters() {} 90 virtual ~EventParameters() {}
94 91
95 // Serializes the parameters to a string representation (this should be a 92 // Serializes the parameters to a Value tree. This is intended to be a
96 // lossless conversion). 93 // lossless conversion, which is used to serialize the parameters to JSON.
97 virtual std::string ToString() const = 0; 94 // The caller takes ownership of the returned Value*.
95 virtual Value* ToValue() const = 0;
98 96
99 private: 97 private:
100 DISALLOW_COPY_AND_ASSIGN(EventParameters); 98 DISALLOW_COPY_AND_ASSIGN(EventParameters);
101 }; 99 };
102 100
103 NetLog() {} 101 NetLog() {}
104 virtual ~NetLog() {} 102 virtual ~NetLog() {}
105 103
106 // Emits an event to the log stream. 104 // Emits an event to the log stream.
107 // |type| - The type of the event. 105 // |type| - The type of the event.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // Convenience methods that call through to the NetLog, passing in the 161 // Convenience methods that call through to the NetLog, passing in the
164 // currently bound source. 162 // currently bound source.
165 void AddEvent(NetLog::EventType event_type) const; 163 void AddEvent(NetLog::EventType event_type) const;
166 void AddEventWithParameters(NetLog::EventType event_type, 164 void AddEventWithParameters(NetLog::EventType event_type,
167 NetLog::EventParameters* params) const; 165 NetLog::EventParameters* params) const;
168 bool HasListener() const; 166 bool HasListener() const;
169 void BeginEvent(NetLog::EventType event_type) const; 167 void BeginEvent(NetLog::EventType event_type) const;
170 void BeginEventWithParameters(NetLog::EventType event_type, 168 void BeginEventWithParameters(NetLog::EventType event_type,
171 NetLog::EventParameters* params) const; 169 NetLog::EventParameters* params) const;
172 void BeginEventWithString(NetLog::EventType event_type, 170 void BeginEventWithString(NetLog::EventType event_type,
173 const std::string& string) const; 171 const char* name, const std::string& value) const;
174 void BeginEventWithInteger(NetLog::EventType event_type, int integer) const; 172 void BeginEventWithInteger(NetLog::EventType event_type,
175 void AddEventWithInteger(NetLog::EventType event_type, int integer) const; 173 const char* name, int value) const;
174 void AddEventWithInteger(NetLog::EventType event_type,
175 const char* name, int value) const;
176 void AddEventWithString(NetLog::EventType event_type,
177 const char* name, const std::string& value) const;
176 void EndEvent(NetLog::EventType event_type) const; 178 void EndEvent(NetLog::EventType event_type) const;
177 void EndEventWithParameters(NetLog::EventType event_type, 179 void EndEventWithParameters(NetLog::EventType event_type,
178 NetLog::EventParameters* params) const; 180 NetLog::EventParameters* params) const;
179 void EndEventWithInteger(NetLog::EventType event_type, int integer) const; 181 void EndEventWithInteger(NetLog::EventType event_type,
180 182 const char* name, int value) const;
181 // Deprecated: Don't add new dependencies that use these methods. Instead, use
182 // AddEventWithParameters().
183 void AddString(const std::string& string) const;
184 void AddStringLiteral(const char* literal) const;
185 183
186 // Helper to create a BoundNetLog given a NetLog and a SourceType. Takes care 184 // Helper to create a BoundNetLog given a NetLog and a SourceType. Takes care
187 // of creating a unique source ID, and handles the case of NULL net_log. 185 // of creating a unique source ID, and handles the case of NULL net_log.
188 static BoundNetLog Make(NetLog* net_log, NetLog::SourceType source_type); 186 static BoundNetLog Make(NetLog* net_log, NetLog::SourceType source_type);
189 187
190 const NetLog::Source& source() const { return source_; } 188 const NetLog::Source& source() const { return source_; }
191 NetLog* net_log() const { return net_log_; } 189 NetLog* net_log() const { return net_log_; }
192 190
193 private: 191 private:
194 NetLog::Source source_; 192 NetLog::Source source_;
195 NetLog* net_log_; 193 NetLog* net_log_;
196 }; 194 };
197 195
198 // NetLogStringParameter is a subclass of EventParameters that encapsulates a 196 // NetLogStringParameter is a subclass of EventParameters that encapsulates a
199 // single std::string parameter. 197 // single std::string parameter.
200 class NetLogStringParameter : public NetLog::EventParameters { 198 class NetLogStringParameter : public NetLog::EventParameters {
201 public: 199 public:
202 explicit NetLogStringParameter(const std::string& value); 200 // |name| must be a string literal.
201 NetLogStringParameter(const char* name, const std::string& value);
203 202
204 const std::string& value() const { 203 const std::string& value() const {
205 return value_; 204 return value_;
206 } 205 }
207 206
208 virtual std::string ToString() const { 207 virtual Value* ToValue() const;
209 return value_;
210 }
211 208
212 private: 209 private:
213 std::string value_; 210 const char* const name_;
211 const std::string value_;
214 }; 212 };
215 213
216 // NetLogIntegerParameter is a subclass of EventParameters that encapsulates a 214 // NetLogIntegerParameter is a subclass of EventParameters that encapsulates a
217 // single integer parameter. 215 // single integer parameter.
218 class NetLogIntegerParameter : public NetLog::EventParameters { 216 class NetLogIntegerParameter : public NetLog::EventParameters {
219 public: 217 public:
220 explicit NetLogIntegerParameter(int value) : value_(value) {} 218 // |name| must be a string literal.
219 NetLogIntegerParameter(const char* name, int value)
220 : name_(name), value_(value) {}
221 221
222 int value() const { 222 int value() const {
223 return value_; 223 return value_;
224 } 224 }
225 225
226 virtual std::string ToString() const; 226 virtual Value* ToValue() const;
227 227
228 private: 228 private:
229 const char* name_;
229 const int value_; 230 const int value_;
230 }; 231 };
231 232
232 // NetLogStringLiteralParameter is a subclass of EventParameters that
233 // encapsulates a single string literal parameter.
234 class NetLogStringLiteralParameter : public NetLog::EventParameters {
235 public:
236 explicit NetLogStringLiteralParameter(const char* value) : value_(value) {}
237
238 const char* const value() const {
239 return value_;
240 }
241
242 virtual std::string ToString() const;
243
244 private:
245 const char* const value_;
246 };
247
248
249 // CapturingNetLog is an implementation of NetLog that saves messages to a 233 // CapturingNetLog is an implementation of NetLog that saves messages to a
250 // bounded buffer. 234 // bounded buffer.
251 class CapturingNetLog : public NetLog { 235 class CapturingNetLog : public NetLog {
252 public: 236 public:
253 struct Entry { 237 struct Entry {
254 Entry(EventType type, 238 Entry(EventType type,
255 const base::TimeTicks& time, 239 const base::TimeTicks& time,
256 Source source, 240 Source source,
257 EventPhase phase, 241 EventPhase phase,
258 EventParameters* extra_parameters) 242 EventParameters* extra_parameters)
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 private: 316 private:
333 NetLog::Source source_; 317 NetLog::Source source_;
334 scoped_ptr<CapturingNetLog> capturing_net_log_; 318 scoped_ptr<CapturingNetLog> capturing_net_log_;
335 319
336 DISALLOW_COPY_AND_ASSIGN(CapturingBoundNetLog); 320 DISALLOW_COPY_AND_ASSIGN(CapturingBoundNetLog);
337 }; 321 };
338 322
339 } // namespace net 323 } // namespace net
340 324
341 #endif // NET_BASE_NET_LOG_H_ 325 #endif // NET_BASE_NET_LOG_H_
OLDNEW
« no previous file with comments | « net/base/host_resolver_impl.cc ('k') | net/base/net_log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698