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

Side by Side Diff: Source/core/fetch/Resource.cpp

Issue 929953002: CachedMetadata support for ServiceWorker script. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: incorporated tkent'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 unified diff | Download patch
« no previous file with comments | « Source/core/fetch/Resource.h ('k') | Source/core/fetch/ResourceTest.cpp » ('j') | 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) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 for (size_t i = 0; i < WTF_ARRAY_LENGTH(headerPrefixesToIgnoreAfterRevalidat ion); i++) { 89 for (size_t i = 0; i < WTF_ARRAY_LENGTH(headerPrefixesToIgnoreAfterRevalidat ion); i++) {
90 if (header.startsWith(headerPrefixesToIgnoreAfterRevalidation[i], false) ) 90 if (header.startsWith(headerPrefixesToIgnoreAfterRevalidation[i], false) )
91 return false; 91 return false;
92 } 92 }
93 return true; 93 return true;
94 } 94 }
95 95
96 DEFINE_DEBUG_ONLY_GLOBAL(RefCountedLeakCounter, cachedResourceLeakCounter, ("Res ource")); 96 DEFINE_DEBUG_ONLY_GLOBAL(RefCountedLeakCounter, cachedResourceLeakCounter, ("Res ource"));
97 unsigned Resource::s_instanceCount = 0; 97 unsigned Resource::s_instanceCount = 0;
98 98
99 class Resource::CacheHandler : public CachedMetadataHandler {
100 public:
101 static PassOwnPtr<CacheHandler> create(Resource* resource)
102 {
103 return adoptPtr(new CacheHandler(resource));
104 }
105 ~CacheHandler() override { }
106 void setCachedMetadata(unsigned, const char*, size_t, CacheType) override;
107 void clearCachedMetadata(CacheType) override;
108 CachedMetadata* cachedMetadata(unsigned) const override;
109 String encoding() const override;
110
111 private:
112 explicit CacheHandler(Resource*);
113 Resource* m_resource;
114 };
115
116 Resource::CacheHandler::CacheHandler(Resource* resource)
117 : m_resource(resource)
118 {
119 }
120
121 void Resource::CacheHandler::setCachedMetadata(unsigned dataTypeID, const char* data, size_t size, CacheType type)
122 {
123 m_resource->setCachedMetadata(dataTypeID, data, size, type);
124 }
125
126 void Resource::CacheHandler::clearCachedMetadata(CacheType type)
127 {
128 m_resource->clearCachedMetadata(type);
129 }
130
131 CachedMetadata* Resource::CacheHandler::cachedMetadata(unsigned dataTypeID) cons t
132 {
133 return m_resource->cachedMetadata(dataTypeID);
134 }
135
136 String Resource::CacheHandler::encoding() const
137 {
138 return m_resource->encoding();
139 }
140
99 Resource::Resource(const ResourceRequest& request, Type type) 141 Resource::Resource(const ResourceRequest& request, Type type)
100 : m_resourceRequest(request) 142 : m_resourceRequest(request)
101 , m_responseTimestamp(currentTime()) 143 , m_responseTimestamp(currentTime())
102 , m_cancelTimer(this, &Resource::cancelTimerFired) 144 , m_cancelTimer(this, &Resource::cancelTimerFired)
103 , m_loadFinishTime(0) 145 , m_loadFinishTime(0)
104 , m_identifier(0) 146 , m_identifier(0)
105 , m_encodedSize(0) 147 , m_encodedSize(0)
106 , m_decodedSize(0) 148 , m_decodedSize(0)
107 , m_handleCount(0) 149 , m_handleCount(0)
108 , m_preloadCount(0) 150 , m_preloadCount(0)
(...skipping 13 matching lines...) Expand all
122 , m_resourceToRevalidate(nullptr) 164 , m_resourceToRevalidate(nullptr)
123 , m_proxyResource(nullptr) 165 , m_proxyResource(nullptr)
124 { 166 {
125 ASSERT(m_type == unsigned(type)); // m_type is a bitfield, so this tests car eless updates of the enum. 167 ASSERT(m_type == unsigned(type)); // m_type is a bitfield, so this tests car eless updates of the enum.
126 ++s_instanceCount; 168 ++s_instanceCount;
127 #ifndef NDEBUG 169 #ifndef NDEBUG
128 cachedResourceLeakCounter.increment(); 170 cachedResourceLeakCounter.increment();
129 #endif 171 #endif
130 memoryCache()->registerLiveResource(*this); 172 memoryCache()->registerLiveResource(*this);
131 173
174 // Currently we support the metadata caching only for HTTP family.
175 if (m_resourceRequest.url().protocolIsInHTTPFamily())
176 m_cacheHandler = CacheHandler::create(this);
177
132 if (!m_resourceRequest.url().hasFragmentIdentifier()) 178 if (!m_resourceRequest.url().hasFragmentIdentifier())
133 return; 179 return;
134 KURL urlForCache = MemoryCache::removeFragmentIdentifierIfNeeded(m_resourceR equest.url()); 180 KURL urlForCache = MemoryCache::removeFragmentIdentifierIfNeeded(m_resourceR equest.url());
135 if (urlForCache.hasFragmentIdentifier()) 181 if (urlForCache.hasFragmentIdentifier())
136 return; 182 return;
137 m_fragmentIdentifierForRequest = m_resourceRequest.url().fragmentIdentifier( ); 183 m_fragmentIdentifierForRequest = m_resourceRequest.url().fragmentIdentifier( );
138 m_resourceRequest.setURL(urlForCache); 184 m_resourceRequest.setURL(urlForCache);
139 } 185 }
140 186
141 Resource::~Resource() 187 Resource::~Resource()
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 { 459 {
414 // We only expect to receive cached metadata from the platform once. 460 // We only expect to receive cached metadata from the platform once.
415 // If this triggers, it indicates an efficiency problem which is most 461 // If this triggers, it indicates an efficiency problem which is most
416 // likely unexpected in code designed to improve performance. 462 // likely unexpected in code designed to improve performance.
417 ASSERT(!m_cachedMetadata); 463 ASSERT(!m_cachedMetadata);
418 ASSERT(!m_resourceToRevalidate); 464 ASSERT(!m_resourceToRevalidate);
419 465
420 m_cachedMetadata = CachedMetadata::deserialize(data, size); 466 m_cachedMetadata = CachedMetadata::deserialize(data, size);
421 } 467 }
422 468
423 void Resource::setCachedMetadata(unsigned dataTypeID, const char* data, size_t s ize, MetadataCacheType cacheType) 469 CachedMetadataHandler* Resource::cacheHandler()
470 {
471 return m_cacheHandler.get();
472 }
473
474 void Resource::setCachedMetadata(unsigned dataTypeID, const char* data, size_t s ize, CachedMetadataHandler::CacheType cacheType)
424 { 475 {
425 // Currently, only one type of cached metadata per resource is supported. 476 // Currently, only one type of cached metadata per resource is supported.
426 // If the need arises for multiple types of metadata per resource this could 477 // If the need arises for multiple types of metadata per resource this could
427 // be enhanced to store types of metadata in a map. 478 // be enhanced to store types of metadata in a map.
428 ASSERT(!m_cachedMetadata); 479 ASSERT(!m_cachedMetadata);
429 480
430 m_cachedMetadata = CachedMetadata::create(dataTypeID, data, size); 481 m_cachedMetadata = CachedMetadata::create(dataTypeID, data, size);
431 482
432 // We don't support sending the metadata to the platform when the response 483 // We don't support sending the metadata to the platform when the response
433 // was fetched via a ServiceWorker to prevent an attacker's Service Worker 484 // was fetched via a ServiceWorker to prevent an attacker's Service Worker
434 // from poisoning the metadata cache. 485 // from poisoning the metadata cache.
435 // FIXME: Support sending the metadata even if the response was fetched via 486 // FIXME: Support sending the metadata even if the response was fetched via
436 // a ServiceWorker. https://crbug.com/448706 487 // a ServiceWorker. https://crbug.com/448706
437 if (cacheType == SendToPlatform && !m_response.wasFetchedViaServiceWorker()) { 488 if (cacheType == CachedMetadataHandler::SendToPlatform && !m_response.wasFet chedViaServiceWorker()) {
438 const Vector<char>& serializedData = m_cachedMetadata->serialize(); 489 const Vector<char>& serializedData = m_cachedMetadata->serialize();
439 blink::Platform::current()->cacheMetadata(m_response.url(), m_response.r esponseTime(), serializedData.data(), serializedData.size()); 490 blink::Platform::current()->cacheMetadata(m_response.url(), m_response.r esponseTime(), serializedData.data(), serializedData.size());
440 } 491 }
441 } 492 }
442 493
443 void Resource::clearCachedMetadata(MetadataCacheType cacheType) 494 void Resource::clearCachedMetadata(CachedMetadataHandler::CacheType cacheType)
444 { 495 {
445 m_cachedMetadata.clear(); 496 m_cachedMetadata.clear();
446 497
447 if (cacheType == SendToPlatform) 498 if (cacheType == CachedMetadataHandler::SendToPlatform)
448 blink::Platform::current()->cacheMetadata(m_response.url(), m_response.r esponseTime(), 0, 0); 499 blink::Platform::current()->cacheMetadata(m_response.url(), m_response.r esponseTime(), 0, 0);
449 } 500 }
450 501
451 bool Resource::canDelete() const 502 bool Resource::canDelete() const
452 { 503 {
453 return !hasClients() && !m_loader && !m_preloadCount && hasRightHandleCountA partFromCache(0) 504 return !hasClients() && !m_loader && !m_preloadCount && hasRightHandleCountA partFromCache(0)
454 && !m_protectorCount && !m_resourceToRevalidate && !m_proxyResource; 505 && !m_protectorCount && !m_resourceToRevalidate && !m_proxyResource;
455 } 506 }
456 507
457 bool Resource::hasOneHandle() const 508 bool Resource::hasOneHandle() const
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 return "ImportResource"; 1073 return "ImportResource";
1023 case Resource::Media: 1074 case Resource::Media:
1024 return "Media"; 1075 return "Media";
1025 } 1076 }
1026 ASSERT_NOT_REACHED(); 1077 ASSERT_NOT_REACHED();
1027 return "Unknown"; 1078 return "Unknown";
1028 } 1079 }
1029 #endif // !LOG_DISABLED 1080 #endif // !LOG_DISABLED
1030 1081
1031 } 1082 }
OLDNEW
« no previous file with comments | « Source/core/fetch/Resource.h ('k') | Source/core/fetch/ResourceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698