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

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

Issue 10565009: (Finally) Remove NetLog::EventParameters. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Missed a file. Will the madness ever end? 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_posix.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/callback_forward.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
eroman 2012/06/16 01:19:15 is this still needed?
mmenke 2012/06/16 02:09:25 Nope.
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/string16.h" 16 #include "base/string16.h"
17 #include "net/base/net_export.h" 17 #include "net/base/net_export.h"
18 18
19 namespace base { 19 namespace base {
20 class DictionaryValue; 20 class DictionaryValue;
21 class TimeTicks; 21 class TimeTicks;
22 class Value; 22 class Value;
23 } 23 }
24 24
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // Identifies the entity that generated this log. The |id| field should 85 // Identifies the entity that generated this log. The |id| field should
86 // uniquely identify the source, and is used by log observers to infer 86 // uniquely identify the source, and is used by log observers to infer
87 // message groupings. Can use NetLog::NextID() to create unique IDs. 87 // message groupings. Can use NetLog::NextID() to create unique IDs.
88 struct NET_EXPORT Source { 88 struct NET_EXPORT Source {
89 static const uint32 kInvalidId = 0; 89 static const uint32 kInvalidId = 0;
90 90
91 Source() : type(SOURCE_NONE), id(kInvalidId) {} 91 Source() : type(SOURCE_NONE), id(kInvalidId) {}
92 Source(SourceType type, uint32 id) : type(type), id(id) {} 92 Source(SourceType type, uint32 id) : type(type), id(id) {}
93 bool is_valid() const { return id != kInvalidId; } 93 bool is_valid() const { return id != kInvalidId; }
94 94
95 // Obsolete. The caller takes ownership of the returned Value*.
96 // TODO(mmenke): Remove this.
97 base::Value* ToValue() const;
98
99 // Adds the source to a DictionaryValue containing event parameters, 95 // Adds the source to a DictionaryValue containing event parameters,
100 // using the name "source_dependency". 96 // using the name "source_dependency".
101 void AddToEventParameters(base::DictionaryValue* event_params) const; 97 void AddToEventParameters(base::DictionaryValue* event_params) const;
102 98
103 // Returns a callback that returns a dictionary with a single entry 99 // Returns a callback that returns a dictionary with a single entry
104 // named "source_dependecy" that describes |this|. 100 // named "source_dependecy" that describes |this|.
105 ParametersCallback ToEventParametersCallback() const; 101 ParametersCallback ToEventParametersCallback() const;
106 102
107 // Attempts to extract a Source from a set of event parameters. Returns 103 // Attempts to extract a Source from a set of event parameters. Returns
108 // true and writes the result to |source| on success. Returns false and 104 // true and writes the result to |source| on success. Returns false and
109 // makes |source| an invalid source on failure. 105 // makes |source| an invalid source on failure.
110 // TODO(mmenke): Long term, we want to remove this. 106 // TODO(mmenke): Long term, we want to remove this.
111 static bool FromEventParameters(base::Value* event_params, Source* source); 107 static bool FromEventParameters(base::Value* event_params, Source* source);
112 108
113 SourceType type; 109 SourceType type;
114 uint32 id; 110 uint32 id;
115 }; 111 };
116 112
117 // Base class for associating additional parameters with an event. Log
118 // observers need to know what specific derivations of EventParameters a
119 // particular EventType uses, in order to get at the individual components.
120 // This class is obsolete. New code should use ParametersCallbacks.
121 // TODO(mmenke): Update users of this class and get rid of it.
122 class NET_EXPORT EventParameters
123 : public base::RefCountedThreadSafe<EventParameters> {
124 public:
125 EventParameters() {}
126
127 // Serializes the parameters to a Value tree. This is intended to be a
128 // lossless conversion, which is used to serialize the parameters to JSON.
129 // The caller takes ownership of the returned Value*.
130 virtual base::Value* ToValue() const = 0;
131
132 protected:
133 virtual ~EventParameters() {}
134
135 private:
136 friend class base::RefCountedThreadSafe<EventParameters>;
137
138 DISALLOW_COPY_AND_ASSIGN(EventParameters);
139 };
140
141 class NET_EXPORT Entry { 113 class NET_EXPORT Entry {
142 public: 114 public:
143 Entry(EventType type, 115 Entry(EventType type,
144 Source source, 116 Source source,
145 EventPhase phase, 117 EventPhase phase,
146 const ParametersCallback* parameters_callback, 118 const ParametersCallback* parameters_callback,
147 LogLevel log_level); 119 LogLevel log_level);
148 ~Entry(); 120 ~Entry();
149 121
150 EventType type() const { return type_; } 122 EventType type() const { return type_; }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 }; 191 };
220 192
221 NetLog() {} 193 NetLog() {}
222 virtual ~NetLog() {} 194 virtual ~NetLog() {}
223 195
224 // Emits a global event to the log stream, with its own unique source ID. 196 // Emits a global event to the log stream, with its own unique source ID.
225 void AddGlobalEntry(EventType type); 197 void AddGlobalEntry(EventType type);
226 void AddGlobalEntry(EventType type, 198 void AddGlobalEntry(EventType type,
227 const NetLog::ParametersCallback& parameters_callback); 199 const NetLog::ParametersCallback& parameters_callback);
228 200
229 // Older, obsolete version of above functions. Use the ParametersCallback
230 // versions instead.
231 // TODO(mmenke): Remove this.
232 void AddGlobalEntry(EventType type,
233 const scoped_refptr<EventParameters>& params);
234
235 // Returns a unique ID which can be used as a source ID. All returned IDs 201 // Returns a unique ID which can be used as a source ID. All returned IDs
236 // will be unique and greater than 0. 202 // will be unique and greater than 0.
237 virtual uint32 NextID() = 0; 203 virtual uint32 NextID() = 0;
238 204
239 // Returns the logging level for this NetLog. This is used to avoid computing 205 // Returns the logging level for this NetLog. This is used to avoid computing
240 // and saving expensive log entries. 206 // and saving expensive log entries.
241 virtual LogLevel GetLogLevel() const = 0; 207 virtual LogLevel GetLogLevel() const = 0;
242 208
243 // Adds an observer and sets its log level. The observer must not be 209 // Adds an observer and sets its log level. The observer must not be
244 // watching any NetLog, including this one, when this is called. 210 // watching any NetLog, including this one, when this is called.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 const NetLog::ParametersCallback& get_parameters) const; 326 const NetLog::ParametersCallback& get_parameters) const;
361 327
362 void EndEvent(NetLog::EventType type) const; 328 void EndEvent(NetLog::EventType type) const;
363 void EndEvent(NetLog::EventType type, 329 void EndEvent(NetLog::EventType type,
364 const NetLog::ParametersCallback& get_parameters) const; 330 const NetLog::ParametersCallback& get_parameters) const;
365 331
366 void AddEvent(NetLog::EventType type) const; 332 void AddEvent(NetLog::EventType type) const;
367 void AddEvent(NetLog::EventType type, 333 void AddEvent(NetLog::EventType type,
368 const NetLog::ParametersCallback& get_parameters) const; 334 const NetLog::ParametersCallback& get_parameters) const;
369 335
370 // Obsolete versions of the above functions.
371 // Use the ParametersCallback versions of these functions instead.
372 // TODO(mmenke): Remove these.
373 void AddEntry(NetLog::EventType type,
374 NetLog::EventPhase phase,
375 const scoped_refptr<NetLog::EventParameters>& params) const;
376 void AddEvent(NetLog::EventType event_type,
377 const scoped_refptr<NetLog::EventParameters>& params) const;
378 void BeginEvent(NetLog::EventType event_type,
379 const scoped_refptr<NetLog::EventParameters>& params) const;
380 void EndEvent(NetLog::EventType event_type,
381 const scoped_refptr<NetLog::EventParameters>& params) const;
382
383 // Just like AddEvent, except |net_error| is a net error code. A parameter 336 // Just like AddEvent, except |net_error| is a net error code. A parameter
384 // called "net_error" with the indicated value will be recorded for the event. 337 // called "net_error" with the indicated value will be recorded for the event.
385 // |net_error| must be negative, and not ERR_IO_PENDING, as it's not a true 338 // |net_error| must be negative, and not ERR_IO_PENDING, as it's not a true
386 // error. 339 // error.
387 void AddEventWithNetErrorCode(NetLog::EventType event_type, 340 void AddEventWithNetErrorCode(NetLog::EventType event_type,
388 int net_error) const; 341 int net_error) const;
389 342
390 // Just like EndEvent, except |net_error| is a net error code. If it's 343 // Just like EndEvent, except |net_error| is a net error code. If it's
391 // negative, a parameter called "net_error" with a value of |net_error| is 344 // negative, a parameter called "net_error" with a value of |net_error| is
392 // associated with the event. Otherwise, the end event has no parameters. 345 // associated with the event. Otherwise, the end event has no parameters.
(...skipping 23 matching lines...) Expand all
416 369
417 private: 370 private:
418 BoundNetLog(const NetLog::Source& source, NetLog* net_log) 371 BoundNetLog(const NetLog::Source& source, NetLog* net_log)
419 : source_(source), net_log_(net_log) { 372 : source_(source), net_log_(net_log) {
420 } 373 }
421 374
422 NetLog::Source source_; 375 NetLog::Source source_;
423 NetLog* net_log_; 376 NetLog* net_log_;
424 }; 377 };
425 378
426 // All the classes below are obsolete. New code should use ParametersCallbacks.
427 // TODO(mmenke): Update users these classes and get rid of them.
428
429 // NetLogStringParameter is a subclass of EventParameters that encapsulates a
430 // single std::string parameter.
431 class NET_EXPORT NetLogStringParameter : public NetLog::EventParameters {
432 public:
433 // |name| must be a string literal.
434 NetLogStringParameter(const char* name, const std::string& value);
435
436 const std::string& value() const {
437 return value_;
438 }
439
440 virtual base::Value* ToValue() const OVERRIDE;
441
442 protected:
443 virtual ~NetLogStringParameter();
444
445 private:
446 const char* const name_;
447 const std::string value_;
448 };
449
450 // NetLogIntegerParameter is a subclass of EventParameters that encapsulates a
451 // single integer parameter.
452 class NET_EXPORT NetLogIntegerParameter : public NetLog::EventParameters {
453 public:
454 // |name| must be a string literal.
455 NetLogIntegerParameter(const char* name, int value)
456 : name_(name), value_(value) {}
457
458 int value() const {
459 return value_;
460 }
461
462 virtual base::Value* ToValue() const OVERRIDE;
463
464 protected:
465 virtual ~NetLogIntegerParameter() {}
466
467 private:
468 const char* name_;
469 const int value_;
470 };
471
472 // NetLogSourceParameter is a subclass of EventParameters that encapsulates a
473 // single NetLog::Source parameter.
474 class NET_EXPORT NetLogSourceParameter : public NetLog::EventParameters {
475 public:
476 // |name| must be a string literal.
477 NetLogSourceParameter(const char* name, const NetLog::Source& value)
478 : name_(name), value_(value) {}
479
480 const NetLog::Source& value() const {
481 return value_;
482 }
483
484 virtual base::Value* ToValue() const OVERRIDE;
485
486 protected:
487 virtual ~NetLogSourceParameter() {}
488
489 private:
490 const char* name_;
491 const NetLog::Source value_;
492 };
493
494 } // namespace net 379 } // namespace net
495 380
496 #endif // NET_BASE_NET_LOG_H_ 381 #endif // NET_BASE_NET_LOG_H_
OLDNEW
« no previous file with comments | « net/base/file_stream_posix.cc ('k') | net/base/net_log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698