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

Side by Side Diff: third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerScriptCachedMetadataHandler.cpp

Issue 2258743002: Reserve Vector's capacity manually in CachedMetadata (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 3 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
« no previous file with comments | « third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerScriptCachedMetadataHandler.h ('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 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 "modules/serviceworkers/ServiceWorkerScriptCachedMetadataHandler.h" 5 #include "modules/serviceworkers/ServiceWorkerScriptCachedMetadataHandler.h"
6 6
7 #include "core/fetch/CachedMetadata.h" 7 #include "core/fetch/CachedMetadata.h"
8 #include "core/workers/WorkerGlobalScope.h" 8 #include "core/workers/WorkerGlobalScope.h"
9 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" 9 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h"
10 10
11 namespace blink { 11 namespace blink {
12 12
13 ServiceWorkerScriptCachedMetadataHandler::ServiceWorkerScriptCachedMetadataHandl er(WorkerGlobalScope* workerGlobalScope, const KURL& scriptURL, const Vector<cha r>* metaData) 13 ServiceWorkerScriptCachedMetadataHandler::ServiceWorkerScriptCachedMetadataHandl er(WorkerGlobalScope* workerGlobalScope, const KURL& scriptURL, const Vector<cha r>* metaData)
14 : m_workerGlobalScope(workerGlobalScope) 14 : m_workerGlobalScope(workerGlobalScope)
15 , m_scriptURL(scriptURL) 15 , m_scriptURL(scriptURL)
16 { 16 {
17 if (metaData) 17 if (metaData)
18 m_cachedMetadata = CachedMetadata::deserialize(metaData->data(), metaDat a->size()); 18 m_cachedMetadata = CachedMetadata::createFromSerializedData(metaData->da ta(), metaData->size());
19 } 19 }
20 20
21 ServiceWorkerScriptCachedMetadataHandler::~ServiceWorkerScriptCachedMetadataHand ler() 21 ServiceWorkerScriptCachedMetadataHandler::~ServiceWorkerScriptCachedMetadataHand ler()
22 { 22 {
23 } 23 }
24 24
25 DEFINE_TRACE(ServiceWorkerScriptCachedMetadataHandler) 25 DEFINE_TRACE(ServiceWorkerScriptCachedMetadataHandler)
26 { 26 {
27 visitor->trace(m_workerGlobalScope); 27 visitor->trace(m_workerGlobalScope);
28 CachedMetadataHandler::trace(visitor); 28 CachedMetadataHandler::trace(visitor);
29 } 29 }
30 30
31 void ServiceWorkerScriptCachedMetadataHandler::setCachedMetadata(unsigned dataTy peID, const char* data, size_t size, CacheType type) 31 void ServiceWorkerScriptCachedMetadataHandler::setCachedMetadata(uint32_t dataTy peID, const char* data, size_t size, CacheType type)
32 { 32 {
33 if (type != SendToPlatform) 33 if (type != SendToPlatform)
34 return; 34 return;
35 m_cachedMetadata = CachedMetadata::create(dataTypeID, data, size); 35 m_cachedMetadata = CachedMetadata::create(dataTypeID, data, size);
36 const Vector<char>& serializedData = m_cachedMetadata->serialize(); 36 const Vector<char>& serializedData = m_cachedMetadata->serializedData();
37 ServiceWorkerGlobalScopeClient::from(m_workerGlobalScope)->setCachedMetadata (m_scriptURL, serializedData.data(), serializedData.size()); 37 ServiceWorkerGlobalScopeClient::from(m_workerGlobalScope)->setCachedMetadata (m_scriptURL, serializedData.data(), serializedData.size());
38 } 38 }
39 39
40 void ServiceWorkerScriptCachedMetadataHandler::clearCachedMetadata(CacheType typ e) 40 void ServiceWorkerScriptCachedMetadataHandler::clearCachedMetadata(CacheType typ e)
41 { 41 {
42 if (type != SendToPlatform) 42 if (type != SendToPlatform)
43 return; 43 return;
44 m_cachedMetadata = nullptr; 44 m_cachedMetadata = nullptr;
45 ServiceWorkerGlobalScopeClient::from(m_workerGlobalScope)->clearCachedMetada ta(m_scriptURL); 45 ServiceWorkerGlobalScopeClient::from(m_workerGlobalScope)->clearCachedMetada ta(m_scriptURL);
46 } 46 }
47 47
48 PassRefPtr<CachedMetadata> ServiceWorkerScriptCachedMetadataHandler::cachedMetad ata(unsigned dataTypeID) const 48 PassRefPtr<CachedMetadata> ServiceWorkerScriptCachedMetadataHandler::cachedMetad ata(uint32_t dataTypeID) const
49 { 49 {
50 if (!m_cachedMetadata || m_cachedMetadata->dataTypeID() != dataTypeID) 50 if (!m_cachedMetadata || m_cachedMetadata->dataTypeID() != dataTypeID)
51 return nullptr; 51 return nullptr;
52 return m_cachedMetadata.get(); 52 return m_cachedMetadata.get();
53 } 53 }
54 54
55 String ServiceWorkerScriptCachedMetadataHandler::encoding() const 55 String ServiceWorkerScriptCachedMetadataHandler::encoding() const
56 { 56 {
57 return emptyString(); 57 return emptyString();
58 } 58 }
59 59
60 } // namespace blink 60 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerScriptCachedMetadataHandler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698