Chromium Code Reviews| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 | 200 |
| 201 // Emits a global event to the log stream, with its own unique source ID. | 201 // Emits a global event to the log stream, with its own unique source ID. |
| 202 void AddGlobalEntry(EventType type); | 202 void AddGlobalEntry(EventType type); |
| 203 void AddGlobalEntry(EventType type, | 203 void AddGlobalEntry(EventType type, |
| 204 const NetLog::ParametersCallback& parameters_callback); | 204 const NetLog::ParametersCallback& parameters_callback); |
| 205 | 205 |
| 206 // Returns a unique ID which can be used as a source ID. All returned IDs | 206 // Returns a unique ID which can be used as a source ID. All returned IDs |
| 207 // will be unique and greater than 0. | 207 // will be unique and greater than 0. |
| 208 uint32 NextID(); | 208 uint32 NextID(); |
| 209 | 209 |
| 210 // Returns the capture mode for this NetLog. This is used to avoid computing | 210 // Returns true if there are any observers attached to the NetLog. This can be |
| 211 // and saving expensive log entries. | 211 // used as an optimization to avoid emitting log entries. |
| 212 NetLogCaptureMode GetCaptureMode() const; | 212 bool HasObservers() const; |
| 213 | 213 |
| 214 // Adds an observer and sets its log capture mode. The observer must not be | 214 // Adds an observer and sets its log capture mode. The observer must not be |
| 215 // watching any NetLog, including this one, when this is called. | 215 // watching any NetLog, including this one, when this is called. |
| 216 // | 216 // |
| 217 // NetLog implementations must call NetLog::OnAddObserver to update the | 217 // NetLog implementations must call NetLog::OnAddObserver to update the |
| 218 // observer's internal state. | 218 // observer's internal state. |
| 219 // | 219 // |
| 220 // DEPRECATED: The ability to watch the netlog stream is being phased out | 220 // DEPRECATED: The ability to watch the netlog stream is being phased out |
| 221 // (crbug.com/472693) as it can be misused in production code. Please consult | 221 // (crbug.com/472693) as it can be misused in production code. Please consult |
| 222 // with a net/log OWNER before introducing a new dependency on this. | 222 // with a net/log OWNER before introducing a new dependency on this. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 const base::string16* value); | 287 const base::string16* value); |
| 288 | 288 |
| 289 private: | 289 private: |
| 290 friend class BoundNetLog; | 290 friend class BoundNetLog; |
| 291 | 291 |
| 292 void AddEntry(EventType type, | 292 void AddEntry(EventType type, |
| 293 const Source& source, | 293 const Source& source, |
| 294 EventPhase phase, | 294 EventPhase phase, |
| 295 const NetLog::ParametersCallback* parameters_callback); | 295 const NetLog::ParametersCallback* parameters_callback); |
| 296 | 296 |
| 297 // Called whenever an observer is added or removed, or has its log | 297 // Called whenever an observer is added or removed, to update has_observers_. |
|
mmenke
2015/05/05 19:45:15
|observers_| is more consistent with the other com
eroman
2015/05/05 22:54:38
Done (I presume you meant |has_observers_|)
| |
| 298 // capture mode changed. Must have acquired |lock_| prior to calling. | 298 // Must have acquired |lock_| prior to calling. |
| 299 void UpdateCaptureMode(); | 299 void UpdateHasObservers(); |
| 300 | 300 |
| 301 // |lock_| protects access to |observers_|. | 301 // |lock_| protects access to |observers_|. |
| 302 base::Lock lock_; | 302 base::Lock lock_; |
| 303 | 303 |
| 304 // Last assigned source ID. Incremented to get the next one. | 304 // Last assigned source ID. Incremented to get the next one. |
| 305 base::subtle::Atomic32 last_id_; | 305 base::subtle::Atomic32 last_id_; |
| 306 | 306 |
| 307 // The current capture mode. Note that the capture mode is stored as an | 307 // Whether there are any observers in |observers_|. Note that this is stored |
| 308 // integer rather than a NetLogCaptureMode so that it can be easily | 308 // as an Atomic32 rather than a boolean so it can be accessed/written without |
| 309 // read/written without a lock using Atomic32. | 309 // needing a lock. |
| 310 base::subtle::Atomic32 effective_capture_mode_int32_; | 310 base::subtle::Atomic32 has_observers_; |
| 311 | 311 |
| 312 // |lock_| must be acquired whenever reading or writing to this. | 312 // |lock_| must be acquired whenever reading or writing to this. |
| 313 ObserverList<ThreadSafeObserver, true> observers_; | 313 ObserverList<ThreadSafeObserver, true> observers_; |
| 314 | 314 |
| 315 DISALLOW_COPY_AND_ASSIGN(NetLog); | 315 DISALLOW_COPY_AND_ASSIGN(NetLog); |
| 316 }; | 316 }; |
| 317 | 317 |
| 318 // Helper that binds a Source to a NetLog, and exposes convenience methods to | 318 // Helper that binds a Source to a NetLog, and exposes convenience methods to |
| 319 // output log messages without needing to pass in the source. | 319 // output log messages without needing to pass in the source. |
| 320 class NET_EXPORT BoundNetLog { | 320 class NET_EXPORT BoundNetLog { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 // |net_error| must not be ERR_IO_PENDING, as it's not a true error. | 355 // |net_error| must not be ERR_IO_PENDING, as it's not a true error. |
| 356 void EndEventWithNetErrorCode(NetLog::EventType event_type, | 356 void EndEventWithNetErrorCode(NetLog::EventType event_type, |
| 357 int net_error) const; | 357 int net_error) const; |
| 358 | 358 |
| 359 // Logs a byte transfer event to the NetLog. Determines whether to log the | 359 // Logs a byte transfer event to the NetLog. Determines whether to log the |
| 360 // received bytes or not based on the current logging level. | 360 // received bytes or not based on the current logging level. |
| 361 void AddByteTransferEvent(NetLog::EventType event_type, | 361 void AddByteTransferEvent(NetLog::EventType event_type, |
| 362 int byte_count, | 362 int byte_count, |
| 363 const char* bytes) const; | 363 const char* bytes) const; |
| 364 | 364 |
| 365 NetLogCaptureMode GetCaptureMode() const; | 365 bool HasObservers() const; |
|
mmenke
2015/05/05 19:45:15
Maybe IsLogging? I don't think consumers of the B
eroman
2015/05/05 22:54:38
Renamed to IsCapturing().
Which I think is in line
| |
| 366 | 366 |
| 367 // Helper to create a BoundNetLog given a NetLog and a SourceType. Takes care | 367 // Helper to create a BoundNetLog given a NetLog and a SourceType. Takes care |
| 368 // of creating a unique source ID, and handles the case of NULL net_log. | 368 // of creating a unique source ID, and handles the case of NULL net_log. |
| 369 static BoundNetLog Make(NetLog* net_log, NetLog::SourceType source_type); | 369 static BoundNetLog Make(NetLog* net_log, NetLog::SourceType source_type); |
| 370 | 370 |
| 371 const NetLog::Source& source() const { return source_; } | 371 const NetLog::Source& source() const { return source_; } |
| 372 NetLog* net_log() const { return net_log_; } | 372 NetLog* net_log() const { return net_log_; } |
| 373 | 373 |
| 374 private: | 374 private: |
| 375 // TODO(eroman): Temporary until crbug.com/467797 is solved. | 375 // TODO(eroman): Temporary until crbug.com/467797 is solved. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 387 NetLog::Source source_; | 387 NetLog::Source source_; |
| 388 NetLog* net_log_; | 388 NetLog* net_log_; |
| 389 | 389 |
| 390 // TODO(eroman): Temporary until crbug.com/467797 is solved. | 390 // TODO(eroman): Temporary until crbug.com/467797 is solved. |
| 391 Liveness liveness_ = ALIVE; | 391 Liveness liveness_ = ALIVE; |
| 392 }; | 392 }; |
| 393 | 393 |
| 394 } // namespace net | 394 } // namespace net |
| 395 | 395 |
| 396 #endif // NET_LOG_NET_LOG_H_ | 396 #endif // NET_LOG_NET_LOG_H_ |
| OLD | NEW |