| 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 #ifndef BASE_MEMORY_REF_COUNTED_MEMORY_H_ | 5 #ifndef BASE_MEMORY_REF_COUNTED_MEMORY_H_ |
| 6 #define BASE_MEMORY_REF_COUNTED_MEMORY_H_ | 6 #define BASE_MEMORY_REF_COUNTED_MEMORY_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // Retrieves a pointer to the beginning of the data we point to. If the data | 23 // Retrieves a pointer to the beginning of the data we point to. If the data |
| 24 // is empty, this will return NULL. | 24 // is empty, this will return NULL. |
| 25 virtual const unsigned char* front() const = 0; | 25 virtual const unsigned char* front() const = 0; |
| 26 | 26 |
| 27 // Size of the memory pointed to. | 27 // Size of the memory pointed to. |
| 28 virtual size_t size() const = 0; | 28 virtual size_t size() const = 0; |
| 29 | 29 |
| 30 // Returns true if |other| is byte for byte equal. | 30 // Returns true if |other| is byte for byte equal. |
| 31 bool Equals(const scoped_refptr<RefCountedMemory>& other) const; | 31 bool Equals(const scoped_refptr<RefCountedMemory>& other) const; |
| 32 | 32 |
| 33 // Handy method to simplify calling front() with a reinterpret_cast. |
| 34 template<typename T> const T* front_as() const { |
| 35 return reinterpret_cast<const T*>(front()); |
| 36 } |
| 37 |
| 33 protected: | 38 protected: |
| 34 friend class base::RefCountedThreadSafe<RefCountedMemory>; | 39 friend class base::RefCountedThreadSafe<RefCountedMemory>; |
| 35 RefCountedMemory(); | 40 RefCountedMemory(); |
| 36 virtual ~RefCountedMemory(); | 41 virtual ~RefCountedMemory(); |
| 37 }; | 42 }; |
| 38 | 43 |
| 39 // An implementation of RefCountedMemory, where the ref counting does not | 44 // An implementation of RefCountedMemory, where the ref counting does not |
| 40 // matter. | 45 // matter. |
| 41 class BASE_EXPORT RefCountedStaticMemory : public RefCountedMemory { | 46 class BASE_EXPORT RefCountedStaticMemory : public RefCountedMemory { |
| 42 public: | 47 public: |
| 43 RefCountedStaticMemory() | 48 RefCountedStaticMemory() |
| 44 : data_(NULL), length_(0) {} | 49 : data_(NULL), length_(0) {} |
| 45 RefCountedStaticMemory(const unsigned char* data, size_t length) | 50 RefCountedStaticMemory(const void* data, size_t length) |
| 46 : data_(length ? data : NULL), length_(length) {} | 51 : data_(static_cast<const unsigned char*>(length ? data : NULL)), |
| 52 length_(length) {} |
| 47 | 53 |
| 48 // Overridden from RefCountedMemory: | 54 // Overridden from RefCountedMemory: |
| 49 virtual const unsigned char* front() const OVERRIDE; | 55 virtual const unsigned char* front() const OVERRIDE; |
| 50 virtual size_t size() const OVERRIDE; | 56 virtual size_t size() const OVERRIDE; |
| 51 | 57 |
| 52 private: | 58 private: |
| 53 virtual ~RefCountedStaticMemory(); | 59 virtual ~RefCountedStaticMemory(); |
| 54 | 60 |
| 55 const unsigned char* data_; | 61 const unsigned char* data_; |
| 56 size_t length_; | 62 size_t length_; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 135 |
| 130 unsigned char* data_; | 136 unsigned char* data_; |
| 131 size_t length_; | 137 size_t length_; |
| 132 | 138 |
| 133 DISALLOW_COPY_AND_ASSIGN(RefCountedMallocedMemory); | 139 DISALLOW_COPY_AND_ASSIGN(RefCountedMallocedMemory); |
| 134 }; | 140 }; |
| 135 | 141 |
| 136 } // namespace base | 142 } // namespace base |
| 137 | 143 |
| 138 #endif // BASE_MEMORY_REF_COUNTED_MEMORY_H_ | 144 #endif // BASE_MEMORY_REF_COUNTED_MEMORY_H_ |
| OLD | NEW |