OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/spdy/hpack/hpack_header_table.h" | 5 #include "net/spdy/hpack/hpack_header_table.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "net/spdy/hpack/hpack_constants.h" | 10 #include "net/spdy/hpack/hpack_constants.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 const HpackEntry* HpackHeaderTable::GetByIndex(size_t index) { | 45 const HpackEntry* HpackHeaderTable::GetByIndex(size_t index) { |
46 if (index == 0) { | 46 if (index == 0) { |
47 return NULL; | 47 return NULL; |
48 } | 48 } |
49 index -= 1; | 49 index -= 1; |
50 if (index < static_entries_.size()) { | 50 if (index < static_entries_.size()) { |
51 return &static_entries_[index]; | 51 return &static_entries_[index]; |
52 } | 52 } |
53 index -= static_entries_.size(); | 53 index -= static_entries_.size(); |
54 if (index < dynamic_entries_.size()) { | 54 if (index < dynamic_entries_.size()) { |
55 return &dynamic_entries_[index]; | 55 const HpackEntry* result = &dynamic_entries_[index]; |
| 56 if (debug_visitor_ != nullptr) { |
| 57 debug_visitor_->OnUseEntry(*result); |
| 58 } |
| 59 return result; |
56 } | 60 } |
57 return NULL; | 61 return NULL; |
58 } | 62 } |
59 | 63 |
60 const HpackEntry* HpackHeaderTable::GetByName(StringPiece name) { | 64 const HpackEntry* HpackHeaderTable::GetByName(StringPiece name) { |
61 { | 65 { |
62 NameToEntryMap::const_iterator it = static_name_index_.find(name); | 66 NameToEntryMap::const_iterator it = static_name_index_.find(name); |
63 if (it != static_name_index_.end()) { | 67 if (it != static_name_index_.end()) { |
64 return it->second; | 68 return it->second; |
65 } | 69 } |
66 } | 70 } |
67 { | 71 { |
68 NameToEntryMap::const_iterator it = dynamic_name_index_.find(name); | 72 NameToEntryMap::const_iterator it = dynamic_name_index_.find(name); |
69 if (it != dynamic_name_index_.end()) { | 73 if (it != dynamic_name_index_.end()) { |
70 return it->second; | 74 const HpackEntry* result = it->second; |
| 75 if (debug_visitor_ != nullptr) { |
| 76 debug_visitor_->OnUseEntry(*result); |
| 77 } |
| 78 return result; |
71 } | 79 } |
72 } | 80 } |
73 return NULL; | 81 return NULL; |
74 } | 82 } |
75 | 83 |
76 const HpackEntry* HpackHeaderTable::GetByNameAndValue(StringPiece name, | 84 const HpackEntry* HpackHeaderTable::GetByNameAndValue(StringPiece name, |
77 StringPiece value) { | 85 StringPiece value) { |
78 HpackEntry query(name, value); | 86 HpackEntry query(name, value); |
79 { | 87 { |
80 UnorderedEntrySet::const_iterator it = static_index_.find(&query); | 88 UnorderedEntrySet::const_iterator it = static_index_.find(&query); |
81 if (it != static_index_.end()) { | 89 if (it != static_index_.end()) { |
82 return *it; | 90 return *it; |
83 } | 91 } |
84 } | 92 } |
85 { | 93 { |
86 UnorderedEntrySet::const_iterator it = dynamic_index_.find(&query); | 94 UnorderedEntrySet::const_iterator it = dynamic_index_.find(&query); |
87 if (it != dynamic_index_.end()) { | 95 if (it != dynamic_index_.end()) { |
88 return *it; | 96 const HpackEntry* result = *it; |
| 97 if (debug_visitor_ != nullptr) { |
| 98 debug_visitor_->OnUseEntry(*result); |
| 99 } |
| 100 return result; |
89 } | 101 } |
90 } | 102 } |
91 return NULL; | 103 return NULL; |
92 } | 104 } |
93 | 105 |
94 size_t HpackHeaderTable::IndexOf(const HpackEntry* entry) const { | 106 size_t HpackHeaderTable::IndexOf(const HpackEntry* entry) const { |
95 if (entry->IsLookup()) { | 107 if (entry->IsLookup()) { |
96 return 0; | 108 return 0; |
97 } else if (entry->IsStatic()) { | 109 } else if (entry->IsStatic()) { |
98 return 1 + entry->InsertionIndex(); | 110 return 1 + entry->InsertionIndex(); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 DCHECK_GT(new_entry->InsertionIndex(), | 225 DCHECK_GT(new_entry->InsertionIndex(), |
214 name_result.first->second->InsertionIndex()); | 226 name_result.first->second->InsertionIndex()); |
215 dynamic_name_index_.erase(name_result.first); | 227 dynamic_name_index_.erase(name_result.first); |
216 auto insert_result = dynamic_name_index_.insert( | 228 auto insert_result = dynamic_name_index_.insert( |
217 std::make_pair(new_entry->name(), new_entry)); | 229 std::make_pair(new_entry->name(), new_entry)); |
218 CHECK(insert_result.second); | 230 CHECK(insert_result.second); |
219 } | 231 } |
220 | 232 |
221 size_ += entry_size; | 233 size_ += entry_size; |
222 ++total_insertions_; | 234 ++total_insertions_; |
| 235 if (debug_visitor_ != nullptr) { |
| 236 // Call |debug_visitor_->OnNewEntry()| to get the current time. |
| 237 HpackEntry& entry = dynamic_entries_.front(); |
| 238 entry.set_time_added(debug_visitor_->OnNewEntry(entry)); |
| 239 } |
223 | 240 |
224 return &dynamic_entries_.front(); | 241 return &dynamic_entries_.front(); |
225 } | 242 } |
226 | 243 |
227 void HpackHeaderTable::DebugLogTableState() const { | 244 void HpackHeaderTable::DebugLogTableState() const { |
228 DVLOG(2) << "Dynamic table:"; | 245 DVLOG(2) << "Dynamic table:"; |
229 for (EntryTable::const_iterator it = dynamic_entries_.begin(); | 246 for (EntryTable::const_iterator it = dynamic_entries_.begin(); |
230 it != dynamic_entries_.end(); ++it) { | 247 it != dynamic_entries_.end(); ++it) { |
231 DVLOG(2) << " " << it->GetDebugString(); | 248 DVLOG(2) << " " << it->GetDebugString(); |
232 } | 249 } |
233 DVLOG(2) << "Full Static Index:"; | 250 DVLOG(2) << "Full Static Index:"; |
234 for (const auto entry : static_index_) { | 251 for (const auto entry : static_index_) { |
235 DVLOG(2) << " " << entry->GetDebugString(); | 252 DVLOG(2) << " " << entry->GetDebugString(); |
236 } | 253 } |
237 DVLOG(2) << "Full Static Name Index:"; | 254 DVLOG(2) << "Full Static Name Index:"; |
238 for (const auto it : static_name_index_) { | 255 for (const auto it : static_name_index_) { |
239 DVLOG(2) << " " << it.first << ": " << it.second->GetDebugString(); | 256 DVLOG(2) << " " << it.first << ": " << it.second->GetDebugString(); |
240 } | 257 } |
241 DVLOG(2) << "Full Dynamic Index:"; | 258 DVLOG(2) << "Full Dynamic Index:"; |
242 for (const auto entry : dynamic_index_) { | 259 for (const auto entry : dynamic_index_) { |
243 DVLOG(2) << " " << entry->GetDebugString(); | 260 DVLOG(2) << " " << entry->GetDebugString(); |
244 } | 261 } |
245 DVLOG(2) << "Full Dynamic Name Index:"; | 262 DVLOG(2) << "Full Dynamic Name Index:"; |
246 for (const auto it : dynamic_name_index_) { | 263 for (const auto it : dynamic_name_index_) { |
247 DVLOG(2) << " " << it.first << ": " << it.second->GetDebugString(); | 264 DVLOG(2) << " " << it.first << ": " << it.second->GetDebugString(); |
248 } | 265 } |
249 } | 266 } |
250 | 267 |
251 } // namespace net | 268 } // namespace net |
OLD | NEW |