Add signalSyncPoint to the WebGraphicsContext3D command buffer impls.
[chromium-blink-merge.git] / net / base / capturing_net_log.cc
blobb90dcae4f860d77ea6fe03bfd910bb5a4a2c8d92
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
3 // found in the LICENSE file.
5 #include "net/base/capturing_net_log.h"
7 #include "base/json/json_writer.h"
8 #include "base/logging.h"
9 #include "base/values.h"
11 namespace net {
13 CapturingNetLog::CapturedEntry::CapturedEntry(
14 EventType type,
15 const base::TimeTicks& time,
16 Source source,
17 EventPhase phase,
18 scoped_ptr<DictionaryValue> params)
19 : type(type),
20 time(time),
21 source(source),
22 phase(phase),
23 params(params.Pass()) {
26 CapturingNetLog::CapturedEntry::CapturedEntry(const CapturedEntry& entry) {
27 *this = entry;
30 CapturingNetLog::CapturedEntry::~CapturedEntry() {}
32 CapturingNetLog::CapturedEntry&
33 CapturingNetLog::CapturedEntry::operator=(const CapturedEntry& entry) {
34 type = entry.type;
35 time = entry.time;
36 source = entry.source;
37 phase = entry.phase;
38 params.reset(entry.params ? entry.params->DeepCopy() : NULL);
39 return *this;
42 bool CapturingNetLog::CapturedEntry::GetStringValue(
43 const std::string& name,
44 std::string* value) const {
45 if (!params)
46 return false;
47 return params->GetString(name, value);
50 bool CapturingNetLog::CapturedEntry::GetIntegerValue(
51 const std::string& name,
52 int* value) const {
53 if (!params)
54 return false;
55 return params->GetInteger(name, value);
58 bool CapturingNetLog::CapturedEntry::GetNetErrorCode(int* value) const {
59 return GetIntegerValue("net_error", value);
62 std::string CapturingNetLog::CapturedEntry::GetParamsJson() const {
63 if (!params)
64 return std::string();
65 std::string json;
66 base::JSONWriter::Write(params.get(), &json);
67 return json;
70 CapturingNetLog::CapturingNetLog()
71 : last_id_(0),
72 log_level_(LOG_ALL_BUT_BYTES) {
75 CapturingNetLog::~CapturingNetLog() {}
77 void CapturingNetLog::GetEntries(CapturedEntryList* entry_list) const {
78 base::AutoLock lock(lock_);
79 *entry_list = captured_entries_;
82 void CapturingNetLog::GetEntriesForSource(NetLog::Source source,
83 CapturedEntryList* entry_list) const {
84 base::AutoLock lock(lock_);
85 entry_list->clear();
86 for (CapturedEntryList::const_iterator entry = captured_entries_.begin();
87 entry != captured_entries_.end(); ++entry) {
88 if (entry->source.id == source.id)
89 entry_list->push_back(*entry);
93 size_t CapturingNetLog::GetSize() const {
94 base::AutoLock lock(lock_);
95 return captured_entries_.size();
98 void CapturingNetLog::Clear() {
99 base::AutoLock lock(lock_);
100 captured_entries_.clear();
103 void CapturingNetLog::SetLogLevel(NetLog::LogLevel log_level) {
104 base::AutoLock lock(lock_);
105 log_level_ = log_level;
108 void CapturingNetLog::OnAddEntry(const net::NetLog::Entry& entry) {
109 // Only BoundNetLogs without a NetLog should have an invalid source.
110 CHECK(entry.source().IsValid());
112 // Using Dictionaries instead of Values makes checking values a little
113 // simpler.
114 DictionaryValue* param_dict = NULL;
115 Value* param_value = entry.ParametersToValue();
116 if (param_value && !param_value->GetAsDictionary(&param_dict))
117 delete param_value;
119 // Only need to acquire the lock when accessing class variables.
120 base::AutoLock lock(lock_);
121 captured_entries_.push_back(
122 CapturedEntry(entry.type(),
123 base::TimeTicks::Now(),
124 entry.source(),
125 entry.phase(),
126 scoped_ptr<DictionaryValue>(param_dict)));
129 uint32 CapturingNetLog::NextID() {
130 return base::subtle::NoBarrier_AtomicIncrement(&last_id_, 1);
133 NetLog::LogLevel CapturingNetLog::GetLogLevel() const {
134 base::AutoLock lock(lock_);
135 return log_level_;
138 void CapturingNetLog::AddThreadSafeObserver(
139 NetLog::ThreadSafeObserver* observer,
140 NetLog::LogLevel log_level) {
141 NOTIMPLEMENTED() << "Not currently used by net unit tests.";
144 void CapturingNetLog::SetObserverLogLevel(ThreadSafeObserver* observer,
145 LogLevel log_level) {
146 NOTIMPLEMENTED() << "Not currently used by net unit tests.";
149 void CapturingNetLog::RemoveThreadSafeObserver(
150 NetLog::ThreadSafeObserver* observer) {
151 NOTIMPLEMENTED() << "Not currently used by net unit tests.";
154 CapturingBoundNetLog::CapturingBoundNetLog()
155 : net_log_(BoundNetLog::Make(&capturing_net_log_,
156 net::NetLog::SOURCE_NONE)) {
159 CapturingBoundNetLog::~CapturingBoundNetLog() {}
161 void CapturingBoundNetLog::GetEntries(
162 CapturingNetLog::CapturedEntryList* entry_list) const {
163 capturing_net_log_.GetEntries(entry_list);
166 void CapturingBoundNetLog::GetEntriesForSource(
167 NetLog::Source source,
168 CapturingNetLog::CapturedEntryList* entry_list) const {
169 capturing_net_log_.GetEntriesForSource(source, entry_list);
172 size_t CapturingBoundNetLog::GetSize() const {
173 return capturing_net_log_.GetSize();
176 void CapturingBoundNetLog::Clear() {
177 capturing_net_log_.Clear();
180 void CapturingBoundNetLog::SetLogLevel(NetLog::LogLevel log_level) {
181 capturing_net_log_.SetLogLevel(log_level);
184 } // namespace net