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

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

Issue 2351513002: net: rename BoundNetLog to NetLogWithSource (Closed)
Patch Set: one more fix, content bound_net_log_ Created 4 years, 3 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
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_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> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 19 matching lines...) Expand all
30 } 30 }
31 31
32 namespace net { 32 namespace net {
33 33
34 // NetLog is the destination for log messages generated by the network stack. 34 // NetLog is the destination for log messages generated by the network stack.
35 // Each log message has a "source" field which identifies the specific entity 35 // Each log message has a "source" field which identifies the specific entity
36 // that generated the message (for example, which URLRequest or which 36 // that generated the message (for example, which URLRequest or which
37 // SpdySession). 37 // SpdySession).
38 // 38 //
39 // To avoid needing to pass in the "source ID" to the logging functions, NetLog 39 // To avoid needing to pass in the "source ID" to the logging functions, NetLog
40 // is usually accessed through a BoundNetLog, which will always pass in a 40 // is usually accessed through a NetLogWithSource, which will always pass in a
41 // specific source ID. 41 // specific source ID.
42 // 42 //
43 // All methods are thread safe, with the exception that no NetLog or 43 // All methods are thread safe, with the exception that no NetLog or
44 // NetLog::ThreadSafeObserver functions may be called by an observer's 44 // NetLog::ThreadSafeObserver functions may be called by an observer's
45 // OnAddEntry() method. Doing so will result in a deadlock. 45 // OnAddEntry() method. Doing so will result in a deadlock.
46 // 46 //
47 // For a broader introduction see the design document: 47 // For a broader introduction see the design document:
48 // https://sites.google.com/a/chromium.org/dev/developers/design-documents/netwo rk-stack/netlog 48 // https://sites.google.com/a/chromium.org/dev/developers/design-documents/netwo rk-stack/netlog
49 class NET_EXPORT NetLog { 49 class NET_EXPORT NetLog {
50 public: 50 public:
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 // Warning: |name| and |value| must remain valid for the life of the callback. 268 // Warning: |name| and |value| must remain valid for the life of the callback.
269 static ParametersCallback StringCallback(const char* name, 269 static ParametersCallback StringCallback(const char* name,
270 const std::string* value); 270 const std::string* value);
271 static ParametersCallback StringCallback(const char* name, const char* value); 271 static ParametersCallback StringCallback(const char* name, const char* value);
272 272
273 // Same as above, but takes in a UTF16 string. 273 // Same as above, but takes in a UTF16 string.
274 static ParametersCallback StringCallback(const char* name, 274 static ParametersCallback StringCallback(const char* name,
275 const base::string16* value); 275 const base::string16* value);
276 276
277 private: 277 private:
278 friend class BoundNetLog; 278 friend class NetLogWithSource;
279 279
280 void AddEntry(NetLogEventType type, 280 void AddEntry(NetLogEventType type,
281 const Source& source, 281 const Source& source,
282 NetLogEventPhase phase, 282 NetLogEventPhase phase,
283 const NetLog::ParametersCallback* parameters_callback); 283 const NetLog::ParametersCallback* parameters_callback);
284 284
285 // Called whenever an observer is added or removed, to update 285 // Called whenever an observer is added or removed, to update
286 // |has_observers_|. Must have acquired |lock_| prior to calling. 286 // |has_observers_|. Must have acquired |lock_| prior to calling.
287 void UpdateIsCapturing(); 287 void UpdateIsCapturing();
288 288
289 // |lock_| protects access to |observers_|. 289 // |lock_| protects access to |observers_|.
290 base::Lock lock_; 290 base::Lock lock_;
291 291
292 // Last assigned source ID. Incremented to get the next one. 292 // Last assigned source ID. Incremented to get the next one.
293 base::subtle::Atomic32 last_id_; 293 base::subtle::Atomic32 last_id_;
294 294
295 // |is_capturing_| will be 0 when there are no observers watching the NetLog, 295 // |is_capturing_| will be 0 when there are no observers watching the NetLog,
296 // 1 otherwise. Note that this is stored as an Atomic32 rather than a boolean 296 // 1 otherwise. Note that this is stored as an Atomic32 rather than a boolean
297 // so it can be accessed without needing a lock. 297 // so it can be accessed without needing a lock.
298 base::subtle::Atomic32 is_capturing_; 298 base::subtle::Atomic32 is_capturing_;
299 299
300 // |lock_| must be acquired whenever reading or writing to this. 300 // |lock_| must be acquired whenever reading or writing to this.
301 base::ObserverList<ThreadSafeObserver, true> observers_; 301 base::ObserverList<ThreadSafeObserver, true> observers_;
302 302
303 DISALLOW_COPY_AND_ASSIGN(NetLog); 303 DISALLOW_COPY_AND_ASSIGN(NetLog);
304 }; 304 };
305 305
306 // Helper that binds a Source to a NetLog, and exposes convenience methods to 306 // Helper that binds a Source to a NetLog, and exposes convenience methods to
307 // output log messages without needing to pass in the source. 307 // output log messages without needing to pass in the source.
308 class NET_EXPORT BoundNetLog { 308 class NET_EXPORT NetLogWithSource {
309 public: 309 public:
310 BoundNetLog() : net_log_(NULL) {} 310 NetLogWithSource() : net_log_(NULL) {}
311 ~BoundNetLog(); 311 ~NetLogWithSource();
312 312
313 // Add a log entry to the NetLog for the bound source. 313 // Add a log entry to the NetLog for the bound source.
314 void AddEntry(NetLogEventType type, NetLogEventPhase phase) const; 314 void AddEntry(NetLogEventType type, NetLogEventPhase phase) const;
315 void AddEntry(NetLogEventType type, 315 void AddEntry(NetLogEventType type,
316 NetLogEventPhase phase, 316 NetLogEventPhase phase,
317 const NetLog::ParametersCallback& get_parameters) const; 317 const NetLog::ParametersCallback& get_parameters) const;
318 318
319 // Convenience methods that call AddEntry with a fixed "capture phase" 319 // Convenience methods that call AddEntry with a fixed "capture phase"
320 // (begin, end, or none). 320 // (begin, end, or none).
321 void BeginEvent(NetLogEventType type) const; 321 void BeginEvent(NetLogEventType type) const;
(...skipping 23 matching lines...) Expand all
345 int net_error) const; 345 int net_error) const;
346 346
347 // Logs a byte transfer event to the NetLog. Determines whether to log the 347 // Logs a byte transfer event to the NetLog. Determines whether to log the
348 // received bytes or not based on the current logging level. 348 // received bytes or not based on the current logging level.
349 void AddByteTransferEvent(NetLogEventType event_type, 349 void AddByteTransferEvent(NetLogEventType event_type,
350 int byte_count, 350 int byte_count,
351 const char* bytes) const; 351 const char* bytes) const;
352 352
353 bool IsCapturing() const; 353 bool IsCapturing() const;
354 354
355 // Helper to create a BoundNetLog given a NetLog and a NetLogSourceType. 355 // Helper to create a NetLogWithSource given a NetLog and a NetLogSourceType.
356 // Takes care of creating a unique source ID, and handles 356 // Takes care of creating a unique source ID, and handles
357 // the case of NULL net_log. 357 // the case of NULL net_log.
358 static BoundNetLog Make(NetLog* net_log, NetLogSourceType source_type); 358 static NetLogWithSource Make(NetLog* net_log, NetLogSourceType source_type);
359 359
360 const NetLog::Source& source() const { return source_; } 360 const NetLog::Source& source() const { return source_; }
361 NetLog* net_log() const { return net_log_; } 361 NetLog* net_log() const { return net_log_; }
362 362
363 private: 363 private:
364 // TODO(eroman): Temporary until crbug.com/467797 is solved. 364 // TODO(eroman): Temporary until crbug.com/467797 is solved.
365 enum Liveness { 365 enum Liveness {
366 ALIVE = 0xCA11AB13, 366 ALIVE = 0xCA11AB13,
367 DEAD = 0xDEADBEEF, 367 DEAD = 0xDEADBEEF,
368 }; 368 };
369 369
370 BoundNetLog(const NetLog::Source& source, NetLog* net_log) 370 NetLogWithSource(const NetLog::Source& source, NetLog* net_log)
371 : source_(source), net_log_(net_log) {} 371 : source_(source), net_log_(net_log) {}
372 372
373 // TODO(eroman): Temporary until crbug.com/467797 is solved. 373 // TODO(eroman): Temporary until crbug.com/467797 is solved.
374 void CrashIfInvalid() const; 374 void CrashIfInvalid() const;
375 375
376 NetLog::Source source_; 376 NetLog::Source source_;
377 NetLog* net_log_; 377 NetLog* net_log_;
378 378
379 // TODO(eroman): Temporary until crbug.com/467797 is solved. 379 // TODO(eroman): Temporary until crbug.com/467797 is solved.
380 Liveness liveness_ = ALIVE; 380 Liveness liveness_ = ALIVE;
381 }; 381 };
382 382
383 } // namespace net 383 } // namespace net
384 384
385 #endif // NET_LOG_NET_LOG_H_ 385 #endif // NET_LOG_NET_LOG_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698