| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "modules/indexeddb/IDBValue.h" | 5 #include "modules/indexeddb/IDBValue.h" |
| 6 | 6 |
| 7 #include <v8.h> |
| 8 |
| 9 #include "bindings/core/v8/SerializedScriptValue.h" |
| 7 #include "platform/blob/BlobData.h" | 10 #include "platform/blob/BlobData.h" |
| 8 #include "public/platform/WebBlobInfo.h" | 11 #include "public/platform/WebBlobInfo.h" |
| 9 #include "public/platform/modules/indexeddb/WebIDBValue.h" | 12 #include "public/platform/modules/indexeddb/WebIDBValue.h" |
| 10 #include "wtf/PtrUtil.h" | 13 #include "wtf/PtrUtil.h" |
| 11 | 14 |
| 12 namespace blink { | 15 namespace blink { |
| 13 | 16 |
| 14 IDBValue::IDBValue() = default; | 17 IDBValue::IDBValue() = default; |
| 15 | 18 |
| 16 IDBValue::IDBValue(const WebIDBValue& value) | 19 IDBValue::IDBValue(const WebIDBValue& value) |
| 17 : IDBValue(value.data, value.webBlobInfo, value.primaryKey, value.keyPath) { | 20 : IDBValue(value.data, value.webBlobInfo, value.primaryKey, value.keyPath) { |
| 21 m_externalAllocatedSize = m_data ? static_cast<int64_t>(m_data->size()) : 0l; |
| 22 if (m_externalAllocatedSize) { |
| 23 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( |
| 24 m_externalAllocatedSize); |
| 25 } |
| 18 } | 26 } |
| 19 | 27 |
| 20 IDBValue::IDBValue(PassRefPtr<SharedBuffer> data, | 28 IDBValue::IDBValue(PassRefPtr<SharedBuffer> data, |
| 21 const WebVector<WebBlobInfo>& webBlobInfo, | 29 const WebVector<WebBlobInfo>& webBlobInfo, |
| 22 IDBKey* primaryKey, | 30 IDBKey* primaryKey, |
| 23 const IDBKeyPath& keyPath) | 31 const IDBKeyPath& keyPath) |
| 24 : m_data(data), | 32 : m_data(data), |
| 25 m_blobData(makeUnique<Vector<RefPtr<BlobDataHandle>>>()), | 33 m_blobData(makeUnique<Vector<RefPtr<BlobDataHandle>>>()), |
| 26 m_blobInfo(wrapUnique(new Vector<WebBlobInfo>(webBlobInfo.size()))), | 34 m_blobInfo(wrapUnique(new Vector<WebBlobInfo>(webBlobInfo.size()))), |
| 27 m_primaryKey(primaryKey && primaryKey->isValid() ? primaryKey : nullptr), | 35 m_primaryKey(primaryKey && primaryKey->isValid() ? primaryKey : nullptr), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 42 wrapUnique(new Vector<WebBlobInfo>(value->m_blobInfo->size()))), | 50 wrapUnique(new Vector<WebBlobInfo>(value->m_blobInfo->size()))), |
| 43 m_primaryKey(primaryKey), | 51 m_primaryKey(primaryKey), |
| 44 m_keyPath(keyPath) { | 52 m_keyPath(keyPath) { |
| 45 for (size_t i = 0; i < value->m_blobInfo->size(); ++i) { | 53 for (size_t i = 0; i < value->m_blobInfo->size(); ++i) { |
| 46 const WebBlobInfo& info = (*m_blobInfo)[i] = value->m_blobInfo->at(i); | 54 const WebBlobInfo& info = (*m_blobInfo)[i] = value->m_blobInfo->at(i); |
| 47 m_blobData->append( | 55 m_blobData->append( |
| 48 BlobDataHandle::create(info.uuid(), info.type(), info.size())); | 56 BlobDataHandle::create(info.uuid(), info.type(), info.size())); |
| 49 } | 57 } |
| 50 } | 58 } |
| 51 | 59 |
| 52 IDBValue::~IDBValue() {} | 60 IDBValue::~IDBValue() { |
| 61 if (m_externalAllocatedSize) { |
| 62 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( |
| 63 -m_externalAllocatedSize); |
| 64 } |
| 65 } |
| 53 | 66 |
| 54 PassRefPtr<IDBValue> IDBValue::create() { | 67 PassRefPtr<IDBValue> IDBValue::create() { |
| 55 return adoptRef(new IDBValue()); | 68 return adoptRef(new IDBValue()); |
| 56 } | 69 } |
| 57 | 70 |
| 58 PassRefPtr<IDBValue> IDBValue::create(const WebIDBValue& value) { | 71 PassRefPtr<IDBValue> IDBValue::create(const WebIDBValue& value) { |
| 59 return adoptRef(new IDBValue(value)); | 72 return adoptRef(new IDBValue(value)); |
| 60 } | 73 } |
| 61 | 74 |
| 62 PassRefPtr<IDBValue> IDBValue::create(const IDBValue* value, | 75 PassRefPtr<IDBValue> IDBValue::create(const IDBValue* value, |
| 63 IDBKey* primaryKey, | 76 IDBKey* primaryKey, |
| 64 const IDBKeyPath& keyPath) { | 77 const IDBKeyPath& keyPath) { |
| 65 return adoptRef(new IDBValue(value, primaryKey, keyPath)); | 78 return adoptRef(new IDBValue(value, primaryKey, keyPath)); |
| 66 } | 79 } |
| 67 | 80 |
| 68 Vector<String> IDBValue::getUUIDs() const { | 81 Vector<String> IDBValue::getUUIDs() const { |
| 69 Vector<String> uuids; | 82 Vector<String> uuids; |
| 70 uuids.reserveCapacity(m_blobInfo->size()); | 83 uuids.reserveCapacity(m_blobInfo->size()); |
| 71 for (const auto& info : *m_blobInfo) | 84 for (const auto& info : *m_blobInfo) |
| 72 uuids.append(info.uuid()); | 85 uuids.append(info.uuid()); |
| 73 return uuids; | 86 return uuids; |
| 74 } | 87 } |
| 75 | 88 |
| 76 const SharedBuffer* IDBValue::data() const { | 89 RefPtr<SerializedScriptValue> IDBValue::createSerializedValue() const { |
| 77 return m_data.get(); | 90 return SerializedScriptValue::create(m_data->data(), m_data->size()); |
| 78 } | 91 } |
| 79 | 92 |
| 80 bool IDBValue::isNull() const { | 93 bool IDBValue::isNull() const { |
| 81 return !m_data.get(); | 94 return !m_data.get(); |
| 82 } | 95 } |
| 83 | 96 |
| 84 } // namespace blink | 97 } // namespace blink |
| OLD | NEW |