| 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 #include "gin/modules/module_registry.h" | 5 #include "gin/modules/module_registry.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 161 |
| 162 void ModuleRegistry::LoadModule(Isolate* isolate, | 162 void ModuleRegistry::LoadModule(Isolate* isolate, |
| 163 const std::string& id, | 163 const std::string& id, |
| 164 LoadModuleCallback callback) { | 164 LoadModuleCallback callback) { |
| 165 if (available_modules_.find(id) != available_modules_.end()) { | 165 if (available_modules_.find(id) != available_modules_.end()) { |
| 166 // Should we call the callback asynchronously? | 166 // Should we call the callback asynchronously? |
| 167 callback.Run(GetModule(isolate, id)); | 167 callback.Run(GetModule(isolate, id)); |
| 168 return; | 168 return; |
| 169 } | 169 } |
| 170 waiting_callbacks_.insert(std::make_pair(id, callback)); | 170 waiting_callbacks_.insert(std::make_pair(id, callback)); |
| 171 |
| 172 for (size_t i = 0; i < pending_modules_.size(); ++i) { |
| 173 if (pending_modules_[i]->id == id) |
| 174 return; |
| 175 } |
| 176 |
| 171 unsatisfied_dependencies_.insert(id); | 177 unsatisfied_dependencies_.insert(id); |
| 172 } | 178 } |
| 173 | 179 |
| 174 void ModuleRegistry::RegisterModule(Isolate* isolate, | 180 void ModuleRegistry::RegisterModule(Isolate* isolate, |
| 175 const std::string& id, | 181 const std::string& id, |
| 176 v8::Handle<Value> module) { | 182 v8::Handle<Value> module) { |
| 177 if (id.empty() || module.IsEmpty()) | 183 if (id.empty() || module.IsEmpty()) |
| 178 return; | 184 return; |
| 179 | 185 |
| 180 unsatisfied_dependencies_.erase(id); | 186 unsatisfied_dependencies_.erase(id); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 for (size_t i = 0; i < pending_modules.size(); ++i) { | 270 for (size_t i = 0; i < pending_modules.size(); ++i) { |
| 265 scoped_ptr<PendingModule> pending(pending_modules[i]); | 271 scoped_ptr<PendingModule> pending(pending_modules[i]); |
| 266 pending_modules[i] = NULL; | 272 pending_modules[i] = NULL; |
| 267 if (AttemptToLoad(isolate, pending.Pass())) | 273 if (AttemptToLoad(isolate, pending.Pass())) |
| 268 keep_trying = true; | 274 keep_trying = true; |
| 269 } | 275 } |
| 270 } | 276 } |
| 271 } | 277 } |
| 272 | 278 |
| 273 } // namespace gin | 279 } // namespace gin |
| OLD | NEW |