OLD | NEW |
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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 if (hasBackingFile() && getFileModificationTime(m_path, modificationTimeMS) && | 249 if (hasBackingFile() && getFileModificationTime(m_path, modificationTimeMS) && |
250 isValidFileTime(modificationTimeMS)) | 250 isValidFileTime(modificationTimeMS)) |
251 return modificationTimeMS; | 251 return modificationTimeMS; |
252 | 252 |
253 return currentTimeMS(); | 253 return currentTimeMS(); |
254 } | 254 } |
255 | 255 |
256 long long File::lastModified() const { | 256 long long File::lastModified() const { |
257 double modifiedDate = lastModifiedMS(); | 257 double modifiedDate = lastModifiedMS(); |
258 | 258 |
259 // The getter should return the current time when the last modification time i
sn't known. | 259 // The getter should return the current time when the last modification time |
| 260 // isn't known. |
260 if (!isValidFileTime(modifiedDate)) | 261 if (!isValidFileTime(modifiedDate)) |
261 modifiedDate = currentTimeMS(); | 262 modifiedDate = currentTimeMS(); |
262 | 263 |
263 // lastModified returns a number, not a Date instance, | 264 // lastModified returns a number, not a Date instance, |
264 // http://dev.w3.org/2006/webapi/FileAPI/#file-attrs | 265 // http://dev.w3.org/2006/webapi/FileAPI/#file-attrs |
265 return floor(modifiedDate); | 266 return floor(modifiedDate); |
266 } | 267 } |
267 | 268 |
268 double File::lastModifiedDate() const { | 269 double File::lastModifiedDate() const { |
269 double modifiedDate = lastModifiedMS(); | 270 double modifiedDate = lastModifiedMS(); |
270 | 271 |
271 // The getter should return the current time when the last modification time i
sn't known. | 272 // The getter should return the current time when the last modification time |
| 273 // isn't known. |
272 if (!isValidFileTime(modifiedDate)) | 274 if (!isValidFileTime(modifiedDate)) |
273 modifiedDate = currentTimeMS(); | 275 modifiedDate = currentTimeMS(); |
274 | 276 |
275 // lastModifiedDate returns a Date instance, | 277 // lastModifiedDate returns a Date instance, |
276 // http://www.w3.org/TR/FileAPI/#dfn-lastModifiedDate | 278 // http://www.w3.org/TR/FileAPI/#dfn-lastModifiedDate |
277 return modifiedDate; | 279 return modifiedDate; |
278 } | 280 } |
279 | 281 |
280 unsigned long long File::size() const { | 282 unsigned long long File::size() const { |
281 if (hasValidSnapshotMetadata()) | 283 if (hasValidSnapshotMetadata()) |
282 return m_snapshotSize; | 284 return m_snapshotSize; |
283 | 285 |
284 // FIXME: JavaScript cannot represent sizes as large as unsigned long long, we
need to | 286 // FIXME: JavaScript cannot represent sizes as large as unsigned long long, we |
285 // come up with an exception to throw if file size is not representable. | 287 // need to come up with an exception to throw if file size is not |
| 288 // representable. |
286 long long size; | 289 long long size; |
287 if (!hasBackingFile() || !getFileSize(m_path, size)) | 290 if (!hasBackingFile() || !getFileSize(m_path, size)) |
288 return 0; | 291 return 0; |
289 return static_cast<unsigned long long>(size); | 292 return static_cast<unsigned long long>(size); |
290 } | 293 } |
291 | 294 |
292 Blob* File::slice(long long start, | 295 Blob* File::slice(long long start, |
293 long long end, | 296 long long end, |
294 const String& contentType, | 297 const String& contentType, |
295 ExceptionState& exceptionState) const { | 298 ExceptionState& exceptionState) const { |
296 if (isClosed()) { | 299 if (isClosed()) { |
297 exceptionState.throwDOMException(InvalidStateError, | 300 exceptionState.throwDOMException(InvalidStateError, |
298 "File has been closed."); | 301 "File has been closed."); |
299 return nullptr; | 302 return nullptr; |
300 } | 303 } |
301 | 304 |
302 if (!m_hasBackingFile) | 305 if (!m_hasBackingFile) |
303 return Blob::slice(start, end, contentType, exceptionState); | 306 return Blob::slice(start, end, contentType, exceptionState); |
304 | 307 |
305 // FIXME: This involves synchronous file operation. We need to figure out how
to make it asynchronous. | 308 // FIXME: This involves synchronous file operation. We need to figure out how |
| 309 // to make it asynchronous. |
306 long long size; | 310 long long size; |
307 double modificationTimeMS; | 311 double modificationTimeMS; |
308 captureSnapshot(size, modificationTimeMS); | 312 captureSnapshot(size, modificationTimeMS); |
309 clampSliceOffsets(size, start, end); | 313 clampSliceOffsets(size, start, end); |
310 | 314 |
311 long long length = end - start; | 315 long long length = end - start; |
312 std::unique_ptr<BlobData> blobData = BlobData::create(); | 316 std::unique_ptr<BlobData> blobData = BlobData::create(); |
313 blobData->setContentType(contentType); | 317 blobData->setContentType(contentType); |
314 if (!m_fileSystemURL.isEmpty()) { | 318 if (!m_fileSystemURL.isEmpty()) { |
315 blobData->appendFileSystemURL(m_fileSystemURL, start, length, | 319 blobData->appendFileSystemURL(m_fileSystemURL, start, length, |
316 modificationTimeMS / msPerSecond); | 320 modificationTimeMS / msPerSecond); |
317 } else { | 321 } else { |
318 ASSERT(!m_path.isEmpty()); | 322 ASSERT(!m_path.isEmpty()); |
319 blobData->appendFile(m_path, start, length, | 323 blobData->appendFile(m_path, start, length, |
320 modificationTimeMS / msPerSecond); | 324 modificationTimeMS / msPerSecond); |
321 } | 325 } |
322 return Blob::create(BlobDataHandle::create(std::move(blobData), length)); | 326 return Blob::create(BlobDataHandle::create(std::move(blobData), length)); |
323 } | 327 } |
324 | 328 |
325 void File::captureSnapshot(long long& snapshotSize, | 329 void File::captureSnapshot(long long& snapshotSize, |
326 double& snapshotModificationTimeMS) const { | 330 double& snapshotModificationTimeMS) const { |
327 if (hasValidSnapshotMetadata()) { | 331 if (hasValidSnapshotMetadata()) { |
328 snapshotSize = m_snapshotSize; | 332 snapshotSize = m_snapshotSize; |
329 snapshotModificationTimeMS = m_snapshotModificationTimeMS; | 333 snapshotModificationTimeMS = m_snapshotModificationTimeMS; |
330 return; | 334 return; |
331 } | 335 } |
332 | 336 |
333 // Obtains a snapshot of the file by capturing its current size and modificati
on time. This is used when we slice a file for the first time. | 337 // Obtains a snapshot of the file by capturing its current size and |
334 // If we fail to retrieve the size or modification time, probably due to that
the file has been deleted, 0 size is returned. | 338 // modification time. This is used when we slice a file for the first time. |
| 339 // If we fail to retrieve the size or modification time, probably due to that |
| 340 // the file has been deleted, 0 size is returned. |
335 FileMetadata metadata; | 341 FileMetadata metadata; |
336 if (!hasBackingFile() || !getFileMetadata(m_path, metadata)) { | 342 if (!hasBackingFile() || !getFileMetadata(m_path, metadata)) { |
337 snapshotSize = 0; | 343 snapshotSize = 0; |
338 snapshotModificationTimeMS = invalidFileTime(); | 344 snapshotModificationTimeMS = invalidFileTime(); |
339 return; | 345 return; |
340 } | 346 } |
341 | 347 |
342 snapshotSize = metadata.length; | 348 snapshotSize = metadata.length; |
343 snapshotModificationTimeMS = metadata.modificationTime; | 349 snapshotModificationTimeMS = metadata.modificationTime; |
344 } | 350 } |
(...skipping 16 matching lines...) Expand all Loading... |
361 m_relativePath = String(); | 367 m_relativePath = String(); |
362 Blob::close(executionContext, exceptionState); | 368 Blob::close(executionContext, exceptionState); |
363 } | 369 } |
364 | 370 |
365 void File::appendTo(BlobData& blobData) const { | 371 void File::appendTo(BlobData& blobData) const { |
366 if (!m_hasBackingFile) { | 372 if (!m_hasBackingFile) { |
367 Blob::appendTo(blobData); | 373 Blob::appendTo(blobData); |
368 return; | 374 return; |
369 } | 375 } |
370 | 376 |
371 // FIXME: This involves synchronous file operation. We need to figure out how
to make it asynchronous. | 377 // FIXME: This involves synchronous file operation. We need to figure out how |
| 378 // to make it asynchronous. |
372 long long size; | 379 long long size; |
373 double modificationTimeMS; | 380 double modificationTimeMS; |
374 captureSnapshot(size, modificationTimeMS); | 381 captureSnapshot(size, modificationTimeMS); |
375 if (!m_fileSystemURL.isEmpty()) { | 382 if (!m_fileSystemURL.isEmpty()) { |
376 blobData.appendFileSystemURL(m_fileSystemURL, 0, size, | 383 blobData.appendFileSystemURL(m_fileSystemURL, 0, size, |
377 modificationTimeMS / msPerSecond); | 384 modificationTimeMS / msPerSecond); |
378 return; | 385 return; |
379 } | 386 } |
380 ASSERT(!m_path.isEmpty()); | 387 ASSERT(!m_path.isEmpty()); |
381 blobData.appendFile(m_path, 0, size, modificationTimeMS / msPerSecond); | 388 blobData.appendFile(m_path, 0, size, modificationTimeMS / msPerSecond); |
382 } | 389 } |
383 | 390 |
384 bool File::hasSameSource(const File& other) const { | 391 bool File::hasSameSource(const File& other) const { |
385 if (m_hasBackingFile != other.m_hasBackingFile) | 392 if (m_hasBackingFile != other.m_hasBackingFile) |
386 return false; | 393 return false; |
387 | 394 |
388 if (m_hasBackingFile) | 395 if (m_hasBackingFile) |
389 return m_path == other.m_path; | 396 return m_path == other.m_path; |
390 | 397 |
391 if (m_fileSystemURL.isEmpty() != other.m_fileSystemURL.isEmpty()) | 398 if (m_fileSystemURL.isEmpty() != other.m_fileSystemURL.isEmpty()) |
392 return false; | 399 return false; |
393 | 400 |
394 if (!m_fileSystemURL.isEmpty()) | 401 if (!m_fileSystemURL.isEmpty()) |
395 return m_fileSystemURL == other.m_fileSystemURL; | 402 return m_fileSystemURL == other.m_fileSystemURL; |
396 | 403 |
397 return uuid() == other.uuid(); | 404 return uuid() == other.uuid(); |
398 } | 405 } |
399 | 406 |
400 } // namespace blink | 407 } // namespace blink |
OLD | NEW |