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

Side by Side Diff: Source/bindings/v8/SerializedScriptValue.cpp

Issue 325383002: Snapshot File metadata when serializing for IDB (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Try a safer approach Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « LayoutTests/storage/indexeddb/blob-basics-metadata.html ('k') | no next file » | 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) 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 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 1303
1304 StateBase* writeFile(v8::Handle<v8::Value> value, StateBase* next) 1304 StateBase* writeFile(v8::Handle<v8::Value> value, StateBase* next)
1305 { 1305 {
1306 File* file = V8File::toNative(value.As<v8::Object>()); 1306 File* file = V8File::toNative(value.As<v8::Object>());
1307 if (!file) 1307 if (!file)
1308 return 0; 1308 return 0;
1309 if (file->hasBeenClosed()) 1309 if (file->hasBeenClosed())
1310 return handleError(DataCloneError, "A File object has been closed, a nd could therefore not be cloned.", next); 1310 return handleError(DataCloneError, "A File object has been closed, a nd could therefore not be cloned.", next);
1311 int blobIndex = -1; 1311 int blobIndex = -1;
1312 m_blobDataHandles.add(file->uuid(), file->blobDataHandle()); 1312 m_blobDataHandles.add(file->uuid(), file->blobDataHandle());
1313 if (appendFileInfo(file->uuid(), file->path(), file->name(), file->type( ), &blobIndex)) { 1313 if (appendFileInfo(file, &blobIndex)) {
1314 ASSERT(blobIndex >= 0); 1314 ASSERT(blobIndex >= 0);
1315 m_writer.writeFileIndex(blobIndex); 1315 m_writer.writeFileIndex(blobIndex);
1316 } else { 1316 } else {
1317 m_writer.writeFile(*file); 1317 m_writer.writeFile(*file);
1318 } 1318 }
1319 return 0; 1319 return 0;
1320 } 1320 }
1321 1321
1322 StateBase* writeFileList(v8::Handle<v8::Value> value, StateBase* next) 1322 StateBase* writeFileList(v8::Handle<v8::Value> value, StateBase* next)
1323 { 1323 {
1324 FileList* fileList = V8FileList::toNative(value.As<v8::Object>()); 1324 FileList* fileList = V8FileList::toNative(value.As<v8::Object>());
1325 if (!fileList) 1325 if (!fileList)
1326 return 0; 1326 return 0;
1327 unsigned length = fileList->length(); 1327 unsigned length = fileList->length();
1328 Vector<int> blobIndices; 1328 Vector<int> blobIndices;
1329 for (unsigned i = 0; i < length; ++i) { 1329 for (unsigned i = 0; i < length; ++i) {
1330 int blobIndex = -1; 1330 int blobIndex = -1;
1331 const File* file = fileList->item(i); 1331 const File* file = fileList->item(i);
1332 if (file->hasBeenClosed()) 1332 if (file->hasBeenClosed())
1333 return handleError(DataCloneError, "A File object has been close d, and could therefore not be cloned.", next); 1333 return handleError(DataCloneError, "A File object has been close d, and could therefore not be cloned.", next);
1334 m_blobDataHandles.add(file->uuid(), file->blobDataHandle()); 1334 m_blobDataHandles.add(file->uuid(), file->blobDataHandle());
1335 if (appendFileInfo(file->uuid(), file->path(), file->name(), file->t ype(), &blobIndex)) { 1335 if (appendFileInfo(file, &blobIndex)) {
1336 ASSERT(!i || blobIndex > 0); 1336 ASSERT(!i || blobIndex > 0);
1337 ASSERT(blobIndex >= 0); 1337 ASSERT(blobIndex >= 0);
1338 blobIndices.append(blobIndex); 1338 blobIndices.append(blobIndex);
1339 } 1339 }
1340 } 1340 }
1341 if (!blobIndices.isEmpty()) 1341 if (!blobIndices.isEmpty())
1342 m_writer.writeFileListIndex(blobIndices); 1342 m_writer.writeFileListIndex(blobIndices);
1343 else 1343 else
1344 m_writer.writeFileList(*fileList); 1344 m_writer.writeFileList(*fileList);
1345 return 0; 1345 return 0;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1463 1463
1464 bool appendBlobInfo(const String& uuid, const String& type, unsigned long lo ng size, int* index) 1464 bool appendBlobInfo(const String& uuid, const String& type, unsigned long lo ng size, int* index)
1465 { 1465 {
1466 if (!m_blobInfo) 1466 if (!m_blobInfo)
1467 return false; 1467 return false;
1468 *index = m_blobInfo->size(); 1468 *index = m_blobInfo->size();
1469 m_blobInfo->append(blink::WebBlobInfo(uuid, type, size)); 1469 m_blobInfo->append(blink::WebBlobInfo(uuid, type, size));
1470 return true; 1470 return true;
1471 } 1471 }
1472 1472
1473 bool appendFileInfo(const String& uuid, const String& filePath, const String & fileName, const String& type, int* index) 1473 bool appendFileInfo(const File* file, int* index)
1474 { 1474 {
1475 if (!m_blobInfo) 1475 if (!m_blobInfo)
1476 return false; 1476 return false;
1477
1478 long long size = -1;
1479 double lastModified = invalidFileTime();
1480 file->captureSnapshot(size, lastModified);
1477 *index = m_blobInfo->size(); 1481 *index = m_blobInfo->size();
1478 m_blobInfo->append(blink::WebBlobInfo(uuid, filePath, fileName, type)); 1482 m_blobInfo->append(blink::WebBlobInfo(file->uuid(), file->path(), file-> name(), file->type(), lastModified, size));
1479 return true; 1483 return true;
1480 } 1484 }
1481 1485
1482 RefPtr<ScriptState> m_scriptState; 1486 RefPtr<ScriptState> m_scriptState;
1483 Writer& m_writer; 1487 Writer& m_writer;
1484 v8::TryCatch& m_tryCatch; 1488 v8::TryCatch& m_tryCatch;
1485 int m_depth; 1489 int m_depth;
1486 Status m_status; 1490 Status m_status;
1487 String m_errorMessage; 1491 String m_errorMessage;
1488 typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool; 1492 typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool;
(...skipping 1560 matching lines...) Expand 10 before | Expand all | Expand 10 after
3049 // If the allocated memory was not registered before, then this class is lik ely 3053 // If the allocated memory was not registered before, then this class is lik ely
3050 // used in a context other then Worker's onmessage environment and the prese nce of 3054 // used in a context other then Worker's onmessage environment and the prese nce of
3051 // current v8 context is not guaranteed. Avoid calling v8 then. 3055 // current v8 context is not guaranteed. Avoid calling v8 then.
3052 if (m_externallyAllocatedMemory) { 3056 if (m_externallyAllocatedMemory) {
3053 ASSERT(v8::Isolate::GetCurrent()); 3057 ASSERT(v8::Isolate::GetCurrent());
3054 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory); 3058 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory);
3055 } 3059 }
3056 } 3060 }
3057 3061
3058 } // namespace WebCore 3062 } // namespace WebCore
OLDNEW
« no previous file with comments | « LayoutTests/storage/indexeddb/blob-basics-metadata.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698