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

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

Issue 2394793002: Resource: helper class to prohibit {add,remove}Client() calls in scope (Closed)
Patch Set: rebase Created 4 years, 2 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 6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
7 rights reserved. 7 rights reserved.
8 8
9 This library is free software; you can redistribute it and/or 9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public 10 modify it under the terms of the GNU Library General Public
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 m_preloadDiscoveryTime(0.0), 309 m_preloadDiscoveryTime(0.0),
310 m_cacheIdentifier(MemoryCache::defaultCacheIdentifier()), 310 m_cacheIdentifier(MemoryCache::defaultCacheIdentifier()),
311 m_preloadResult(PreloadNotReferenced), 311 m_preloadResult(PreloadNotReferenced),
312 m_type(type), 312 m_type(type),
313 m_status(NotStarted), 313 m_status(NotStarted),
314 m_needsSynchronousCacheHit(false), 314 m_needsSynchronousCacheHit(false),
315 m_linkPreload(false), 315 m_linkPreload(false),
316 m_isRevalidating(false), 316 m_isRevalidating(false),
317 m_isAlive(false), 317 m_isAlive(false),
318 m_integrityDisposition(ResourceIntegrityDisposition::NotChecked), 318 m_integrityDisposition(ResourceIntegrityDisposition::NotChecked),
319 m_isAddRemoveClientProhibited(false),
319 m_options(options), 320 m_options(options),
320 m_responseTimestamp(currentTime()), 321 m_responseTimestamp(currentTime()),
321 m_cancelTimer(this, &Resource::cancelTimerFired), 322 m_cancelTimer(this, &Resource::cancelTimerFired),
322 m_resourceRequest(request) { 323 m_resourceRequest(request) {
323 // m_type is a bitfield, so this tests careless updates of the enum. 324 // m_type is a bitfield, so this tests careless updates of the enum.
324 DCHECK_EQ(m_type, unsigned(type)); 325 DCHECK_EQ(m_type, unsigned(type));
325 InstanceCounters::incrementCounter(InstanceCounters::ResourceCounter); 326 InstanceCounters::incrementCounter(InstanceCounters::ResourceCounter);
326 327
327 // Currently we support the metadata caching only for HTTP family. 328 // Currently we support the metadata caching only for HTTP family.
328 if (m_resourceRequest.url().protocolIsInHTTPFamily()) 329 if (m_resourceRequest.url().protocolIsInHTTPFamily())
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 } 701 }
701 } 702 }
702 if (!hasClientsOrObservers()) { 703 if (!hasClientsOrObservers()) {
703 m_isAlive = true; 704 m_isAlive = true;
704 memoryCache()->makeLive(this); 705 memoryCache()->makeLive(this);
705 } 706 }
706 } 707 }
707 708
708 void Resource::addClient(ResourceClient* client, 709 void Resource::addClient(ResourceClient* client,
709 PreloadReferencePolicy policy) { 710 PreloadReferencePolicy policy) {
711 CHECK(!m_isAddRemoveClientProhibited);
712
710 willAddClientOrObserver(policy); 713 willAddClientOrObserver(policy);
711 714
712 if (m_isRevalidating) { 715 if (m_isRevalidating) {
713 m_clients.add(client); 716 m_clients.add(client);
714 return; 717 return;
715 } 718 }
716 719
717 // If we have existing data to send to the new client and the resource type 720 // If we have existing data to send to the new client and the resource type
718 // supprts it, send it asynchronously. 721 // supprts it, send it asynchronously.
719 if (!m_response.isNull() && 722 if (!m_response.isNull() &&
720 !shouldSendCachedDataSynchronouslyForType(getType()) && 723 !shouldSendCachedDataSynchronouslyForType(getType()) &&
721 !m_needsSynchronousCacheHit) { 724 !m_needsSynchronousCacheHit) {
722 m_clientsAwaitingCallback.add(client); 725 m_clientsAwaitingCallback.add(client);
723 ResourceCallback::callbackHandler().schedule(this); 726 ResourceCallback::callbackHandler().schedule(this);
724 return; 727 return;
725 } 728 }
726 729
727 m_clients.add(client); 730 m_clients.add(client);
728 didAddClient(client); 731 didAddClient(client);
729 return; 732 return;
730 } 733 }
731 734
732 void Resource::removeClient(ResourceClient* client) { 735 void Resource::removeClient(ResourceClient* client) {
736 CHECK(!m_isAddRemoveClientProhibited);
737
733 // This code may be called in a pre-finalizer, where weak members in the 738 // This code may be called in a pre-finalizer, where weak members in the
734 // HashCountedSet are already swept out. 739 // HashCountedSet are already swept out.
735 740
736 if (m_finishedClients.contains(client)) 741 if (m_finishedClients.contains(client))
737 m_finishedClients.remove(client); 742 m_finishedClients.remove(client);
738 else if (m_clientsAwaitingCallback.contains(client)) 743 else if (m_clientsAwaitingCallback.contains(client))
739 m_clientsAwaitingCallback.remove(client); 744 m_clientsAwaitingCallback.remove(client);
740 else 745 else
741 m_clients.remove(client); 746 m_clients.remove(client);
742 747
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 case Resource::TextTrack: 1097 case Resource::TextTrack:
1093 case Resource::Media: 1098 case Resource::Media:
1094 case Resource::Manifest: 1099 case Resource::Manifest:
1095 return false; 1100 return false;
1096 } 1101 }
1097 NOTREACHED(); 1102 NOTREACHED();
1098 return false; 1103 return false;
1099 } 1104 }
1100 1105
1101 } // namespace blink 1106 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/Resource.h ('k') | third_party/WebKit/Source/core/fetch/ResourceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698