| 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" |
| 36 #include "wtf/PassRefPtr.h" | 37 #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> | |
| 43 | 42 |
| 44 namespace blink { | 43 namespace blink { |
| 45 | 44 |
| 46 namespace { | 45 namespace { |
| 47 | 46 |
| 48 // All consecutive items that are accumulate to < this number will have the | 47 // All consecutive items that are accumulate to < this number will have the |
| 49 // data appended to the same item. | 48 // data appended to the same item. |
| 50 static const size_t kMaxConsolidatedItemSizeInBytes = 15 * 1024; | 49 static const size_t kMaxConsolidatedItemSizeInBytes = 15 * 1024; |
| 51 | 50 |
| 52 // http://dev.w3.org/2006/webapi/FileAPI/#constructorBlob | 51 // http://dev.w3.org/2006/webapi/FileAPI/#constructorBlob |
| (...skipping 19 matching lines...) Expand all Loading... |
| 72 { | 71 { |
| 73 } | 72 } |
| 74 | 73 |
| 75 void BlobDataItem::detachFromCurrentThread() | 74 void BlobDataItem::detachFromCurrentThread() |
| 76 { | 75 { |
| 77 data->detachFromCurrentThread(); | 76 data->detachFromCurrentThread(); |
| 78 path = path.isolatedCopy(); | 77 path = path.isolatedCopy(); |
| 79 fileSystemURL = fileSystemURL.copy(); | 78 fileSystemURL = fileSystemURL.copy(); |
| 80 } | 79 } |
| 81 | 80 |
| 82 std::unique_ptr<BlobData> BlobData::create() | 81 PassOwnPtr<BlobData> BlobData::create() |
| 83 { | 82 { |
| 84 return wrapUnique(new BlobData()); | 83 return adoptPtr(new BlobData()); |
| 85 } | 84 } |
| 86 | 85 |
| 87 void BlobData::detachFromCurrentThread() | 86 void BlobData::detachFromCurrentThread() |
| 88 { | 87 { |
| 89 m_contentType = m_contentType.isolatedCopy(); | 88 m_contentType = m_contentType.isolatedCopy(); |
| 90 for (size_t i = 0; i < m_items.size(); ++i) | 89 for (size_t i = 0; i < m_items.size(); ++i) |
| 91 m_items.at(i).detachFromCurrentThread(); | 90 m_items.at(i).detachFromCurrentThread(); |
| 92 } | 91 } |
| 93 | 92 |
| 94 void BlobData::setContentType(const String& contentType) | 93 void BlobData::setContentType(const String& contentType) |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 return true; | 196 return true; |
| 198 } | 197 } |
| 199 | 198 |
| 200 BlobDataHandle::BlobDataHandle() | 199 BlobDataHandle::BlobDataHandle() |
| 201 : m_uuid(createCanonicalUUIDString()) | 200 : m_uuid(createCanonicalUUIDString()) |
| 202 , m_size(0) | 201 , m_size(0) |
| 203 { | 202 { |
| 204 BlobRegistry::registerBlobData(m_uuid, BlobData::create()); | 203 BlobRegistry::registerBlobData(m_uuid, BlobData::create()); |
| 205 } | 204 } |
| 206 | 205 |
| 207 BlobDataHandle::BlobDataHandle(std::unique_ptr<BlobData> data, long long size) | 206 BlobDataHandle::BlobDataHandle(PassOwnPtr<BlobData> data, long long size) |
| 208 : m_uuid(createCanonicalUUIDString()) | 207 : m_uuid(createCanonicalUUIDString()) |
| 209 , m_type(data->contentType().isolatedCopy()) | 208 , m_type(data->contentType().isolatedCopy()) |
| 210 , m_size(size) | 209 , m_size(size) |
| 211 { | 210 { |
| 212 BlobRegistry::registerBlobData(m_uuid, std::move(data)); | 211 BlobRegistry::registerBlobData(m_uuid, std::move(data)); |
| 213 } | 212 } |
| 214 | 213 |
| 215 BlobDataHandle::BlobDataHandle(const String& uuid, const String& type, long long
size) | 214 BlobDataHandle::BlobDataHandle(const String& uuid, const String& type, long long
size) |
| 216 : m_uuid(uuid.isolatedCopy()) | 215 : m_uuid(uuid.isolatedCopy()) |
| 217 , m_type(isValidBlobType(type) ? type.isolatedCopy() : "") | 216 , m_type(isValidBlobType(type) ? type.isolatedCopy() : "") |
| 218 , m_size(size) | 217 , m_size(size) |
| 219 { | 218 { |
| 220 BlobRegistry::addBlobDataRef(m_uuid); | 219 BlobRegistry::addBlobDataRef(m_uuid); |
| 221 } | 220 } |
| 222 | 221 |
| 223 BlobDataHandle::~BlobDataHandle() | 222 BlobDataHandle::~BlobDataHandle() |
| 224 { | 223 { |
| 225 BlobRegistry::removeBlobDataRef(m_uuid); | 224 BlobRegistry::removeBlobDataRef(m_uuid); |
| 226 } | 225 } |
| 227 | 226 |
| 228 } // namespace blink | 227 } // namespace blink |
| OLD | NEW |