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

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

Issue 10399083: Make NetLog take in callbacks that return Values (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix merge error Created 8 years, 6 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/file_stream_unittest.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) 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
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback_forward.h"
12 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
14 #include "net/base/net_export.h" 16 #include "net/base/net_export.h"
15 17
16 namespace base { 18 namespace base {
19 class DictionaryValue;
17 class TimeTicks; 20 class TimeTicks;
18 class Value; 21 class Value;
19 } 22 }
20 23
21 namespace net { 24 namespace net {
22 25
23 // NetLog is the destination for log messages generated by the network stack. 26 // NetLog is the destination for log messages generated by the network stack.
24 // Each log message has a "source" field which identifies the specific entity 27 // Each log message has a "source" field which identifies the specific entity
25 // that generated the message (for example, which URLRequest or which 28 // that generated the message (for example, which URLRequest or which
26 // SocketStream). 29 // SocketStream).
27 // 30 //
28 // To avoid needing to pass in the "source ID" to the logging functions, NetLog 31 // To avoid needing to pass in the "source ID" to the logging functions, NetLog
29 // is usually accessed through a BoundNetLog, which will always pass in a 32 // is usually accessed through a BoundNetLog, which will always pass in a
30 // specific source ID. 33 // specific source ID.
31 // 34 //
35 // All NetLog methods must be thread-safe.
32 class NET_EXPORT NetLog { 36 class NET_EXPORT NetLog {
33 public: 37 public:
34 enum EventType { 38 enum EventType {
35 #define EVENT_TYPE(label) TYPE_ ## label, 39 #define EVENT_TYPE(label) TYPE_ ## label,
36 #include "net/base/net_log_event_type_list.h" 40 #include "net/base/net_log_event_type_list.h"
37 #undef EVENT_TYPE 41 #undef EVENT_TYPE
38 EVENT_COUNT 42 EVENT_COUNT
39 }; 43 };
40 44
41 // The 'phase' of an event trace (whether it marks the beginning or end 45 // The 'phase' of an event trace (whether it marks the beginning or end
42 // of an event.). 46 // of an event.).
43 enum EventPhase { 47 enum EventPhase {
44 PHASE_NONE, 48 PHASE_NONE,
45 PHASE_BEGIN, 49 PHASE_BEGIN,
46 PHASE_END, 50 PHASE_END,
47 }; 51 };
48 52
49 // The "source" identifies the entity that generated the log message. 53 // The "source" identifies the entity that generated the log message.
50 enum SourceType { 54 enum SourceType {
51 #define SOURCE_TYPE(label) SOURCE_ ## label, 55 #define SOURCE_TYPE(label) SOURCE_ ## label,
52 #include "net/base/net_log_source_type_list.h" 56 #include "net/base/net_log_source_type_list.h"
53 #undef SOURCE_TYPE 57 #undef SOURCE_TYPE
54 SOURCE_COUNT 58 SOURCE_COUNT
55 }; 59 };
56 60
61 // Specifies the granularity of events that should be emitted to the log.
62 enum LogLevel {
63 // Log everything possible, even if it is slow and memory expensive.
64 // Includes logging of transferred bytes.
65 LOG_ALL,
66
67 // Log all events, but do not include the actual transferred bytes as
68 // parameters for bytes sent/received events.
69 LOG_ALL_BUT_BYTES,
70
71 // Only log events which are cheap, and don't consume much memory.
72 LOG_BASIC,
73 };
74
75 // A callback function that return a Value representation of the parameters
76 // associated with an event. If called, it will be called synchonously,
77 // so it need not have owning references. May be called more than once, or
78 // not at all. May return NULL.
79 typedef base::Callback<base::Value*(LogLevel)> ParametersCallback;
80
57 // Identifies the entity that generated this log. The |id| field should 81 // Identifies the entity that generated this log. The |id| field should
58 // uniquely identify the source, and is used by log observers to infer 82 // uniquely identify the source, and is used by log observers to infer
59 // message groupings. Can use NetLog::NextID() to create unique IDs. 83 // message groupings. Can use NetLog::NextID() to create unique IDs.
60 struct NET_EXPORT Source { 84 struct NET_EXPORT Source {
61 static const uint32 kInvalidId = 0; 85 static const uint32 kInvalidId = 0;
62 86
63 Source() : type(SOURCE_NONE), id(kInvalidId) {} 87 Source() : type(SOURCE_NONE), id(kInvalidId) {}
64 Source(SourceType type, uint32 id) : type(type), id(id) {} 88 Source(SourceType type, uint32 id) : type(type), id(id) {}
65 bool is_valid() const { return id != kInvalidId; } 89 bool is_valid() const { return id != kInvalidId; }
66 90
67 // The caller takes ownership of the returned Value*. 91 // Obsolete. The caller takes ownership of the returned Value*.
92 // TODO(mmenke): Remove this.
68 base::Value* ToValue() const; 93 base::Value* ToValue() const;
69 94
95 // Adds the source to a DictionaryValue containing event parameters,
96 // using the name "source_dependency".
97 void AddToEventParameters(base::DictionaryValue* event_params) const;
98
99 // Returns a callback that returns a dictionary with a single entry
100 // named "source_dependecy" that describes |this|.
101 ParametersCallback ToEventParametersCallback() const;
102
103 // Attempts to extract a Source from a set of event parameters. Returns
104 // true and writes the result to |source| on success. Returns false and
105 // makes |source| an invalid source on failure.
106 // TODO(mmenke): Long term, we want to remove this.
107 static bool FromEventParameters(base::Value* event_params, Source* source);
108
70 SourceType type; 109 SourceType type;
71 uint32 id; 110 uint32 id;
72 }; 111 };
73 112
74 // Base class for associating additional parameters with an event. Log 113 // Base class for associating additional parameters with an event. Log
75 // observers need to know what specific derivations of EventParameters a 114 // observers need to know what specific derivations of EventParameters a
76 // particular EventType uses, in order to get at the individual components. 115 // particular EventType uses, in order to get at the individual components.
116 // This class is obsolete. New code should use ParametersCallbacks.
117 // TODO(mmenke): Update users of this class and get rid of it.
77 class NET_EXPORT EventParameters 118 class NET_EXPORT EventParameters
78 : public base::RefCountedThreadSafe<EventParameters> { 119 : public base::RefCountedThreadSafe<EventParameters> {
79 public: 120 public:
80 EventParameters() {} 121 EventParameters() {}
81 122
82 // Serializes the parameters to a Value tree. This is intended to be a 123 // Serializes the parameters to a Value tree. This is intended to be a
83 // lossless conversion, which is used to serialize the parameters to JSON. 124 // lossless conversion, which is used to serialize the parameters to JSON.
84 // The caller takes ownership of the returned Value*. 125 // The caller takes ownership of the returned Value*.
85 virtual base::Value* ToValue() const = 0; 126 virtual base::Value* ToValue() const = 0;
86 127
87 protected: 128 protected:
88 virtual ~EventParameters() {} 129 virtual ~EventParameters() {}
89 130
90 private: 131 private:
91 friend class base::RefCountedThreadSafe<EventParameters>; 132 friend class base::RefCountedThreadSafe<EventParameters>;
92 133
93 DISALLOW_COPY_AND_ASSIGN(EventParameters); 134 DISALLOW_COPY_AND_ASSIGN(EventParameters);
94 }; 135 };
95 136
96 // Specifies the granularity of events that should be emitted to the log. 137 class NET_EXPORT Entry {
97 enum LogLevel { 138 public:
98 // Log everything possible, even if it is slow and memory expensive. 139 Entry(EventType type,
99 // Includes logging of transferred bytes. 140 Source source,
100 LOG_ALL, 141 EventPhase phase,
142 const ParametersCallback* parameters_callback,
143 LogLevel log_level);
144 ~Entry();
101 145
102 // Log all events, but do not include the actual transferred bytes as 146 EventType type() const { return type_; }
103 // parameters for bytes sent/received events. 147 Source source() const { return source_; }
104 LOG_ALL_BUT_BYTES, 148 EventPhase phase() const { return phase_; }
105 149
106 // Only log events which are cheap, and don't consume much memory. 150 // Serializes the specified event to a Value. The Value also includes the
107 LOG_BASIC, 151 // current time. Caller takes ownership of returned Value.
152 base::Value* ToValue() const;
153
154 // Returns the parameters as a Value. Returns NULL if there are no
155 // parameters. Caller takes ownership of returned Value.
156 base::Value* ParametersToValue() const;
157
158 private:
159 const EventType type_;
160 const Source source_;
161 const EventPhase phase_;
162 const ParametersCallback* parameters_callback_;
163
164 // Log level when the event occurred.
165 const LogLevel log_level_;
166
167 // It is not safe to copy this class, since |parameters_callback_| may
168 // include pointers that become stale immediately after the event is added,
169 // even if the code were modified to keep its own copy of the callback.
170 DISALLOW_COPY_AND_ASSIGN(Entry);
108 }; 171 };
109 172
110 // An observer, that must ensure its own thread safety, for events 173 // An observer, that must ensure its own thread safety, for events
111 // being added to a NetLog. 174 // being added to a NetLog.
112 class NET_EXPORT ThreadSafeObserver { 175 class NET_EXPORT ThreadSafeObserver {
113 public: 176 public:
114 // Constructs an observer that wants to see network events, with 177 // Constructs an observer that wants to see network events, with
115 // the specified minimum event granularity. A ThreadSafeObserver can only 178 // the specified minimum event granularity. A ThreadSafeObserver can only
116 // observe a single NetLog at a time. 179 // observe a single NetLog at a time.
117 // 180 //
(...skipping 11 matching lines...) Expand all
129 // Returns the NetLog we are currently watching, if any. Returns NULL 192 // Returns the NetLog we are currently watching, if any. Returns NULL
130 // otherwise. 193 // otherwise.
131 NetLog* net_log() const; 194 NetLog* net_log() const;
132 195
133 // This method will be called on the thread that the event occurs on. It 196 // This method will be called on the thread that the event occurs on. It
134 // is the responsibility of the observer to handle it in a thread safe 197 // is the responsibility of the observer to handle it in a thread safe
135 // manner. 198 // manner.
136 // 199 //
137 // It is illegal for an Observer to call any NetLog or 200 // It is illegal for an Observer to call any NetLog or
138 // NetLog::Observer functions in response to a call to OnAddEntry. 201 // NetLog::Observer functions in response to a call to OnAddEntry.
139 // 202 virtual void OnAddEntry(const Entry& entry) = 0;
140 // |type| - The type of the event.
141 // |time| - The time when the event occurred.
142 // |source| - The source that generated the event.
143 // |phase| - An optional parameter indicating whether this is the start/end
144 // of an action.
145 // |params| - Optional (may be NULL) parameters for this event.
146 // The specific subclass of EventParameters is defined
147 // by the contract for events of this |type|.
148 // TODO(eroman): Take a scoped_refptr<EventParameters> instead.
149 virtual void OnAddEntry(EventType type,
150 const base::TimeTicks& time,
151 const Source& source,
152 EventPhase phase,
153 EventParameters* params) = 0;
154 203
155 protected: 204 protected:
156 virtual ~ThreadSafeObserver(); 205 virtual ~ThreadSafeObserver();
157 206
158 private: 207 private:
159 friend class NetLog; 208 friend class NetLog;
160 209
161 // Both of these values are only modified by the NetLog. 210 // Both of these values are only modified by the NetLog.
162 LogLevel log_level_; 211 LogLevel log_level_;
163 NetLog* net_log_; 212 NetLog* net_log_;
164 213
165 DISALLOW_COPY_AND_ASSIGN(ThreadSafeObserver); 214 DISALLOW_COPY_AND_ASSIGN(ThreadSafeObserver);
166 }; 215 };
167 216
168 NetLog() {} 217 NetLog() {}
169 virtual ~NetLog() {} 218 virtual ~NetLog() {}
170 219
171 // Emits a global event to the log stream, with its own unique source ID. 220 // Emits a global event to the log stream, with its own unique source ID.
221 void AddGlobalEntry(EventType type);
222 void AddGlobalEntry(EventType type,
223 const NetLog::ParametersCallback& parameters_callback);
224
225 // Older, obsolete version of above functions. Use the ParametersCallback
226 // versions instead.
227 // TODO(mmenke): Remove this.
172 void AddGlobalEntry(EventType type, 228 void AddGlobalEntry(EventType type,
173 const scoped_refptr<EventParameters>& params); 229 const scoped_refptr<EventParameters>& params);
174 230
175 // Returns a unique ID which can be used as a source ID. 231 // Returns a unique ID which can be used as a source ID. All returned IDs
232 // will be unique and greater than 0.
176 virtual uint32 NextID() = 0; 233 virtual uint32 NextID() = 0;
177 234
178 // Returns the logging level for this NetLog. This is used to avoid computing 235 // Returns the logging level for this NetLog. This is used to avoid computing
179 // and saving expensive log entries. 236 // and saving expensive log entries.
180 virtual LogLevel GetLogLevel() const = 0; 237 virtual LogLevel GetLogLevel() const = 0;
181 238
182 // Adds an observer and sets its log level. The observer must not be 239 // Adds an observer and sets its log level. The observer must not be
183 // watching any NetLog, including this one, when this is called. 240 // watching any NetLog, including this one, when this is called.
184 // 241 //
185 // Typical observers should specify LOG_BASIC. 242 // Typical observers should specify LOG_BASIC.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 // Returns a C-String symbolic name for |source_type|. 276 // Returns a C-String symbolic name for |source_type|.
220 static const char* SourceTypeToString(SourceType source_type); 277 static const char* SourceTypeToString(SourceType source_type);
221 278
222 // Returns a dictionary that maps source type symbolic names to their enum 279 // Returns a dictionary that maps source type symbolic names to their enum
223 // values. Caller takes ownership of the returned Value. 280 // values. Caller takes ownership of the returned Value.
224 static base::Value* GetSourceTypesAsValue(); 281 static base::Value* GetSourceTypesAsValue();
225 282
226 // Returns a C-String symbolic name for |event_phase|. 283 // Returns a C-String symbolic name for |event_phase|.
227 static const char* EventPhaseToString(EventPhase event_phase); 284 static const char* EventPhaseToString(EventPhase event_phase);
228 285
229 // Serializes the specified event to a DictionaryValue. 286 // Returns true if |log_level| indicates the actual bytes transferred should
230 // If |use_strings| is true, uses strings rather than numeric ids. 287 // be logged. This is only the case when |log_level| is LOG_ALL.
231 static base::Value* EntryToDictionaryValue(NetLog::EventType type, 288 static bool IsLoggingBytes(LogLevel log_level);
232 const base::TimeTicks& time, 289
233 const NetLog::Source& source, 290 // Returns true if |log_level| indicates that all events should be logged,
234 NetLog::EventPhase phase, 291 // including frequently occuring ones that may impact performances.
235 NetLog::EventParameters* params, 292 // This is the case when |log_level| is LOG_ALL or LOG_ALL_BUT_BYTES.
236 bool use_strings); 293 static bool IsLoggingAllEvents(LogLevel log_level);
294
295 // Creates a ParametersCallback that encapsulates a single integer.
296 // Warning: |name| must remain valid for the life of the callback.
297 static ParametersCallback IntegerCallback(const char* name, int value);
237 298
238 protected: 299 protected:
239 // This is the internal function used by AddGlobalEntry and BoundNetLogs. 300 // Child classes should respond to the new entry here. This includes
240 virtual void AddEntry( 301 // creating the Entry object and alerting their observers.
241 EventType type, 302 virtual void OnAddEntry(const Entry& entry) = 0;
242 const Source& source,
243 EventPhase phase,
244 const scoped_refptr<NetLog::EventParameters>& params) = 0;
245 303
246 // Subclasses must call these in the corresponding functions to set an 304 // Subclasses must call these in the corresponding functions to set an
247 // observer's |net_log_| and |log_level_| values. 305 // observer's |net_log_| and |log_level_| values.
248 void OnAddObserver(ThreadSafeObserver* observer, LogLevel log_level); 306 void OnAddObserver(ThreadSafeObserver* observer, LogLevel log_level);
249 void OnSetObserverLogLevel(ThreadSafeObserver* observer, 307 void OnSetObserverLogLevel(ThreadSafeObserver* observer,
250 LogLevel log_level); 308 LogLevel log_level);
251 void OnRemoveObserver(ThreadSafeObserver* observer); 309 void OnRemoveObserver(ThreadSafeObserver* observer);
252 310
253 private: 311 private:
254 friend class BoundNetLog; 312 friend class BoundNetLog;
255 313
314 void AddEntry(EventType type,
315 const Source& source,
316 EventPhase phase,
317 const NetLog::ParametersCallback* parameters_callback);
318
256 DISALLOW_COPY_AND_ASSIGN(NetLog); 319 DISALLOW_COPY_AND_ASSIGN(NetLog);
257 }; 320 };
258 321
259 // Helper that binds a Source to a NetLog, and exposes convenience methods to 322 // Helper that binds a Source to a NetLog, and exposes convenience methods to
260 // output log messages without needing to pass in the source. 323 // output log messages without needing to pass in the source.
261 class NET_EXPORT BoundNetLog { 324 class NET_EXPORT BoundNetLog {
262 public: 325 public:
263 BoundNetLog() : net_log_(NULL) {} 326 BoundNetLog() : net_log_(NULL) {}
264 327
265 // Convenience methods that call through to the NetLog, passing in the 328 // Add a log entry to the NetLog for the bound source.
266 // currently bound source. 329 void AddEntry(NetLog::EventType type, NetLog::EventPhase phase) const;
330 void AddEntry(NetLog::EventType type,
331 NetLog::EventPhase phase,
332 const NetLog::ParametersCallback& get_parameters) const;
333
334 // Convenience methods that call AddEntry with a fixed "capture phase"
335 // (begin, end, or none).
336 void BeginEvent(NetLog::EventType type) const;
337 void BeginEvent(NetLog::EventType type,
338 const NetLog::ParametersCallback& get_parameters) const;
339
340 void EndEvent(NetLog::EventType type) const;
341 void EndEvent(NetLog::EventType type,
342 const NetLog::ParametersCallback& get_parameters) const;
343
344 void AddEvent(NetLog::EventType type) const;
345 void AddEvent(NetLog::EventType type,
346 const NetLog::ParametersCallback& get_parameters) const;
347
348 // Obsolete versions of the above functions.
349 // Use the ParametersCallback versions of these functions instead.
350 // TODO(mmenke): Remove these.
267 void AddEntry(NetLog::EventType type, 351 void AddEntry(NetLog::EventType type,
268 NetLog::EventPhase phase, 352 NetLog::EventPhase phase,
269 const scoped_refptr<NetLog::EventParameters>& params) const; 353 const scoped_refptr<NetLog::EventParameters>& params) const;
270
271 // Convenience methods that call through to the NetLog, passing in the
272 // currently bound source, current time, and a fixed "capture phase"
273 // (begin, end, or none).
274 void AddEvent(NetLog::EventType event_type, 354 void AddEvent(NetLog::EventType event_type,
275 const scoped_refptr<NetLog::EventParameters>& params) const; 355 const scoped_refptr<NetLog::EventParameters>& params) const;
276 void BeginEvent(NetLog::EventType event_type, 356 void BeginEvent(NetLog::EventType event_type,
277 const scoped_refptr<NetLog::EventParameters>& params) const; 357 const scoped_refptr<NetLog::EventParameters>& params) const;
278 void EndEvent(NetLog::EventType event_type, 358 void EndEvent(NetLog::EventType event_type,
279 const scoped_refptr<NetLog::EventParameters>& params) const; 359 const scoped_refptr<NetLog::EventParameters>& params) const;
280 360
281 // Just like AddEvent, except |net_error| is a net error code. A parameter 361 // Just like AddEvent, except |net_error| is a net error code. A parameter
282 // called "net_error" with the indicated value will be recorded for the event. 362 // called "net_error" with the indicated value will be recorded for the event.
283 // |net_error| must be negative, and not ERR_IO_PENDING, as it's not a true 363 // |net_error| must be negative, and not ERR_IO_PENDING, as it's not a true
284 // error. 364 // error.
285 void AddEventWithNetErrorCode(NetLog::EventType event_type, 365 void AddEventWithNetErrorCode(NetLog::EventType event_type,
286 int net_error) const; 366 int net_error) const;
287 367
288 // Just like EndEvent, except |net_error| is a net error code. If it's 368 // Just like EndEvent, except |net_error| is a net error code. If it's
289 // negative, a parameter called "net_error" with a value of |net_error| is 369 // negative, a parameter called "net_error" with a value of |net_error| is
290 // associated with the event. Otherwise, the end event has no parameters. 370 // associated with the event. Otherwise, the end event has no parameters.
291 // |net_error| must not be ERR_IO_PENDING, as it's not a true error. 371 // |net_error| must not be ERR_IO_PENDING, as it's not a true error.
292 void EndEventWithNetErrorCode(NetLog::EventType event_type, 372 void EndEventWithNetErrorCode(NetLog::EventType event_type,
293 int net_error) const; 373 int net_error) const;
294 374
295 // Logs a byte transfer event to the NetLog. Determines whether to log the 375 // Logs a byte transfer event to the NetLog. Determines whether to log the
296 // received bytes or not based on the current logging level. 376 // received bytes or not based on the current logging level.
297 void AddByteTransferEvent(NetLog::EventType event_type, 377 void AddByteTransferEvent(NetLog::EventType event_type,
298 int byte_count, const char* bytes) const; 378 int byte_count, const char* bytes) const;
299 379
300 NetLog::LogLevel GetLogLevel() const; 380 NetLog::LogLevel GetLogLevel() const;
301 381
302 // Returns true if the log level is LOG_ALL. 382 // Shortcut for NetLog::IsLoggingBytes(this->GetLogLevel()).
303 bool IsLoggingBytes() const; 383 bool IsLoggingBytes() const;
304 384
305 // Returns true if the log level is LOG_ALL or LOG_ALL_BUT_BYTES. 385 // Shortcut for NetLog::IsLoggingAllEvents(this->GetLogLevel()).
306 bool IsLoggingAllEvents() const; 386 bool IsLoggingAllEvents() const;
307 387
308 // Helper to create a BoundNetLog given a NetLog and a SourceType. Takes care 388 // Helper to create a BoundNetLog given a NetLog and a SourceType. Takes care
309 // of creating a unique source ID, and handles the case of NULL net_log. 389 // of creating a unique source ID, and handles the case of NULL net_log.
310 static BoundNetLog Make(NetLog* net_log, NetLog::SourceType source_type); 390 static BoundNetLog Make(NetLog* net_log, NetLog::SourceType source_type);
311 391
312 const NetLog::Source& source() const { return source_; } 392 const NetLog::Source& source() const { return source_; }
313 NetLog* net_log() const { return net_log_; } 393 NetLog* net_log() const { return net_log_; }
314 394
315 private: 395 private:
316 BoundNetLog(const NetLog::Source& source, NetLog* net_log) 396 BoundNetLog(const NetLog::Source& source, NetLog* net_log)
317 : source_(source), net_log_(net_log) { 397 : source_(source), net_log_(net_log) {
318 } 398 }
319 399
320 NetLog::Source source_; 400 NetLog::Source source_;
321 NetLog* net_log_; 401 NetLog* net_log_;
322 }; 402 };
323 403
404 // All the classes below are obsolete. New code should use ParametersCallbacks.
405 // TODO(mmenke): Update users these classes and get rid of them.
406
324 // NetLogStringParameter is a subclass of EventParameters that encapsulates a 407 // NetLogStringParameter is a subclass of EventParameters that encapsulates a
325 // single std::string parameter. 408 // single std::string parameter.
326 class NET_EXPORT NetLogStringParameter : public NetLog::EventParameters { 409 class NET_EXPORT NetLogStringParameter : public NetLog::EventParameters {
327 public: 410 public:
328 // |name| must be a string literal. 411 // |name| must be a string literal.
329 NetLogStringParameter(const char* name, const std::string& value); 412 NetLogStringParameter(const char* name, const std::string& value);
330 413
331 const std::string& value() const { 414 const std::string& value() const {
332 return value_; 415 return value_;
333 } 416 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 virtual base::Value* ToValue() const OVERRIDE; 462 virtual base::Value* ToValue() const OVERRIDE;
380 463
381 protected: 464 protected:
382 virtual ~NetLogSourceParameter() {} 465 virtual ~NetLogSourceParameter() {}
383 466
384 private: 467 private:
385 const char* name_; 468 const char* name_;
386 const NetLog::Source value_; 469 const NetLog::Source value_;
387 }; 470 };
388 471
389 // ScopedNetLogEvent logs a begin event on creation, and the corresponding end
390 // event on destruction.
391 class NET_EXPORT_PRIVATE ScopedNetLogEvent {
392 public:
393 ScopedNetLogEvent(const BoundNetLog& net_log,
394 NetLog::EventType event_type,
395 const scoped_refptr<NetLog::EventParameters>& params);
396
397 ~ScopedNetLogEvent();
398
399 // Sets the parameters that will logged on object destruction. Can be called
400 // at most once for a given ScopedNetLogEvent object. If not called, the end
401 // event will have no parameters.
402 void SetEndEventParameters(
403 const scoped_refptr<NetLog::EventParameters>& end_event_params);
404
405 const BoundNetLog& net_log() const;
406
407 private:
408 BoundNetLog net_log_;
409 const NetLog::EventType event_type_;
410 scoped_refptr<NetLog::EventParameters> end_event_params_;
411 };
412
413 } // namespace net 472 } // namespace net
414 473
415 #endif // NET_BASE_NET_LOG_H_ 474 #endif // NET_BASE_NET_LOG_H_
OLDNEW
« no previous file with comments | « net/base/file_stream_unittest.cc ('k') | net/base/net_log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698