OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "modules/serviceworkers/ServiceWorkerScriptCachedMetadataHandler.h" |
| 7 |
| 8 #include "core/fetch/CachedMetadata.h" |
| 9 #include "core/workers/WorkerGlobalScope.h" |
| 10 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 ServiceWorkerScriptCachedMetadataHandler::ServiceWorkerScriptCachedMetadataHandl
er(WorkerGlobalScope* workerGlobalScope, const KURL& scriptURL, const Vector<cha
r>* metaData) |
| 15 : m_workerGlobalScope(workerGlobalScope) |
| 16 , m_scriptURL(scriptURL) |
| 17 { |
| 18 if (metaData) |
| 19 m_cachedMetadata = CachedMetadata::deserialize(metaData->data(), metaDat
a->size()); |
| 20 } |
| 21 |
| 22 ServiceWorkerScriptCachedMetadataHandler::~ServiceWorkerScriptCachedMetadataHand
ler() |
| 23 { |
| 24 } |
| 25 |
| 26 void ServiceWorkerScriptCachedMetadataHandler::setCachedMetadata(unsigned dataTy
peID, const char* data, size_t size, CacheType type) |
| 27 { |
| 28 if (type != SendToPlatform) |
| 29 return; |
| 30 m_cachedMetadata = CachedMetadata::create(dataTypeID, data, size); |
| 31 const Vector<char>& serializedData = m_cachedMetadata->serialize(); |
| 32 ServiceWorkerGlobalScopeClient::from(m_workerGlobalScope)->setCachedMetadata
(m_scriptURL, serializedData.data(), serializedData.size()); |
| 33 } |
| 34 |
| 35 void ServiceWorkerScriptCachedMetadataHandler::clearCachedMetadata(CacheType typ
e) |
| 36 { |
| 37 if (type != SendToPlatform) |
| 38 return; |
| 39 m_cachedMetadata = nullptr; |
| 40 ServiceWorkerGlobalScopeClient::from(m_workerGlobalScope)->clearCachedMetada
ta(m_scriptURL); |
| 41 } |
| 42 |
| 43 CachedMetadata* ServiceWorkerScriptCachedMetadataHandler::cachedMetadata(unsigne
d dataTypeID) const |
| 44 { |
| 45 if (!m_cachedMetadata || m_cachedMetadata->dataTypeID() != dataTypeID) |
| 46 return nullptr; |
| 47 return m_cachedMetadata.get(); |
| 48 } |
| 49 |
| 50 String ServiceWorkerScriptCachedMetadataHandler::encoding() const |
| 51 { |
| 52 return emptyString(); |
| 53 } |
| 54 |
| 55 } // namespace blink |
OLD | NEW |