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

Unified Diff: gin/modules/module_registry.h

Issue 179803007: Refactors parts of gin: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge 2 trunk Created 6 years, 10 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: gin/modules/module_registry.h
diff --git a/gin/modules/module_registry.h b/gin/modules/module_registry.h
index 755875c3539dc9290d456b42bcb51553febe08b8..6eac9b03a8f4e38d440699c5989b34f01fd480f6 100644
--- a/gin/modules/module_registry.h
+++ b/gin/modules/module_registry.h
@@ -9,6 +9,7 @@
#include <map>
#include <set>
#include <string>
+#include <vector>
#include "base/callback.h"
#include "base/compiler_specific.h"
@@ -18,7 +19,46 @@
namespace gin {
-struct PendingModule;
+struct GIN_EXPORT PendingModule {
+ PendingModule();
+ ~PendingModule();
+
+ std::string id;
+ std::vector<std::string> dependencies;
+ v8::Persistent<v8::Value> factory;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PendingModule);
+};
+
+// ModuleLoader is responsible for registering the necessary bindings for
+// modules with v8 as well as responding to the bindings (by way of
+// Load()). Subclasses should invoke the appropriate RegisterGlobals
+// function. ModuleLoader is owned by the context.
+class GIN_EXPORT ModuleLoader : public ContextSupplement {
+ public:
+ static ModuleLoader* From(v8::Handle<v8::Context> context);
+
+ // Loads the specified module. Loading need not be synchronous, and often is
+ // not.
+ virtual void Load(v8::Handle<v8::Context> context,
+ scoped_ptr<PendingModule> pending) = 0;
+
+ protected:
+ explicit ModuleLoader(v8::Handle<v8::Context> context);
+ virtual ~ModuleLoader();
+
+ static void RegisterGlobals(v8::Isolate* isolate,
+ v8::Handle<v8::ObjectTemplate> templ);
+ static void RegisterGlobalsObject(v8::Isolate* isolate,
+ v8::Handle<v8::Object> obj);
+
+ private:
+ // From ContextSupplement:
+ virtual void Detach(v8::Handle<v8::Context> context) OVERRIDE;
+
+ DISALLOW_COPY_AND_ASSIGN(ModuleLoader);
+};
// This class implements the Asynchronous Module Definition (AMD) API.
// https://github.com/amdjs/amdjs-api/wiki/AMD
@@ -39,9 +79,6 @@ class GIN_EXPORT ModuleRegistry : public ContextSupplement {
static ModuleRegistry* From(v8::Handle<v8::Context> context);
- static void RegisterGlobals(v8::Isolate* isolate,
- v8::Handle<v8::ObjectTemplate> templ);
-
// The caller must have already entered our context.
void AddBuiltinModule(v8::Isolate* isolate, const std::string& id,
v8::Handle<v8::Value> module);

Powered by Google App Engine
This is Rietveld 408576698