OLD | NEW |
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 #include "base/pickle.h" | 5 #include "base/pickle.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 | 8 |
9 #include <algorithm> // for max() | 9 #include <algorithm> // for max() |
10 #include <limits> | 10 #include <limits> |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 } | 201 } |
202 | 202 |
203 bool PickleIterator::ReadBytes(const char** data, int length) { | 203 bool PickleIterator::ReadBytes(const char** data, int length) { |
204 const char* read_from = GetReadPointerAndAdvance(length); | 204 const char* read_from = GetReadPointerAndAdvance(length); |
205 if (!read_from) | 205 if (!read_from) |
206 return false; | 206 return false; |
207 *data = read_from; | 207 *data = read_from; |
208 return true; | 208 return true; |
209 } | 209 } |
210 | 210 |
| 211 Pickle::Attachment::Attachment() {} |
| 212 |
| 213 Pickle::Attachment::~Attachment() {} |
| 214 |
211 // Payload is uint32_t aligned. | 215 // Payload is uint32_t aligned. |
212 | 216 |
213 Pickle::Pickle() | 217 Pickle::Pickle() |
214 : header_(NULL), | 218 : header_(NULL), |
215 header_size_(sizeof(Header)), | 219 header_size_(sizeof(Header)), |
216 capacity_after_header_(0), | 220 capacity_after_header_(0), |
217 write_offset_(0) { | 221 write_offset_(0) { |
218 static_assert((Pickle::kPayloadUnit & (Pickle::kPayloadUnit - 1)) == 0, | 222 static_assert((Pickle::kPayloadUnit & (Pickle::kPayloadUnit - 1)) == 0, |
219 "Pickle::kPayloadUnit must be a power of two"); | 223 "Pickle::kPayloadUnit must be a power of two"); |
220 Resize(kPayloadUnit); | 224 Resize(kPayloadUnit); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 DCHECK_GE(data_len, length); | 319 DCHECK_GE(data_len, length); |
316 #ifdef ARCH_CPU_64_BITS | 320 #ifdef ARCH_CPU_64_BITS |
317 DCHECK_LE(data_len, std::numeric_limits<uint32_t>::max()); | 321 DCHECK_LE(data_len, std::numeric_limits<uint32_t>::max()); |
318 #endif | 322 #endif |
319 DCHECK_LE(write_offset_, std::numeric_limits<uint32_t>::max() - data_len); | 323 DCHECK_LE(write_offset_, std::numeric_limits<uint32_t>::max() - data_len); |
320 size_t new_size = write_offset_ + data_len; | 324 size_t new_size = write_offset_ + data_len; |
321 if (new_size > capacity_after_header_) | 325 if (new_size > capacity_after_header_) |
322 Resize(capacity_after_header_ * 2 + new_size); | 326 Resize(capacity_after_header_ * 2 + new_size); |
323 } | 327 } |
324 | 328 |
| 329 bool Pickle::WriteAttachment(scoped_refptr<Attachment> attachment) { |
| 330 return false; |
| 331 } |
| 332 |
| 333 bool Pickle::ReadAttachment(base::PickleIterator* iter, |
| 334 scoped_refptr<Attachment>* attachment) const { |
| 335 return false; |
| 336 } |
| 337 |
| 338 bool Pickle::HasAttachments() const { |
| 339 return false; |
| 340 } |
| 341 |
325 void Pickle::Resize(size_t new_capacity) { | 342 void Pickle::Resize(size_t new_capacity) { |
326 CHECK_NE(capacity_after_header_, kCapacityReadOnly); | 343 CHECK_NE(capacity_after_header_, kCapacityReadOnly); |
327 capacity_after_header_ = bits::Align(new_capacity, kPayloadUnit); | 344 capacity_after_header_ = bits::Align(new_capacity, kPayloadUnit); |
328 void* p = realloc(header_, GetTotalAllocatedSize()); | 345 void* p = realloc(header_, GetTotalAllocatedSize()); |
329 CHECK(p); | 346 CHECK(p); |
330 header_ = reinterpret_cast<Header*>(p); | 347 header_ = reinterpret_cast<Header*>(p); |
331 } | 348 } |
332 | 349 |
333 void* Pickle::ClaimBytes(size_t num_bytes) { | 350 void* Pickle::ClaimBytes(size_t num_bytes) { |
334 void* p = ClaimUninitializedBytesInternal(num_bytes); | 351 void* p = ClaimUninitializedBytesInternal(num_bytes); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 | 436 |
420 inline void Pickle::WriteBytesCommon(const void* data, size_t length) { | 437 inline void Pickle::WriteBytesCommon(const void* data, size_t length) { |
421 DCHECK_NE(kCapacityReadOnly, capacity_after_header_) | 438 DCHECK_NE(kCapacityReadOnly, capacity_after_header_) |
422 << "oops: pickle is readonly"; | 439 << "oops: pickle is readonly"; |
423 MSAN_CHECK_MEM_IS_INITIALIZED(data, length); | 440 MSAN_CHECK_MEM_IS_INITIALIZED(data, length); |
424 void* write = ClaimUninitializedBytesInternal(length); | 441 void* write = ClaimUninitializedBytesInternal(length); |
425 memcpy(write, data, length); | 442 memcpy(write, data, length); |
426 } | 443 } |
427 | 444 |
428 } // namespace base | 445 } // namespace base |
OLD | NEW |