1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_STYLE_SVG_RESOURCE_H_
6 #define THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_STYLE_SVG_RESOURCE_H_
7 
8 #include "base/memory/scoped_refptr.h"
9 #include "third_party/blink/renderer/core/svg/svg_resource.h"
10 #include "third_party/blink/renderer/platform/heap/persistent.h"
11 #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
12 #include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
13 
14 namespace blink {
15 
16 class StyleSVGResource : public RefCounted<StyleSVGResource> {
17   USING_FAST_MALLOC(StyleSVGResource);
18 
19  public:
Create(SVGResource * resource,const AtomicString & url)20   static scoped_refptr<StyleSVGResource> Create(SVGResource* resource,
21                                                 const AtomicString& url) {
22     return base::AdoptRef(new StyleSVGResource(resource, url));
23   }
24 
25   bool operator==(const StyleSVGResource& other) const {
26     return resource_.Get() == other.resource_.Get();
27   }
28 
AddClient(SVGResourceClient & client)29   void AddClient(SVGResourceClient& client) {
30     if (resource_)
31       resource_->AddClient(client);
32   }
RemoveClient(SVGResourceClient & client)33   void RemoveClient(SVGResourceClient& client) {
34     if (resource_)
35       resource_->RemoveClient(client);
36   }
37 
Resource()38   SVGResource* Resource() const { return resource_; }
Url()39   const AtomicString& Url() const { return url_; }
40 
41  private:
StyleSVGResource(SVGResource * resource,const AtomicString & url)42   StyleSVGResource(SVGResource* resource, const AtomicString& url)
43       : resource_(resource), url_(url) {}
44 
45   Persistent<SVGResource> resource_;
46   const AtomicString url_;
47 
48   StyleSVGResource(const StyleSVGResource&) = delete;
49   StyleSVGResource& operator=(const StyleSVGResource&) = delete;
50 };
51 
52 }  // namespace blink
53 
54 #endif  // THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_STYLE_SVG_RESOURCE_H_
55