Remove linux_chromium_gn_dbg from the chromium CQ.
[chromium-blink-merge.git] / extensions / renderer / renderer_extension_registry.cc
blobddc3a1b89f31f89dc6174b7de27b756acb79c293
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.
5 #include "extensions/renderer/renderer_extension_registry.h"
7 #include "base/lazy_instance.h"
8 #include "base/logging.h"
9 #include "content/public/renderer/render_thread.h"
11 namespace extensions {
13 namespace {
15 base::LazyInstance<RendererExtensionRegistry> g_renderer_extension_registry =
16 LAZY_INSTANCE_INITIALIZER;
18 } // namespace
20 RendererExtensionRegistry::RendererExtensionRegistry() {}
22 RendererExtensionRegistry::~RendererExtensionRegistry() {}
24 // static
25 RendererExtensionRegistry* RendererExtensionRegistry::Get() {
26 return g_renderer_extension_registry.Pointer();
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_;
41 size_t RendererExtensionRegistry::size() const {
42 base::AutoLock lock(lock_);
43 return extensions_.size();
46 bool RendererExtensionRegistry::is_empty() const {
47 base::AutoLock lock(lock_);
48 return extensions_.is_empty();
51 bool RendererExtensionRegistry::Contains(
52 const std::string& extension_id) const {
53 base::AutoLock lock(lock_);
54 return extensions_.Contains(extension_id);
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);
64 bool RendererExtensionRegistry::Remove(const std::string& id) {
65 DCHECK(content::RenderThread::Get());
66 base::AutoLock lock(lock_);
67 return extensions_.Remove(id);
70 std::string RendererExtensionRegistry::GetExtensionOrAppIDByURL(
71 const GURL& url) const {
72 base::AutoLock lock(lock_);
73 return extensions_.GetExtensionOrAppIDByURL(url);
76 const Extension* RendererExtensionRegistry::GetExtensionOrAppByURL(
77 const GURL& url) const {
78 base::AutoLock lock(lock_);
79 return extensions_.GetExtensionOrAppByURL(url);
82 const Extension* RendererExtensionRegistry::GetHostedAppByURL(
83 const GURL& url) const {
84 base::AutoLock lock(lock_);
85 return extensions_.GetHostedAppByURL(url);
88 const Extension* RendererExtensionRegistry::GetByID(
89 const std::string& id) const {
90 base::AutoLock lock(lock_);
91 return extensions_.GetByID(id);
94 ExtensionIdSet RendererExtensionRegistry::GetIDs() const {
95 base::AutoLock lock(lock_);
96 return extensions_.GetIDs();
99 bool RendererExtensionRegistry::ExtensionBindingsAllowed(
100 const GURL& url) const {
101 base::AutoLock lock(lock_);
102 return extensions_.ExtensionBindingsAllowed(url);
105 } // namespace extensions