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

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

Issue 2249373002: Make Resource MemoryCoordinatorClient. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added comment 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
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 class Resource::CachedMetadataHandlerImpl : public CachedMetadataHandler { 97 class Resource::CachedMetadataHandlerImpl : public CachedMetadataHandler {
98 public: 98 public:
99 static Resource::CachedMetadataHandlerImpl* create(Resource* resource) 99 static Resource::CachedMetadataHandlerImpl* create(Resource* resource)
100 { 100 {
101 return new CachedMetadataHandlerImpl(resource); 101 return new CachedMetadataHandlerImpl(resource);
102 } 102 }
103 ~CachedMetadataHandlerImpl() override {} 103 ~CachedMetadataHandlerImpl() override {}
104 DECLARE_VIRTUAL_TRACE(); 104 DECLARE_VIRTUAL_TRACE();
105 void setCachedMetadata(unsigned, const char*, size_t, CacheType) override; 105 void setCachedMetadata(unsigned, const char*, size_t, CacheType) override;
106 void clearCachedMetadata(CacheType) override; 106 void clearCachedMetadata(CacheType) override;
107 CachedMetadata* cachedMetadata(unsigned) const override; 107 PassRefPtr<CachedMetadata> cachedMetadata(unsigned) const override;
108 String encoding() const override; 108 String encoding() const override;
109 // Sets the serialized metadata retrieved from the platform's cache. 109 // Sets the serialized metadata retrieved from the platform's cache.
110 void setSerializedCachedMetadata(const char*, size_t); 110 void setSerializedCachedMetadata(const char*, size_t);
111 111
112 protected: 112 protected:
113 explicit CachedMetadataHandlerImpl(Resource*); 113 explicit CachedMetadataHandlerImpl(Resource*);
114 virtual void sendToPlatform(); 114 virtual void sendToPlatform();
115 const ResourceResponse& response() const { return m_resource->response(); } 115 const ResourceResponse& response() const { return m_resource->response(); }
116 116
117 RefPtr<CachedMetadata> m_cachedMetadata; 117 RefPtr<CachedMetadata> m_cachedMetadata;
(...skipping 24 matching lines...) Expand all
142 sendToPlatform(); 142 sendToPlatform();
143 } 143 }
144 144
145 void Resource::CachedMetadataHandlerImpl::clearCachedMetadata(CachedMetadataHand ler::CacheType cacheType) 145 void Resource::CachedMetadataHandlerImpl::clearCachedMetadata(CachedMetadataHand ler::CacheType cacheType)
146 { 146 {
147 m_cachedMetadata.clear(); 147 m_cachedMetadata.clear();
148 if (cacheType == CachedMetadataHandler::SendToPlatform) 148 if (cacheType == CachedMetadataHandler::SendToPlatform)
149 sendToPlatform(); 149 sendToPlatform();
150 } 150 }
151 151
152 CachedMetadata* Resource::CachedMetadataHandlerImpl::cachedMetadata(unsigned dat aTypeID) const 152 PassRefPtr<CachedMetadata> Resource::CachedMetadataHandlerImpl::cachedMetadata(u nsigned dataTypeID) const
153 { 153 {
154 if (!m_cachedMetadata || m_cachedMetadata->dataTypeID() != dataTypeID) 154 if (!m_cachedMetadata || m_cachedMetadata->dataTypeID() != dataTypeID)
155 return nullptr; 155 return nullptr;
156 return m_cachedMetadata.get(); 156 return m_cachedMetadata.get();
hiroshige 2016/08/25 12:48:11 We can remove .get() here.
157 } 157 }
158 158
159 String Resource::CachedMetadataHandlerImpl::encoding() const 159 String Resource::CachedMetadataHandlerImpl::encoding() const
160 { 160 {
161 return m_resource->encoding(); 161 return m_resource->encoding();
162 } 162 }
163 163
164 void Resource::CachedMetadataHandlerImpl::setSerializedCachedMetadata(const char * data, size_t size) 164 void Resource::CachedMetadataHandlerImpl::setSerializedCachedMetadata(const char * data, size_t size)
165 { 165 {
166 // We only expect to receive cached metadata from the platform once. 166 // We only expect to receive cached metadata from the platform once.
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 , m_responseTimestamp(currentTime()) 312 , m_responseTimestamp(currentTime())
313 , m_cancelTimer(this, &Resource::cancelTimerFired) 313 , m_cancelTimer(this, &Resource::cancelTimerFired)
314 , m_resourceRequest(request) 314 , m_resourceRequest(request)
315 { 315 {
316 ASSERT(m_type == unsigned(type)); // m_type is a bitfield, so this tests car eless updates of the enum. 316 ASSERT(m_type == unsigned(type)); // m_type is a bitfield, so this tests car eless updates of the enum.
317 InstanceCounters::incrementCounter(InstanceCounters::ResourceCounter); 317 InstanceCounters::incrementCounter(InstanceCounters::ResourceCounter);
318 318
319 // Currently we support the metadata caching only for HTTP family. 319 // Currently we support the metadata caching only for HTTP family.
320 if (m_resourceRequest.url().protocolIsInHTTPFamily()) 320 if (m_resourceRequest.url().protocolIsInHTTPFamily())
321 m_cacheHandler = CachedMetadataHandlerImpl::create(this); 321 m_cacheHandler = CachedMetadataHandlerImpl::create(this);
322 MemoryCoordinator::instance().registerClient(this);
322 } 323 }
323 324
324 Resource::~Resource() 325 Resource::~Resource()
325 { 326 {
326 InstanceCounters::decrementCounter(InstanceCounters::ResourceCounter); 327 InstanceCounters::decrementCounter(InstanceCounters::ResourceCounter);
327 } 328 }
328 329
329 DEFINE_TRACE(Resource) 330 DEFINE_TRACE(Resource)
330 { 331 {
331 visitor->trace(m_loader); 332 visitor->trace(m_loader);
332 visitor->trace(m_cacheHandler); 333 visitor->trace(m_cacheHandler);
334 MemoryCoordinatorClient::trace(visitor);
333 } 335 }
334 336
335 void Resource::setLoader(ResourceLoader* loader) 337 void Resource::setLoader(ResourceLoader* loader)
336 { 338 {
337 RELEASE_ASSERT(!m_loader); 339 RELEASE_ASSERT(!m_loader);
338 ASSERT(stillNeedsLoad()); 340 ASSERT(stillNeedsLoad());
339 m_loader = loader; 341 m_loader = loader;
340 m_status = Pending; 342 m_status = Pending;
341 } 343 }
342 344
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 805
804 // Prevent the case when there are clients waiting but no callback scheduled . 806 // Prevent the case when there are clients waiting but no callback scheduled .
805 ASSERT(m_clientsAwaitingCallback.isEmpty() || scheduled); 807 ASSERT(m_clientsAwaitingCallback.isEmpty() || scheduled);
806 } 808 }
807 809
808 void Resource::prune() 810 void Resource::prune()
809 { 811 {
810 destroyDecodedDataIfPossible(); 812 destroyDecodedDataIfPossible();
811 } 813 }
812 814
815 void Resource::prepareToSuspend()
816 {
817 prune();
818 if (!m_cacheHandler)
819 return;
820 m_cacheHandler->clearCachedMetadata(CachedMetadataHandler::CacheLocally);
821 }
822
813 void Resource::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfDetail, WebProcess MemoryDump* memoryDump) const 823 void Resource::onMemoryDump(WebMemoryDumpLevelOfDetail levelOfDetail, WebProcess MemoryDump* memoryDump) const
814 { 824 {
815 static const size_t kMaxURLReportLength = 128; 825 static const size_t kMaxURLReportLength = 128;
816 static const int kMaxResourceClientToShowInMemoryInfra = 10; 826 static const int kMaxResourceClientToShowInMemoryInfra = 10;
817 827
818 const String dumpName = getMemoryDumpName(); 828 const String dumpName = getMemoryDumpName();
819 WebMemoryAllocatorDump* dump = memoryDump->createMemoryAllocatorDump(dumpNam e); 829 WebMemoryAllocatorDump* dump = memoryDump->createMemoryAllocatorDump(dumpNam e);
820 dump->addScalar("encoded_size", "bytes", m_encodedSize); 830 dump->addScalar("encoded_size", "bytes", m_encodedSize);
821 if (hasClientsOrObservers()) 831 if (hasClientsOrObservers())
822 dump->addScalar("live_size", "bytes", m_encodedSize); 832 dump->addScalar("live_size", "bytes", m_encodedSize);
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 case Resource::TextTrack: 1059 case Resource::TextTrack:
1050 case Resource::Media: 1060 case Resource::Media:
1051 case Resource::Manifest: 1061 case Resource::Manifest:
1052 return false; 1062 return false;
1053 } 1063 }
1054 ASSERT_NOT_REACHED(); 1064 ASSERT_NOT_REACHED();
1055 return false; 1065 return false;
1056 } 1066 }
1057 1067
1058 } // namespace blink 1068 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698