| OLD | NEW |
| 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_LOG_NET_LOG_H_ | 5 #ifndef NET_LOG_NET_LOG_H_ |
| 6 #define NET_LOG_NET_LOG_H_ | 6 #define NET_LOG_NET_LOG_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include <string> | 10 #include <string> |
| 9 | 11 |
| 10 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 11 | 13 |
| 12 #include "base/atomicops.h" | 14 #include "base/atomicops.h" |
| 13 #include "base/basictypes.h" | |
| 14 #include "base/callback_forward.h" | 15 #include "base/callback_forward.h" |
| 15 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 17 #include "base/macros.h" |
| 16 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
| 17 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
| 18 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
| 19 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 20 #include "net/base/net_export.h" | 22 #include "net/base/net_export.h" |
| 21 #include "net/log/net_log_capture_mode.h" | 23 #include "net/log/net_log_capture_mode.h" |
| 22 | 24 |
| 23 namespace base { | 25 namespace base { |
| 24 class DictionaryValue; | 26 class DictionaryValue; |
| 25 class Value; | 27 class Value; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 // associated with an event. If called, it will be called synchronously, | 73 // associated with an event. If called, it will be called synchronously, |
| 72 // so it need not have owning references. May be called more than once, or | 74 // so it need not have owning references. May be called more than once, or |
| 73 // not at all. May return NULL. | 75 // not at all. May return NULL. |
| 74 typedef base::Callback<scoped_ptr<base::Value>(NetLogCaptureMode)> | 76 typedef base::Callback<scoped_ptr<base::Value>(NetLogCaptureMode)> |
| 75 ParametersCallback; | 77 ParametersCallback; |
| 76 | 78 |
| 77 // Identifies the entity that generated this log. The |id| field should | 79 // Identifies the entity that generated this log. The |id| field should |
| 78 // uniquely identify the source, and is used by log observers to infer | 80 // uniquely identify the source, and is used by log observers to infer |
| 79 // message groupings. Can use NetLog::NextID() to create unique IDs. | 81 // message groupings. Can use NetLog::NextID() to create unique IDs. |
| 80 struct NET_EXPORT Source { | 82 struct NET_EXPORT Source { |
| 81 static const uint32 kInvalidId; | 83 static const uint32_t kInvalidId; |
| 82 | 84 |
| 83 Source(); | 85 Source(); |
| 84 Source(SourceType type, uint32 id); | 86 Source(SourceType type, uint32_t id); |
| 85 bool IsValid() const; | 87 bool IsValid() const; |
| 86 | 88 |
| 87 // Adds the source to a DictionaryValue containing event parameters, | 89 // Adds the source to a DictionaryValue containing event parameters, |
| 88 // using the name "source_dependency". | 90 // using the name "source_dependency". |
| 89 void AddToEventParameters(base::DictionaryValue* event_params) const; | 91 void AddToEventParameters(base::DictionaryValue* event_params) const; |
| 90 | 92 |
| 91 // Returns a callback that returns a dictionary with a single entry | 93 // Returns a callback that returns a dictionary with a single entry |
| 92 // named "source_dependency" that describes |this|. | 94 // named "source_dependency" that describes |this|. |
| 93 ParametersCallback ToEventParametersCallback() const; | 95 ParametersCallback ToEventParametersCallback() const; |
| 94 | 96 |
| 95 // Attempts to extract a Source from a set of event parameters. Returns | 97 // Attempts to extract a Source from a set of event parameters. Returns |
| 96 // true and writes the result to |source| on success. Returns false and | 98 // true and writes the result to |source| on success. Returns false and |
| 97 // makes |source| an invalid source on failure. | 99 // makes |source| an invalid source on failure. |
| 98 // TODO(mmenke): Long term, we want to remove this. | 100 // TODO(mmenke): Long term, we want to remove this. |
| 99 static bool FromEventParameters(base::Value* event_params, Source* source); | 101 static bool FromEventParameters(base::Value* event_params, Source* source); |
| 100 | 102 |
| 101 SourceType type; | 103 SourceType type; |
| 102 uint32 id; | 104 uint32_t id; |
| 103 }; | 105 }; |
| 104 | 106 |
| 105 struct NET_EXPORT EntryData { | 107 struct NET_EXPORT EntryData { |
| 106 EntryData(EventType type, | 108 EntryData(EventType type, |
| 107 Source source, | 109 Source source, |
| 108 EventPhase phase, | 110 EventPhase phase, |
| 109 base::TimeTicks time, | 111 base::TimeTicks time, |
| 110 const ParametersCallback* parameters_callback); | 112 const ParametersCallback* parameters_callback); |
| 111 ~EntryData(); | 113 ~EntryData(); |
| 112 | 114 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 NetLog(); | 201 NetLog(); |
| 200 virtual ~NetLog(); | 202 virtual ~NetLog(); |
| 201 | 203 |
| 202 // Emits a global event to the log stream, with its own unique source ID. | 204 // Emits a global event to the log stream, with its own unique source ID. |
| 203 void AddGlobalEntry(EventType type); | 205 void AddGlobalEntry(EventType type); |
| 204 void AddGlobalEntry(EventType type, | 206 void AddGlobalEntry(EventType type, |
| 205 const NetLog::ParametersCallback& parameters_callback); | 207 const NetLog::ParametersCallback& parameters_callback); |
| 206 | 208 |
| 207 // Returns a unique ID which can be used as a source ID. All returned IDs | 209 // Returns a unique ID which can be used as a source ID. All returned IDs |
| 208 // will be unique and greater than 0. | 210 // will be unique and greater than 0. |
| 209 uint32 NextID(); | 211 uint32_t NextID(); |
| 210 | 212 |
| 211 // Returns true if there are any observers attached to the NetLog. This can be | 213 // Returns true if there are any observers attached to the NetLog. This can be |
| 212 // used as an optimization to avoid emitting log entries when there is no | 214 // used as an optimization to avoid emitting log entries when there is no |
| 213 // chance that the data will be consumed. | 215 // chance that the data will be consumed. |
| 214 bool IsCapturing() const; | 216 bool IsCapturing() const; |
| 215 | 217 |
| 216 // Adds an observer and sets its log capture mode. The observer must not be | 218 // Adds an observer and sets its log capture mode. The observer must not be |
| 217 // watching any NetLog, including this one, when this is called. | 219 // watching any NetLog, including this one, when this is called. |
| 218 // | 220 // |
| 219 // NetLog implementations must call NetLog::OnAddObserver to update the | 221 // NetLog implementations must call NetLog::OnAddObserver to update the |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 // Returns a C-String symbolic name for |event_phase|. | 265 // Returns a C-String symbolic name for |event_phase|. |
| 264 static const char* EventPhaseToString(EventPhase event_phase); | 266 static const char* EventPhaseToString(EventPhase event_phase); |
| 265 | 267 |
| 266 // Creates a ParametersCallback that encapsulates a single bool. | 268 // Creates a ParametersCallback that encapsulates a single bool. |
| 267 // Warning: |name| must remain valid for the life of the callback. | 269 // Warning: |name| must remain valid for the life of the callback. |
| 268 static ParametersCallback BoolCallback(const char* name, bool value); | 270 static ParametersCallback BoolCallback(const char* name, bool value); |
| 269 | 271 |
| 270 // Warning: |name| must remain valid for the life of the callback. | 272 // Warning: |name| must remain valid for the life of the callback. |
| 271 static ParametersCallback IntCallback(const char* name, int value); | 273 static ParametersCallback IntCallback(const char* name, int value); |
| 272 | 274 |
| 273 // Creates a ParametersCallback that encapsulates a single int64. The | 275 // Creates a ParametersCallback that encapsulates a single int64_t. The |
| 274 // callback will return the value as a StringValue, since IntegerValues | 276 // callback will return the value as a StringValue, since IntegerValues |
| 275 // only support 32-bit values. | 277 // only support 32-bit values. |
| 276 // Warning: |name| must remain valid for the life of the callback. | 278 // Warning: |name| must remain valid for the life of the callback. |
| 277 static ParametersCallback Int64Callback(const char* name, int64 value); | 279 static ParametersCallback Int64Callback(const char* name, int64_t value); |
| 278 | 280 |
| 279 // Creates a ParametersCallback that encapsulates a single UTF8 string. Takes | 281 // Creates a ParametersCallback that encapsulates a single UTF8 string. Takes |
| 280 // |value| as a pointer to avoid copying, and emphasize it must be valid for | 282 // |value| as a pointer to avoid copying, and emphasize it must be valid for |
| 281 // the life of the callback. |value| may not be NULL. | 283 // the life of the callback. |value| may not be NULL. |
| 282 // Warning: |name| and |value| must remain valid for the life of the callback. | 284 // Warning: |name| and |value| must remain valid for the life of the callback. |
| 283 static ParametersCallback StringCallback(const char* name, | 285 static ParametersCallback StringCallback(const char* name, |
| 284 const std::string* value); | 286 const std::string* value); |
| 285 | 287 |
| 286 // Same as above, but takes in a UTF16 string. | 288 // Same as above, but takes in a UTF16 string. |
| 287 static ParametersCallback StringCallback(const char* name, | 289 static ParametersCallback StringCallback(const char* name, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 NetLog::Source source_; | 390 NetLog::Source source_; |
| 389 NetLog* net_log_; | 391 NetLog* net_log_; |
| 390 | 392 |
| 391 // TODO(eroman): Temporary until crbug.com/467797 is solved. | 393 // TODO(eroman): Temporary until crbug.com/467797 is solved. |
| 392 Liveness liveness_ = ALIVE; | 394 Liveness liveness_ = ALIVE; |
| 393 }; | 395 }; |
| 394 | 396 |
| 395 } // namespace net | 397 } // namespace net |
| 396 | 398 |
| 397 #endif // NET_LOG_NET_LOG_H_ | 399 #endif // NET_LOG_NET_LOG_H_ |
| OLD | NEW |