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

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

Issue 74753002: Introduce gin_shell (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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
(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
8 #include "base/bind.h"
9 #include "base/file_util.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/strings/string_split.h"
12 #include "gin/converter.h"
13 namespace gin {
14
15 namespace {
16
17 void AttempToLoadModule(base::WeakPtr<Runner> runner,
18 base::FilePath base,
19 std::string id) {
20 if (!runner.get())
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) {
27 path = path.AppendASCII(components[i]);
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), StringToV8(runner->isolate(), id));
38 runner->Run(script);
39 }
40
41 }
42
43 FileModuleProvider::FileModuleProvider(const base::FilePath& base)
44 : base_(base) {
45 }
46
47 FileModuleProvider::~FileModuleProvider() {
48 }
49
50 void FileModuleProvider::AttempToLoadModules(
51 Runner* runner, const std::set<std::string>& ids) {
52 std::set<std::string> modules = ids;
53 for (std::set<std::string>::const_iterator it = modules.begin();
54 it != modules.end(); ++it) {
55 const std::string& id = *it;
56 if (attempted_ids_.count(id))
57 continue;
58 attempted_ids_.insert(id);
59 base::MessageLoop::current()->PostTask(FROM_HERE,
60 base::Bind(AttempToLoadModule, runner->GetWeakPtr(), base_, id));
61 }
62 }
63
64 } // namespace gin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698