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

Unified Diff: extensions/renderer/renderer_extension_registry.h

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 side-by-side diff with in-line comments
Download patch
Index: extensions/renderer/renderer_extension_registry.h
diff --git a/extensions/renderer/renderer_extension_registry.h b/extensions/renderer/renderer_extension_registry.h
new file mode 100644
index 0000000000000000000000000000000000000000..4802875fd5ffcc82760cb79968116752b1a4318a
--- /dev/null
+++ b/extensions/renderer/renderer_extension_registry.h
@@ -0,0 +1,82 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef EXTENSIONS_RENDERER_RENDERER_EXTENSION_REGISTRY_H_
+#define EXTENSIONS_RENDERER_RENDERER_EXTENSION_REGISTRY_H_
+
+#include <iterator>
+#include <string>
+
+#include "base/synchronization/lock.h"
+#include "extensions/common/extension.h"
+#include "extensions/common/extension_set.h"
+#include "url/gurl.h"
+
+namespace extensions {
+
+// Thread safe container for all loaded extensions in this process,
+// essentially the renderer counterpart to ExtensionRegistry.
+class RendererExtensionRegistry {
+ public:
+ RendererExtensionRegistry();
+ ~RendererExtensionRegistry();
+
+ static RendererExtensionRegistry* Get();
+
+ const ExtensionSet* GetMainThreadExtensionSet() const;
Devlin 2015/08/18 15:40:55 This should definitely have a comment, and probabl
annekao 2015/08/18 17:43:31 Done.
+
+ size_t size() const;
+ bool is_empty() const;
+
+ // Iteration support.
+ ExtensionSet::const_iterator begin() const { return extensions_.begin(); }
Devlin 2015/08/18 15:40:55 This is thread-unsafe. If the main thread acquire
annekao 2015/08/18 17:43:31 Done. Used in IsRuntimeAvailableToConnect() and U
+ ExtensionSet::const_iterator end() const { return extensions_.end(); }
+
+ // Returns true if the set contains the specified extension.
+ bool Contains(const std::string& id) const;
Devlin 2015/08/18 15:40:55 I think for these you can (and probably should) ju
annekao 2015/08/18 17:43:31 Done.
+
+ // Adds the specified extension to the set. The set becomes an owner. Any
+ // previous extension with the same ID is removed.
+ // Returns true if there is no previous extension.
+ bool Insert(const scoped_refptr<const Extension>& extension);
+
+ // Removes the specified extension.
+ // Returns true if the set contained the specified extnesion.
+ bool Remove(const std::string& id);
+
+ // Returns the extension ID, or empty if none. This includes web URLs that
+ // are part of an extension's web extent.
+ std::string GetExtensionOrAppIDByURL(const GURL& url) const;
+
+ // Returns the Extension, or NULL if none. This includes web URLs that are
+ // part of an extension's web extent.
+ // NOTE: This can return NULL if called before UpdateExtensions receives
+ // bulk extension data (e.g. if called from
+ // EventBindings::HandleContextCreated)
+ const Extension* GetExtensionOrAppByURL(const GURL& url) const;
+
+ const Extension* GetHostedAppByURL(const GURL& url) const;
+
+ // Look up an Extension object by id.
+ const Extension* GetByID(const std::string& id) const;
+
+ // Gets the IDs of all extensions in the set.
+ ExtensionIdSet GetIDs() const;
+
+ // Returns true if |info| should get extension api bindings and be permitted
+ // to make api calls. Note that this is independent of what extension
+ // permissions the given extension has been granted.
+ bool ExtensionBindingsAllowed(const GURL& url) const;
+
+ private:
+ ExtensionSet extensions_;
+
+ mutable base::Lock lock_;
+
+ DISALLOW_COPY_AND_ASSIGN(RendererExtensionRegistry);
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_RENDERER_RENDERER_EXTENSION_REGISTRY_H_

Powered by Google App Engine
This is Rietveld 408576698