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

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: export base::Pickle::Attachment 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 //
jam 2016/02/02 18:00:45 nit: add comment
128 class BASE_EXPORT Attachment : public RefCountedThreadSafe<Attachment> {
129 public:
130 Attachment();
131
132 protected:
133 friend class RefCountedThreadSafe<Attachment>;
134 virtual ~Attachment();
135
136 DISALLOW_COPY_AND_ASSIGN(Attachment);
137 };
138
126 // Initialize a Pickle object using the default header size. 139 // Initialize a Pickle object using the default header size.
127 Pickle(); 140 Pickle();
128 141
129 // Initialize a Pickle object with the specified header size in bytes, which 142 // 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 143 // 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. 144 // will be rounded up to ensure that the header size is 32bit-aligned.
132 explicit Pickle(int header_size); 145 explicit Pickle(int header_size);
133 146
134 // Initializes a Pickle from a const block of data. The data is not copied; 147 // 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 148 // 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); 212 bool WriteString(const StringPiece& value);
200 bool WriteString16(const StringPiece16& value); 213 bool WriteString16(const StringPiece16& value);
201 // "Data" is a blob with a length. When you read it out you will be given the 214 // "Data" is a blob with a length. When you read it out you will be given the
202 // length. See also WriteBytes. 215 // length. See also WriteBytes.
203 bool WriteData(const char* data, int length); 216 bool WriteData(const char* data, int length);
204 // "Bytes" is a blob with no length. The caller must specify the length both 217 // "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 218 // when reading and writing. It is normally used to serialize PoD types of a
206 // known size. See also WriteData. 219 // known size. See also WriteData.
207 bool WriteBytes(const void* data, int length); 220 bool WriteBytes(const void* data, int length);
208 221
222 // WriteAttachment appends |attachment| to the pickle. It returns
223 // false iff the set is full.
224 //
225 // NOTE: It is NOT OK to call this or ReadAttachment() on a simple
226 // base::Pickle. These must be implemented and called only on subclasses that
227 // support attachments.
228 virtual bool WriteAttachment(scoped_refptr<Attachment> attachment);
229
230 // ReadAttachment parses an attachment given the parsing state |iter| and
231 // writes it to |*attachment|. It returns true on success.
232 //
233 // NOTE: It is NOT OK to call this or WriteAttachment() on a simple
234 // base::Pickle. These must be implemented and called only subclasses that
235 // support attachments.
236 virtual bool ReadAttachment(base::PickleIterator* iter,
237 scoped_refptr<Attachment>* attachment) const;
238
209 // Reserves space for upcoming writes when multiple writes will be made and 239 // 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 240 // their sizes are computed in advance. It can be significantly faster to call
211 // Reserve() before calling WriteFoo() multiple times. 241 // Reserve() before calling WriteFoo() multiple times.
212 void Reserve(size_t additional_capacity); 242 void Reserve(size_t additional_capacity);
213 243
214 // Payload follows after allocation of Header (header size is customizable). 244 // Payload follows after allocation of Header (header size is customizable).
215 struct Header { 245 struct Header {
216 uint32_t payload_size; // Specifies the size of the payload. 246 uint32_t payload_size; // Specifies the size of the payload.
217 }; 247 };
218 248
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNext); 346 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNext);
317 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNextOverflow); 347 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNextOverflow);
318 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); 348 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext);
319 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); 349 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader);
320 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow); 350 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow);
321 }; 351 };
322 352
323 } // namespace base 353 } // namespace base
324 354
325 #endif // BASE_PICKLE_H_ 355 #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