OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_REF_COUNTED_MEMORY_H_ | 5 #ifndef BASE_REF_COUNTED_MEMORY_H_ |
6 #define BASE_REF_COUNTED_MEMORY_H_ | 6 #define BASE_REF_COUNTED_MEMORY_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
11 | 11 |
12 // TODO(erg): The contents of this file should be in a namespace. This would | 12 // TODO(erg): The contents of this file should be in a namespace. This would |
13 // require touching >100 files in chrome/ though. | 13 // require touching >100 files in chrome/ though. |
14 | 14 |
15 // A generic interface to memory. This object is reference counted because one | 15 // A generic interface to memory. This object is reference counted because one |
16 // of its two subclasses own the data they carry, and we need to have | 16 // of its two subclasses own the data they carry, and we need to have |
17 // heterogeneous containers of these two types of memory. | 17 // heterogeneous containers of these two types of memory. |
18 class RefCountedMemory : public base::RefCountedThreadSafe< RefCountedMemory > { | 18 class RefCountedMemory : public base::RefCountedThreadSafe<RefCountedMemory> { |
19 public: | 19 public: |
20 virtual ~RefCountedMemory() {} | |
21 | |
22 // Retrieves a pointer to the beginning of the data we point to. If the data | 20 // Retrieves a pointer to the beginning of the data we point to. If the data |
23 // is empty, this will return NULL. | 21 // is empty, this will return NULL. |
24 virtual const unsigned char* front() const = 0; | 22 virtual const unsigned char* front() const = 0; |
25 | 23 |
26 // Size of the memory pointed to. | 24 // Size of the memory pointed to. |
27 virtual size_t size() const = 0; | 25 virtual size_t size() const = 0; |
| 26 |
| 27 protected: |
| 28 friend class base::RefCountedThreadSafe<RefCountedMemory>; |
| 29 |
| 30 virtual ~RefCountedMemory() {} |
28 }; | 31 }; |
29 | 32 |
30 // An implementation of RefCountedMemory, where the ref counting does not | 33 // An implementation of RefCountedMemory, where the ref counting does not |
31 // matter. | 34 // matter. |
32 class RefCountedStaticMemory : public RefCountedMemory { | 35 class RefCountedStaticMemory : public RefCountedMemory { |
33 public: | 36 public: |
34 RefCountedStaticMemory() | 37 RefCountedStaticMemory() |
35 : data_(NULL), length_(0) {} | 38 : data_(NULL), length_(0) {} |
36 RefCountedStaticMemory(const unsigned char* data, size_t length) | 39 RefCountedStaticMemory(const unsigned char* data, size_t length) |
37 : data_(data), length_(length) {} | 40 : data_(data), length_(length) {} |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 } | 75 } |
73 virtual size_t size() const { return data.size(); } | 76 virtual size_t size() const { return data.size(); } |
74 | 77 |
75 std::vector<unsigned char> data; | 78 std::vector<unsigned char> data; |
76 | 79 |
77 private: | 80 private: |
78 DISALLOW_COPY_AND_ASSIGN(RefCountedBytes); | 81 DISALLOW_COPY_AND_ASSIGN(RefCountedBytes); |
79 }; | 82 }; |
80 | 83 |
81 #endif // BASE_REF_COUNTED_MEMORY_H_ | 84 #endif // BASE_REF_COUNTED_MEMORY_H_ |
OLD | NEW |