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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 private: | 58 private: |
59 virtual ~RefCountedStaticMemory(); | 59 virtual ~RefCountedStaticMemory(); |
60 | 60 |
61 const unsigned char* data_; | 61 const unsigned char* data_; |
62 size_t length_; | 62 size_t length_; |
63 | 63 |
64 DISALLOW_COPY_AND_ASSIGN(RefCountedStaticMemory); | 64 DISALLOW_COPY_AND_ASSIGN(RefCountedStaticMemory); |
65 }; | 65 }; |
66 | 66 |
67 // An implementation of RefCountedMemory, where we own our the data in a | 67 // An implementation of RefCountedMemory, where we own the data in a vector. |
68 // vector. | |
69 class BASE_EXPORT RefCountedBytes : public RefCountedMemory { | 68 class BASE_EXPORT RefCountedBytes : public RefCountedMemory { |
70 public: | 69 public: |
71 RefCountedBytes(); | 70 RefCountedBytes(); |
72 | 71 |
73 // Constructs a RefCountedBytes object by _copying_ from |initializer|. | 72 // Constructs a RefCountedBytes object by _copying_ from |initializer|. |
74 explicit RefCountedBytes(const std::vector<unsigned char>& initializer); | 73 explicit RefCountedBytes(const std::vector<unsigned char>& initializer); |
75 | 74 |
| 75 // Constructs a RefCountedBytes object by copying |size| bytes from |p|. |
| 76 RefCountedBytes(const unsigned char* p, size_t size); |
| 77 |
76 // Constructs a RefCountedBytes object by performing a swap. (To non | 78 // Constructs a RefCountedBytes object by performing a swap. (To non |
77 // destructively build a RefCountedBytes, use the constructor that takes a | 79 // destructively build a RefCountedBytes, use the constructor that takes a |
78 // vector.) | 80 // vector.) |
79 static RefCountedBytes* TakeVector(std::vector<unsigned char>* to_destroy); | 81 static RefCountedBytes* TakeVector(std::vector<unsigned char>* to_destroy); |
80 | 82 |
81 // Overridden from RefCountedMemory: | 83 // Overridden from RefCountedMemory: |
82 virtual const unsigned char* front() const OVERRIDE; | 84 virtual const unsigned char* front() const OVERRIDE; |
83 virtual size_t size() const OVERRIDE; | 85 virtual size_t size() const OVERRIDE; |
84 | 86 |
85 const std::vector<unsigned char>& data() const { return data_; } | 87 const std::vector<unsigned char>& data() const { return data_; } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 137 |
136 unsigned char* data_; | 138 unsigned char* data_; |
137 size_t length_; | 139 size_t length_; |
138 | 140 |
139 DISALLOW_COPY_AND_ASSIGN(RefCountedMallocedMemory); | 141 DISALLOW_COPY_AND_ASSIGN(RefCountedMallocedMemory); |
140 }; | 142 }; |
141 | 143 |
142 } // namespace base | 144 } // namespace base |
143 | 145 |
144 #endif // BASE_MEMORY_REF_COUNTED_MEMORY_H_ | 146 #endif // BASE_MEMORY_REF_COUNTED_MEMORY_H_ |
OLD | NEW |