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

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

Issue 157363003: Implement Blob.close(). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased Created 6 years, 10 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
« no previous file with comments | « Source/core/fileapi/File.h ('k') | Source/core/fileapi/FileReader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 { 155 {
156 ScriptWrappable::init(this); 156 ScriptWrappable::init(this);
157 } 157 }
158 158
159 double File::lastModifiedDate() const 159 double File::lastModifiedDate() const
160 { 160 {
161 if (hasValidSnapshotMetadata() && isValidFileTime(m_snapshotModificationTime )) 161 if (hasValidSnapshotMetadata() && isValidFileTime(m_snapshotModificationTime ))
162 return m_snapshotModificationTime * msPerSecond; 162 return m_snapshotModificationTime * msPerSecond;
163 163
164 time_t modificationTime; 164 time_t modificationTime;
165 if (getFileModificationTime(m_path, modificationTime) && isValidFileTime(mod ificationTime)) 165 if (hasBackingFile() && getFileModificationTime(m_path, modificationTime) && isValidFileTime(modificationTime))
166 return modificationTime * msPerSecond; 166 return modificationTime * msPerSecond;
167 167
168 return currentTime() * msPerSecond; 168 return currentTime() * msPerSecond;
169 } 169 }
170 170
171 unsigned long long File::size() const 171 unsigned long long File::size() const
172 { 172 {
173 if (hasValidSnapshotMetadata()) 173 if (hasValidSnapshotMetadata())
174 return m_snapshotSize; 174 return m_snapshotSize;
175 175
176 // FIXME: JavaScript cannot represent sizes as large as unsigned long long, we need to 176 // FIXME: JavaScript cannot represent sizes as large as unsigned long long, we need to
177 // come up with an exception to throw if file size is not representable. 177 // come up with an exception to throw if file size is not representable.
178 long long size; 178 long long size;
179 if (!getFileSize(m_path, size)) 179 if (!hasBackingFile() || !getFileSize(m_path, size))
180 return 0; 180 return 0;
181 return static_cast<unsigned long long>(size); 181 return static_cast<unsigned long long>(size);
182 } 182 }
183 183
184 PassRefPtr<Blob> File::slice(long long start, long long end, const String& conte ntType) const 184 PassRefPtr<Blob> File::slice(long long start, long long end, const String& conte ntType) const
185 { 185 {
186 if (!m_hasBackingFile) 186 if (!m_hasBackingFile)
187 return Blob::slice(start, end, contentType); 187 return Blob::slice(start, end, contentType);
188 188
189 // FIXME: This involves synchronous file operation. We need to figure out ho w to make it asynchronous. 189 // FIXME: This involves synchronous file operation. We need to figure out ho w to make it asynchronous.
(...skipping 18 matching lines...) Expand all
208 { 208 {
209 if (hasValidSnapshotMetadata()) { 209 if (hasValidSnapshotMetadata()) {
210 snapshotSize = m_snapshotSize; 210 snapshotSize = m_snapshotSize;
211 snapshotModificationTime = m_snapshotModificationTime; 211 snapshotModificationTime = m_snapshotModificationTime;
212 return; 212 return;
213 } 213 }
214 214
215 // Obtains a snapshot of the file by capturing its current size and modifica tion time. This is used when we slice a file for the first time. 215 // Obtains a snapshot of the file by capturing its current size and modifica tion time. This is used when we slice a file for the first time.
216 // If we fail to retrieve the size or modification time, probably due to tha t the file has been deleted, 0 size is returned. 216 // If we fail to retrieve the size or modification time, probably due to tha t the file has been deleted, 0 size is returned.
217 FileMetadata metadata; 217 FileMetadata metadata;
218 if (!getFileMetadata(m_path, metadata)) { 218 if (!hasBackingFile() || !getFileMetadata(m_path, metadata)) {
219 snapshotSize = 0; 219 snapshotSize = 0;
220 snapshotModificationTime = invalidFileTime(); 220 snapshotModificationTime = invalidFileTime();
221 return; 221 return;
222 } 222 }
223 223
224 snapshotSize = metadata.length; 224 snapshotSize = metadata.length;
225 snapshotModificationTime = metadata.modificationTime; 225 snapshotModificationTime = metadata.modificationTime;
226 } 226 }
227 227
228 void File::close(ExecutionContext* executionContext)
229 {
230 if (!hasBeenClosed()) {
231 // Reset the File to its closed representation, an empty
232 // Blob. The name isn't cleared, as it should still be
233 // available.
234 m_hasBackingFile = false;
235 m_path = String();
236 m_fileSystemURL = KURL();
237 invalidateSnapshotMetadata();
238 m_relativePath = String();
239 Blob::close(executionContext);
240 }
241 }
242
228 void File::appendTo(BlobData& blobData) const 243 void File::appendTo(BlobData& blobData) const
229 { 244 {
230 if (!m_hasBackingFile) { 245 if (!m_hasBackingFile) {
231 Blob::appendTo(blobData); 246 Blob::appendTo(blobData);
232 return; 247 return;
233 } 248 }
234 249
235 // FIXME: This involves synchronous file operation. We need to figure out ho w to make it asynchronous. 250 // FIXME: This involves synchronous file operation. We need to figure out ho w to make it asynchronous.
236 long long size; 251 long long size;
237 double modificationTime; 252 double modificationTime;
238 captureSnapshot(size, modificationTime); 253 captureSnapshot(size, modificationTime);
239 if (!m_fileSystemURL.isEmpty()) { 254 if (!m_fileSystemURL.isEmpty()) {
240 blobData.appendFileSystemURL(m_fileSystemURL, 0, size, modificationTime) ; 255 blobData.appendFileSystemURL(m_fileSystemURL, 0, size, modificationTime) ;
241 return; 256 return;
242 } 257 }
243 ASSERT(!m_path.isEmpty()); 258 ASSERT(!m_path.isEmpty());
244 blobData.appendFile(m_path, 0, size, modificationTime); 259 blobData.appendFile(m_path, 0, size, modificationTime);
245 } 260 }
246 261
247 } // namespace WebCore 262 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/fileapi/File.h ('k') | Source/core/fileapi/FileReader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698