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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/base_export.h" | 12 #include "base/base_export.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 | 15 |
16 // TODO(erg): The contents of this file should be in a namespace. This would | 16 namespace base { |
17 // require touching >100 files in chrome/ though. | |
18 | 17 |
19 // 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 |
20 // 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 |
21 // heterogeneous containers of these two types of memory. | 20 // heterogeneous containers of these two types of memory. |
22 class BASE_EXPORT RefCountedMemory | 21 class BASE_EXPORT RefCountedMemory |
23 : public base::RefCountedThreadSafe<RefCountedMemory> { | 22 : public base::RefCountedThreadSafe<RefCountedMemory> { |
24 public: | 23 public: |
25 // Retrieves a pointer to the beginning of the data we point to. If the data | 24 // Retrieves a pointer to the beginning of the data we point to. If the data |
26 // is empty, this will return NULL. | 25 // is empty, this will return NULL. |
27 virtual const unsigned char* front() const = 0; | 26 virtual const unsigned char* front() const = 0; |
28 | 27 |
29 // Size of the memory pointed to. | 28 // Size of the memory pointed to. |
30 virtual size_t size() const = 0; | 29 virtual size_t size() const = 0; |
31 | 30 |
32 protected: | 31 protected: |
33 friend class base::RefCountedThreadSafe<RefCountedMemory>; | 32 friend class base::RefCountedThreadSafe<RefCountedMemory>; |
34 RefCountedMemory(); | 33 RefCountedMemory(); |
35 virtual ~RefCountedMemory(); | 34 virtual ~RefCountedMemory(); |
36 }; | 35 }; |
37 | 36 |
38 namespace base { | |
39 | |
40 // An implementation of RefCountedMemory, where the ref counting does not | 37 // An implementation of RefCountedMemory, where the ref counting does not |
41 // matter. | 38 // matter. |
42 class BASE_EXPORT RefCountedStaticMemory : public RefCountedMemory { | 39 class BASE_EXPORT RefCountedStaticMemory : public RefCountedMemory { |
43 public: | 40 public: |
44 RefCountedStaticMemory() | 41 RefCountedStaticMemory() |
45 : data_(NULL), length_(0) {} | 42 : data_(NULL), length_(0) {} |
46 RefCountedStaticMemory(const unsigned char* data, size_t length) | 43 RefCountedStaticMemory(const unsigned char* data, size_t length) |
47 : data_(length ? data : NULL), length_(length) {} | 44 : data_(length ? data : NULL), length_(length) {} |
48 | 45 |
49 // Overridden from RefCountedMemory: | 46 // Overridden from RefCountedMemory: |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 virtual ~RefCountedString(); | 107 virtual ~RefCountedString(); |
111 | 108 |
112 std::string data_; | 109 std::string data_; |
113 | 110 |
114 DISALLOW_COPY_AND_ASSIGN(RefCountedString); | 111 DISALLOW_COPY_AND_ASSIGN(RefCountedString); |
115 }; | 112 }; |
116 | 113 |
117 } // namespace base | 114 } // namespace base |
118 | 115 |
119 #endif // BASE_MEMORY_REF_COUNTED_MEMORY_H_ | 116 #endif // BASE_MEMORY_REF_COUNTED_MEMORY_H_ |
OLD | NEW |