Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: base/memory/ref_counted_memory.h

Issue 126103003: Changed RefCountedStaticMemory() to accept a void pointer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/memory/ref_counted_memory_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12 matching lines...) Expand all
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. 30 // Returns true if |other| is byte for byte equal.
31 bool Equals(const scoped_refptr<RefCountedMemory>& other) const; 31 bool Equals(const scoped_refptr<RefCountedMemory>& other) const;
32 32
33 // Handy method to simplify calling front() with a reinterpret_cast.
34 template<typename T> const T* front_as() const {
35 return reinterpret_cast<const T*>(front());
36 }
37
33 protected: 38 protected:
34 friend class base::RefCountedThreadSafe<RefCountedMemory>; 39 friend class base::RefCountedThreadSafe<RefCountedMemory>;
35 RefCountedMemory(); 40 RefCountedMemory();
36 virtual ~RefCountedMemory(); 41 virtual ~RefCountedMemory();
37 }; 42 };
38 43
39 // An implementation of RefCountedMemory, where the ref counting does not 44 // An implementation of RefCountedMemory, where the ref counting does not
40 // matter. 45 // matter.
41 class BASE_EXPORT RefCountedStaticMemory : public RefCountedMemory { 46 class BASE_EXPORT RefCountedStaticMemory : public RefCountedMemory {
42 public: 47 public:
43 RefCountedStaticMemory() 48 RefCountedStaticMemory()
44 : data_(NULL), length_(0) {} 49 : data_(NULL), length_(0) {}
45 RefCountedStaticMemory(const unsigned char* data, size_t length) 50 RefCountedStaticMemory(const void* data, size_t length)
46 : data_(length ? data : NULL), length_(length) {} 51 : data_(static_cast<const unsigned char*>(length ? data : NULL)),
52 length_(length) {}
47 53
48 // Overridden from RefCountedMemory: 54 // Overridden from RefCountedMemory:
49 virtual const unsigned char* front() const OVERRIDE; 55 virtual const unsigned char* front() const OVERRIDE;
50 virtual size_t size() const OVERRIDE; 56 virtual size_t size() const OVERRIDE;
51 57
52 private: 58 private:
53 virtual ~RefCountedStaticMemory(); 59 virtual ~RefCountedStaticMemory();
54 60
55 const unsigned char* data_; 61 const unsigned char* data_;
56 size_t length_; 62 size_t length_;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 135
130 unsigned char* data_; 136 unsigned char* data_;
131 size_t length_; 137 size_t length_;
132 138
133 DISALLOW_COPY_AND_ASSIGN(RefCountedMallocedMemory); 139 DISALLOW_COPY_AND_ASSIGN(RefCountedMallocedMemory);
134 }; 140 };
135 141
136 } // namespace base 142 } // namespace base
137 143
138 #endif // BASE_MEMORY_REF_COUNTED_MEMORY_H_ 144 #endif // BASE_MEMORY_REF_COUNTED_MEMORY_H_
OLDNEW
« no previous file with comments | « no previous file | base/memory/ref_counted_memory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698