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

Side by Side 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, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef GIN_MODULES_MODULE_REGISTRY_H_ 5 #ifndef GIN_MODULES_MODULE_REGISTRY_H_
6 #define GIN_MODULES_MODULE_REGISTRY_H_ 6 #define GIN_MODULES_MODULE_REGISTRY_H_
7 7
8 #include <list> 8 #include <list>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <vector>
12 13
13 #include "base/callback.h" 14 #include "base/callback.h"
14 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
15 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
16 #include "gin/gin_export.h" 17 #include "gin/gin_export.h"
17 #include "gin/per_context_data.h" 18 #include "gin/per_context_data.h"
18 19
19 namespace gin { 20 namespace gin {
20 21
21 struct PendingModule; 22 struct GIN_EXPORT PendingModule {
23 PendingModule();
24 ~PendingModule();
25
26 std::string id;
27 std::vector<std::string> dependencies;
28 v8::Persistent<v8::Value> factory;
29
30 private:
31 DISALLOW_COPY_AND_ASSIGN(PendingModule);
32 };
33
34 // ModuleLoader is responsible for registering the necessary bindings for
35 // modules with v8 as well as responding to the bindings (by way of
36 // Load()). Subclasses should invoke the appropriate RegisterGlobals
37 // function. ModuleLoader is owned by the context.
38 class GIN_EXPORT ModuleLoader : public ContextSupplement {
39 public:
40 static ModuleLoader* From(v8::Handle<v8::Context> context);
41
42 // Loads the specified module. Loading need not be synchronous, and often is
43 // not.
44 virtual void Load(v8::Handle<v8::Context> context,
45 scoped_ptr<PendingModule> pending) = 0;
46
47 protected:
48 explicit ModuleLoader(v8::Handle<v8::Context> context);
49 virtual ~ModuleLoader();
50
51 static void RegisterGlobals(v8::Isolate* isolate,
52 v8::Handle<v8::ObjectTemplate> templ);
53 static void RegisterGlobalsObject(v8::Isolate* isolate,
54 v8::Handle<v8::Object> obj);
55
56 private:
57 // From ContextSupplement:
58 virtual void Detach(v8::Handle<v8::Context> context) OVERRIDE;
59
60 DISALLOW_COPY_AND_ASSIGN(ModuleLoader);
61 };
22 62
23 // This class implements the Asynchronous Module Definition (AMD) API. 63 // This class implements the Asynchronous Module Definition (AMD) API.
24 // https://github.com/amdjs/amdjs-api/wiki/AMD 64 // https://github.com/amdjs/amdjs-api/wiki/AMD
25 // 65 //
26 // Our implementation isn't complete yet. Missing features: 66 // Our implementation isn't complete yet. Missing features:
27 // 1) Built-in support for require, exports, and module. 67 // 1) Built-in support for require, exports, and module.
28 // 2) Path resoltuion in module names. 68 // 2) Path resoltuion in module names.
29 // 69 //
30 // For these reasons, we don't have an "amd" property on the "define" 70 // For these reasons, we don't have an "amd" property on the "define"
31 // function. The spec says we should only add that property once our 71 // function. The spec says we should only add that property once our
32 // implementation complies with the specification. 72 // implementation complies with the specification.
33 // 73 //
34 class GIN_EXPORT ModuleRegistry : public ContextSupplement { 74 class GIN_EXPORT ModuleRegistry : public ContextSupplement {
35 public: 75 public:
36 typedef base::Callback<void (v8::Handle<v8::Value>)> LoadModuleCallback; 76 typedef base::Callback<void (v8::Handle<v8::Value>)> LoadModuleCallback;
37 77
38 virtual ~ModuleRegistry(); 78 virtual ~ModuleRegistry();
39 79
40 static ModuleRegistry* From(v8::Handle<v8::Context> context); 80 static ModuleRegistry* From(v8::Handle<v8::Context> context);
41 81
42 static void RegisterGlobals(v8::Isolate* isolate,
43 v8::Handle<v8::ObjectTemplate> templ);
44
45 // The caller must have already entered our context. 82 // The caller must have already entered our context.
46 void AddBuiltinModule(v8::Isolate* isolate, const std::string& id, 83 void AddBuiltinModule(v8::Isolate* isolate, const std::string& id,
47 v8::Handle<v8::Value> module); 84 v8::Handle<v8::Value> module);
48 85
49 // The caller must have already entered our context. 86 // The caller must have already entered our context.
50 void AddPendingModule(v8::Isolate* isolate, 87 void AddPendingModule(v8::Isolate* isolate,
51 scoped_ptr<PendingModule> pending); 88 scoped_ptr<PendingModule> pending);
52 89
53 void LoadModule(v8::Isolate* isolate, 90 void LoadModule(v8::Isolate* isolate,
54 const std::string& id, 91 const std::string& id,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 128
92 PendingModuleVector pending_modules_; 129 PendingModuleVector pending_modules_;
93 v8::Persistent<v8::Object> modules_; 130 v8::Persistent<v8::Object> modules_;
94 131
95 DISALLOW_COPY_AND_ASSIGN(ModuleRegistry); 132 DISALLOW_COPY_AND_ASSIGN(ModuleRegistry);
96 }; 133 };
97 134
98 } // namespace gin 135 } // namespace gin
99 136
100 #endif // GIN_MODULES_MODULE_REGISTRY_H_ 137 #endif // GIN_MODULES_MODULE_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698