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

Unified Diff: services/dart/dart_app.cc

Issue 816113004: Dart: Adds a content handler and a test. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Merge CLs that address comments Created 5 years, 11 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
Index: services/dart/dart_app.cc
diff --git a/services/dart/dart_app.cc b/services/dart/dart_app.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a9a728a4f632e51b898a20d52c6e7cd017fa95f3
--- /dev/null
+++ b/services/dart/dart_app.cc
@@ -0,0 +1,73 @@
+// Copyright 2014 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 "services/dart/dart_app.h"
+
+#include "base/bind.h"
+#include "base/files/file_util.h"
+#include "base/logging.h"
+#include "base/message_loop/message_loop.h"
+#include "base/path_service.h"
+#include "crypto/random.h"
+#include "mojo/common/data_pipe_utils.h"
+#include "mojo/dart/embedder/dart_controller.h"
+#include "mojo/dart/embedder/isolate_data.h"
+#include "mojo/public/cpp/bindings/interface_request.h"
+
+namespace dart {
+
+static bool generateEntropy(uint8_t* buffer, intptr_t length) {
+ crypto::RandBytes(reinterpret_cast<void*>(buffer), length);
+ return true;
+}
+
+DartApp::DartApp(mojo::ShellPtr shell, mojo::URLResponsePtr response)
+ : shell_(shell.Pass()) {
+ DCHECK(!response.is_null());
+ std::string url(response->url);
+ std::string source;
+ CHECK(mojo::common::BlockingCopyToString(response->body.Pass(), &source));
+
+ // TODO(zra): Where is the package root? For now, use DIR_EXE/gen.
+ base::FilePath package_root;
+ PathService::Get(base::DIR_EXE, &package_root);
+ package_root = package_root.AppendASCII("gen");
+
+ // TODO(zra): Instead of hard-coding these testing arguments here, parse them
+ // out of the script, looking for vmoptions as we do in Dart VM tests.
+ const int kNumArgs = 3;
+ const char* args[kNumArgs];
+ args[0] = "--enable_asserts";
+ args[1] = "--enable_type_checks";
+ args[2] = "--error_on_bad_type";
+
+ _config.application_data = reinterpret_cast<void*>(this);
+ _config.script = source;
+ _config.script_uri = url;
+ _config.package_root = package_root.AsUTF8Unsafe();
+ _config.entropy = generateEntropy;
+ _config.arguments = args;
+ _config.arguments_count = kNumArgs;
+ _config.compile_all = false;
+
+ base::MessageLoop::current()->PostTask(FROM_HERE,
+ base::Bind(&DartApp::OnAppLoaded, base::Unretained(this)));
+}
+
+DartApp::~DartApp() {
+}
+
+void DartApp::OnAppLoaded() {
+ char* error = nullptr;
+ _config.handle = shell_.PassMessagePipe().release().value();
+ _config.error = &error;
+ bool success = mojo::dart::DartController::RunDartScript(_config);
+ if (!success) {
+ LOG(ERROR) << error;
+ free(error);
+ }
+ base::MessageLoop::current()->QuitWhenIdle();
+}
+
+} // namespace dart

Powered by Google App Engine
This is Rietveld 408576698