| OLD | NEW |
| 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 <memory> |
| 10 #include <set> | 11 #include <set> |
| 11 #include <string> | 12 #include <string> |
| 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/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/memory/scoped_ptr.h" | |
| 17 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
| 18 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
| 19 #include "gin/gin_export.h" | 19 #include "gin/gin_export.h" |
| 20 #include "v8/include/v8.h" | 20 #include "v8/include/v8.h" |
| 21 | 21 |
| 22 namespace gin { | 22 namespace gin { |
| 23 | 23 |
| 24 class ModuleRegistryObserver; | 24 class ModuleRegistryObserver; |
| 25 struct PendingModule; | 25 struct PendingModule; |
| 26 | 26 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 52 | 52 |
| 53 void AddObserver(ModuleRegistryObserver* observer); | 53 void AddObserver(ModuleRegistryObserver* observer); |
| 54 void RemoveObserver(ModuleRegistryObserver* observer); | 54 void RemoveObserver(ModuleRegistryObserver* observer); |
| 55 | 55 |
| 56 // The caller must have already entered our context. | 56 // The caller must have already entered our context. |
| 57 void AddBuiltinModule(v8::Isolate* isolate, const std::string& id, | 57 void AddBuiltinModule(v8::Isolate* isolate, const std::string& id, |
| 58 v8::Local<v8::Value> module); | 58 v8::Local<v8::Value> module); |
| 59 | 59 |
| 60 // The caller must have already entered our context. | 60 // The caller must have already entered our context. |
| 61 void AddPendingModule(v8::Isolate* isolate, | 61 void AddPendingModule(v8::Isolate* isolate, |
| 62 scoped_ptr<PendingModule> pending); | 62 std::unique_ptr<PendingModule> pending); |
| 63 | 63 |
| 64 void LoadModule(v8::Isolate* isolate, | 64 void LoadModule(v8::Isolate* isolate, |
| 65 const std::string& id, | 65 const std::string& id, |
| 66 LoadModuleCallback callback); | 66 LoadModuleCallback callback); |
| 67 | 67 |
| 68 // The caller must have already entered our context. | 68 // The caller must have already entered our context. |
| 69 void AttemptToLoadMoreModules(v8::Isolate* isolate); | 69 void AttemptToLoadMoreModules(v8::Isolate* isolate); |
| 70 | 70 |
| 71 const std::set<std::string>& available_modules() const { | 71 const std::set<std::string>& available_modules() const { |
| 72 return available_modules_; | 72 return available_modules_; |
| 73 } | 73 } |
| 74 | 74 |
| 75 const std::set<std::string>& unsatisfied_dependencies() const { | 75 const std::set<std::string>& unsatisfied_dependencies() const { |
| 76 return unsatisfied_dependencies_; | 76 return unsatisfied_dependencies_; |
| 77 } | 77 } |
| 78 | 78 |
| 79 private: | 79 private: |
| 80 typedef ScopedVector<PendingModule> PendingModuleVector; | 80 typedef ScopedVector<PendingModule> PendingModuleVector; |
| 81 typedef std::multimap<std::string, LoadModuleCallback> LoadModuleCallbackMap; | 81 typedef std::multimap<std::string, LoadModuleCallback> LoadModuleCallbackMap; |
| 82 | 82 |
| 83 explicit ModuleRegistry(v8::Isolate* isolate); | 83 explicit ModuleRegistry(v8::Isolate* isolate); |
| 84 | 84 |
| 85 bool Load(v8::Isolate* isolate, scoped_ptr<PendingModule> pending); | 85 bool Load(v8::Isolate* isolate, std::unique_ptr<PendingModule> pending); |
| 86 bool RegisterModule(v8::Isolate* isolate, | 86 bool RegisterModule(v8::Isolate* isolate, |
| 87 const std::string& id, | 87 const std::string& id, |
| 88 v8::Local<v8::Value> module); | 88 v8::Local<v8::Value> module); |
| 89 | 89 |
| 90 bool CheckDependencies(PendingModule* pending); | 90 bool CheckDependencies(PendingModule* pending); |
| 91 bool AttemptToLoad(v8::Isolate* isolate, scoped_ptr<PendingModule> pending); | 91 bool AttemptToLoad(v8::Isolate* isolate, |
| 92 std::unique_ptr<PendingModule> pending); |
| 92 | 93 |
| 93 v8::Local<v8::Value> GetModule(v8::Isolate* isolate, const std::string& id); | 94 v8::Local<v8::Value> GetModule(v8::Isolate* isolate, const std::string& id); |
| 94 | 95 |
| 95 std::set<std::string> available_modules_; | 96 std::set<std::string> available_modules_; |
| 96 std::set<std::string> unsatisfied_dependencies_; | 97 std::set<std::string> unsatisfied_dependencies_; |
| 97 | 98 |
| 98 LoadModuleCallbackMap waiting_callbacks_; | 99 LoadModuleCallbackMap waiting_callbacks_; |
| 99 | 100 |
| 100 PendingModuleVector pending_modules_; | 101 PendingModuleVector pending_modules_; |
| 101 v8::Persistent<v8::Object> modules_; | 102 v8::Persistent<v8::Object> modules_; |
| 102 | 103 |
| 103 base::ObserverList<ModuleRegistryObserver> observer_list_; | 104 base::ObserverList<ModuleRegistryObserver> observer_list_; |
| 104 | 105 |
| 105 DISALLOW_COPY_AND_ASSIGN(ModuleRegistry); | 106 DISALLOW_COPY_AND_ASSIGN(ModuleRegistry); |
| 106 }; | 107 }; |
| 107 | 108 |
| 108 } // namespace gin | 109 } // namespace gin |
| 109 | 110 |
| 110 #endif // GIN_MODULES_MODULE_REGISTRY_H_ | 111 #endif // GIN_MODULES_MODULE_REGISTRY_H_ |
| OLD | NEW |