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

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

Issue 900773003: Revert of 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: 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"
22 #include "wtf/text/StringHash.h" 21 #include "wtf/text/StringHash.h"
23 #include "wtf/text/StringUTF8Adaptor.h" 22 #include "wtf/text/StringUTF8Adaptor.h"
24 23
25 // FIXME: consider crashing in debug mode on deserialization errors 24 // FIXME: consider crashing in debug mode on deserialization errors
26 // NOTE: be sure to change wireFormatVersion as necessary! 25 // NOTE: be sure to change wireFormatVersion as necessary!
27 26
28 namespace blink { 27 namespace blink {
29 28
30 // This code implements the HTML5 Structured Clone algorithm: 29 // This code implements the HTML5 Structured Clone algorithm:
31 // http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#safe-pa ssing-of-structured-data 30 // 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
375 doWriteWebCoreString(file.name()); 374 doWriteWebCoreString(file.name());
376 doWriteWebCoreString(file.webkitRelativePath()); 375 doWriteWebCoreString(file.webkitRelativePath());
377 doWriteWebCoreString(file.uuid()); 376 doWriteWebCoreString(file.uuid());
378 doWriteWebCoreString(file.type()); 377 doWriteWebCoreString(file.type());
379 378
380 // FIXME don't use 1 byte to encode a flag. 379 // FIXME don't use 1 byte to encode a flag.
381 if (file.hasValidSnapshotMetadata()) { 380 if (file.hasValidSnapshotMetadata()) {
382 doWriteUint32(static_cast<uint8_t>(1)); 381 doWriteUint32(static_cast<uint8_t>(1));
383 382
384 long long size; 383 long long size;
385 double lastModifiedMS; 384 double lastModified;
386 file.captureSnapshot(size, lastModifiedMS); 385 file.captureSnapshot(size, lastModified);
387 doWriteUint64(static_cast<uint64_t>(size)); 386 doWriteUint64(static_cast<uint64_t>(size));
388 doWriteNumber(lastModifiedMS); 387 doWriteNumber(lastModified);
389 } else { 388 } else {
390 doWriteUint32(static_cast<uint8_t>(0)); 389 doWriteUint32(static_cast<uint8_t>(0));
391 } 390 }
392 391
393 doWriteUint32(static_cast<uint8_t>((file.userVisibility() == File::IsUserVis ible) ? 1 : 0)); 392 doWriteUint32(static_cast<uint8_t>((file.userVisibility() == File::IsUserVis ible) ? 1 : 0));
394 } 393 }
395 394
396 void SerializedScriptValueWriter::doWriteArrayBuffer(const DOMArrayBuffer& array Buffer) 395 void SerializedScriptValueWriter::doWriteArrayBuffer(const DOMArrayBuffer& array Buffer)
397 { 396 {
398 uint32_t byteLength = arrayBuffer.byteLength(); 397 uint32_t byteLength = arrayBuffer.byteLength();
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 m_blobInfo->append(WebBlobInfo(uuid, type, size)); 982 m_blobInfo->append(WebBlobInfo(uuid, type, size));
984 return true; 983 return true;
985 } 984 }
986 985
987 bool ScriptValueSerializer::appendFileInfo(const File* file, int* index) 986 bool ScriptValueSerializer::appendFileInfo(const File* file, int* index)
988 { 987 {
989 if (!m_blobInfo) 988 if (!m_blobInfo)
990 return false; 989 return false;
991 990
992 long long size = -1; 991 long long size = -1;
993 double lastModifiedMS = invalidFileTime(); 992 double lastModified = invalidFileTime();
994 file->captureSnapshot(size, lastModifiedMS); 993 file->captureSnapshot(size, lastModified);
995 *index = m_blobInfo->size(); 994 *index = m_blobInfo->size();
996 // FIXME: transition WebBlobInfo.lastModified to be milliseconds-based also.
997 double lastModified = lastModifiedMS / msPerSecond;
998 m_blobInfo->append(WebBlobInfo(file->uuid(), file->path(), file->name(), fil e->type(), lastModified, size)); 995 m_blobInfo->append(WebBlobInfo(file->uuid(), file->path(), file->name(), fil e->type(), lastModified, size));
999 return true; 996 return true;
1000 } 997 }
1001 998
1002 bool SerializedScriptValueReader::read(v8::Handle<v8::Value>* value, ScriptValue CompositeCreator& creator) 999 bool SerializedScriptValueReader::read(v8::Handle<v8::Value>* value, ScriptValue CompositeCreator& creator)
1003 { 1000 {
1004 SerializationTag tag; 1001 SerializationTag tag;
1005 if (!readTag(&tag)) 1002 if (!readTag(&tag))
1006 return false; 1003 return false;
1007 return readWithTag(tag, value, creator); 1004 return readWithTag(tag, value, creator);
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 if (m_version < 3) 1591 if (m_version < 3)
1595 return nullptr; 1592 return nullptr;
1596 ASSERT(!m_blobInfo); 1593 ASSERT(!m_blobInfo);
1597 String path; 1594 String path;
1598 String name; 1595 String name;
1599 String relativePath; 1596 String relativePath;
1600 String uuid; 1597 String uuid;
1601 String type; 1598 String type;
1602 uint32_t hasSnapshot = 0; 1599 uint32_t hasSnapshot = 0;
1603 uint64_t size = 0; 1600 uint64_t size = 0;
1604 double lastModifiedMS = 0; 1601 double lastModified = 0;
1605 if (!readWebCoreString(&path)) 1602 if (!readWebCoreString(&path))
1606 return nullptr; 1603 return nullptr;
1607 if (m_version >= 4 && !readWebCoreString(&name)) 1604 if (m_version >= 4 && !readWebCoreString(&name))
1608 return nullptr; 1605 return nullptr;
1609 if (m_version >= 4 && !readWebCoreString(&relativePath)) 1606 if (m_version >= 4 && !readWebCoreString(&relativePath))
1610 return nullptr; 1607 return nullptr;
1611 if (!readWebCoreString(&uuid)) 1608 if (!readWebCoreString(&uuid))
1612 return nullptr; 1609 return nullptr;
1613 if (!readWebCoreString(&type)) 1610 if (!readWebCoreString(&type))
1614 return nullptr; 1611 return nullptr;
1615 if (m_version >= 4 && !doReadUint32(&hasSnapshot)) 1612 if (m_version >= 4 && !doReadUint32(&hasSnapshot))
1616 return nullptr; 1613 return nullptr;
1617 if (hasSnapshot) { 1614 if (hasSnapshot) {
1618 if (!doReadUint64(&size)) 1615 if (!doReadUint64(&size))
1619 return nullptr; 1616 return nullptr;
1620 if (!doReadNumber(&lastModifiedMS)) 1617 if (!doReadNumber(&lastModified))
1621 return nullptr; 1618 return nullptr;
1622 if (m_version < 8)
1623 lastModifiedMS *= msPerSecond;
1624 } 1619 }
1625 uint32_t isUserVisible = 1; 1620 uint32_t isUserVisible = 1;
1626 if (m_version >= 7 && !doReadUint32(&isUserVisible)) 1621 if (m_version >= 7 && !doReadUint32(&isUserVisible))
1627 return nullptr; 1622 return nullptr;
1628 const File::UserVisibility userVisibility = (isUserVisible > 0) ? File::IsUs erVisible : File::IsNotUserVisible; 1623 const File::UserVisibility userVisibility = (isUserVisible > 0) ? File::IsUs erVisible : File::IsNotUserVisible;
1629 return File::createFromSerialization(path, name, relativePath, userVisibilit y, hasSnapshot > 0, size, lastModifiedMS, getOrCreateBlobDataHandle(uuid, type)) ; 1624 return File::createFromSerialization(path, name, relativePath, userVisibilit y, hasSnapshot > 0, size, lastModified, getOrCreateBlobDataHandle(uuid, type));
1630 } 1625 }
1631 1626
1632 File* SerializedScriptValueReader::readFileIndexHelper() 1627 File* SerializedScriptValueReader::readFileIndexHelper()
1633 { 1628 {
1634 if (m_version < 3) 1629 if (m_version < 3)
1635 return nullptr; 1630 return nullptr;
1636 ASSERT(m_blobInfo); 1631 ASSERT(m_blobInfo);
1637 uint32_t index; 1632 uint32_t index;
1638 if (!doReadUint32(&index) || index >= m_blobInfo->size()) 1633 if (!doReadUint32(&index) || index >= m_blobInfo->size())
1639 return nullptr; 1634 return nullptr;
1640 const WebBlobInfo& info = (*m_blobInfo)[index]; 1635 const WebBlobInfo& info = (*m_blobInfo)[index];
1641 // FIXME: transition WebBlobInfo.lastModified to be milliseconds-based also. 1636 return File::createFromIndexedSerialization(info.filePath(), info.fileName() , info.size(), info.lastModified(), getOrCreateBlobDataHandle(info.uuid(), info. type(), info.size()));
1642 double lastModifiedMS = info.lastModified() * msPerSecond;
1643 return File::createFromIndexedSerialization(info.filePath(), info.fileName() , info.size(), lastModifiedMS, getOrCreateBlobDataHandle(info.uuid(), info.type( ), info.size()));
1644 } 1637 }
1645 1638
1646 bool SerializedScriptValueReader::doReadUint32(uint32_t* value) 1639 bool SerializedScriptValueReader::doReadUint32(uint32_t* value)
1647 { 1640 {
1648 return doReadUintHelper(value); 1641 return doReadUintHelper(value);
1649 } 1642 }
1650 1643
1651 bool SerializedScriptValueReader::doReadUint64(uint64_t* value) 1644 bool SerializedScriptValueReader::doReadUint64(uint64_t* value)
1652 { 1645 {
1653 return doReadUintHelper(value); 1646 return doReadUintHelper(value);
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1884 return false; 1877 return false;
1885 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe renceStack.size() - 1]; 1878 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe renceStack.size() - 1];
1886 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() - 1); 1879 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() - 1);
1887 if (objectReference >= m_objectPool.size()) 1880 if (objectReference >= m_objectPool.size())
1888 return false; 1881 return false;
1889 *object = m_objectPool[objectReference]; 1882 *object = m_objectPool[objectReference];
1890 return true; 1883 return true;
1891 } 1884 }
1892 1885
1893 } // namespace blink 1886 } // 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