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 | 14 |
15 namespace base { | 15 namespace base { |
16 | 16 |
17 // A generic interface to memory. This object is reference counted because one | 17 // 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 | 18 // of its two subclasses own the data they carry, and we need to have |
19 // heterogeneous containers of these two types of memory. | 19 // heterogeneous containers of these two types of memory. |
20 class BASE_EXPORT RefCountedMemory | 20 class BASE_EXPORT RefCountedMemory |
21 : public base::RefCountedThreadSafe<RefCountedMemory> { | 21 : public base::RefCountedThreadSafe<RefCountedMemory> { |
22 public: | 22 public: |
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. |
| 31 bool Equals(const scoped_refptr<RefCountedMemory>& other) const; |
| 32 |
30 protected: | 33 protected: |
31 friend class base::RefCountedThreadSafe<RefCountedMemory>; | 34 friend class base::RefCountedThreadSafe<RefCountedMemory>; |
32 RefCountedMemory(); | 35 RefCountedMemory(); |
33 virtual ~RefCountedMemory(); | 36 virtual ~RefCountedMemory(); |
34 }; | 37 }; |
35 | 38 |
36 // An implementation of RefCountedMemory, where the ref counting does not | 39 // An implementation of RefCountedMemory, where the ref counting does not |
37 // matter. | 40 // matter. |
38 class BASE_EXPORT RefCountedStaticMemory : public RefCountedMemory { | 41 class BASE_EXPORT RefCountedStaticMemory : public RefCountedMemory { |
39 public: | 42 public: |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 virtual ~RefCountedString(); | 109 virtual ~RefCountedString(); |
107 | 110 |
108 std::string data_; | 111 std::string data_; |
109 | 112 |
110 DISALLOW_COPY_AND_ASSIGN(RefCountedString); | 113 DISALLOW_COPY_AND_ASSIGN(RefCountedString); |
111 }; | 114 }; |
112 | 115 |
113 } // namespace base | 116 } // namespace base |
114 | 117 |
115 #endif // BASE_MEMORY_REF_COUNTED_MEMORY_H_ | 118 #endif // BASE_MEMORY_REF_COUNTED_MEMORY_H_ |
OLD | NEW |