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

Side by Side Diff: Source/bindings/core/v8/ScriptValueSerializer.cpp

Issue 884393002: Upgrade Blink to milliseconds-based last modified filetimes, part 3. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@sof-fileinfo-modtime-in-ms-1
Patch Set: Stop using time_t over getFileModificationTime(); not sound Created 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "bindings/core/v8/ScriptValueSerializer.h" 6 #include "bindings/core/v8/ScriptValueSerializer.h"
7 7
8 #include "bindings/core/v8/V8ArrayBuffer.h" 8 #include "bindings/core/v8/V8ArrayBuffer.h"
9 #include "bindings/core/v8/V8ArrayBufferView.h" 9 #include "bindings/core/v8/V8ArrayBufferView.h"
10 #include "bindings/core/v8/V8Blob.h" 10 #include "bindings/core/v8/V8Blob.h"
11 #include "bindings/core/v8/V8File.h" 11 #include "bindings/core/v8/V8File.h"
12 #include "bindings/core/v8/V8FileList.h" 12 #include "bindings/core/v8/V8FileList.h"
13 #include "bindings/core/v8/V8ImageData.h" 13 #include "bindings/core/v8/V8ImageData.h"
14 #include "bindings/core/v8/V8MessagePort.h" 14 #include "bindings/core/v8/V8MessagePort.h"
15 #include "core/dom/DOMDataView.h" 15 #include "core/dom/DOMDataView.h"
16 #include "core/fileapi/Blob.h" 16 #include "core/fileapi/Blob.h"
17 #include "core/fileapi/File.h" 17 #include "core/fileapi/File.h"
18 #include "core/fileapi/FileList.h" 18 #include "core/fileapi/FileList.h"
19 #include "public/platform/Platform.h" 19 #include "public/platform/Platform.h"
20 #include "public/platform/WebBlobInfo.h" 20 #include "public/platform/WebBlobInfo.h"
21 #include "wtf/DateMath.h"
21 #include "wtf/text/StringHash.h" 22 #include "wtf/text/StringHash.h"
22 #include "wtf/text/StringUTF8Adaptor.h" 23 #include "wtf/text/StringUTF8Adaptor.h"
23 24
24 // FIXME: consider crashing in debug mode on deserialization errors 25 // FIXME: consider crashing in debug mode on deserialization errors
25 // NOTE: be sure to change wireFormatVersion as necessary! 26 // NOTE: be sure to change wireFormatVersion as necessary!
26 27
27 namespace blink { 28 namespace blink {
28 29
29 // This code implements the HTML5 Structured Clone algorithm: 30 // This code implements the HTML5 Structured Clone algorithm:
30 // http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#safe-pa ssing-of-structured-data 31 // http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#safe-pa ssing-of-structured-data
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 doWriteWebCoreString(file.name()); 375 doWriteWebCoreString(file.name());
375 doWriteWebCoreString(file.webkitRelativePath()); 376 doWriteWebCoreString(file.webkitRelativePath());
376 doWriteWebCoreString(file.uuid()); 377 doWriteWebCoreString(file.uuid());
377 doWriteWebCoreString(file.type()); 378 doWriteWebCoreString(file.type());
378 379
379 // FIXME don't use 1 byte to encode a flag. 380 // FIXME don't use 1 byte to encode a flag.
380 if (file.hasValidSnapshotMetadata()) { 381 if (file.hasValidSnapshotMetadata()) {
381 doWriteUint32(static_cast<uint8_t>(1)); 382 doWriteUint32(static_cast<uint8_t>(1));
382 383
383 long long size; 384 long long size;
384 double lastModified; 385 double lastModifiedMS;
385 file.captureSnapshot(size, lastModified); 386 file.captureSnapshot(size, lastModifiedMS);
386 doWriteUint64(static_cast<uint64_t>(size)); 387 doWriteUint64(static_cast<uint64_t>(size));
387 doWriteNumber(lastModified); 388 doWriteNumber(lastModifiedMS);
388 } else { 389 } else {
389 doWriteUint32(static_cast<uint8_t>(0)); 390 doWriteUint32(static_cast<uint8_t>(0));
390 } 391 }
391 392
392 doWriteUint32(static_cast<uint8_t>((file.userVisibility() == File::IsUserVis ible) ? 1 : 0)); 393 doWriteUint32(static_cast<uint8_t>((file.userVisibility() == File::IsUserVis ible) ? 1 : 0));
393 } 394 }
394 395
395 void SerializedScriptValueWriter::doWriteArrayBuffer(const DOMArrayBuffer& array Buffer) 396 void SerializedScriptValueWriter::doWriteArrayBuffer(const DOMArrayBuffer& array Buffer)
396 { 397 {
397 uint32_t byteLength = arrayBuffer.byteLength(); 398 uint32_t byteLength = arrayBuffer.byteLength();
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 m_blobInfo->append(WebBlobInfo(uuid, type, size)); 983 m_blobInfo->append(WebBlobInfo(uuid, type, size));
983 return true; 984 return true;
984 } 985 }
985 986
986 bool ScriptValueSerializer::appendFileInfo(const File* file, int* index) 987 bool ScriptValueSerializer::appendFileInfo(const File* file, int* index)
987 { 988 {
988 if (!m_blobInfo) 989 if (!m_blobInfo)
989 return false; 990 return false;
990 991
991 long long size = -1; 992 long long size = -1;
992 double lastModified = invalidFileTime(); 993 double lastModifiedMS = invalidFileTime();
993 file->captureSnapshot(size, lastModified); 994 file->captureSnapshot(size, lastModifiedMS);
994 *index = m_blobInfo->size(); 995 *index = m_blobInfo->size();
996 // FIXME: transition WebBlobInfo.lastModified to be milliseconds-based also.
997 double lastModified = lastModifiedMS / msPerSecond;
995 m_blobInfo->append(WebBlobInfo(file->uuid(), file->path(), file->name(), fil e->type(), lastModified, size)); 998 m_blobInfo->append(WebBlobInfo(file->uuid(), file->path(), file->name(), fil e->type(), lastModified, size));
996 return true; 999 return true;
997 } 1000 }
998 1001
999 bool SerializedScriptValueReader::read(v8::Handle<v8::Value>* value, ScriptValue CompositeCreator& creator) 1002 bool SerializedScriptValueReader::read(v8::Handle<v8::Value>* value, ScriptValue CompositeCreator& creator)
1000 { 1003 {
1001 SerializationTag tag; 1004 SerializationTag tag;
1002 if (!readTag(&tag)) 1005 if (!readTag(&tag))
1003 return false; 1006 return false;
1004 return readWithTag(tag, value, creator); 1007 return readWithTag(tag, value, creator);
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
1591 if (m_version < 3) 1594 if (m_version < 3)
1592 return nullptr; 1595 return nullptr;
1593 ASSERT(!m_blobInfo); 1596 ASSERT(!m_blobInfo);
1594 String path; 1597 String path;
1595 String name; 1598 String name;
1596 String relativePath; 1599 String relativePath;
1597 String uuid; 1600 String uuid;
1598 String type; 1601 String type;
1599 uint32_t hasSnapshot = 0; 1602 uint32_t hasSnapshot = 0;
1600 uint64_t size = 0; 1603 uint64_t size = 0;
1601 double lastModified = 0; 1604 double lastModifiedMS = 0;
1602 if (!readWebCoreString(&path)) 1605 if (!readWebCoreString(&path))
1603 return nullptr; 1606 return nullptr;
1604 if (m_version >= 4 && !readWebCoreString(&name)) 1607 if (m_version >= 4 && !readWebCoreString(&name))
1605 return nullptr; 1608 return nullptr;
1606 if (m_version >= 4 && !readWebCoreString(&relativePath)) 1609 if (m_version >= 4 && !readWebCoreString(&relativePath))
1607 return nullptr; 1610 return nullptr;
1608 if (!readWebCoreString(&uuid)) 1611 if (!readWebCoreString(&uuid))
1609 return nullptr; 1612 return nullptr;
1610 if (!readWebCoreString(&type)) 1613 if (!readWebCoreString(&type))
1611 return nullptr; 1614 return nullptr;
1612 if (m_version >= 4 && !doReadUint32(&hasSnapshot)) 1615 if (m_version >= 4 && !doReadUint32(&hasSnapshot))
1613 return nullptr; 1616 return nullptr;
1614 if (hasSnapshot) { 1617 if (hasSnapshot) {
1615 if (!doReadUint64(&size)) 1618 if (!doReadUint64(&size))
1616 return nullptr; 1619 return nullptr;
1617 if (!doReadNumber(&lastModified)) 1620 if (!doReadNumber(&lastModifiedMS))
1618 return nullptr; 1621 return nullptr;
1622 if (m_version < 8)
1623 lastModifiedMS *= msPerSecond;
1619 } 1624 }
1620 uint32_t isUserVisible = 1; 1625 uint32_t isUserVisible = 1;
1621 if (m_version >= 7 && !doReadUint32(&isUserVisible)) 1626 if (m_version >= 7 && !doReadUint32(&isUserVisible))
1622 return nullptr; 1627 return nullptr;
1623 const File::UserVisibility userVisibility = (isUserVisible > 0) ? File::IsUs erVisible : File::IsNotUserVisible; 1628 const File::UserVisibility userVisibility = (isUserVisible > 0) ? File::IsUs erVisible : File::IsNotUserVisible;
1624 return File::createFromSerialization(path, name, relativePath, userVisibilit y, hasSnapshot > 0, size, lastModified, getOrCreateBlobDataHandle(uuid, type)); 1629 return File::createFromSerialization(path, name, relativePath, userVisibilit y, hasSnapshot > 0, size, lastModifiedMS, getOrCreateBlobDataHandle(uuid, type)) ;
1625 } 1630 }
1626 1631
1627 File* SerializedScriptValueReader::readFileIndexHelper() 1632 File* SerializedScriptValueReader::readFileIndexHelper()
1628 { 1633 {
1629 if (m_version < 3) 1634 if (m_version < 3)
1630 return nullptr; 1635 return nullptr;
1631 ASSERT(m_blobInfo); 1636 ASSERT(m_blobInfo);
1632 uint32_t index; 1637 uint32_t index;
1633 if (!doReadUint32(&index) || index >= m_blobInfo->size()) 1638 if (!doReadUint32(&index) || index >= m_blobInfo->size())
1634 return nullptr; 1639 return nullptr;
1635 const WebBlobInfo& info = (*m_blobInfo)[index]; 1640 const WebBlobInfo& info = (*m_blobInfo)[index];
1636 return File::createFromIndexedSerialization(info.filePath(), info.fileName() , info.size(), info.lastModified(), getOrCreateBlobDataHandle(info.uuid(), info. type(), info.size())); 1641 // FIXME: transition WebBlobInfo.lastModified to be milliseconds-based also.
1642 double lastModifiedMS = info.lastModified() * msPerSecond;
1643 return File::createFromIndexedSerialization(info.filePath(), info.fileName() , info.size(), lastModifiedMS, getOrCreateBlobDataHandle(info.uuid(), info.type( ), info.size()));
1637 } 1644 }
1638 1645
1639 bool SerializedScriptValueReader::doReadUint32(uint32_t* value) 1646 bool SerializedScriptValueReader::doReadUint32(uint32_t* value)
1640 { 1647 {
1641 return doReadUintHelper(value); 1648 return doReadUintHelper(value);
1642 } 1649 }
1643 1650
1644 bool SerializedScriptValueReader::doReadUint64(uint64_t* value) 1651 bool SerializedScriptValueReader::doReadUint64(uint64_t* value)
1645 { 1652 {
1646 return doReadUintHelper(value); 1653 return doReadUintHelper(value);
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1877 return false; 1884 return false;
1878 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe renceStack.size() - 1]; 1885 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe renceStack.size() - 1];
1879 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() - 1); 1886 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() - 1);
1880 if (objectReference >= m_objectPool.size()) 1887 if (objectReference >= m_objectPool.size())
1881 return false; 1888 return false;
1882 *object = m_objectPool[objectReference]; 1889 *object = m_objectPool[objectReference];
1883 return true; 1890 return true;
1884 } 1891 }
1885 1892
1886 } // namespace blink 1893 } // namespace blink
OLDNEW
« no previous file with comments | « LayoutTests/fast/storage/resources/serialized-script-value.js ('k') | Source/bindings/core/v8/SerializedScriptValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698