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

Side by Side Diff: Source/core/fileapi/BlobBuilder.cpp

Issue 57483002: Implement File constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Answered feedback, part 2. 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 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 if (!arrayBufferView) 87 if (!arrayBufferView)
88 return; 88 return;
89 89
90 appendBytesData(arrayBufferView->baseAddress(), arrayBufferView->byteLength( )); 90 appendBytesData(arrayBufferView->baseAddress(), arrayBufferView->byteLength( ));
91 } 91 }
92 92
93 void BlobBuilder::append(Blob* blob) 93 void BlobBuilder::append(Blob* blob)
94 { 94 {
95 if (!blob) 95 if (!blob)
96 return; 96 return;
97 if (blob->isFile()) { 97 if (blob->isOnFilesystem()) {
98 File* file = toFile(blob); 98 File* file = toFile(blob);
99 // If the blob is file that is not snapshoted, capture the snapshot now. 99 // If the blob is file that is not snapshoted, capture the snapshot now.
100 // FIXME: This involves synchronous file operation. We need to figure ou t how to make it asynchronous. 100 // FIXME: This involves synchronous file operation. We need to figure ou t how to make it asynchronous.
101 long long snapshotSize; 101 long long snapshotSize;
102 double snapshotModificationTime; 102 double snapshotModificationTime;
103 file->captureSnapshot(snapshotSize, snapshotModificationTime); 103 file->captureSnapshot(snapshotSize, snapshotModificationTime);
104 104
105 m_size += snapshotSize; 105 m_size += snapshotSize;
106 if (!file->fileSystemURL().isEmpty()) 106 if (!file->fileSystemURL().isEmpty())
107 m_items.append(BlobDataItem(file->fileSystemURL(), 0, snapshotSize, snapshotModificationTime)); 107 m_items.append(BlobDataItem(file->fileSystemURL(), 0, snapshotSize, snapshotModificationTime));
(...skipping 19 matching lines...) Expand all
127 OwnPtr<BlobData> blobData = BlobData::create(); 127 OwnPtr<BlobData> blobData = BlobData::create();
128 blobData->setContentType(contentType); 128 blobData->setContentType(contentType);
129 blobData->swapItems(m_items); 129 blobData->swapItems(m_items);
130 130
131 RefPtr<Blob> blob = Blob::create(BlobDataHandle::create(blobData.release(), m_size)); 131 RefPtr<Blob> blob = Blob::create(BlobDataHandle::create(blobData.release(), m_size));
132 132
133 // After creating a blob from the current blob data, we do not need to keep the data around any more. 133 // After creating a blob from the current blob data, we do not need to keep the data around any more.
134 // Instead, we only need to keep a reference to the blob data just created. 134 // Instead, we only need to keep a reference to the blob data just created.
135 m_items.append(BlobDataItem(blob->blobDataHandle(), 0, m_size)); 135 m_items.append(BlobDataItem(blob->blobDataHandle(), 0, m_size));
136 136
137 return blob; 137 return blob.release();
138 }
139
140 PassRefPtr<File> BlobBuilder::getFile(const String& contentType, const String& f ileName, double modificationTime)
esprehn 2013/11/04 19:28:08 createFile, method that create objects shouldn't b
pwnall-personal 2013/11/04 23:01:21 Actually, I think this whole class should be moved
141 {
142 OwnPtr<BlobData> blobData = BlobData::create();
143 blobData->setContentType(contentType);
144 blobData->swapItems(m_items);
145
146 RefPtr<File> file = File::create(fileName, modificationTime, BlobDataHandle: :create(blobData.release(), m_size));
147
148 // After creating a file from the current blob data, we do not need to keep the data around any more.
149 // Instead, we only need to keep a reference to the blob data just created.
150 m_items.append(BlobDataItem(file->blobDataHandle(), 0, m_size));
esprehn 2013/11/04 19:28:08 What cleans this up to prevent leaks?
pwnall-personal 2013/11/04 23:01:21 I borrowed this code from "getBlob", so I don't kn
151
152 return file.release();
138 } 153 }
139 154
140 } // namespace WebCore 155 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698