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

Side by Side Diff: base/ref_counted_memory.h

Issue 333048: Fix an exception in the ref counted data. This appeares as a crash on startip... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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) 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() {} 20 virtual ~RefCountedMemory() {}
21 21
22 // Retrieves a pointer to the beginning of the data we point to. 22 // Retrieves a pointer to the beginning of the data we point to. If the data
23 // is empty, this will return NULL.
23 virtual const unsigned char* front() const = 0; 24 virtual const unsigned char* front() const = 0;
24 25
25 // Size of the memory pointed to. 26 // Size of the memory pointed to.
26 virtual size_t size() const = 0; 27 virtual size_t size() const = 0;
27 }; 28 };
28 29
29 // An implementation of RefCountedMemory, where the ref counting does not 30 // An implementation of RefCountedMemory, where the ref counting does not
30 // matter. 31 // matter.
31 class RefCountedStaticMemory : public RefCountedMemory { 32 class RefCountedStaticMemory : public RefCountedMemory {
32 public: 33 public:
(...skipping 24 matching lines...) Expand all
57 bytes->data.swap(*to_destroy); 58 bytes->data.swap(*to_destroy);
58 return bytes; 59 return bytes;
59 } 60 }
60 61
61 RefCountedBytes() {} 62 RefCountedBytes() {}
62 63
63 // Constructs a RefCountedBytes object by _copying_ from |initializer|. 64 // Constructs a RefCountedBytes object by _copying_ from |initializer|.
64 RefCountedBytes(const std::vector<unsigned char>& initializer) 65 RefCountedBytes(const std::vector<unsigned char>& initializer)
65 : data(initializer) {} 66 : data(initializer) {}
66 67
67 virtual const unsigned char* front() const { return &data.front(); } 68 virtual const unsigned char* front() const {
69 // STL will assert if we do front() on an empty vector, but calling code
70 // expects a NULL.
71 return size() ? &data.front() : NULL;
72 }
68 virtual size_t size() const { return data.size(); } 73 virtual size_t size() const { return data.size(); }
69 74
70 std::vector<unsigned char> data; 75 std::vector<unsigned char> data;
71 76
72 private: 77 private:
73 DISALLOW_COPY_AND_ASSIGN(RefCountedBytes); 78 DISALLOW_COPY_AND_ASSIGN(RefCountedBytes);
74 }; 79 };
75 80
76 #endif // BASE_REF_COUNTED_MEMORY_H_ 81 #endif // BASE_REF_COUNTED_MEMORY_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698