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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: gin/modules/file_module_provider.cc
diff --git a/gin/modules/file_module_provider.cc b/gin/modules/file_module_provider.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0f2d9c9101c588e90f67d9abb1ff872bfa3c287b
--- /dev/null
+++ b/gin/modules/file_module_provider.cc
@@ -0,0 +1,64 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "gin/modules/file_module_provider.h"
+
+
+#include "base/bind.h"
+#include "base/file_util.h"
+#include "base/message_loop/message_loop.h"
+#include "base/strings/string_split.h"
+#include "gin/converter.h"
+namespace gin {
+
+namespace {
+
+void AttempToLoadModule(base::WeakPtr<Runner> runner,
+ base::FilePath base,
+ std::string id) {
+ if (!runner.get())
+ return;
+
+ std::vector<std::string> components;
+ base::SplitString(id, '/', &components);
+ base::FilePath path = base;
+ for (size_t i = 0; i < components.size(); ++i) {
+ path = path.AppendASCII(components[i]);
+ }
+ path = path.AddExtension(FILE_PATH_LITERAL("js"));
+
+ std::string source;
+ if (!ReadFileToString(path, &source))
+ return;
+
+ Runner::Scope scope(runner.get());
+ v8::Handle<v8::Script> script = v8::Script::New(
+ StringToV8(runner->isolate(), source), StringToV8(runner->isolate(), id));
+ runner->Run(script);
+}
+
+}
+
+FileModuleProvider::FileModuleProvider(const base::FilePath& base)
+ : base_(base) {
+}
+
+FileModuleProvider::~FileModuleProvider() {
+}
+
+void FileModuleProvider::AttempToLoadModules(
+ Runner* runner, const std::set<std::string>& ids) {
+ std::set<std::string> modules = ids;
+ for (std::set<std::string>::const_iterator it = modules.begin();
+ it != modules.end(); ++it) {
+ const std::string& id = *it;
+ if (attempted_ids_.count(id))
+ continue;
+ attempted_ids_.insert(id);
+ base::MessageLoop::current()->PostTask(FROM_HERE,
+ base::Bind(AttempToLoadModule, runner->GetWeakPtr(), base_, id));
+ }
+}
+
+} // namespace gin

Powered by Google App Engine
This is Rietveld 408576698