| 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/core/hpack/hpack_encoder.h" | 5 #include "net/spdy/core/hpack/hpack_encoder.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "net/spdy/core/hpack/hpack_constants.h" | 12 #include "net/spdy/core/hpack/hpack_constants.h" |
| 13 #include "net/spdy/core/hpack/hpack_header_table.h" | 13 #include "net/spdy/core/hpack/hpack_header_table.h" |
| 14 #include "net/spdy/core/hpack/hpack_huffman_table.h" | 14 #include "net/spdy/core/hpack/hpack_huffman_table.h" |
| 15 #include "net/spdy/core/hpack/hpack_output_stream.h" | 15 #include "net/spdy/core/hpack/hpack_output_stream.h" |
| 16 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h" | 16 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h" |
| 17 #include "net/spdy/platform/api/spdy_ptr_util.h" |
| 17 | 18 |
| 18 namespace net { | 19 namespace net { |
| 19 | 20 |
| 20 class HpackEncoder::RepresentationIterator { | 21 class HpackEncoder::RepresentationIterator { |
| 21 public: | 22 public: |
| 22 // |pseudo_headers| and |regular_headers| must outlive the iterator. | 23 // |pseudo_headers| and |regular_headers| must outlive the iterator. |
| 23 RepresentationIterator(const Representations& pseudo_headers, | 24 RepresentationIterator(const Representations& pseudo_headers, |
| 24 const Representations& regular_headers) | 25 const Representations& regular_headers) |
| 25 : pseudo_begin_(pseudo_headers.begin()), | 26 : pseudo_begin_(pseudo_headers.begin()), |
| 26 pseudo_end_(pseudo_headers.end()), | 27 pseudo_end_(pseudo_headers.end()), |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 CookieToCrumbs(header, ®ular_headers_); | 321 CookieToCrumbs(header, ®ular_headers_); |
| 321 } else if (!header.first.empty() && | 322 } else if (!header.first.empty() && |
| 322 header.first[0] == kPseudoHeaderPrefix) { | 323 header.first[0] == kPseudoHeaderPrefix) { |
| 323 use_compression ? DecomposeRepresentation(header, &pseudo_headers_) | 324 use_compression ? DecomposeRepresentation(header, &pseudo_headers_) |
| 324 : GatherRepresentation(header, &pseudo_headers_); | 325 : GatherRepresentation(header, &pseudo_headers_); |
| 325 } else { | 326 } else { |
| 326 use_compression ? DecomposeRepresentation(header, ®ular_headers_) | 327 use_compression ? DecomposeRepresentation(header, ®ular_headers_) |
| 327 : GatherRepresentation(header, ®ular_headers_); | 328 : GatherRepresentation(header, ®ular_headers_); |
| 328 } | 329 } |
| 329 } | 330 } |
| 330 header_it_ = base::MakeUnique<RepresentationIterator>(pseudo_headers_, | 331 header_it_ = |
| 331 regular_headers_); | 332 SpdyMakeUnique<RepresentationIterator>(pseudo_headers_, regular_headers_); |
| 332 | 333 |
| 333 encoder_->MaybeEmitTableSize(); | 334 encoder_->MaybeEmitTableSize(); |
| 334 } | 335 } |
| 335 | 336 |
| 336 void HpackEncoder::Encoderator::Next(size_t max_encoded_bytes, | 337 void HpackEncoder::Encoderator::Next(size_t max_encoded_bytes, |
| 337 SpdyString* output) { | 338 SpdyString* output) { |
| 338 SPDY_BUG_IF(!has_next_) | 339 SPDY_BUG_IF(!has_next_) |
| 339 << "Encoderator::Next called with nothing left to encode."; | 340 << "Encoderator::Next called with nothing left to encode."; |
| 340 const bool use_compression = encoder_->enable_compression_; | 341 const bool use_compression = encoder_->enable_compression_; |
| 341 | 342 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 358 encoder_->EmitNonIndexedLiteral(header); | 359 encoder_->EmitNonIndexedLiteral(header); |
| 359 } | 360 } |
| 360 } | 361 } |
| 361 | 362 |
| 362 has_next_ = encoder_->output_stream_.size() > max_encoded_bytes; | 363 has_next_ = encoder_->output_stream_.size() > max_encoded_bytes; |
| 363 encoder_->output_stream_.BoundedTakeString(max_encoded_bytes, output); | 364 encoder_->output_stream_.BoundedTakeString(max_encoded_bytes, output); |
| 364 } | 365 } |
| 365 | 366 |
| 366 std::unique_ptr<HpackEncoder::ProgressiveEncoder> HpackEncoder::EncodeHeaderSet( | 367 std::unique_ptr<HpackEncoder::ProgressiveEncoder> HpackEncoder::EncodeHeaderSet( |
| 367 const SpdyHeaderBlock& header_set) { | 368 const SpdyHeaderBlock& header_set) { |
| 368 return base::MakeUnique<Encoderator>(header_set, this); | 369 return SpdyMakeUnique<Encoderator>(header_set, this); |
| 369 } | 370 } |
| 370 | 371 |
| 371 } // namespace net | 372 } // namespace net |
| OLD | NEW |