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

Side by Side 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: 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 unified diff | Download patch
« no previous file with comments | « services/dart/dart_app.h ('k') | services/dart/echo_apptest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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 "services/dart/dart_app.h"
6
7 #include "base/bind.h"
8 #include "base/files/file_util.h"
9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/path_service.h"
12 #include "crypto/random.h"
13 #include "mojo/common/data_pipe_utils.h"
14 #include "mojo/dart/embedder/dart_controller.h"
15 #include "mojo/dart/embedder/isolate_data.h"
16 #include "mojo/public/cpp/bindings/interface_request.h"
17
18 namespace dart {
19
20 static bool generateEntropy(uint8_t* buffer, intptr_t length) {
21 crypto::RandBytes(reinterpret_cast<void*>(buffer), length);
22 return true;
23 }
24
25 DartApp::DartApp(mojo::ShellPtr shell, mojo::URLResponsePtr response)
26 : shell_(shell.Pass()) {
27 DCHECK(!response.is_null());
28 std::string url(response->url);
29 std::string source;
30 CHECK(mojo::common::BlockingCopyToString(response->body.Pass(), &source));
31
32 // TODO(zra): Where is the package root? For now, use DIR_EXE/gen.
33 base::FilePath package_root;
34 PathService::Get(base::DIR_EXE, &package_root);
35 package_root = package_root.AppendASCII("gen");
36
37 // TODO(zra): Instead of hard-coding these testing arguments here, parse them
38 // out of the script, looking for vmoptions as we do in Dart VM tests.
39 const int kNumArgs = 3;
40 const char* args[kNumArgs];
41 args[0] = "--enable_asserts";
42 args[1] = "--enable_type_checks";
43 args[2] = "--error_on_bad_type";
44
45 config_.application_data = reinterpret_cast<void*>(this);
46 config_.script = source;
47 config_.script_uri = url;
48 config_.package_root = package_root.AsUTF8Unsafe();
49 config_.entropy = generateEntropy;
50 config_.arguments = args;
51 config_.arguments_count = kNumArgs;
52 config_.compile_all = false;
53
54 base::MessageLoop::current()->PostTask(FROM_HERE,
55 base::Bind(&DartApp::OnAppLoaded, base::Unretained(this)));
56 }
57
58 DartApp::~DartApp() {
59 }
60
61 void DartApp::OnAppLoaded() {
62 char* error = nullptr;
63 config_.handle = shell_.PassMessagePipe().release().value();
64 config_.error = &error;
65 bool success = mojo::dart::DartController::RunDartScript(config_);
66 if (!success) {
67 LOG(ERROR) << error;
68 free(error);
69 }
70 base::MessageLoop::current()->QuitWhenIdle();
71 }
72
73 } // namespace dart
OLDNEW
« no previous file with comments | « services/dart/dart_app.h ('k') | services/dart/echo_apptest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698