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

Unified Diff: gin/modules/module_registry.cc

Issue 373973003: Gin: Allow multiple callers to wait for the same module in ModuleRegistry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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
« no previous file with comments | « gin/modules/module_registry.h ('k') | gin/modules/module_registry_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gin/modules/module_registry.cc
diff --git a/gin/modules/module_registry.cc b/gin/modules/module_registry.cc
index 3712f1a41ac79fe29a33fcfadd73ee4a2d52ed42..cfb5291c0df4fc7bc006e9e98b018b65ad095540 100644
--- a/gin/modules/module_registry.cc
+++ b/gin/modules/module_registry.cc
@@ -167,9 +167,7 @@ void ModuleRegistry::LoadModule(Isolate* isolate,
callback.Run(GetModule(isolate, id));
return;
}
- // Should we support multiple callers waiting on the same module?
- DCHECK(waiting_callbacks_.find(id) == waiting_callbacks_.end());
- waiting_callbacks_[id] = callback;
+ waiting_callbacks_.insert(std::make_pair(id, callback));
unsatisfied_dependencies_.insert(id);
}
@@ -184,13 +182,20 @@ void ModuleRegistry::RegisterModule(Isolate* isolate,
v8::Handle<Object> modules = Local<Object>::New(isolate, modules_);
modules->Set(StringToSymbol(isolate, id), module);
- LoadModuleCallbackMap::iterator it = waiting_callbacks_.find(id);
- if (it == waiting_callbacks_.end())
- return;
- LoadModuleCallback callback = it->second;
- waiting_callbacks_.erase(it);
- // Should we call the callback asynchronously?
- callback.Run(module);
+ std::pair<LoadModuleCallbackMap::iterator, LoadModuleCallbackMap::iterator>
+ range = waiting_callbacks_.equal_range(id);
+ std::vector<LoadModuleCallback> callbacks;
abarth-chromium 2014/07/08 14:20:30 Can you preallocate the correct number of slots in
Sam McNally 2014/07/09 00:22:51 Done.
+ for (LoadModuleCallbackMap::iterator it = range.first; it != range.second;
+ ++it) {
+ callbacks.push_back(it->second);
+ }
+ waiting_callbacks_.erase(range.first, range.second);
+ for (std::vector<LoadModuleCallback>::iterator it = callbacks.begin();
+ it != callbacks.end();
+ ++it) {
+ // Should we call the callback asynchronously?
+ it->Run(module);
+ }
}
bool ModuleRegistry::CheckDependencies(PendingModule* pending) {
« no previous file with comments | « gin/modules/module_registry.h ('k') | gin/modules/module_registry_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698