OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
(...skipping 21 matching lines...) Expand all Loading... |
33 | 33 |
34 // An implementation of RefCountedMemory, where the ref counting does not | 34 // An implementation of RefCountedMemory, where the ref counting does not |
35 // matter. | 35 // matter. |
36 class RefCountedStaticMemory : public RefCountedMemory { | 36 class RefCountedStaticMemory : public RefCountedMemory { |
37 public: | 37 public: |
38 RefCountedStaticMemory() | 38 RefCountedStaticMemory() |
39 : data_(NULL), length_(0) {} | 39 : data_(NULL), length_(0) {} |
40 RefCountedStaticMemory(const unsigned char* data, size_t length) | 40 RefCountedStaticMemory(const unsigned char* data, size_t length) |
41 : data_(data), length_(length) {} | 41 : data_(data), length_(length) {} |
42 | 42 |
| 43 // Overriden from RefCountedMemory: |
43 virtual const unsigned char* front() const; | 44 virtual const unsigned char* front() const; |
44 virtual size_t size() const; | 45 virtual size_t size() const; |
45 | 46 |
46 private: | 47 private: |
47 const unsigned char* data_; | 48 const unsigned char* data_; |
48 size_t length_; | 49 size_t length_; |
49 | 50 |
50 DISALLOW_COPY_AND_ASSIGN(RefCountedStaticMemory); | 51 DISALLOW_COPY_AND_ASSIGN(RefCountedStaticMemory); |
51 }; | 52 }; |
52 | 53 |
53 // An implementation of RefCountedMemory, where we own our the data in a | 54 // An implementation of RefCountedMemory, where we own our the data in a |
54 // vector. | 55 // vector. |
55 class RefCountedBytes : public RefCountedMemory { | 56 class RefCountedBytes : public RefCountedMemory { |
56 public: | 57 public: |
| 58 RefCountedBytes(); |
| 59 |
| 60 // Constructs a RefCountedBytes object by _copying_ from |initializer|. |
| 61 RefCountedBytes(const std::vector<unsigned char>& initializer); |
| 62 |
57 // Constructs a RefCountedBytes object by performing a swap. (To non | 63 // Constructs a RefCountedBytes object by performing a swap. (To non |
58 // destructively build a RefCountedBytes, use the constructor that takes a | 64 // destructively build a RefCountedBytes, use the constructor that takes a |
59 // vector.) | 65 // vector.) |
60 static RefCountedBytes* TakeVector(std::vector<unsigned char>* to_destroy); | 66 static RefCountedBytes* TakeVector(std::vector<unsigned char>* to_destroy); |
61 | 67 |
62 RefCountedBytes(); | 68 // Overriden from RefCountedMemory: |
63 | |
64 // Constructs a RefCountedBytes object by _copying_ from |initializer|. | |
65 RefCountedBytes(const std::vector<unsigned char>& initializer); | |
66 | |
67 virtual const unsigned char* front() const; | 69 virtual const unsigned char* front() const; |
68 virtual size_t size() const; | 70 virtual size_t size() const; |
69 | 71 |
70 std::vector<unsigned char> data; | 72 std::vector<unsigned char> data; |
71 | 73 |
72 protected: | 74 protected: |
73 friend class base::RefCountedThreadSafe<RefCountedBytes>; | 75 friend class base::RefCountedThreadSafe<RefCountedBytes>; |
74 virtual ~RefCountedBytes(); | 76 virtual ~RefCountedBytes(); |
75 | 77 |
76 private: | 78 private: |
77 DISALLOW_COPY_AND_ASSIGN(RefCountedBytes); | 79 DISALLOW_COPY_AND_ASSIGN(RefCountedBytes); |
78 }; | 80 }; |
79 | 81 |
80 #endif // BASE_REF_COUNTED_MEMORY_H_ | 82 #endif // BASE_REF_COUNTED_MEMORY_H_ |
OLD | NEW |