| Index: third_party/WebKit/Source/core/layout/svg/SVGResourcesCache.cpp | 
| diff --git a/third_party/WebKit/Source/core/layout/svg/SVGResourcesCache.cpp b/third_party/WebKit/Source/core/layout/svg/SVGResourcesCache.cpp | 
| index dc9cdff976402988c24be236fe841681199c2aaf..d0a4d7d881c4b72d254c3c915d5fd9be6f1973c1 100644 | 
| --- a/third_party/WebKit/Source/core/layout/svg/SVGResourcesCache.cpp | 
| +++ b/third_party/WebKit/Source/core/layout/svg/SVGResourcesCache.cpp | 
| @@ -70,8 +70,13 @@ void SVGResourcesCache::RemoveResourcesFromLayoutObject(LayoutObject* object) { | 
| HashSet<LayoutSVGResourceContainer*> resource_set; | 
| resources->BuildSetOfResources(resource_set); | 
|  | 
| +  bool did_empty_client_set = false; | 
| for (auto* resource_container : resource_set) | 
| -    resource_container->RemoveClient(object); | 
| +    did_empty_client_set |= resource_container->RemoveClient(object); | 
| + | 
| +  // Remove any registrations that became empty after the above. | 
| +  if (did_empty_client_set) | 
| +    SVGResources::RemoveUnreferencedResources(*object); | 
| } | 
|  | 
| static inline SVGResourcesCache& ResourcesCache(Document& document) { | 
| @@ -150,6 +155,26 @@ void SVGResourcesCache::ClientStyleChanged(LayoutObject* layout_object, | 
| layout_object, needs_layout); | 
| } | 
|  | 
| +void SVGResourcesCache::ResourceReferenceChanged(LayoutObject& layout_object) { | 
| +  DCHECK(layout_object.IsSVG()); | 
| +  DCHECK(layout_object.GetNode()); | 
| +  DCHECK(layout_object.GetNode()->IsSVGElement()); | 
| + | 
| +  if (!layout_object.Parent()) | 
| +    return; | 
| + | 
| +  // Only LayoutObjects that can actually have resources should be pending and | 
| +  // hence be able to call this method. | 
| +  DCHECK(LayoutObjectCanHaveResources(&layout_object)); | 
| + | 
| +  SVGResourcesCache& cache = ResourcesCache(layout_object.GetDocument()); | 
| +  cache.RemoveResourcesFromLayoutObject(&layout_object); | 
| +  cache.AddResourcesFromLayoutObject(&layout_object, layout_object.StyleRef()); | 
| + | 
| +  LayoutSVGResourceContainer::MarkForLayoutAndParentResourceInvalidation( | 
| +      &layout_object, true); | 
| +} | 
| + | 
| void SVGResourcesCache::ClientWasAddedToTree(LayoutObject* layout_object, | 
| const ComputedStyle& new_style) { | 
| if (!layout_object->GetNode()) | 
|  |