OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 #include "extensions/renderer/renderer_extension_registry.h" |
| 6 |
| 7 #include "base/lazy_instance.h" |
| 8 #include "base/logging.h" |
| 9 #include "content/public/renderer/render_thread.h" |
| 10 |
| 11 namespace extensions { |
| 12 |
| 13 namespace { |
| 14 |
| 15 base::LazyInstance<RendererExtensionRegistry> g_renderer_extension_registry = |
| 16 LAZY_INSTANCE_INITIALIZER; |
| 17 |
| 18 } // namespace |
| 19 |
| 20 RendererExtensionRegistry::RendererExtensionRegistry() {} |
| 21 |
| 22 RendererExtensionRegistry::~RendererExtensionRegistry() {} |
| 23 |
| 24 // static |
| 25 RendererExtensionRegistry* RendererExtensionRegistry::Get() { |
| 26 return g_renderer_extension_registry.Pointer(); |
| 27 } |
| 28 |
| 29 const ExtensionSet* RendererExtensionRegistry::GetMainThreadExtensionSet() |
| 30 const { |
| 31 // This can only be modified on the RenderThread, because |
| 32 // GetMainThreadExtensionSet is inherently thread unsafe. |
| 33 // Enforcing single-thread modification at least mitigates this. |
| 34 // TODO(annekao): Remove this restriction once GetMainThreadExtensionSet is |
| 35 // fixed. |
| 36 DCHECK(content::RenderThread::Get()); |
| 37 base::AutoLock lock(lock_); |
| 38 return &extensions_; |
| 39 } |
| 40 |
| 41 size_t RendererExtensionRegistry::size() const { |
| 42 base::AutoLock lock(lock_); |
| 43 return extensions_.size(); |
| 44 } |
| 45 |
| 46 bool RendererExtensionRegistry::is_empty() const { |
| 47 base::AutoLock lock(lock_); |
| 48 return extensions_.is_empty(); |
| 49 } |
| 50 |
| 51 bool RendererExtensionRegistry::Contains( |
| 52 const std::string& extension_id) const { |
| 53 base::AutoLock lock(lock_); |
| 54 return extensions_.Contains(extension_id); |
| 55 } |
| 56 |
| 57 bool RendererExtensionRegistry::Insert( |
| 58 const scoped_refptr<const Extension>& extension) { |
| 59 DCHECK(content::RenderThread::Get()); |
| 60 base::AutoLock lock(lock_); |
| 61 return extensions_.Insert(extension); |
| 62 } |
| 63 |
| 64 bool RendererExtensionRegistry::Remove(const std::string& id) { |
| 65 DCHECK(content::RenderThread::Get()); |
| 66 base::AutoLock lock(lock_); |
| 67 return extensions_.Remove(id); |
| 68 } |
| 69 |
| 70 std::string RendererExtensionRegistry::GetExtensionOrAppIDByURL( |
| 71 const GURL& url) const { |
| 72 base::AutoLock lock(lock_); |
| 73 return extensions_.GetExtensionOrAppIDByURL(url); |
| 74 } |
| 75 |
| 76 const Extension* RendererExtensionRegistry::GetExtensionOrAppByURL( |
| 77 const GURL& url) const { |
| 78 base::AutoLock lock(lock_); |
| 79 return extensions_.GetExtensionOrAppByURL(url); |
| 80 } |
| 81 |
| 82 const Extension* RendererExtensionRegistry::GetHostedAppByURL( |
| 83 const GURL& url) const { |
| 84 base::AutoLock lock(lock_); |
| 85 return extensions_.GetHostedAppByURL(url); |
| 86 } |
| 87 |
| 88 const Extension* RendererExtensionRegistry::GetByID( |
| 89 const std::string& id) const { |
| 90 base::AutoLock lock(lock_); |
| 91 return extensions_.GetByID(id); |
| 92 } |
| 93 |
| 94 ExtensionIdSet RendererExtensionRegistry::GetIDs() const { |
| 95 base::AutoLock lock(lock_); |
| 96 return extensions_.GetIDs(); |
| 97 } |
| 98 |
| 99 bool RendererExtensionRegistry::ExtensionBindingsAllowed( |
| 100 const GURL& url) const { |
| 101 base::AutoLock lock(lock_); |
| 102 return extensions_.ExtensionBindingsAllowed(url); |
| 103 } |
| 104 |
| 105 } // namespace extensions |
OLD | NEW |