@@ -105,24 +105,45 @@ class DataMapping final : public Mapping {
105
105
class NonOwnedMapping final : public Mapping {
106
106
public:
107
107
using ReleaseProc = std::function<void (const uint8_t * data, size_t size)>;
108
- NonOwnedMapping ();
109
-
110
108
NonOwnedMapping (const uint8_t * data,
111
109
size_t size,
112
110
const ReleaseProc& release_proc = nullptr );
113
111
114
- NonOwnedMapping (fml::NonOwnedMapping&& mapping);
115
-
116
112
~NonOwnedMapping () override ;
117
113
114
+ // |Mapping|
115
+ size_t GetSize () const override ;
116
+
117
+ // |Mapping|
118
+ const uint8_t * GetMapping () const override ;
119
+
120
+ private:
121
+ const uint8_t * data_;
122
+ const size_t size_;
123
+ const ReleaseProc release_proc_;
124
+
125
+ FML_DISALLOW_COPY_AND_ASSIGN (NonOwnedMapping);
126
+ };
127
+
128
+ // / A Mapping like NonOwnedMapping, but uses Free as its release proc.
129
+ class MallocMapping final : public Mapping {
130
+ public:
131
+ MallocMapping ();
132
+
133
+ MallocMapping (const uint8_t * data, size_t size);
134
+
135
+ MallocMapping (fml::MallocMapping&& mapping);
136
+
137
+ ~MallocMapping () override ;
138
+
118
139
// / Copies the data from `begin` to `end`.
119
140
// / It's templated since void* arithemetic isn't allowed and we want support
120
141
// / for `uint8_t` and `char`.
121
142
template <typename T>
122
- static NonOwnedMapping Copy (const T* begin, const T* end) {
143
+ static MallocMapping Copy (const T* begin, const T* end) {
123
144
size_t length = end - begin;
124
- auto result = NonOwnedMapping::WithFree (
125
- reinterpret_cast <uint8_t *>(malloc (length)), length);
145
+ auto result =
146
+ MallocMapping ( reinterpret_cast <uint8_t *>(malloc (length)), length);
126
147
memcpy (const_cast <uint8_t *>(result.GetMapping ()), begin, length);
127
148
return result;
128
149
}
@@ -136,21 +157,11 @@ class NonOwnedMapping final : public Mapping {
136
157
// / Removes ownership of the data buffer.
137
158
const uint8_t * Release ();
138
159
139
- // / Returns true if the Mapping uses `free` to delete the memory.
140
- // / This is important for passing ownership to C/ObjC code like NSData. It
141
- // / has to be a special case because std::function comparisions aren't
142
- // / possible.
143
- bool UsesFree () const { return uses_free_; }
144
-
145
160
private:
146
- static NonOwnedMapping WithFree (const uint8_t * data, size_t size);
147
-
148
161
const uint8_t * data_;
149
162
size_t size_;
150
- ReleaseProc release_proc_;
151
- bool uses_free_;
152
163
153
- FML_DISALLOW_COPY_AND_ASSIGN (NonOwnedMapping );
164
+ FML_DISALLOW_COPY_AND_ASSIGN (MallocMapping );
154
165
};
155
166
156
167
class SymbolMapping final : public Mapping {
0 commit comments