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

Side by Side Diff: third_party/WebKit/Source/core/fileapi/Blob.cpp

Issue 1983753002: Remove OwnPtr::release() calls in core/ (part 2). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months 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
OLDNEW
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 bool normalizeLineEndingsToNative = options.endings() == "native"; 98 bool normalizeLineEndingsToNative = options.endings() == "native";
99 if (normalizeLineEndingsToNative) 99 if (normalizeLineEndingsToNative)
100 UseCounter::count(context, UseCounter::FileAPINativeLineEndings); 100 UseCounter::count(context, UseCounter::FileAPINativeLineEndings);
101 101
102 OwnPtr<BlobData> blobData = BlobData::create(); 102 OwnPtr<BlobData> blobData = BlobData::create();
103 blobData->setContentType(options.type().lower()); 103 blobData->setContentType(options.type().lower());
104 104
105 populateBlobData(blobData.get(), blobParts, normalizeLineEndingsToNative); 105 populateBlobData(blobData.get(), blobParts, normalizeLineEndingsToNative);
106 106
107 long long blobSize = blobData->length(); 107 long long blobSize = blobData->length();
108 return new Blob(BlobDataHandle::create(blobData.release(), blobSize)); 108 return new Blob(BlobDataHandle::create(std::move(blobData), blobSize));
109 } 109 }
110 110
111 Blob* Blob::create(const unsigned char* data, size_t bytes, const String& conten tType) 111 Blob* Blob::create(const unsigned char* data, size_t bytes, const String& conten tType)
112 { 112 {
113 ASSERT(data); 113 ASSERT(data);
114 114
115 OwnPtr<BlobData> blobData = BlobData::create(); 115 OwnPtr<BlobData> blobData = BlobData::create();
116 blobData->setContentType(contentType); 116 blobData->setContentType(contentType);
117 blobData->appendBytes(data, bytes); 117 blobData->appendBytes(data, bytes);
118 long long blobSize = blobData->length(); 118 long long blobSize = blobData->length();
119 119
120 return new Blob(BlobDataHandle::create(blobData.release(), blobSize)); 120 return new Blob(BlobDataHandle::create(std::move(blobData), blobSize));
121 } 121 }
122 122
123 // static 123 // static
124 void Blob::populateBlobData(BlobData* blobData, const HeapVector<ArrayBufferOrAr rayBufferViewOrBlobOrUSVString>& parts, bool normalizeLineEndingsToNative) 124 void Blob::populateBlobData(BlobData* blobData, const HeapVector<ArrayBufferOrAr rayBufferViewOrBlobOrUSVString>& parts, bool normalizeLineEndingsToNative)
125 { 125 {
126 for (const auto& item : parts) { 126 for (const auto& item : parts) {
127 if (item.isArrayBuffer()) { 127 if (item.isArrayBuffer()) {
128 DOMArrayBuffer* arrayBuffer = item.getAsArrayBuffer(); 128 DOMArrayBuffer* arrayBuffer = item.getAsArrayBuffer();
129 blobData->appendBytes(arrayBuffer->data(), arrayBuffer->byteLength() ); 129 blobData->appendBytes(arrayBuffer->data(), arrayBuffer->byteLength() );
130 } else if (item.isArrayBufferView()) { 130 } else if (item.isArrayBufferView()) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 return nullptr; 173 return nullptr;
174 } 174 }
175 175
176 long long size = this->size(); 176 long long size = this->size();
177 clampSliceOffsets(size, start, end); 177 clampSliceOffsets(size, start, end);
178 178
179 long long length = end - start; 179 long long length = end - start;
180 OwnPtr<BlobData> blobData = BlobData::create(); 180 OwnPtr<BlobData> blobData = BlobData::create();
181 blobData->setContentType(contentType); 181 blobData->setContentType(contentType);
182 blobData->appendBlob(m_blobDataHandle, start, length); 182 blobData->appendBlob(m_blobDataHandle, start, length);
183 return Blob::create(BlobDataHandle::create(blobData.release(), length)); 183 return Blob::create(BlobDataHandle::create(std::move(blobData), length));
184 } 184 }
185 185
186 void Blob::close(ExecutionContext* executionContext, ExceptionState& exceptionSt ate) 186 void Blob::close(ExecutionContext* executionContext, ExceptionState& exceptionSt ate)
187 { 187 {
188 if (isClosed()) { 188 if (isClosed()) {
189 exceptionState.throwDOMException(InvalidStateError, "Blob has been close d."); 189 exceptionState.throwDOMException(InvalidStateError, "Blob has been close d.");
190 return; 190 return;
191 } 191 }
192 192
193 // Dereferencing a Blob that has been closed should result in 193 // Dereferencing a Blob that has been closed should result in
194 // a network error. Revoke URLs registered against it through 194 // a network error. Revoke URLs registered against it through
195 // its UUID. 195 // its UUID.
196 DOMURL::revokeObjectUUID(executionContext, uuid()); 196 DOMURL::revokeObjectUUID(executionContext, uuid());
197 197
198 // A Blob enters a 'readability state' of closed, where it will report its 198 // A Blob enters a 'readability state' of closed, where it will report its
199 // size as zero. Blob and FileReader operations now throws on 199 // size as zero. Blob and FileReader operations now throws on
200 // being passed a Blob in that state. Downstream uses of closed Blobs 200 // being passed a Blob in that state. Downstream uses of closed Blobs
201 // (e.g., XHR.send()) consider them as empty. 201 // (e.g., XHR.send()) consider them as empty.
202 OwnPtr<BlobData> blobData = BlobData::create(); 202 OwnPtr<BlobData> blobData = BlobData::create();
203 blobData->setContentType(type()); 203 blobData->setContentType(type());
204 m_blobDataHandle = BlobDataHandle::create(blobData.release(), 0); 204 m_blobDataHandle = BlobDataHandle::create(std::move(blobData), 0);
205 m_isClosed = true; 205 m_isClosed = true;
206 } 206 }
207 207
208 void Blob::appendTo(BlobData& blobData) const 208 void Blob::appendTo(BlobData& blobData) const
209 { 209 {
210 blobData.appendBlob(m_blobDataHandle, 0, m_blobDataHandle->size()); 210 blobData.appendBlob(m_blobDataHandle, 0, m_blobDataHandle->size());
211 } 211 }
212 212
213 URLRegistry& Blob::registry() const 213 URLRegistry& Blob::registry() const
214 { 214 {
215 return BlobURLRegistry::registry(); 215 return BlobURLRegistry::registry();
216 } 216 }
217 217
218 } // namespace blink 218 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/ResourceLoader.cpp ('k') | third_party/WebKit/Source/core/fileapi/File.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698