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

Side by Side Diff: base/pickle.h

Issue 1659003003: IPC::Message -> base::Pickle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix missing comment Created 4 years, 10 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 | « no previous file | base/pickle.cc » ('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 BASE_PICKLE_H_ 5 #ifndef BASE_PICKLE_H_
6 #define BASE_PICKLE_H_ 6 #define BASE_PICKLE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <string> 11 #include <string>
12 12
13 #include "base/base_export.h" 13 #include "base/base_export.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/memory/ref_counted.h"
17 #include "base/strings/string16.h" 18 #include "base/strings/string16.h"
18 #include "base/strings/string_piece.h" 19 #include "base/strings/string_piece.h"
19 20
20 namespace base { 21 namespace base {
21 22
22 class Pickle; 23 class Pickle;
23 24
24 // PickleIterator reads data from a Pickle. The Pickle object must remain valid 25 // PickleIterator reads data from a Pickle. The Pickle object must remain valid
25 // while the PickleIterator object is in use. 26 // while the PickleIterator object is in use.
26 class BASE_EXPORT PickleIterator { 27 class BASE_EXPORT PickleIterator {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // what value types to read and in what order to read them as the Pickle does 117 // what value types to read and in what order to read them as the Pickle does
117 // not keep track of the type of data written to it. 118 // not keep track of the type of data written to it.
118 // 119 //
119 // The Pickle's data has a header which contains the size of the Pickle's 120 // The Pickle's data has a header which contains the size of the Pickle's
120 // payload. It can optionally support additional space in the header. That 121 // payload. It can optionally support additional space in the header. That
121 // space is controlled by the header_size parameter passed to the Pickle 122 // space is controlled by the header_size parameter passed to the Pickle
122 // constructor. 123 // constructor.
123 // 124 //
124 class BASE_EXPORT Pickle { 125 class BASE_EXPORT Pickle {
125 public: 126 public:
127 // A base attachment type for a Pickle subclass to implement if it supports
128 // reading and writing attachments.
129 class BASE_EXPORT Attachment : public RefCountedThreadSafe<Attachment> {
130 public:
131 Attachment();
132
133 protected:
134 friend class RefCountedThreadSafe<Attachment>;
135 virtual ~Attachment();
136
137 DISALLOW_COPY_AND_ASSIGN(Attachment);
138 };
139
126 // Initialize a Pickle object using the default header size. 140 // Initialize a Pickle object using the default header size.
127 Pickle(); 141 Pickle();
128 142
129 // Initialize a Pickle object with the specified header size in bytes, which 143 // Initialize a Pickle object with the specified header size in bytes, which
130 // must be greater-than-or-equal-to sizeof(Pickle::Header). The header size 144 // must be greater-than-or-equal-to sizeof(Pickle::Header). The header size
131 // will be rounded up to ensure that the header size is 32bit-aligned. 145 // will be rounded up to ensure that the header size is 32bit-aligned.
132 explicit Pickle(int header_size); 146 explicit Pickle(int header_size);
133 147
134 // Initializes a Pickle from a const block of data. The data is not copied; 148 // Initializes a Pickle from a const block of data. The data is not copied;
135 // instead the data is merely referenced by this Pickle. Only const methods 149 // instead the data is merely referenced by this Pickle. Only const methods
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 bool WriteString(const StringPiece& value); 213 bool WriteString(const StringPiece& value);
200 bool WriteString16(const StringPiece16& value); 214 bool WriteString16(const StringPiece16& value);
201 // "Data" is a blob with a length. When you read it out you will be given the 215 // "Data" is a blob with a length. When you read it out you will be given the
202 // length. See also WriteBytes. 216 // length. See also WriteBytes.
203 bool WriteData(const char* data, int length); 217 bool WriteData(const char* data, int length);
204 // "Bytes" is a blob with no length. The caller must specify the length both 218 // "Bytes" is a blob with no length. The caller must specify the length both
205 // when reading and writing. It is normally used to serialize PoD types of a 219 // when reading and writing. It is normally used to serialize PoD types of a
206 // known size. See also WriteData. 220 // known size. See also WriteData.
207 bool WriteBytes(const void* data, int length); 221 bool WriteBytes(const void* data, int length);
208 222
223 // WriteAttachment appends |attachment| to the pickle. It returns
224 // false iff the set is full.
225 //
226 // NOTE: It is NOT OK to call this or ReadAttachment() on a simple
Tom Sepez 2016/02/02 19:25:55 It feels wrong to design a virtual API that requir
227 // base::Pickle. These must be implemented and called only on subclasses that
228 // support attachments.
229 virtual bool WriteAttachment(scoped_refptr<Attachment> attachment);
230
231 // ReadAttachment parses an attachment given the parsing state |iter| and
232 // writes it to |*attachment|. It returns true on success.
233 //
234 // NOTE: It is NOT OK to call this or WriteAttachment() on a simple
235 // base::Pickle. These must be implemented and called only subclasses that
236 // support attachments.
237 virtual bool ReadAttachment(base::PickleIterator* iter,
238 scoped_refptr<Attachment>* attachment) const;
239
209 // Reserves space for upcoming writes when multiple writes will be made and 240 // Reserves space for upcoming writes when multiple writes will be made and
210 // their sizes are computed in advance. It can be significantly faster to call 241 // their sizes are computed in advance. It can be significantly faster to call
211 // Reserve() before calling WriteFoo() multiple times. 242 // Reserve() before calling WriteFoo() multiple times.
212 void Reserve(size_t additional_capacity); 243 void Reserve(size_t additional_capacity);
213 244
214 // Payload follows after allocation of Header (header size is customizable). 245 // Payload follows after allocation of Header (header size is customizable).
215 struct Header { 246 struct Header {
216 uint32_t payload_size; // Specifies the size of the payload. 247 uint32_t payload_size; // Specifies the size of the payload.
217 }; 248 };
218 249
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNext); 347 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNext);
317 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNextOverflow); 348 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNextOverflow);
318 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); 349 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext);
319 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); 350 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader);
320 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow); 351 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow);
321 }; 352 };
322 353
323 } // namespace base 354 } // namespace base
324 355
325 #endif // BASE_PICKLE_H_ 356 #endif // BASE_PICKLE_H_
OLDNEW
« no previous file with comments | « no previous file | base/pickle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698