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

Unified Diff: mojo/shell/app_container.cc

Issue 25895002: Simple shell that loads a dll and calls an entrypoint function passing in a handle to a pipe create… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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: mojo/shell/app_container.cc
diff --git a/mojo/shell/app_container.cc b/mojo/shell/app_container.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2dbf378d77bd5c854120f11c632e9e349f241835
--- /dev/null
+++ b/mojo/shell/app_container.cc
@@ -0,0 +1,91 @@
+// Copyright (c) 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 "base/bind.h"
+#include "base/callback_forward.h"
+#include "base/files/file_path.h"
+#include "base/threading/thread.h"
+#include "mojo/public/system/core.h"
+#include "mojo/shell/app_container.h"
+
+typedef MojoResult (*MojoMainFunction)(MojoHandle pipe);
+
+namespace mojo {
+namespace shell {
+
+void LaunchAppOnThread(const base::FilePath& app_path,
+ MojoHandle app_handle,
+ base::MessageLoop* main_thread_loop,
+ const base::Callback<void()>& callback) {
+ HINSTANCE app_library = LoadLibrary(app_path.value().c_str());
+ if (!app_library) {
+ LOG(ERROR) << "Failed to load library: " << app_path.value().c_str();
+ goto completed;
+ }
+
+ MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>(
+ GetProcAddress(app_library, "MojoMain"));
+ if (!main_function) {
+ LOG(ERROR) << "Entrypoint MojoMain not found.";
+ goto completed;
darin (slow to review) 2013/10/04 21:47:14 in these other error cases, we'll want to make sur
+ }
+
+ MojoResult result = main_function(app_handle);
+ if (result < MOJO_RESULT_OK) {
+ LOG(ERROR) << "MojoMain returned an error: " << result;
+ // Failure..
+ goto completed;
+ }
+
darin (slow to review) 2013/10/04 21:47:14 i guess there is a TODO here for error handling.
+completed:
+ main_thread_loop->PostTask(FROM_HERE, callback);
+}
+
+AppContainer::AppContainer()
+ : weak_factory_(this),
+ shell_handle_(NULL) {
+}
+
+AppContainer::~AppContainer() {
+}
+
+void AppContainer::LaunchApp(const base::FilePath& app_path) {
+ MojoHandle app_handle = MOJO_HANDLE_INVALID;
+ MojoResult result = MojoCreateMessagePipe(&shell_handle_, &app_handle);
+ if (result < MOJO_RESULT_OK) {
+ // Failure..
+ }
+
+ // Launch the app on its own thread.
+ // TODO(beng): Create a unique thread name.
+ thread_.reset(new base::Thread("app_thread"));
+ thread_->Start();
+ thread_->message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&LaunchAppOnThread,
+ app_path,
+ app_handle,
+ base::MessageLoop::current(),
darin (slow to review) 2013/10/04 21:47:14 there's an effort to move away from MessageLoop an
Ben Goodger (Google) 2013/10/07 23:48:44 I can easily pass a threadtaskrunner to my functio
+ base::Bind(&AppContainer::AppCompleted,
+ weak_factory_.GetWeakPtr())));
+
+ const char* hello_msg = "Hello";
+ result = MojoWriteMessage(shell_handle_, hello_msg, strlen(hello_msg)+1,
+ NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE);
+ if (result < MOJO_RESULT_OK) {
+ // Failure..
+ }
+}
+
+
+void AppContainer::AppCompleted() {
+ thread_.reset();
+
+ // Probably want to do something more sophisticated here, like notify someone
+ // else to do this.
+ base::MessageLoop::current()->Quit();
+}
+
+} // namespace shell
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698