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

Side by Side Diff: gin/modules/module_runner_delegate.cc

Issue 401723002: Mojo: Log an error when we fail to find a JS module. (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 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 #include "gin/modules/module_runner_delegate.h" 5 #include "gin/modules/module_runner_delegate.h"
6 6
7 #include "gin/modules/module_registry.h" 7 #include "gin/modules/module_registry.h"
8 #include "gin/object_template_builder.h" 8 #include "gin/object_template_builder.h"
9 #include "gin/public/context_holder.h" 9 #include "gin/public/context_holder.h"
10 10
11 namespace gin { 11 namespace gin {
12 12
13 ModuleRunnerDelegate::ModuleRunnerDelegate( 13 ModuleRunnerDelegate::ModuleRunnerDelegate(
14 const std::vector<base::FilePath>& search_paths) 14 const std::vector<base::FilePath>& search_paths)
15 : module_provider_(search_paths) { 15 : module_provider_(search_paths) {
16 module_provider_.set_completion_callback(
17 base::Bind(&ModuleRunnerDelegate::DidLoadFileModules,
18 base::Unretained(this)));
16 } 19 }
17 20
18 ModuleRunnerDelegate::~ModuleRunnerDelegate() { 21 ModuleRunnerDelegate::~ModuleRunnerDelegate() {
22 module_provider_.reset_completion_callback();
19 } 23 }
20 24
21 void ModuleRunnerDelegate::AddBuiltinModule(const std::string& id, 25 void ModuleRunnerDelegate::AddBuiltinModule(const std::string& id,
22 ModuleGetter getter) { 26 ModuleGetter getter) {
23 builtin_modules_[id] = getter; 27 builtin_modules_[id] = getter;
24 } 28 }
25 29
26 void ModuleRunnerDelegate::AttemptToLoadMoreModules(Runner* runner) { 30 void ModuleRunnerDelegate::AttemptToLoadMoreModules(Runner* runner) {
27 ModuleRegistry* registry = ModuleRegistry::From( 31 ModuleRegistry* registry = ModuleRegistry::From(
28 runner->GetContextHolder()->context()); 32 runner->GetContextHolder()->context());
29 registry->AttemptToLoadMoreModules(runner->GetContextHolder()->isolate()); 33 registry->AttemptToLoadMoreModules(runner->GetContextHolder()->isolate());
30 module_provider_.AttempToLoadModules( 34 unsatisfied_dependencies_ = registry->unsatisfied_dependencies();
31 runner, registry->unsatisfied_dependencies()); 35 module_provider_.AttemptToLoadModules(runner, unsatisfied_dependencies_);
32 } 36 }
33 37
34 v8::Handle<v8::ObjectTemplate> ModuleRunnerDelegate::GetGlobalTemplate( 38 v8::Handle<v8::ObjectTemplate> ModuleRunnerDelegate::GetGlobalTemplate(
35 ShellRunner* runner, 39 ShellRunner* runner,
36 v8::Isolate* isolate) { 40 v8::Isolate* isolate) {
37 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplateBuilder(isolate).Build(); 41 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplateBuilder(isolate).Build();
38 ModuleRegistry::RegisterGlobals(isolate, templ); 42 ModuleRegistry::RegisterGlobals(isolate, templ);
39 return templ; 43 return templ;
40 } 44 }
41 45
42 void ModuleRunnerDelegate::DidCreateContext(ShellRunner* runner) { 46 void ModuleRunnerDelegate::DidCreateContext(ShellRunner* runner) {
43 ShellRunnerDelegate::DidCreateContext(runner); 47 ShellRunnerDelegate::DidCreateContext(runner);
44 48
45 v8::Handle<v8::Context> context = runner->GetContextHolder()->context(); 49 v8::Handle<v8::Context> context = runner->GetContextHolder()->context();
46 ModuleRegistry* registry = ModuleRegistry::From(context); 50 ModuleRegistry* registry = ModuleRegistry::From(context);
47 51
48 v8::Isolate* isolate = runner->GetContextHolder()->isolate(); 52 v8::Isolate* isolate = runner->GetContextHolder()->isolate();
49 for (BuiltinModuleMap::const_iterator it = builtin_modules_.begin(); 53 for (BuiltinModuleMap::const_iterator it = builtin_modules_.begin();
50 it != builtin_modules_.end(); ++it) { 54 it != builtin_modules_.end(); ++it) {
51 registry->AddBuiltinModule(isolate, it->first, it->second(isolate)); 55 registry->AddBuiltinModule(isolate, it->first, it->second(isolate));
52 } 56 }
53 } 57 }
54 58
55 void ModuleRunnerDelegate::DidRunScript(ShellRunner* runner) { 59 void ModuleRunnerDelegate::DidRunScript(ShellRunner* runner) {
56 AttemptToLoadMoreModules(runner); 60 AttemptToLoadMoreModules(runner);
57 } 61 }
58 62
63 void ModuleRunnerDelegate::DidLoadFileModules(
64 const std::set<std::string>& loaded_modules) {
65 std::set<std::string> failed_modules;
66 std::set_difference(
67 unsatisfied_dependencies_.begin(), unsatisfied_dependencies_.end(),
68 loaded_modules.begin(), loaded_modules.end(),
69 std::inserter(failed_modules, failed_modules.end()));
70 for (std::set<std::string>::const_iterator it = failed_modules.begin();
71 it != failed_modules.end(); ++it) {
72 LOG(ERROR) << "Failed to load module: " << *it;
73 }
74 }
75
59 } // namespace gin 76 } // namespace gin
OLDNEW
« gin/modules/file_module_provider.cc ('K') | « gin/modules/module_runner_delegate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698