OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 15 matching lines...) Expand all Loading... |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "platform/blob/BlobData.h" | 31 #include "platform/blob/BlobData.h" |
32 | 32 |
33 #include "platform/UUID.h" | 33 #include "platform/UUID.h" |
34 #include "platform/blob/BlobRegistry.h" | 34 #include "platform/blob/BlobRegistry.h" |
35 #include "platform/text/LineEnding.h" | 35 #include "platform/text/LineEnding.h" |
36 #include "wtf/OwnPtr.h" | |
37 #include "wtf/PassRefPtr.h" | 36 #include "wtf/PassRefPtr.h" |
| 37 #include "wtf/PtrUtil.h" |
38 #include "wtf/RefPtr.h" | 38 #include "wtf/RefPtr.h" |
39 #include "wtf/Vector.h" | 39 #include "wtf/Vector.h" |
40 #include "wtf/text/CString.h" | 40 #include "wtf/text/CString.h" |
41 #include "wtf/text/TextEncoding.h" | 41 #include "wtf/text/TextEncoding.h" |
| 42 #include <memory> |
42 | 43 |
43 namespace blink { | 44 namespace blink { |
44 | 45 |
45 namespace { | 46 namespace { |
46 | 47 |
47 // All consecutive items that are accumulate to < this number will have the | 48 // All consecutive items that are accumulate to < this number will have the |
48 // data appended to the same item. | 49 // data appended to the same item. |
49 static const size_t kMaxConsolidatedItemSizeInBytes = 15 * 1024; | 50 static const size_t kMaxConsolidatedItemSizeInBytes = 15 * 1024; |
50 | 51 |
51 // http://dev.w3.org/2006/webapi/FileAPI/#constructorBlob | 52 // http://dev.w3.org/2006/webapi/FileAPI/#constructorBlob |
(...skipping 19 matching lines...) Expand all Loading... |
71 { | 72 { |
72 } | 73 } |
73 | 74 |
74 void BlobDataItem::detachFromCurrentThread() | 75 void BlobDataItem::detachFromCurrentThread() |
75 { | 76 { |
76 data->detachFromCurrentThread(); | 77 data->detachFromCurrentThread(); |
77 path = path.isolatedCopy(); | 78 path = path.isolatedCopy(); |
78 fileSystemURL = fileSystemURL.copy(); | 79 fileSystemURL = fileSystemURL.copy(); |
79 } | 80 } |
80 | 81 |
81 PassOwnPtr<BlobData> BlobData::create() | 82 std::unique_ptr<BlobData> BlobData::create() |
82 { | 83 { |
83 return adoptPtr(new BlobData()); | 84 return wrapUnique(new BlobData()); |
84 } | 85 } |
85 | 86 |
86 void BlobData::detachFromCurrentThread() | 87 void BlobData::detachFromCurrentThread() |
87 { | 88 { |
88 m_contentType = m_contentType.isolatedCopy(); | 89 m_contentType = m_contentType.isolatedCopy(); |
89 for (size_t i = 0; i < m_items.size(); ++i) | 90 for (size_t i = 0; i < m_items.size(); ++i) |
90 m_items.at(i).detachFromCurrentThread(); | 91 m_items.at(i).detachFromCurrentThread(); |
91 } | 92 } |
92 | 93 |
93 void BlobData::setContentType(const String& contentType) | 94 void BlobData::setContentType(const String& contentType) |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 return true; | 197 return true; |
197 } | 198 } |
198 | 199 |
199 BlobDataHandle::BlobDataHandle() | 200 BlobDataHandle::BlobDataHandle() |
200 : m_uuid(createCanonicalUUIDString()) | 201 : m_uuid(createCanonicalUUIDString()) |
201 , m_size(0) | 202 , m_size(0) |
202 { | 203 { |
203 BlobRegistry::registerBlobData(m_uuid, BlobData::create()); | 204 BlobRegistry::registerBlobData(m_uuid, BlobData::create()); |
204 } | 205 } |
205 | 206 |
206 BlobDataHandle::BlobDataHandle(PassOwnPtr<BlobData> data, long long size) | 207 BlobDataHandle::BlobDataHandle(std::unique_ptr<BlobData> data, long long size) |
207 : m_uuid(createCanonicalUUIDString()) | 208 : m_uuid(createCanonicalUUIDString()) |
208 , m_type(data->contentType().isolatedCopy()) | 209 , m_type(data->contentType().isolatedCopy()) |
209 , m_size(size) | 210 , m_size(size) |
210 { | 211 { |
211 BlobRegistry::registerBlobData(m_uuid, std::move(data)); | 212 BlobRegistry::registerBlobData(m_uuid, std::move(data)); |
212 } | 213 } |
213 | 214 |
214 BlobDataHandle::BlobDataHandle(const String& uuid, const String& type, long long
size) | 215 BlobDataHandle::BlobDataHandle(const String& uuid, const String& type, long long
size) |
215 : m_uuid(uuid.isolatedCopy()) | 216 : m_uuid(uuid.isolatedCopy()) |
216 , m_type(isValidBlobType(type) ? type.isolatedCopy() : "") | 217 , m_type(isValidBlobType(type) ? type.isolatedCopy() : "") |
217 , m_size(size) | 218 , m_size(size) |
218 { | 219 { |
219 BlobRegistry::addBlobDataRef(m_uuid); | 220 BlobRegistry::addBlobDataRef(m_uuid); |
220 } | 221 } |
221 | 222 |
222 BlobDataHandle::~BlobDataHandle() | 223 BlobDataHandle::~BlobDataHandle() |
223 { | 224 { |
224 BlobRegistry::removeBlobDataRef(m_uuid); | 225 BlobRegistry::removeBlobDataRef(m_uuid); |
225 } | 226 } |
226 | 227 |
227 } // namespace blink | 228 } // namespace blink |
OLD | NEW |