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/spdy/core/spdy_header_block.h" | 5 #include "net/spdy/core/spdy_header_block.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "net/base/arena.h" | 15 #include "net/base/arena.h" |
16 #include "net/http/http_log_util.h" | 16 #include "net/http/http_log_util.h" |
17 #include "net/log/net_log_capture_mode.h" | 17 #include "net/log/net_log_capture_mode.h" |
18 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h" | 18 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h" |
| 19 #include "net/spdy/platform/api/spdy_ptr_util.h" |
19 #include "net/spdy/platform/api/spdy_string_utils.h" | 20 #include "net/spdy/platform/api/spdy_string_utils.h" |
20 | 21 |
21 namespace net { | 22 namespace net { |
22 namespace { | 23 namespace { |
23 | 24 |
24 // By default, linked_hash_map's internal map allocates space for 100 map | 25 // By default, linked_hash_map's internal map allocates space for 100 map |
25 // buckets on construction, which is larger than necessary. Standard library | 26 // buckets on construction, which is larger than necessary. Standard library |
26 // unordered map implementations use a list of prime numbers to set the bucket | 27 // unordered map implementations use a list of prime numbers to set the bucket |
27 // count for a particular capacity. |kInitialMapBuckets| is chosen to reduce | 28 // count for a particular capacity. |kInitialMapBuckets| is chosen to reduce |
28 // memory usage for small header blocks, at the cost of having to rehash for | 29 // memory usage for small header blocks, at the cost of having to rehash for |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 | 315 |
315 void SpdyHeaderBlock::AppendHeader(const SpdyStringPiece key, | 316 void SpdyHeaderBlock::AppendHeader(const SpdyStringPiece key, |
316 const SpdyStringPiece value) { | 317 const SpdyStringPiece value) { |
317 auto* storage = GetStorage(); | 318 auto* storage = GetStorage(); |
318 auto backed_key = storage->Write(key); | 319 auto backed_key = storage->Write(key); |
319 block_.emplace(std::make_pair( | 320 block_.emplace(std::make_pair( |
320 backed_key, HeaderValue(storage, backed_key, storage->Write(value)))); | 321 backed_key, HeaderValue(storage, backed_key, storage->Write(value)))); |
321 } | 322 } |
322 | 323 |
323 SpdyHeaderBlock::Storage* SpdyHeaderBlock::GetStorage() { | 324 SpdyHeaderBlock::Storage* SpdyHeaderBlock::GetStorage() { |
324 if (!storage_) { | 325 if (storage_ == nullptr) { |
325 storage_.reset(new Storage); | 326 storage_ = SpdyMakeUnique<Storage>(); |
326 } | 327 } |
327 return storage_.get(); | 328 return storage_.get(); |
328 } | 329 } |
329 | 330 |
330 std::unique_ptr<base::Value> SpdyHeaderBlockNetLogCallback( | 331 std::unique_ptr<base::Value> SpdyHeaderBlockNetLogCallback( |
331 const SpdyHeaderBlock* headers, | 332 const SpdyHeaderBlock* headers, |
332 NetLogCaptureMode capture_mode) { | 333 NetLogCaptureMode capture_mode) { |
333 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 334 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
334 base::DictionaryValue* headers_dict = new base::DictionaryValue(); | 335 base::DictionaryValue* headers_dict = new base::DictionaryValue(); |
335 for (SpdyHeaderBlock::const_iterator it = headers->begin(); | 336 for (SpdyHeaderBlock::const_iterator it = headers->begin(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 for (++it; it != fragments.end(); ++it) { | 391 for (++it; it != fragments.end(); ++it) { |
391 memcpy(dst, separator.data(), separator.size()); | 392 memcpy(dst, separator.data(), separator.size()); |
392 dst += separator.size(); | 393 dst += separator.size(); |
393 memcpy(dst, it->data(), it->size()); | 394 memcpy(dst, it->data(), it->size()); |
394 dst += it->size(); | 395 dst += it->size(); |
395 } | 396 } |
396 return dst - original_dst; | 397 return dst - original_dst; |
397 } | 398 } |
398 | 399 |
399 } // namespace net | 400 } // namespace net |
OLD | NEW |