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 #include "net/base/capturing_net_log.h" | 5 #include "net/base/capturing_net_log.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 | 10 |
11 namespace net { | 11 namespace net { |
12 | 12 |
13 CapturingNetLog::CapturedEntry::CapturedEntry( | 13 CapturingNetLog::CapturedEntry::CapturedEntry( |
14 EventType type, | 14 EventType type, |
15 const base::TimeTicks& time, | 15 const base::TimeTicks& time, |
16 Source source, | 16 Source source, |
17 EventPhase phase, | 17 EventPhase phase, |
18 scoped_ptr<DictionaryValue> params) | 18 scoped_ptr<base::DictionaryValue> params) |
19 : type(type), | 19 : type(type), |
20 time(time), | 20 time(time), |
21 source(source), | 21 source(source), |
22 phase(phase), | 22 phase(phase), |
23 params(params.Pass()) { | 23 params(params.Pass()) { |
24 } | 24 } |
25 | 25 |
26 CapturingNetLog::CapturedEntry::CapturedEntry(const CapturedEntry& entry) { | 26 CapturingNetLog::CapturedEntry::CapturedEntry(const CapturedEntry& entry) { |
27 *this = entry; | 27 *this = entry; |
28 } | 28 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 base::AutoLock lock(lock_); | 98 base::AutoLock lock(lock_); |
99 captured_entries_.clear(); | 99 captured_entries_.clear(); |
100 } | 100 } |
101 | 101 |
102 void CapturingNetLog::Observer::OnAddEntry(const net::NetLog::Entry& entry) { | 102 void CapturingNetLog::Observer::OnAddEntry(const net::NetLog::Entry& entry) { |
103 // Only BoundNetLogs without a NetLog should have an invalid source. | 103 // Only BoundNetLogs without a NetLog should have an invalid source. |
104 CHECK(entry.source().IsValid()); | 104 CHECK(entry.source().IsValid()); |
105 | 105 |
106 // Using Dictionaries instead of Values makes checking values a little | 106 // Using Dictionaries instead of Values makes checking values a little |
107 // simpler. | 107 // simpler. |
108 DictionaryValue* param_dict = NULL; | 108 base::DictionaryValue* param_dict = NULL; |
109 Value* param_value = entry.ParametersToValue(); | 109 Value* param_value = entry.ParametersToValue(); |
110 if (param_value && !param_value->GetAsDictionary(¶m_dict)) | 110 if (param_value && !param_value->GetAsDictionary(¶m_dict)) |
111 delete param_value; | 111 delete param_value; |
112 | 112 |
113 // Only need to acquire the lock when accessing class variables. | 113 // Only need to acquire the lock when accessing class variables. |
114 base::AutoLock lock(lock_); | 114 base::AutoLock lock(lock_); |
115 captured_entries_.push_back( | 115 captured_entries_.push_back( |
116 CapturedEntry(entry.type(), | 116 CapturedEntry(entry.type(), |
117 base::TimeTicks::Now(), | 117 base::TimeTicks::Now(), |
118 entry.source(), | 118 entry.source(), |
119 entry.phase(), | 119 entry.phase(), |
120 scoped_ptr<DictionaryValue>(param_dict))); | 120 scoped_ptr<base::DictionaryValue>(param_dict))); |
121 } | 121 } |
122 | 122 |
123 CapturingNetLog::CapturingNetLog() { | 123 CapturingNetLog::CapturingNetLog() { |
124 AddThreadSafeObserver(&capturing_net_log_observer_, LOG_ALL_BUT_BYTES); | 124 AddThreadSafeObserver(&capturing_net_log_observer_, LOG_ALL_BUT_BYTES); |
125 } | 125 } |
126 | 126 |
127 CapturingNetLog::~CapturingNetLog() { | 127 CapturingNetLog::~CapturingNetLog() { |
128 RemoveThreadSafeObserver(&capturing_net_log_observer_); | 128 RemoveThreadSafeObserver(&capturing_net_log_observer_); |
129 } | 129 } |
130 | 130 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 175 |
176 void CapturingBoundNetLog::Clear() { | 176 void CapturingBoundNetLog::Clear() { |
177 capturing_net_log_.Clear(); | 177 capturing_net_log_.Clear(); |
178 } | 178 } |
179 | 179 |
180 void CapturingBoundNetLog::SetLogLevel(NetLog::LogLevel log_level) { | 180 void CapturingBoundNetLog::SetLogLevel(NetLog::LogLevel log_level) { |
181 capturing_net_log_.SetLogLevel(log_level); | 181 capturing_net_log_.SetLogLevel(log_level); |
182 } | 182 } |
183 | 183 |
184 } // namespace net | 184 } // namespace net |
OLD | NEW |