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

Unified Diff: Source/core/fileapi/BlobBuilder.cpp

Issue 57483002: Implement File constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Addressed most feedback. Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/fileapi/BlobBuilder.h ('k') | Source/core/fileapi/File.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/fileapi/BlobBuilder.cpp
diff --git a/Source/core/fileapi/BlobBuilder.cpp b/Source/core/fileapi/BlobBuilder.cpp
index 8be60c17f457fc44cbcd3860d14bce7dd0ed2539..70583af4105f23d0038b602c226828432fc45acb 100644
--- a/Source/core/fileapi/BlobBuilder.cpp
+++ b/Source/core/fileapi/BlobBuilder.cpp
@@ -94,7 +94,7 @@ void BlobBuilder::append(Blob* blob)
{
if (!blob)
return;
- if (blob->isFile()) {
+ if (blob->hasBackingFile()) {
File* file = toFile(blob);
// If the blob is file that is not snapshoted, capture the snapshot now.
// FIXME: This involves synchronous file operation. We need to figure out how to make it asynchronous.
@@ -122,7 +122,7 @@ void BlobBuilder::appendBytesData(const void* data, size_t length)
m_size += buffer.size() - oldSize;
}
-PassRefPtr<Blob> BlobBuilder::getBlob(const String& contentType)
+PassRefPtr<Blob> BlobBuilder::createBlob(const String& contentType)
{
OwnPtr<BlobData> blobData = BlobData::create();
blobData->setContentType(contentType);
@@ -134,7 +134,22 @@ PassRefPtr<Blob> BlobBuilder::getBlob(const String& contentType)
// Instead, we only need to keep a reference to the blob data just created.
m_items.append(BlobDataItem(blob->blobDataHandle(), 0, m_size));
- return blob;
+ return blob.release();
+}
+
+PassRefPtr<File> BlobBuilder::createFile(const String& contentType, const String& fileName, double modificationTime)
+{
+ OwnPtr<BlobData> blobData = BlobData::create();
+ blobData->setContentType(contentType);
+ blobData->swapItems(m_items);
+
+ RefPtr<File> file = File::create(fileName, modificationTime, BlobDataHandle::create(blobData.release(), m_size));
+
+ // After creating a file from the current blob data, we do not need to keep the data around any more.
+ // Instead, we only need to keep a reference to the blob data just created.
+ m_items.append(BlobDataItem(file->blobDataHandle(), 0, m_size));
+
+ return file.release();
}
} // namespace WebCore
« no previous file with comments | « Source/core/fileapi/BlobBuilder.h ('k') | Source/core/fileapi/File.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698