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

Side by Side Diff: net/spdy/core/spdy_header_block.h

Issue 2839373002: Implement SPDY_EXPORT and SPDY_EXPORT_PRIVATE macros. (Closed)
Patch Set: Rebase: manually resolve trivial merge conflicts. Created 3 years, 7 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
« no previous file with comments | « net/spdy/core/spdy_framer.h ('k') | net/spdy/core/spdy_header_indexing.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef NET_SPDY_CORE_SPDY_HEADER_BLOCK_H_ 5 #ifndef NET_SPDY_CORE_SPDY_HEADER_BLOCK_H_
6 #define NET_SPDY_CORE_SPDY_HEADER_BLOCK_H_ 6 #define NET_SPDY_CORE_SPDY_HEADER_BLOCK_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <list> 10 #include <list>
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 #include <utility> 13 #include <utility>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "net/base/linked_hash_map.h" 17 #include "net/base/linked_hash_map.h"
18 #include "net/base/net_export.h"
19 #include "net/log/net_log.h" 18 #include "net/log/net_log.h"
19 #include "net/spdy/platform/api/spdy_export.h"
20 #include "net/spdy/platform/api/spdy_string.h" 20 #include "net/spdy/platform/api/spdy_string.h"
21 #include "net/spdy/platform/api/spdy_string_piece.h" 21 #include "net/spdy/platform/api/spdy_string_piece.h"
22 22
23 namespace base { 23 namespace base {
24 class Value; 24 class Value;
25 } 25 }
26 26
27 namespace net { 27 namespace net {
28 28
29 class NetLogCaptureMode; 29 class NetLogCaptureMode;
30 30
31 namespace test { 31 namespace test {
32 class SpdyHeaderBlockPeer; 32 class SpdyHeaderBlockPeer;
33 class ValueProxyPeer; 33 class ValueProxyPeer;
34 } 34 }
35 35
36 // This class provides a key-value map that can be used to store SPDY header 36 // This class provides a key-value map that can be used to store SPDY header
37 // names and values. This data structure preserves insertion order. 37 // names and values. This data structure preserves insertion order.
38 // 38 //
39 // Under the hood, this data structure uses large, contiguous blocks of memory 39 // Under the hood, this data structure uses large, contiguous blocks of memory
40 // to store names and values. Lookups may be performed with SpdyStringPiece 40 // to store names and values. Lookups may be performed with SpdyStringPiece
41 // keys, and values are returned as SpdyStringPieces (via ValueProxy, below). 41 // keys, and values are returned as SpdyStringPieces (via ValueProxy, below).
42 // Value SpdyStringPieces are valid as long as the SpdyHeaderBlock exists; 42 // Value SpdyStringPieces are valid as long as the SpdyHeaderBlock exists;
43 // allocated memory is never freed until SpdyHeaderBlock's destruction. 43 // allocated memory is never freed until SpdyHeaderBlock's destruction.
44 // 44 //
45 // This implementation does not make much of an effort to minimize wasted space. 45 // This implementation does not make much of an effort to minimize wasted space.
46 // It's expected that keys are rarely deleted from a SpdyHeaderBlock. 46 // It's expected that keys are rarely deleted from a SpdyHeaderBlock.
47 class NET_EXPORT SpdyHeaderBlock { 47 class SPDY_EXPORT_PRIVATE SpdyHeaderBlock {
48 private: 48 private:
49 class Storage; 49 class Storage;
50 50
51 // Stores a list of value fragments that can be joined later with a 51 // Stores a list of value fragments that can be joined later with a
52 // key-dependent separator. 52 // key-dependent separator.
53 class NET_EXPORT HeaderValue { 53 class SPDY_EXPORT_PRIVATE HeaderValue {
54 public: 54 public:
55 HeaderValue(Storage* storage, 55 HeaderValue(Storage* storage,
56 SpdyStringPiece key, 56 SpdyStringPiece key,
57 SpdyStringPiece initial_value); 57 SpdyStringPiece initial_value);
58 58
59 // Moves are allowed. 59 // Moves are allowed.
60 HeaderValue(HeaderValue&& other); 60 HeaderValue(HeaderValue&& other);
61 HeaderValue& operator=(HeaderValue&& other); 61 HeaderValue& operator=(HeaderValue&& other);
62 62
63 // Copies are not. 63 // Copies are not.
(...skipping 22 matching lines...) Expand all
86 typedef linked_hash_map<SpdyStringPiece, HeaderValue, base::StringPieceHash> 86 typedef linked_hash_map<SpdyStringPiece, HeaderValue, base::StringPieceHash>
87 MapType; 87 MapType;
88 88
89 public: 89 public:
90 typedef std::pair<SpdyStringPiece, SpdyStringPiece> value_type; 90 typedef std::pair<SpdyStringPiece, SpdyStringPiece> value_type;
91 91
92 // Provides iteration over a sequence of std::pair<SpdyStringPiece, 92 // Provides iteration over a sequence of std::pair<SpdyStringPiece,
93 // SpdyStringPiece>, even though the underlying MapType::value_type is 93 // SpdyStringPiece>, even though the underlying MapType::value_type is
94 // different. Dereferencing the iterator will result in memory allocation for 94 // different. Dereferencing the iterator will result in memory allocation for
95 // multi-value headers. 95 // multi-value headers.
96 class NET_EXPORT iterator { 96 class SPDY_EXPORT_PRIVATE iterator {
97 public: 97 public:
98 // The following type definitions fulfill the requirements for iterator 98 // The following type definitions fulfill the requirements for iterator
99 // implementations. 99 // implementations.
100 typedef std::pair<SpdyStringPiece, SpdyStringPiece> value_type; 100 typedef std::pair<SpdyStringPiece, SpdyStringPiece> value_type;
101 typedef value_type& reference; 101 typedef value_type& reference;
102 typedef value_type* pointer; 102 typedef value_type* pointer;
103 typedef std::forward_iterator_tag iterator_category; 103 typedef std::forward_iterator_tag iterator_category;
104 typedef MapType::iterator::difference_type difference_type; 104 typedef MapType::iterator::difference_type difference_type;
105 105
106 // In practice, this iterator only offers access to const value_type. 106 // In practice, this iterator only offers access to const value_type.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // If there is no such key, a new header with the key and value is added. 180 // If there is no such key, a new header with the key and value is added.
181 void AppendValueOrAddHeader(const SpdyStringPiece key, 181 void AppendValueOrAddHeader(const SpdyStringPiece key,
182 const SpdyStringPiece value); 182 const SpdyStringPiece value);
183 183
184 // Allows either lookup or mutation of the value associated with a key. 184 // Allows either lookup or mutation of the value associated with a key.
185 ValueProxy operator[](const SpdyStringPiece key); 185 ValueProxy operator[](const SpdyStringPiece key);
186 186
187 // This object provides automatic conversions that allow SpdyHeaderBlock to be 187 // This object provides automatic conversions that allow SpdyHeaderBlock to be
188 // nearly a drop-in replacement for linked_hash_map<SpdyString, SpdyString>. 188 // nearly a drop-in replacement for linked_hash_map<SpdyString, SpdyString>.
189 // It reads data from or writes data to a SpdyHeaderBlock::Storage. 189 // It reads data from or writes data to a SpdyHeaderBlock::Storage.
190 class NET_EXPORT ValueProxy { 190 class SPDY_EXPORT_PRIVATE ValueProxy {
191 public: 191 public:
192 ~ValueProxy(); 192 ~ValueProxy();
193 193
194 // Moves are allowed. 194 // Moves are allowed.
195 ValueProxy(ValueProxy&& other); 195 ValueProxy(ValueProxy&& other);
196 ValueProxy& operator=(ValueProxy&& other); 196 ValueProxy& operator=(ValueProxy&& other);
197 197
198 // Copies are not. 198 // Copies are not.
199 ValueProxy(const ValueProxy& other) = delete; 199 ValueProxy(const ValueProxy& other) = delete;
200 ValueProxy& operator=(const ValueProxy& other) = delete; 200 ValueProxy& operator=(const ValueProxy& other) = delete;
(...skipping 30 matching lines...) Expand all
231 size_t bytes_allocated() const; 231 size_t bytes_allocated() const;
232 232
233 // SpdyStringPieces held by |block_| point to memory owned by |*storage_|. 233 // SpdyStringPieces held by |block_| point to memory owned by |*storage_|.
234 // |storage_| might be nullptr as long as |block_| is empty. 234 // |storage_| might be nullptr as long as |block_| is empty.
235 MapType block_; 235 MapType block_;
236 std::unique_ptr<Storage> storage_; 236 std::unique_ptr<Storage> storage_;
237 }; 237 };
238 238
239 // Writes |fragments| to |dst|, joined by |separator|. |dst| must be large 239 // Writes |fragments| to |dst|, joined by |separator|. |dst| must be large
240 // enough to hold the result. Returns the number of bytes written. 240 // enough to hold the result. Returns the number of bytes written.
241 NET_EXPORT size_t Join(char* dst, 241 SPDY_EXPORT_PRIVATE size_t Join(char* dst,
242 const std::vector<SpdyStringPiece>& fragments, 242 const std::vector<SpdyStringPiece>& fragments,
243 SpdyStringPiece separator); 243 SpdyStringPiece separator);
244 244
245 // Converts a SpdyHeaderBlock into NetLog event parameters. 245 // Converts a SpdyHeaderBlock into NetLog event parameters.
246 NET_EXPORT std::unique_ptr<base::Value> SpdyHeaderBlockNetLogCallback( 246 SPDY_EXPORT_PRIVATE std::unique_ptr<base::Value> SpdyHeaderBlockNetLogCallback(
247 const SpdyHeaderBlock* headers, 247 const SpdyHeaderBlock* headers,
248 NetLogCaptureMode capture_mode); 248 NetLogCaptureMode capture_mode);
249 249
250 // Converts NetLog event parameters into a SPDY header block and writes them 250 // Converts NetLog event parameters into a SPDY header block and writes them
251 // to |headers|. |event_param| must have been created by 251 // to |headers|. |event_param| must have been created by
252 // SpdyHeaderBlockNetLogCallback. On failure, returns false and clears 252 // SpdyHeaderBlockNetLogCallback. On failure, returns false and clears
253 // |headers|. 253 // |headers|.
254 NET_EXPORT bool SpdyHeaderBlockFromNetLogParam( 254 SPDY_EXPORT_PRIVATE bool SpdyHeaderBlockFromNetLogParam(
255 const base::Value* event_param, 255 const base::Value* event_param,
256 SpdyHeaderBlock* headers); 256 SpdyHeaderBlock* headers);
257 257
258 } // namespace net 258 } // namespace net
259 259
260 #endif // NET_SPDY_CORE_SPDY_HEADER_BLOCK_H_ 260 #endif // NET_SPDY_CORE_SPDY_HEADER_BLOCK_H_
OLDNEW
« no previous file with comments | « net/spdy/core/spdy_framer.h ('k') | net/spdy/core/spdy_header_indexing.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698