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_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 <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/atomicops.h" | 12 #include "base/atomicops.h" |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 18 #include "base/time.h" | 18 #include "base/time.h" |
| 19 #include "net/base/net_export.h" | 19 #include "net/base/net_export.h" |
| 20 #include "net/base/net_log.h" | 20 #include "net/base/net_log.h" |
| 21 | 21 |
| 22 namespace base { | 22 namespace base { |
| 23 class DictionaryValue; | 23 class DictionaryValue; |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace net { | 26 namespace net { |
| 27 | 27 |
| 28 // CapturingNetLog is an implementation of NetLog that saves messages to a | 28 // CapturingNetLog is an implementation of NetLog that saves messages to a |
| 29 // bounded buffer. CapturingNetLogs should only be used in unit tests, never | 29 // bounded buffer. It is intended for testing only, and is part of the |
| 30 // in production code. | 30 // net_test_support project. |
| 31 // TODO(mmenke): Move CapturingNetLog to net_unittests project, once the CL | 31 class CapturingNetLog : public NetLog { |
|
eroman
2012/06/08 18:24:41
Oh I see, you removed the comment as part of this
mmenke
2012/06/08 18:28:11
Just forgot to copy it to the other one (Was think
| |
| 32 // to remove the use of it in the Jingle unit tests has landed. | |
| 33 class NET_EXPORT CapturingNetLog : public NetLog { | |
| 34 public: | 32 public: |
| 35 struct NET_EXPORT_PRIVATE CapturedEntry { | 33 struct CapturedEntry { |
| 36 CapturedEntry(EventType type, | 34 CapturedEntry(EventType type, |
| 37 const base::TimeTicks& time, | 35 const base::TimeTicks& time, |
| 38 Source source, | 36 Source source, |
| 39 EventPhase phase, | 37 EventPhase phase, |
| 40 scoped_ptr<base::DictionaryValue> params); | 38 scoped_ptr<base::DictionaryValue> params); |
| 41 // Copy constructor needed to store in a std::vector because of the | 39 // Copy constructor needed to store in a std::vector because of the |
| 42 // scoped_ptr. | 40 // scoped_ptr. |
| 43 CapturedEntry(const CapturedEntry& entry); | 41 CapturedEntry(const CapturedEntry& entry); |
| 44 | 42 |
| 45 ~CapturedEntry(); | 43 ~CapturedEntry(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 61 EventType type; | 59 EventType type; |
| 62 base::TimeTicks time; | 60 base::TimeTicks time; |
| 63 Source source; | 61 Source source; |
| 64 EventPhase phase; | 62 EventPhase phase; |
| 65 scoped_ptr<base::DictionaryValue> params; | 63 scoped_ptr<base::DictionaryValue> params; |
| 66 }; | 64 }; |
| 67 | 65 |
| 68 // Ordered set of entries that were logged. | 66 // Ordered set of entries that were logged. |
| 69 typedef std::vector<CapturedEntry> CapturedEntryList; | 67 typedef std::vector<CapturedEntry> CapturedEntryList; |
| 70 | 68 |
| 71 enum { kUnbounded = -1 }; | 69 enum { kUnbounded = -1 }; |
|
eroman
2012/06/08 18:24:41
Delete
mmenke
2012/06/08 18:28:11
Thanks, done.
| |
| 72 | 70 |
| 73 // Creates a CapturingNetLog that logs a maximum of |max_num_entries| | 71 CapturingNetLog(); |
| 74 // messages. | |
| 75 explicit CapturingNetLog(size_t max_num_entries); | |
| 76 virtual ~CapturingNetLog(); | 72 virtual ~CapturingNetLog(); |
| 77 | 73 |
| 78 // Returns the list of all entries in the log. | 74 // Returns the list of all entries in the log. |
| 79 void GetEntries(CapturedEntryList* entry_list) const; | 75 void GetEntries(CapturedEntryList* entry_list) const; |
| 80 | 76 |
| 81 void Clear(); | 77 void Clear(); |
| 82 | 78 |
| 83 void SetLogLevel(NetLog::LogLevel log_level); | 79 void SetLogLevel(NetLog::LogLevel log_level); |
| 84 | 80 |
| 85 // NetLog implementation: | 81 // NetLog implementation: |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 96 LogLevel log_level) OVERRIDE; | 92 LogLevel log_level) OVERRIDE; |
| 97 virtual void RemoveThreadSafeObserver(ThreadSafeObserver* observer) OVERRIDE; | 93 virtual void RemoveThreadSafeObserver(ThreadSafeObserver* observer) OVERRIDE; |
| 98 | 94 |
| 99 private: | 95 private: |
| 100 // Needs to be "mutable" so can use it in GetEntries(). | 96 // Needs to be "mutable" so can use it in GetEntries(). |
| 101 mutable base::Lock lock_; | 97 mutable base::Lock lock_; |
| 102 | 98 |
| 103 // Last assigned source ID. Incremented to get the next one. | 99 // Last assigned source ID. Incremented to get the next one. |
| 104 base::subtle::Atomic32 last_id_; | 100 base::subtle::Atomic32 last_id_; |
| 105 | 101 |
| 106 size_t max_num_entries_; | |
| 107 CapturedEntryList captured_entries_; | 102 CapturedEntryList captured_entries_; |
| 108 | 103 |
| 109 NetLog::LogLevel log_level_; | 104 NetLog::LogLevel log_level_; |
| 110 | 105 |
| 111 DISALLOW_COPY_AND_ASSIGN(CapturingNetLog); | 106 DISALLOW_COPY_AND_ASSIGN(CapturingNetLog); |
| 112 }; | 107 }; |
| 113 | 108 |
| 114 // Helper class that exposes a similar API as BoundNetLog, but uses a | 109 // Helper class that exposes a similar API as BoundNetLog, but uses a |
| 115 // CapturingNetLog rather than the more generic NetLog. | 110 // CapturingNetLog rather than the more generic NetLog. |
| 116 // | 111 // |
| 117 // CapturingBoundNetLog can easily be converted to a BoundNetLog using the | 112 // CapturingBoundNetLog can easily be converted to a BoundNetLog using the |
| 118 // bound() method. | 113 // bound() method. |
| 119 class NET_EXPORT_PRIVATE CapturingBoundNetLog { | 114 class CapturingBoundNetLog { |
| 120 public: | 115 public: |
| 121 explicit CapturingBoundNetLog(size_t max_num_entries); | 116 CapturingBoundNetLog(); |
| 122 | |
| 123 ~CapturingBoundNetLog(); | 117 ~CapturingBoundNetLog(); |
| 124 | 118 |
| 125 // The returned BoundNetLog is only valid while |this| is alive. | 119 // The returned BoundNetLog is only valid while |this| is alive. |
| 126 BoundNetLog bound() const { return net_log_; } | 120 BoundNetLog bound() const { return net_log_; } |
| 127 | 121 |
| 128 // Fills |entry_list| with all entries in the log. | 122 // Fills |entry_list| with all entries in the log. |
| 129 void GetEntries(CapturingNetLog::CapturedEntryList* entry_list) const; | 123 void GetEntries(CapturingNetLog::CapturedEntryList* entry_list) const; |
| 130 | 124 |
| 131 void Clear(); | 125 void Clear(); |
| 132 | 126 |
| 133 // Sets the log level of the underlying CapturingNetLog. | 127 // Sets the log level of the underlying CapturingNetLog. |
| 134 void SetLogLevel(NetLog::LogLevel log_level); | 128 void SetLogLevel(NetLog::LogLevel log_level); |
| 135 | 129 |
| 136 private: | 130 private: |
| 137 CapturingNetLog capturing_net_log_; | 131 CapturingNetLog capturing_net_log_; |
| 138 const BoundNetLog net_log_; | 132 const BoundNetLog net_log_; |
| 139 | 133 |
| 140 DISALLOW_COPY_AND_ASSIGN(CapturingBoundNetLog); | 134 DISALLOW_COPY_AND_ASSIGN(CapturingBoundNetLog); |
| 141 }; | 135 }; |
| 142 | 136 |
| 143 } // namespace net | 137 } // namespace net |
| 144 | 138 |
| 145 #endif // NET_BASE_CAPTURING_NET_LOG_H_ | 139 #endif // NET_BASE_CAPTURING_NET_LOG_H_ |
| OLD | NEW |