| 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 |
| 11 #include "base/base_export.h" | 11 #include "base/base_export.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/strings/string_piece.h" |
| 14 | 15 |
| 15 namespace base { | 16 namespace base { |
| 16 | 17 |
| 17 // A generic interface to memory. This object is reference counted because one | 18 // A generic interface to memory. This object is reference counted because one |
| 18 // of its two subclasses own the data they carry, and we need to have | 19 // of its two subclasses own the data they carry, and we need to have |
| 19 // heterogeneous containers of these two types of memory. | 20 // heterogeneous containers of these two types of memory. |
| 20 class BASE_EXPORT RefCountedMemory | 21 class BASE_EXPORT RefCountedMemory |
| 21 : public base::RefCountedThreadSafe<RefCountedMemory> { | 22 : public base::RefCountedThreadSafe<RefCountedMemory> { |
| 22 public: | 23 public: |
| 24 // Returns a StringPiece representing this memory, or an empty StringPiece |
| 25 // if |memory| is NULL. |
| 26 static base::StringPiece AsString(const RefCountedMemory* memory); |
| 27 |
| 23 // Retrieves a pointer to the beginning of the data we point to. If the data | 28 // Retrieves a pointer to the beginning of the data we point to. If the data |
| 24 // is empty, this will return NULL. | 29 // is empty, this will return NULL. |
| 25 virtual const unsigned char* front() const = 0; | 30 virtual const unsigned char* front() const = 0; |
| 26 | 31 |
| 27 // Size of the memory pointed to. | 32 // Size of the memory pointed to. |
| 28 virtual size_t size() const = 0; | 33 virtual size_t size() const = 0; |
| 29 | 34 |
| 30 // Returns true if |other| is byte for byte equal. | 35 // Returns true if |other| is byte for byte equal. |
| 31 bool Equals(const scoped_refptr<RefCountedMemory>& other) const; | 36 bool Equals(const scoped_refptr<RefCountedMemory>& other) const; |
| 32 | 37 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 134 |
| 130 unsigned char* data_; | 135 unsigned char* data_; |
| 131 size_t length_; | 136 size_t length_; |
| 132 | 137 |
| 133 DISALLOW_COPY_AND_ASSIGN(RefCountedMallocedMemory); | 138 DISALLOW_COPY_AND_ASSIGN(RefCountedMallocedMemory); |
| 134 }; | 139 }; |
| 135 | 140 |
| 136 } // namespace base | 141 } // namespace base |
| 137 | 142 |
| 138 #endif // BASE_MEMORY_REF_COUNTED_MEMORY_H_ | 143 #endif // BASE_MEMORY_REF_COUNTED_MEMORY_H_ |
| OLD | NEW |