Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_CAPTURING_NET_LOG_H_ | 5 #ifndef NET_BASE_CAPTURING_NET_LOG_H_ |
| 6 #define NET_BASE_CAPTURING_NET_LOG_H_ | 6 #define NET_BASE_CAPTURING_NET_LOG_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/atomicops.h" | |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/lock.h" | |
| 12 #include "base/ref_counted.h" | 14 #include "base/ref_counted.h" |
| 13 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
| 14 #include "base/time.h" | 16 #include "base/time.h" |
| 15 #include "net/base/net_log.h" | 17 #include "net/base/net_log.h" |
| 16 | 18 |
| 17 namespace net { | 19 namespace net { |
| 18 | 20 |
| 19 // CapturingNetLog is an implementation of NetLog that saves messages to a | 21 // CapturingNetLog is an implementation of NetLog that saves messages to a |
| 20 // bounded buffer. | 22 // bounded buffer. |
| 21 class CapturingNetLog : public NetLog { | 23 class CapturingNetLog : public NetLog { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 48 // NetLog implementation: | 50 // NetLog implementation: |
| 49 virtual void AddEntry(EventType type, | 51 virtual void AddEntry(EventType type, |
| 50 const base::TimeTicks& time, | 52 const base::TimeTicks& time, |
| 51 const Source& source, | 53 const Source& source, |
| 52 EventPhase phase, | 54 EventPhase phase, |
| 53 EventParameters* extra_parameters); | 55 EventParameters* extra_parameters); |
| 54 virtual uint32 NextID(); | 56 virtual uint32 NextID(); |
| 55 virtual LogLevel GetLogLevel() const { return LOG_ALL_BUT_BYTES; } | 57 virtual LogLevel GetLogLevel() const { return LOG_ALL_BUT_BYTES; } |
| 56 | 58 |
| 57 // Returns the list of all entries in the log. | 59 // Returns the list of all entries in the log. |
| 58 const EntryList& entries() const { return entries_; } | 60 void GetEntries(EntryList* entry_list) const; |
| 59 | 61 |
| 60 void Clear(); | 62 void Clear(); |
| 61 | 63 |
| 62 private: | 64 private: |
| 63 uint32 next_id_; | 65 // Needs to be "mutable" so can use it in GetEntries(). |
| 66 mutable Lock lock_; | |
| 67 base::subtle::Atomic32 next_id_; | |
|
eroman
2010/11/18 18:04:03
nit: For consistency with ChromeNetLog, you should
mmenke
2010/11/23 16:48:45
ChromeNetLog's is the id of the last event that oc
| |
| 64 size_t max_num_entries_; | 68 size_t max_num_entries_; |
| 65 EntryList entries_; | 69 EntryList entries_; |
| 66 | 70 |
| 67 DISALLOW_COPY_AND_ASSIGN(CapturingNetLog); | 71 DISALLOW_COPY_AND_ASSIGN(CapturingNetLog); |
| 68 }; | 72 }; |
| 69 | 73 |
| 70 // Helper class that exposes a similar API as BoundNetLog, but uses a | 74 // Helper class that exposes a similar API as BoundNetLog, but uses a |
| 71 // CapturingNetLog rather than the more generic NetLog. | 75 // CapturingNetLog rather than the more generic NetLog. |
| 72 // | 76 // |
| 73 // CapturingBoundNetLog can easily be converted to a BoundNetLog using the | 77 // CapturingBoundNetLog can easily be converted to a BoundNetLog using the |
| 74 // bound() method. | 78 // bound() method. |
| 75 class CapturingBoundNetLog { | 79 class CapturingBoundNetLog { |
| 76 public: | 80 public: |
| 77 CapturingBoundNetLog(const NetLog::Source& source, CapturingNetLog* net_log); | 81 CapturingBoundNetLog(const NetLog::Source& source, |
| 82 scoped_refptr<CapturingNetLog>& net_log); | |
|
eroman
2010/11/18 18:04:03
I didn't think CapturingNetLog was refcounted?
mmenke
2010/11/23 16:48:45
Thanks. Holdover from the first pass.
| |
| 78 | 83 |
| 79 explicit CapturingBoundNetLog(size_t max_num_entries); | 84 explicit CapturingBoundNetLog(size_t max_num_entries); |
| 80 | 85 |
| 81 ~CapturingBoundNetLog(); | 86 ~CapturingBoundNetLog(); |
| 82 | 87 |
| 83 // The returned BoundNetLog is only valid while |this| is alive. | 88 // The returned BoundNetLog is only valid while |this| is alive. |
| 84 BoundNetLog bound() const { | 89 BoundNetLog bound() const { |
| 85 return BoundNetLog(source_, capturing_net_log_.get()); | 90 return BoundNetLog(source_, capturing_net_log_.get()); |
| 86 } | 91 } |
| 87 | 92 |
| 88 // Returns the list of all entries in the log. | 93 // Returns the list of all entries in the log. |
|
eroman
2010/11/18 18:04:03
nit: "Returns" --> "Fills" ?
| |
| 89 const CapturingNetLog::EntryList& entries() const { | 94 void GetEntries(CapturingNetLog::EntryList* entry_list) const; |
| 90 return capturing_net_log_->entries(); | |
| 91 } | |
| 92 | 95 |
| 93 void Clear(); | 96 void Clear(); |
| 94 | 97 |
| 95 // Sends all of captured messages to |net_log|, using the same source ID | 98 // Sends all of captured messages to |net_log|, using the same source ID |
| 96 // as |net_log|. | 99 // as |net_log|. |
| 97 void AppendTo(const BoundNetLog& net_log) const; | 100 void AppendTo(const BoundNetLog& net_log) const; |
|
eroman
2010/11/18 18:04:03
I wander if we still need this method now?
mmenke
2010/11/23 16:48:45
I can't see a use for it.
| |
| 98 | 101 |
| 99 private: | 102 private: |
| 100 NetLog::Source source_; | 103 NetLog::Source source_; |
| 101 scoped_ptr<CapturingNetLog> capturing_net_log_; | 104 scoped_ptr<CapturingNetLog> capturing_net_log_; |
| 102 | 105 |
| 103 DISALLOW_COPY_AND_ASSIGN(CapturingBoundNetLog); | 106 DISALLOW_COPY_AND_ASSIGN(CapturingBoundNetLog); |
| 104 }; | 107 }; |
| 105 | 108 |
| 106 } // namespace net | 109 } // namespace net |
| 107 | 110 |
| 108 #endif // NET_BASE_CAPTURING_NET_LOG_H_ | 111 #endif // NET_BASE_CAPTURING_NET_LOG_H_ |
| 109 | 112 |
| OLD | NEW |