| 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_constants.h" | 5 #include "net/spdy/core/hpack/hpack_constants.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "net/spdy/core/hpack/hpack_huffman_table.h" | 12 #include "net/spdy/core/hpack/hpack_huffman_table.h" |
| 13 #include "net/spdy/core/hpack/hpack_static_table.h" | 13 #include "net/spdy/core/hpack/hpack_static_table.h" |
| 14 #include "net/spdy/platform/api/spdy_ptr_util.h" |
| 14 | 15 |
| 15 namespace net { | 16 namespace net { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 // SharedHpackHuffmanTable is a Singleton wrapping a HpackHuffmanTable | 20 // SharedHpackHuffmanTable is a Singleton wrapping a HpackHuffmanTable |
| 20 // instance initialized with |kHpackHuffmanCode|. | 21 // instance initialized with |kHpackHuffmanCode|. |
| 21 struct SharedHpackHuffmanTable { | 22 struct SharedHpackHuffmanTable { |
| 22 public: | 23 public: |
| 23 SharedHpackHuffmanTable() { | 24 SharedHpackHuffmanTable() { |
| 24 std::vector<HpackHuffmanSymbol> code = HpackHuffmanCode(); | 25 std::vector<HpackHuffmanSymbol> code = HpackHuffmanCode(); |
| 25 std::unique_ptr<HpackHuffmanTable> mutable_table(new HpackHuffmanTable()); | 26 auto mutable_table = SpdyMakeUnique<HpackHuffmanTable>(); |
| 26 CHECK(mutable_table->Initialize(&code[0], code.size())); | 27 CHECK(mutable_table->Initialize(&code[0], code.size())); |
| 27 CHECK(mutable_table->IsInitialized()); | 28 CHECK(mutable_table->IsInitialized()); |
| 28 table = std::move(mutable_table); | 29 table = std::move(mutable_table); |
| 29 } | 30 } |
| 30 | 31 |
| 31 static SharedHpackHuffmanTable* GetInstance() { | 32 static SharedHpackHuffmanTable* GetInstance() { |
| 32 return base::Singleton<SharedHpackHuffmanTable>::get(); | 33 return base::Singleton<SharedHpackHuffmanTable>::get(); |
| 33 } | 34 } |
| 34 | 35 |
| 35 std::unique_ptr<const HpackHuffmanTable> table; | 36 std::unique_ptr<const HpackHuffmanTable> table; |
| 36 }; | 37 }; |
| 37 | 38 |
| 38 // SharedHpackStaticTable is a Singleton wrapping a HpackStaticTable | 39 // SharedHpackStaticTable is a Singleton wrapping a HpackStaticTable |
| 39 // instance initialized with |kHpackStaticTable|. | 40 // instance initialized with |kHpackStaticTable|. |
| 40 struct SharedHpackStaticTable { | 41 struct SharedHpackStaticTable { |
| 41 public: | 42 public: |
| 42 SharedHpackStaticTable() { | 43 SharedHpackStaticTable() { |
| 43 std::vector<HpackStaticEntry> static_table = HpackStaticTableVector(); | 44 std::vector<HpackStaticEntry> static_table = HpackStaticTableVector(); |
| 44 std::unique_ptr<HpackStaticTable> mutable_table(new HpackStaticTable()); | 45 auto mutable_table = SpdyMakeUnique<HpackStaticTable>(); |
| 45 mutable_table->Initialize(&static_table[0], static_table.size()); | 46 mutable_table->Initialize(&static_table[0], static_table.size()); |
| 46 CHECK(mutable_table->IsInitialized()); | 47 CHECK(mutable_table->IsInitialized()); |
| 47 table = std::move(mutable_table); | 48 table = std::move(mutable_table); |
| 48 } | 49 } |
| 49 | 50 |
| 50 static SharedHpackStaticTable* GetInstance() { | 51 static SharedHpackStaticTable* GetInstance() { |
| 51 return base::Singleton<SharedHpackStaticTable>::get(); | 52 return base::Singleton<SharedHpackStaticTable>::get(); |
| 52 } | 53 } |
| 53 | 54 |
| 54 std::unique_ptr<const HpackStaticTable> table; | 55 std::unique_ptr<const HpackStaticTable> table; |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 | 407 |
| 407 const HpackHuffmanTable& ObtainHpackHuffmanTable() { | 408 const HpackHuffmanTable& ObtainHpackHuffmanTable() { |
| 408 return *SharedHpackHuffmanTable::GetInstance()->table; | 409 return *SharedHpackHuffmanTable::GetInstance()->table; |
| 409 } | 410 } |
| 410 | 411 |
| 411 const HpackStaticTable& ObtainHpackStaticTable() { | 412 const HpackStaticTable& ObtainHpackStaticTable() { |
| 412 return *SharedHpackStaticTable::GetInstance()->table; | 413 return *SharedHpackStaticTable::GetInstance()->table; |
| 413 } | 414 } |
| 414 | 415 |
| 415 } // namespace net | 416 } // namespace net |
| OLD | NEW |