| 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> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 EventType type; | 58 EventType type; |
| 59 base::TimeTicks time; | 59 base::TimeTicks time; |
| 60 Source source; | 60 Source source; |
| 61 EventPhase phase; | 61 EventPhase phase; |
| 62 scoped_ptr<base::DictionaryValue> params; | 62 scoped_ptr<base::DictionaryValue> params; |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 // Ordered set of entries that were logged. | 65 // Ordered set of entries that were logged. |
| 66 typedef std::vector<CapturedEntry> CapturedEntryList; | 66 typedef std::vector<CapturedEntry> CapturedEntryList; |
| 67 | 67 |
| 68 enum { kUnbounded = -1 }; | 68 CapturingNetLog(); |
| 69 | |
| 70 // Creates a CapturingNetLog that logs a maximum of |max_num_entries| | |
| 71 // messages. | |
| 72 explicit CapturingNetLog(size_t max_num_entries); | |
| 73 virtual ~CapturingNetLog(); | 69 virtual ~CapturingNetLog(); |
| 74 | 70 |
| 75 // Returns the list of all entries in the log. | 71 // Returns the list of all entries in the log. |
| 76 void GetEntries(CapturedEntryList* entry_list) const; | 72 void GetEntries(CapturedEntryList* entry_list) const; |
| 77 | 73 |
| 78 void Clear(); | 74 void Clear(); |
| 79 | 75 |
| 80 void SetLogLevel(NetLog::LogLevel log_level); | 76 void SetLogLevel(NetLog::LogLevel log_level); |
| 81 | 77 |
| 82 // NetLog implementation: | 78 // NetLog implementation: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 93 LogLevel log_level) OVERRIDE; | 89 LogLevel log_level) OVERRIDE; |
| 94 virtual void RemoveThreadSafeObserver(ThreadSafeObserver* observer) OVERRIDE; | 90 virtual void RemoveThreadSafeObserver(ThreadSafeObserver* observer) OVERRIDE; |
| 95 | 91 |
| 96 private: | 92 private: |
| 97 // Needs to be "mutable" so can use it in GetEntries(). | 93 // Needs to be "mutable" so can use it in GetEntries(). |
| 98 mutable base::Lock lock_; | 94 mutable base::Lock lock_; |
| 99 | 95 |
| 100 // Last assigned source ID. Incremented to get the next one. | 96 // Last assigned source ID. Incremented to get the next one. |
| 101 base::subtle::Atomic32 last_id_; | 97 base::subtle::Atomic32 last_id_; |
| 102 | 98 |
| 103 size_t max_num_entries_; | |
| 104 CapturedEntryList captured_entries_; | 99 CapturedEntryList captured_entries_; |
| 105 | 100 |
| 106 NetLog::LogLevel log_level_; | 101 NetLog::LogLevel log_level_; |
| 107 | 102 |
| 108 DISALLOW_COPY_AND_ASSIGN(CapturingNetLog); | 103 DISALLOW_COPY_AND_ASSIGN(CapturingNetLog); |
| 109 }; | 104 }; |
| 110 | 105 |
| 111 // Helper class that exposes a similar API as BoundNetLog, but uses a | 106 // Helper class that exposes a similar API as BoundNetLog, but uses a |
| 112 // CapturingNetLog rather than the more generic NetLog. | 107 // CapturingNetLog rather than the more generic NetLog. |
| 113 // | 108 // |
| 114 // CapturingBoundNetLog can easily be converted to a BoundNetLog using the | 109 // CapturingBoundNetLog can easily be converted to a BoundNetLog using the |
| 115 // bound() method. | 110 // bound() method. |
| 116 class CapturingBoundNetLog { | 111 class CapturingBoundNetLog { |
| 117 public: | 112 public: |
| 118 explicit CapturingBoundNetLog(size_t max_num_entries); | 113 CapturingBoundNetLog(); |
| 119 | |
| 120 ~CapturingBoundNetLog(); | 114 ~CapturingBoundNetLog(); |
| 121 | 115 |
| 122 // The returned BoundNetLog is only valid while |this| is alive. | 116 // The returned BoundNetLog is only valid while |this| is alive. |
| 123 BoundNetLog bound() const { return net_log_; } | 117 BoundNetLog bound() const { return net_log_; } |
| 124 | 118 |
| 125 // Fills |entry_list| with all entries in the log. | 119 // Fills |entry_list| with all entries in the log. |
| 126 void GetEntries(CapturingNetLog::CapturedEntryList* entry_list) const; | 120 void GetEntries(CapturingNetLog::CapturedEntryList* entry_list) const; |
| 127 | 121 |
| 128 void Clear(); | 122 void Clear(); |
| 129 | 123 |
| 130 // Sets the log level of the underlying CapturingNetLog. | 124 // Sets the log level of the underlying CapturingNetLog. |
| 131 void SetLogLevel(NetLog::LogLevel log_level); | 125 void SetLogLevel(NetLog::LogLevel log_level); |
| 132 | 126 |
| 133 private: | 127 private: |
| 134 CapturingNetLog capturing_net_log_; | 128 CapturingNetLog capturing_net_log_; |
| 135 const BoundNetLog net_log_; | 129 const BoundNetLog net_log_; |
| 136 | 130 |
| 137 DISALLOW_COPY_AND_ASSIGN(CapturingBoundNetLog); | 131 DISALLOW_COPY_AND_ASSIGN(CapturingBoundNetLog); |
| 138 }; | 132 }; |
| 139 | 133 |
| 140 } // namespace net | 134 } // namespace net |
| 141 | 135 |
| 142 #endif // NET_BASE_CAPTURING_NET_LOG_H_ | 136 #endif // NET_BASE_CAPTURING_NET_LOG_H_ |
| OLD | NEW |