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

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: Fix a couple more files 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"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/string16.h" 14 #include "base/string16.h"
17 #include "net/base/net_export.h" 15 #include "net/base/net_export.h"
18 16
19 namespace base { 17 namespace base {
20 class DictionaryValue; 18 class DictionaryValue;
21 class TimeTicks; 19 class TimeTicks;
22 class Value; 20 class Value;
23 } 21 }
24 22
25 namespace net { 23 namespace net {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // Identifies the entity that generated this log. The |id| field should 83 // Identifies the entity that generated this log. The |id| field should
86 // uniquely identify the source, and is used by log observers to infer 84 // uniquely identify the source, and is used by log observers to infer
87 // message groupings. Can use NetLog::NextID() to create unique IDs. 85 // message groupings. Can use NetLog::NextID() to create unique IDs.
88 struct NET_EXPORT Source { 86 struct NET_EXPORT Source {
89 static const uint32 kInvalidId = 0; 87 static const uint32 kInvalidId = 0;
90 88
91 Source() : type(SOURCE_NONE), id(kInvalidId) {} 89 Source() : type(SOURCE_NONE), id(kInvalidId) {}
92 Source(SourceType type, uint32 id) : type(type), id(id) {} 90 Source(SourceType type, uint32 id) : type(type), id(id) {}
93 bool is_valid() const { return id != kInvalidId; } 91 bool is_valid() const { return id != kInvalidId; }
94 92
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, 93 // Adds the source to a DictionaryValue containing event parameters,
100 // using the name "source_dependency". 94 // using the name "source_dependency".
101 void AddToEventParameters(base::DictionaryValue* event_params) const; 95 void AddToEventParameters(base::DictionaryValue* event_params) const;
102 96
103 // Returns a callback that returns a dictionary with a single entry 97 // Returns a callback that returns a dictionary with a single entry
104 // named "source_dependecy" that describes |this|. 98 // named "source_dependecy" that describes |this|.
105 ParametersCallback ToEventParametersCallback() const; 99 ParametersCallback ToEventParametersCallback() const;
106 100
107 // Attempts to extract a Source from a set of event parameters. Returns 101 // 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 102 // true and writes the result to |source| on success. Returns false and
109 // makes |source| an invalid source on failure. 103 // makes |source| an invalid source on failure.
110 // TODO(mmenke): Long term, we want to remove this. 104 // TODO(mmenke): Long term, we want to remove this.
111 static bool FromEventParameters(base::Value* event_params, Source* source); 105 static bool FromEventParameters(base::Value* event_params, Source* source);
112 106
113 SourceType type; 107 SourceType type;
114 uint32 id; 108 uint32 id;
115 }; 109 };
116 110
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 { 111 class NET_EXPORT Entry {
142 public: 112 public:
143 Entry(EventType type, 113 Entry(EventType type,
144 Source source, 114 Source source,
145 EventPhase phase, 115 EventPhase phase,
146 const ParametersCallback* parameters_callback, 116 const ParametersCallback* parameters_callback,
147 LogLevel log_level); 117 LogLevel log_level);
148 ~Entry(); 118 ~Entry();
149 119
150 EventType type() const { return type_; } 120 EventType type() const { return type_; }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 }; 189 };
220 190
221 NetLog() {} 191 NetLog() {}
222 virtual ~NetLog() {} 192 virtual ~NetLog() {}
223 193
224 // Emits a global event to the log stream, with its own unique source ID. 194 // Emits a global event to the log stream, with its own unique source ID.
225 void AddGlobalEntry(EventType type); 195 void AddGlobalEntry(EventType type);
226 void AddGlobalEntry(EventType type, 196 void AddGlobalEntry(EventType type,
227 const NetLog::ParametersCallback& parameters_callback); 197 const NetLog::ParametersCallback& parameters_callback);
228 198
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 199 // Returns a unique ID which can be used as a source ID. All returned IDs
236 // will be unique and greater than 0. 200 // will be unique and greater than 0.
237 virtual uint32 NextID() = 0; 201 virtual uint32 NextID() = 0;
238 202
239 // Returns the logging level for this NetLog. This is used to avoid computing 203 // Returns the logging level for this NetLog. This is used to avoid computing
240 // and saving expensive log entries. 204 // and saving expensive log entries.
241 virtual LogLevel GetLogLevel() const = 0; 205 virtual LogLevel GetLogLevel() const = 0;
242 206
243 // Adds an observer and sets its log level. The observer must not be 207 // Adds an observer and sets its log level. The observer must not be
244 // watching any NetLog, including this one, when this is called. 208 // 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; 324 const NetLog::ParametersCallback& get_parameters) const;
361 325
362 void EndEvent(NetLog::EventType type) const; 326 void EndEvent(NetLog::EventType type) const;
363 void EndEvent(NetLog::EventType type, 327 void EndEvent(NetLog::EventType type,
364 const NetLog::ParametersCallback& get_parameters) const; 328 const NetLog::ParametersCallback& get_parameters) const;
365 329
366 void AddEvent(NetLog::EventType type) const; 330 void AddEvent(NetLog::EventType type) const;
367 void AddEvent(NetLog::EventType type, 331 void AddEvent(NetLog::EventType type,
368 const NetLog::ParametersCallback& get_parameters) const; 332 const NetLog::ParametersCallback& get_parameters) const;
369 333
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 334 // 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. 335 // 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 336 // |net_error| must be negative, and not ERR_IO_PENDING, as it's not a true
386 // error. 337 // error.
387 void AddEventWithNetErrorCode(NetLog::EventType event_type, 338 void AddEventWithNetErrorCode(NetLog::EventType event_type,
388 int net_error) const; 339 int net_error) const;
389 340
390 // Just like EndEvent, except |net_error| is a net error code. If it's 341 // 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 342 // 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. 343 // associated with the event. Otherwise, the end event has no parameters.
(...skipping 23 matching lines...) Expand all
416 367
417 private: 368 private:
418 BoundNetLog(const NetLog::Source& source, NetLog* net_log) 369 BoundNetLog(const NetLog::Source& source, NetLog* net_log)
419 : source_(source), net_log_(net_log) { 370 : source_(source), net_log_(net_log) {
420 } 371 }
421 372
422 NetLog::Source source_; 373 NetLog::Source source_;
423 NetLog* net_log_; 374 NetLog* net_log_;
424 }; 375 };
425 376
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 377 } // namespace net
495 378
496 #endif // NET_BASE_NET_LOG_H_ 379 #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