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

Unified Diff: third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp

Issue 1481383002: [Experimental] CSSSerializer Proof-of-concept Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: snapshot: top_25 sites ser/dser now works Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp
diff --git a/third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp b/third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp
index f1abd0c675da5e5b73784664ad5d8da3541490e3..31cdc1e01a3efbd8b6d9e1a65c160be8a47ead28 100644
--- a/third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp
+++ b/third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.cpp
@@ -27,11 +27,15 @@
#include "core/fetch/CSSStyleSheetResource.h"
#include "core/css/StyleSheetContents.h"
+#include "core/css/serializer/CSSDeserializeStream.h"
+#include "core/css/serializer/CSSSerializeStream.h"
+#include "core/fetch/CachedMetadata.h"
#include "core/fetch/FetchRequest.h"
#include "core/fetch/ResourceClientWalker.h"
#include "core/fetch/ResourceFetcher.h"
#include "core/fetch/StyleSheetResourceClient.h"
#include "platform/SharedBuffer.h"
+#include "platform/TraceEvent.h"
#include "platform/network/HTTPParsers.h"
#include "wtf/CurrentTime.h"
@@ -150,10 +154,35 @@ bool CSSStyleSheetResource::canUseSheet(MIMETypeCheck mimeTypeCheck) const
return mimeType().isEmpty() || equalIgnoringCase(mimeType(), "text/css") || equalIgnoringCase(mimeType(), "application/x-unknown-content-type");
}
+PassRefPtrWillBeRawPtr<StyleSheetContents> CSSStyleSheetResource::deserializeStyleSheet(const CSSParserContext& context)
+{
+ TRACE_EVENT0("blink", "CSSStyleSheetResource::deserializeStyleSheet");
+ auto handler = cacheHandler();
+ if (!handler)
+ return nullptr;
+
+ unsigned cacheTag = 1; // wtf?
+ CachedMetadata* cachedMetadata = handler->cachedMetadata(cacheTag);
+ if (!cachedMetadata)
+ return nullptr;
+
+ CSDEBUG("found cachedMetadata: %zu\n", cachedMetadata->size());
+
+ RefPtrWillBeRawPtr<StyleSheetContents> sheet;
+ // for (unsigned i = 0; i < 10000; ++ i)
+ {
+ sheet = StyleSheetContents::create(m_response.url(), context);
+ CSSDeserializeStream stream(cachedMetadata->data(), cachedMetadata->size());
+ sheet->deserialize(&stream);
+ }
+
+ return sheet.release();
+}
+
PassRefPtrWillBeRawPtr<StyleSheetContents> CSSStyleSheetResource::restoreParsedStyleSheet(const CSSParserContext& context)
{
if (!m_parsedStyleSheetCache)
- return nullptr;
+ return deserializeStyleSheet(context);
if (m_parsedStyleSheetCache->hasFailedOrCanceledSubresources()) {
m_parsedStyleSheetCache->removedFromMemoryCache();
m_parsedStyleSheetCache.clear();
@@ -176,12 +205,35 @@ void CSSStyleSheetResource::saveParsedStyleSheet(PassRefPtrWillBeRawPtr<StyleShe
{
ASSERT(sheet && sheet->isCacheable());
+#if 0
if (m_parsedStyleSheetCache)
m_parsedStyleSheetCache->removedFromMemoryCache();
m_parsedStyleSheetCache = sheet;
m_parsedStyleSheetCache->addedToMemoryCache();
setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes());
+#else
+ RefPtr<StyleSheetContents> parsedStyleSheet = sheet;
+
+ if (auto handler = cacheHandler()) {
+ TRACE_EVENT0("blink", "CSSStyleSheetResource::serializeStyleSheet");
+ CSSSerializeStream stream;
+ parsedStyleSheet->serialize(&stream);
+ CSDEBUG("serialized size: %zu\n", stream.data().size());
+
+ handler->clearCachedMetadata(CachedMetadataHandler::SendToPlatform);
+ unsigned cacheTag = 1; // wtf?
+ handler->setCachedMetadata(cacheTag, stream.data().data(), stream.data().size(), CachedMetadataHandler::SendToPlatform);
+
+ /*
+ FILE* fp = fopen("/usr/local/google/home/kouhei/cssserdestest/cssblob", "w");
+ fwrite(stream.data().data(), stream.data().size(), 1, fp);
+ fclose(fp);
+ */
+ } else {
+ CSDEBUG("no cacheHandler!\n");
+ }
+#endif
}
}
« no previous file with comments | « third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.h ('k') | third_party/WebKit/Source/core/fetch/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698