Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(606)

Side by Side Diff: net/base/capturing_net_log.cc

Issue 754433003: Update from https://crrev.com/305340 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/base/capturing_net_log.h ('k') | net/base/capturing_net_log_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
8 #include "base/logging.h"
9 #include "base/values.h"
10
11 namespace net { 7 namespace net {
12 8
13 CapturingNetLog::CapturedEntry::CapturedEntry(
14 EventType type,
15 const base::TimeTicks& time,
16 Source source,
17 EventPhase phase,
18 scoped_ptr<base::DictionaryValue> params)
19 : type(type),
20 time(time),
21 source(source),
22 phase(phase),
23 params(params.Pass()) {
24 }
25
26 CapturingNetLog::CapturedEntry::CapturedEntry(const CapturedEntry& entry) {
27 *this = entry;
28 }
29
30 CapturingNetLog::CapturedEntry::~CapturedEntry() {}
31
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;
40 }
41
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);
48 }
49
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);
56 }
57
58 bool CapturingNetLog::CapturedEntry::GetListValue(
59 const std::string& name,
60 base::ListValue** value) const {
61 if (!params)
62 return false;
63 return params->GetList(name, value);
64 }
65
66 bool CapturingNetLog::CapturedEntry::GetNetErrorCode(int* value) const {
67 return GetIntegerValue("net_error", value);
68 }
69
70 std::string CapturingNetLog::CapturedEntry::GetParamsJson() const {
71 if (!params)
72 return std::string();
73 std::string json;
74 base::JSONWriter::Write(params.get(), &json);
75 return json;
76 }
77
78 CapturingNetLog::Observer::Observer() {}
79
80 CapturingNetLog::Observer::~Observer() {}
81
82 void CapturingNetLog::Observer::GetEntries(
83 CapturedEntryList* entry_list) const {
84 base::AutoLock lock(lock_);
85 *entry_list = captured_entries_;
86 }
87
88 void CapturingNetLog::Observer::GetEntriesForSource(
89 NetLog::Source source,
90 CapturedEntryList* entry_list) const {
91 base::AutoLock lock(lock_);
92 entry_list->clear();
93 for (CapturedEntryList::const_iterator entry = captured_entries_.begin();
94 entry != captured_entries_.end(); ++entry) {
95 if (entry->source.id == source.id)
96 entry_list->push_back(*entry);
97 }
98 }
99
100 size_t CapturingNetLog::Observer::GetSize() const {
101 base::AutoLock lock(lock_);
102 return captured_entries_.size();
103 }
104
105 void CapturingNetLog::Observer::Clear() {
106 base::AutoLock lock(lock_);
107 captured_entries_.clear();
108 }
109
110 void CapturingNetLog::Observer::OnAddEntry(const net::NetLog::Entry& entry) {
111 // Only BoundNetLogs without a NetLog should have an invalid source.
112 CHECK(entry.source().IsValid());
113
114 // Using Dictionaries instead of Values makes checking values a little
115 // simpler.
116 base::DictionaryValue* param_dict = NULL;
117 base::Value* param_value = entry.ParametersToValue();
118 if (param_value && !param_value->GetAsDictionary(&param_dict))
119 delete param_value;
120
121 // Only need to acquire the lock when accessing class variables.
122 base::AutoLock lock(lock_);
123 captured_entries_.push_back(
124 CapturedEntry(entry.type(),
125 base::TimeTicks::Now(),
126 entry.source(),
127 entry.phase(),
128 scoped_ptr<base::DictionaryValue>(param_dict)));
129 }
130
131 CapturingNetLog::CapturingNetLog() { 9 CapturingNetLog::CapturingNetLog() {
132 AddThreadSafeObserver(&capturing_net_log_observer_, LOG_ALL_BUT_BYTES); 10 AddThreadSafeObserver(&capturing_net_log_observer_, LOG_ALL_BUT_BYTES);
133 } 11 }
134 12
135 CapturingNetLog::~CapturingNetLog() { 13 CapturingNetLog::~CapturingNetLog() {
136 RemoveThreadSafeObserver(&capturing_net_log_observer_); 14 RemoveThreadSafeObserver(&capturing_net_log_observer_);
137 } 15 }
138 16
139 void CapturingNetLog::SetLogLevel(NetLog::LogLevel log_level) { 17 void CapturingNetLog::SetLogLevel(NetLog::LogLevel log_level) {
140 SetObserverLogLevel(&capturing_net_log_observer_, log_level); 18 SetObserverLogLevel(&capturing_net_log_observer_, log_level);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 61
184 void CapturingBoundNetLog::Clear() { 62 void CapturingBoundNetLog::Clear() {
185 capturing_net_log_.Clear(); 63 capturing_net_log_.Clear();
186 } 64 }
187 65
188 void CapturingBoundNetLog::SetLogLevel(NetLog::LogLevel log_level) { 66 void CapturingBoundNetLog::SetLogLevel(NetLog::LogLevel log_level) {
189 capturing_net_log_.SetLogLevel(log_level); 67 capturing_net_log_.SetLogLevel(log_level);
190 } 68 }
191 69
192 } // namespace net 70 } // namespace net
OLDNEW
« no previous file with comments | « net/base/capturing_net_log.h ('k') | net/base/capturing_net_log_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698