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

Side by Side Diff: net/log/test_net_log.cc

Issue 2333923004: Extracting NetLog inner classes into their own classes. (Closed)
Patch Set: Some nit fixes and better, impl-agnostic naming of net_log_parameters_callback_typedef.h -> net/log… Created 4 years, 2 months 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
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/log/test_net_log.h" 5 #include "net/log/test_net_log.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/synchronization/lock.h" 8 #include "base/synchronization/lock.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "net/log/net_log_capture_mode.h"
11 #include "net/log/net_log_entry.h"
12 #include "net/log/net_log_source.h"
10 #include "net/log/net_log_source_type.h" 13 #include "net/log/net_log_source_type.h"
11 14
12 namespace net { 15 namespace net {
13 16
14 // TestNetLog::Observer is an implementation of NetLog::ThreadSafeObserver 17 // TestNetLog::Observer is an implementation of NetLog::ThreadSafeObserver
15 // that saves messages to a buffer. 18 // that saves messages to a buffer.
16 class TestNetLog::Observer : public NetLog::ThreadSafeObserver { 19 class TestNetLog::Observer : public NetLog::ThreadSafeObserver {
17 public: 20 public:
18 Observer() {} 21 Observer() {}
19 ~Observer() override {} 22 ~Observer() override {}
20 23
21 // Returns the list of all entries in the log. 24 // Returns the list of all entries in the log.
22 void GetEntries(TestNetLogEntry::List* entry_list) const { 25 void GetEntries(TestNetLogEntry::List* entry_list) const {
23 base::AutoLock lock(lock_); 26 base::AutoLock lock(lock_);
24 *entry_list = entry_list_; 27 *entry_list = entry_list_;
25 } 28 }
26 29
27 // Fills |entry_list| with all entries in the log from the specified Source. 30 // Fills |entry_list| with all entries in the log from the specified Source.
28 void GetEntriesForSource(NetLog::Source source, 31 void GetEntriesForSource(NetLogSource source,
29 TestNetLogEntry::List* entry_list) const { 32 TestNetLogEntry::List* entry_list) const {
30 base::AutoLock lock(lock_); 33 base::AutoLock lock(lock_);
31 entry_list->clear(); 34 entry_list->clear();
32 for (const auto& entry : entry_list_) { 35 for (const auto& entry : entry_list_) {
33 if (entry.source.id == source.id) 36 if (entry.source.id == source.id)
34 entry_list->push_back(entry); 37 entry_list->push_back(entry);
35 } 38 }
36 } 39 }
37 40
38 // Returns the number of entries in the log. 41 // Returns the number of entries in the log.
39 size_t GetSize() const { 42 size_t GetSize() const {
40 base::AutoLock lock(lock_); 43 base::AutoLock lock(lock_);
41 return entry_list_.size(); 44 return entry_list_.size();
42 } 45 }
43 46
44 void Clear() { 47 void Clear() {
45 base::AutoLock lock(lock_); 48 base::AutoLock lock(lock_);
46 entry_list_.clear(); 49 entry_list_.clear();
47 } 50 }
48 51
49 private: 52 private:
50 // ThreadSafeObserver implementation: 53 // ThreadSafeObserver implementation:
51 void OnAddEntry(const NetLog::Entry& entry) override { 54 void OnAddEntry(const NetLogEntry& entry) override {
52 // Using Dictionaries instead of Values makes checking values a little 55 // Using Dictionaries instead of Values makes checking values a little
53 // simpler. 56 // simpler.
54 std::unique_ptr<base::DictionaryValue> param_dict = 57 std::unique_ptr<base::DictionaryValue> param_dict =
55 base::DictionaryValue::From(entry.ParametersToValue()); 58 base::DictionaryValue::From(entry.ParametersToValue());
56 59
57 // Only need to acquire the lock when accessing class variables. 60 // Only need to acquire the lock when accessing class variables.
58 base::AutoLock lock(lock_); 61 base::AutoLock lock(lock_);
59 entry_list_.push_back(TestNetLogEntry(entry.type(), base::TimeTicks::Now(), 62 entry_list_.push_back(TestNetLogEntry(entry.type(), base::TimeTicks::Now(),
60 entry.source(), entry.phase(), 63 entry.source(), entry.phase(),
61 std::move(param_dict))); 64 std::move(param_dict)));
(...skipping 17 matching lines...) Expand all
79 } 82 }
80 83
81 void TestNetLog::SetCaptureMode(NetLogCaptureMode capture_mode) { 84 void TestNetLog::SetCaptureMode(NetLogCaptureMode capture_mode) {
82 SetObserverCaptureMode(observer_.get(), capture_mode); 85 SetObserverCaptureMode(observer_.get(), capture_mode);
83 } 86 }
84 87
85 void TestNetLog::GetEntries(TestNetLogEntry::List* entry_list) const { 88 void TestNetLog::GetEntries(TestNetLogEntry::List* entry_list) const {
86 observer_->GetEntries(entry_list); 89 observer_->GetEntries(entry_list);
87 } 90 }
88 91
89 void TestNetLog::GetEntriesForSource(NetLog::Source source, 92 void TestNetLog::GetEntriesForSource(NetLogSource source,
90 TestNetLogEntry::List* entry_list) const { 93 TestNetLogEntry::List* entry_list) const {
91 observer_->GetEntriesForSource(source, entry_list); 94 observer_->GetEntriesForSource(source, entry_list);
92 } 95 }
93 96
94 size_t TestNetLog::GetSize() const { 97 size_t TestNetLog::GetSize() const {
95 return observer_->GetSize(); 98 return observer_->GetSize();
96 } 99 }
97 100
98 void TestNetLog::Clear() { 101 void TestNetLog::Clear() {
99 observer_->Clear(); 102 observer_->Clear();
100 } 103 }
101 104
102 NetLog::ThreadSafeObserver* TestNetLog::GetObserver() const { 105 NetLog::ThreadSafeObserver* TestNetLog::GetObserver() const {
103 return observer_.get(); 106 return observer_.get();
104 } 107 }
105 108
106 BoundTestNetLog::BoundTestNetLog() 109 BoundTestNetLog::BoundTestNetLog()
107 : net_log_(NetLogWithSource::Make(&test_net_log_, NetLogSourceType::NONE)) { 110 : net_log_(NetLogWithSource::Make(&test_net_log_, NetLogSourceType::NONE)) {
108 } 111 }
109 112
110 BoundTestNetLog::~BoundTestNetLog() { 113 BoundTestNetLog::~BoundTestNetLog() {
111 } 114 }
112 115
113 void BoundTestNetLog::GetEntries(TestNetLogEntry::List* entry_list) const { 116 void BoundTestNetLog::GetEntries(TestNetLogEntry::List* entry_list) const {
114 test_net_log_.GetEntries(entry_list); 117 test_net_log_.GetEntries(entry_list);
115 } 118 }
116 119
117 void BoundTestNetLog::GetEntriesForSource( 120 void BoundTestNetLog::GetEntriesForSource(
118 NetLog::Source source, 121 NetLogSource source,
119 TestNetLogEntry::List* entry_list) const { 122 TestNetLogEntry::List* entry_list) const {
120 test_net_log_.GetEntriesForSource(source, entry_list); 123 test_net_log_.GetEntriesForSource(source, entry_list);
121 } 124 }
122 125
123 size_t BoundTestNetLog::GetSize() const { 126 size_t BoundTestNetLog::GetSize() const {
124 return test_net_log_.GetSize(); 127 return test_net_log_.GetSize();
125 } 128 }
126 129
127 void BoundTestNetLog::Clear() { 130 void BoundTestNetLog::Clear() {
128 test_net_log_.Clear(); 131 test_net_log_.Clear();
129 } 132 }
130 133
131 void BoundTestNetLog::SetCaptureMode(NetLogCaptureMode capture_mode) { 134 void BoundTestNetLog::SetCaptureMode(NetLogCaptureMode capture_mode) {
132 test_net_log_.SetCaptureMode(capture_mode); 135 test_net_log_.SetCaptureMode(capture_mode);
133 } 136 }
134 137
135 } // namespace net 138 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698