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

Unified Diff: Source/core/workers/WorkerScriptCachedMetadataHandler.cpp

Issue 929953002: CachedMetadata support for ServiceWorker script. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: incorporated kinuko's comment 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/workers/WorkerScriptCachedMetadataHandler.cpp
diff --git a/Source/core/workers/WorkerScriptCachedMetadataHandler.cpp b/Source/core/workers/WorkerScriptCachedMetadataHandler.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..7c445d8f7235fdcbc6744a99e793a636581de50b
--- /dev/null
+++ b/Source/core/workers/WorkerScriptCachedMetadataHandler.cpp
@@ -0,0 +1,55 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+
+#include "core/workers/WorkerScriptCachedMetadataHandler.h"
+
+#include "core/fetch/CachedMetadata.h"
+#include "core/workers/WorkerGlobalScope.h"
+
+namespace blink {
+
+WorkerScriptCachedMetadataHandler::WorkerScriptCachedMetadataHandler(WorkerGlobalScope* workerGlobalScope, const KURL& scriptURL, const Vector<char>* metaData)
+ : m_workerGlobalScope(workerGlobalScope)
+ , m_scriptURL(scriptURL)
+{
+ if (metaData)
+ m_cachedMetadata = CachedMetadata::deserialize(metaData->data(), metaData->size());
+}
+
+WorkerScriptCachedMetadataHandler::~WorkerScriptCachedMetadataHandler()
+{
+}
+
+void WorkerScriptCachedMetadataHandler::setCachedMetadata(unsigned dataTypeID, const char* data, size_t size, CacheType type)
+{
+ if (type != SendToPlatform)
+ return;
+ m_cachedMetadata = CachedMetadata::create(dataTypeID, data, size);
+ const Vector<char>& serializedData = m_cachedMetadata->serialize();
+ m_workerGlobalScope->setCachedMetadata(m_scriptURL, serializedData.data(), serializedData.size());
+}
+
+void WorkerScriptCachedMetadataHandler::clearCachedMetadata(CacheType type)
+{
+ if (type != SendToPlatform)
+ return;
+ m_cachedMetadata = nullptr;
+ m_workerGlobalScope->clearCachedMetadata(m_scriptURL);
+}
+
+CachedMetadata* WorkerScriptCachedMetadataHandler::cachedMetadata(unsigned dataTypeID) const
+{
+ if (!m_cachedMetadata || m_cachedMetadata->dataTypeID() != dataTypeID)
+ return nullptr;
+ return m_cachedMetadata.get();
+}
+
+String WorkerScriptCachedMetadataHandler::encoding() const
+{
+ return "";
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698