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

Side by Side Diff: extensions/renderer/renderer_extension_registry.cc

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

Powered by Google App Engine
This is Rietveld 408576698