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

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

Issue 1915833002: Introduce Platform::cacheMetadataInCacheStorage() to store V8 code cache in CacheStorage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 7 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
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 23 matching lines...) Expand all
34 #include "core/inspector/InspectorInstrumentation.h" 34 #include "core/inspector/InspectorInstrumentation.h"
35 #include "core/inspector/InstanceCounters.h" 35 #include "core/inspector/InstanceCounters.h"
36 #include "platform/Logging.h" 36 #include "platform/Logging.h"
37 #include "platform/SharedBuffer.h" 37 #include "platform/SharedBuffer.h"
38 #include "platform/TraceEvent.h" 38 #include "platform/TraceEvent.h"
39 #include "platform/network/HTTPParsers.h" 39 #include "platform/network/HTTPParsers.h"
40 #include "platform/weborigin/KURL.h" 40 #include "platform/weborigin/KURL.h"
41 #include "public/platform/Platform.h" 41 #include "public/platform/Platform.h"
42 #include "public/platform/WebProcessMemoryDump.h" 42 #include "public/platform/WebProcessMemoryDump.h"
43 #include "public/platform/WebScheduler.h" 43 #include "public/platform/WebScheduler.h"
44 #include "public/platform/WebSecurityOrigin.h"
44 #include "wtf/CurrentTime.h" 45 #include "wtf/CurrentTime.h"
45 #include "wtf/MathExtras.h" 46 #include "wtf/MathExtras.h"
46 #include "wtf/StdLibExtras.h" 47 #include "wtf/StdLibExtras.h"
47 #include "wtf/Vector.h" 48 #include "wtf/Vector.h"
48 #include "wtf/WeakPtr.h" 49 #include "wtf/WeakPtr.h"
49 #include "wtf/text/CString.h" 50 #include "wtf/text/CString.h"
50 #include <algorithm> 51 #include <algorithm>
51 52
52 namespace blink { 53 namespace blink {
53 54
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 static CacheHandler* create(Resource* resource) 99 static CacheHandler* create(Resource* resource)
99 { 100 {
100 return new CacheHandler(resource); 101 return new CacheHandler(resource);
101 } 102 }
102 ~CacheHandler() override { } 103 ~CacheHandler() override { }
103 DECLARE_VIRTUAL_TRACE(); 104 DECLARE_VIRTUAL_TRACE();
104 void setCachedMetadata(unsigned, const char*, size_t, CacheType) override; 105 void setCachedMetadata(unsigned, const char*, size_t, CacheType) override;
105 void clearCachedMetadata(CacheType) override; 106 void clearCachedMetadata(CacheType) override;
106 CachedMetadata* cachedMetadata(unsigned) const override; 107 CachedMetadata* cachedMetadata(unsigned) const override;
107 String encoding() const override; 108 String encoding() const override;
109 bool shouldAggressivelyCache() const override;
108 110
109 private: 111 private:
110 explicit CacheHandler(Resource*); 112 explicit CacheHandler(Resource*);
111 Member<Resource> m_resource; 113 Member<Resource> m_resource;
112 }; 114 };
113 115
114 Resource::CacheHandler::CacheHandler(Resource* resource) 116 Resource::CacheHandler::CacheHandler(Resource* resource)
115 : m_resource(resource) 117 : m_resource(resource)
116 { 118 {
117 } 119 }
(...skipping 17 matching lines...) Expand all
135 CachedMetadata* Resource::CacheHandler::cachedMetadata(unsigned dataTypeID) cons t 137 CachedMetadata* Resource::CacheHandler::cachedMetadata(unsigned dataTypeID) cons t
136 { 138 {
137 return m_resource->cachedMetadata(dataTypeID); 139 return m_resource->cachedMetadata(dataTypeID);
138 } 140 }
139 141
140 String Resource::CacheHandler::encoding() const 142 String Resource::CacheHandler::encoding() const
141 { 143 {
142 return m_resource->encoding(); 144 return m_resource->encoding();
143 } 145 }
144 146
147 bool Resource::CacheHandler::shouldAggressivelyCache() const
148 {
149 return m_resource->shouldAggressivelyCacheMetadata();
150 }
151
145 class Resource::ResourceCallback final : public GarbageCollectedFinalized<Resour ceCallback> { 152 class Resource::ResourceCallback final : public GarbageCollectedFinalized<Resour ceCallback> {
146 public: 153 public:
147 static ResourceCallback& callbackHandler(); 154 static ResourceCallback& callbackHandler();
148 DECLARE_TRACE(); 155 DECLARE_TRACE();
149 void schedule(Resource*); 156 void schedule(Resource*);
150 void cancel(Resource*); 157 void cancel(Resource*);
151 bool isScheduled(Resource*) const; 158 bool isScheduled(Resource*) const;
152 private: 159 private:
153 ResourceCallback(); 160 ResourceCallback();
154 161
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 return; 266 return;
260 267
261 RELEASE_ASSERT(!m_loader); 268 RELEASE_ASSERT(!m_loader);
262 ASSERT(stillNeedsLoad()); 269 ASSERT(stillNeedsLoad());
263 m_status = Pending; 270 m_status = Pending;
264 271
265 ResourceRequest& request(m_revalidatingRequest.isNull() ? m_resourceRequest : m_revalidatingRequest); 272 ResourceRequest& request(m_revalidatingRequest.isNull() ? m_resourceRequest : m_revalidatingRequest);
266 KURL url = request.url(); 273 KURL url = request.url();
267 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC redentials); 274 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC redentials);
268 275
276 m_fetcherSecurityOrigin = fetcher->context().getSecurityOrigin();
269 m_loader = ResourceLoader::create(fetcher, this); 277 m_loader = ResourceLoader::create(fetcher, this);
270 m_loader->start(request); 278 m_loader->start(request);
271 // If the request reference is null (i.e., a synchronous revalidation will 279 // If the request reference is null (i.e., a synchronous revalidation will
272 // null the request), don't make the request non-null by setting the url. 280 // null the request), don't make the request non-null by setting the url.
273 if (!request.isNull()) 281 if (!request.isNull())
274 request.setURL(url); 282 request.setURL(url);
275 } 283 }
276 284
277 void Resource::checkNotify() 285 void Resource::checkNotify()
278 { 286 {
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 // be enhanced to store types of metadata in a map. 535 // be enhanced to store types of metadata in a map.
528 ASSERT(!m_cachedMetadata); 536 ASSERT(!m_cachedMetadata);
529 537
530 m_cachedMetadata = CachedMetadata::create(dataTypeID, data, size); 538 m_cachedMetadata = CachedMetadata::create(dataTypeID, data, size);
531 539
532 // We don't support sending the metadata to the platform when the response 540 // We don't support sending the metadata to the platform when the response
533 // was fetched via a ServiceWorker to prevent an attacker's Service Worker 541 // was fetched via a ServiceWorker to prevent an attacker's Service Worker
534 // from poisoning the metadata cache. 542 // from poisoning the metadata cache.
535 // FIXME: Support sending the metadata even if the response was fetched via 543 // FIXME: Support sending the metadata even if the response was fetched via
536 // a ServiceWorker. https://crbug.com/448706 544 // a ServiceWorker. https://crbug.com/448706
537 if (cacheType == CachedMetadataHandler::SendToPlatform && !m_response.wasFet chedViaServiceWorker()) { 545 if (cacheType == CachedMetadataHandler::SendToPlatform) {
538 const Vector<char>& serializedData = m_cachedMetadata->serialize(); 546 if (cacheMetadataSendToPlatformDisabled())
539 Platform::current()->cacheMetadata(m_response.url(), m_response.response Time(), serializedData.data(), serializedData.size()); 547 return;
548
549 if (!m_response.wasFetchedViaServiceWorker()) {
550 const Vector<char>& serializedData = m_cachedMetadata->serialize();
551 Platform::current()->cacheMetadata(m_response.url(), m_response.resp onseTime(), serializedData.data(), serializedData.size());
552 } else if (!m_response.cacheStorageCacheName().isNull()) {
553 const Vector<char>& serializedData = m_cachedMetadata->serialize();
554 Platform::current()->cacheMetadataInCacheStorage(m_response.url(), m _response.responseTime(), serializedData.data(), serializedData.size(), WebSecur ityOrigin(m_fetcherSecurityOrigin), m_response.cacheStorageCacheName());
555 }
540 } 556 }
541 } 557 }
542 558
543 void Resource::clearCachedMetadata(CachedMetadataHandler::CacheType cacheType) 559 void Resource::clearCachedMetadata(CachedMetadataHandler::CacheType cacheType)
544 { 560 {
545 m_cachedMetadata.clear(); 561 m_cachedMetadata.clear();
546 562
547 if (cacheType == CachedMetadataHandler::SendToPlatform) 563 if (cacheType == CachedMetadataHandler::SendToPlatform) {
548 Platform::current()->cacheMetadata(m_response.url(), m_response.response Time(), 0, 0); 564 if (!m_response.wasFetchedViaServiceWorker()) {
565 Platform::current()->cacheMetadata(m_response.url(), m_response.resp onseTime(), 0, 0);
566 } else if (!m_response.cacheStorageCacheName().isNull()) {
567 Platform::current()->cacheMetadataInCacheStorage(m_response.url(), m _response.responseTime(), 0, 0, WebSecurityOrigin(m_fetcherSecurityOrigin), m_re sponse.cacheStorageCacheName());
568 }
569 }
549 } 570 }
550 571
551 String Resource::reasonNotDeletable() const 572 String Resource::reasonNotDeletable() const
552 { 573 {
553 StringBuilder builder; 574 StringBuilder builder;
554 if (hasClientsOrObservers()) { 575 if (hasClientsOrObservers()) {
555 builder.append("hasClients("); 576 builder.append("hasClients(");
556 builder.appendNumber(m_clients.size()); 577 builder.appendNumber(m_clients.size());
557 if (!m_clientsAwaitingCallback.isEmpty()) { 578 if (!m_clientsAwaitingCallback.isEmpty()) {
558 builder.append(", AwaitingCallback="); 579 builder.append(", AwaitingCallback=");
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 case Resource::Media: 1096 case Resource::Media:
1076 return "Media"; 1097 return "Media";
1077 case Resource::Manifest: 1098 case Resource::Manifest:
1078 return "Manifest"; 1099 return "Manifest";
1079 } 1100 }
1080 ASSERT_NOT_REACHED(); 1101 ASSERT_NOT_REACHED();
1081 return "Unknown"; 1102 return "Unknown";
1082 } 1103 }
1083 1104
1084 } // namespace blink 1105 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698