OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "gin/modules/file_module_provider.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/file_util.h" | |
9 #include "base/message_loop/message_loop.h" | |
10 #include "base/strings/string_split.h" | |
11 #include "gin/converter.h" | |
12 | |
13 namespace gin { | |
14 | |
15 namespace { | |
16 | |
17 void AttempToLoadModule(base::WeakPtr<Runner> runner, | |
jochen (gone - plz use gerrit)
2013/11/18 12:46:05
should all these parameters be const references?
abarth-chromium
2013/11/18 15:33:05
Done.
| |
18 base::FilePath base, | |
19 std::string id) { | |
20 if (!runner.get()) | |
jochen (gone - plz use gerrit)
2013/11/18 12:46:05
no get() needed
abarth-chromium
2013/11/18 15:33:05
Done.
| |
21 return; | |
22 | |
23 std::vector<std::string> components; | |
24 base::SplitString(id, '/', &components); | |
25 base::FilePath path = base; | |
26 for (size_t i = 0; i < components.size(); ++i) { | |
jochen (gone - plz use gerrit)
2013/11/18 12:46:05
no { } needed
| |
27 path = path.AppendASCII(components[i]); | |
jochen (gone - plz use gerrit)
2013/11/18 12:46:05
the id is actually utf8, isn't it?
abarth-chromium
2013/11/18 15:33:05
I've added a TODO about this issue.
| |
28 } | |
29 path = path.AddExtension(FILE_PATH_LITERAL("js")); | |
30 | |
31 std::string source; | |
32 if (!ReadFileToString(path, &source)) | |
33 return; | |
34 | |
35 Runner::Scope scope(runner.get()); | |
36 v8::Handle<v8::Script> script = v8::Script::New( | |
37 StringToV8(runner->isolate(), source), | |
38 StringToV8(runner->isolate(), id)); | |
39 runner->Run(script); | |
40 } | |
41 | |
42 } | |
jochen (gone - plz use gerrit)
2013/11/18 12:46:05
add // namespace
abarth-chromium
2013/11/18 15:33:05
Done.
| |
43 | |
44 FileModuleProvider::FileModuleProvider(const base::FilePath& base) | |
45 : base_(base) { | |
46 } | |
47 | |
48 FileModuleProvider::~FileModuleProvider() { | |
49 } | |
50 | |
51 void FileModuleProvider::AttempToLoadModules( | |
52 Runner* runner, const std::set<std::string>& ids) { | |
53 std::set<std::string> modules = ids; | |
54 for (std::set<std::string>::const_iterator it = modules.begin(); | |
55 it != modules.end(); ++it) { | |
56 const std::string& id = *it; | |
57 if (attempted_ids_.count(id)) | |
58 continue; | |
59 attempted_ids_.insert(id); | |
60 base::MessageLoop::current()->PostTask(FROM_HERE, | |
61 base::Bind(AttempToLoadModule, runner->GetWeakPtr(), base_, id)); | |
62 } | |
63 } | |
64 | |
65 } // namespace gin | |
OLD | NEW |