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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 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 "base/bind.h"
6 #include "base/callback_forward.h"
7 #include "base/files/file_path.h"
8 #include "base/threading/thread.h"
9 #include "mojo/public/system/core.h"
10 #include "mojo/shell/app_container.h"
11
12 typedef MojoResult (*MojoMainFunction)(MojoHandle pipe);
13
14 namespace mojo {
15 namespace shell {
16
17 void LaunchAppOnThread(const base::FilePath& app_path,
18 MojoHandle app_handle,
19 base::MessageLoop* main_thread_loop,
20 const base::Callback<void()>& callback) {
21 HINSTANCE app_library = LoadLibrary(app_path.value().c_str());
22 if (!app_library) {
23 LOG(ERROR) << "Failed to load library: " << app_path.value().c_str();
24 goto completed;
25 }
26
27 MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>(
28 GetProcAddress(app_library, "MojoMain"));
29 if (!main_function) {
30 LOG(ERROR) << "Entrypoint MojoMain not found.";
31 goto completed;
darin (slow to review) 2013/10/04 21:47:14 in these other error cases, we'll want to make sur
32 }
33
34 MojoResult result = main_function(app_handle);
35 if (result < MOJO_RESULT_OK) {
36 LOG(ERROR) << "MojoMain returned an error: " << result;
37 // Failure..
38 goto completed;
39 }
40
darin (slow to review) 2013/10/04 21:47:14 i guess there is a TODO here for error handling.
41 completed:
42 main_thread_loop->PostTask(FROM_HERE, callback);
43 }
44
45 AppContainer::AppContainer()
46 : weak_factory_(this),
47 shell_handle_(NULL) {
48 }
49
50 AppContainer::~AppContainer() {
51 }
52
53 void AppContainer::LaunchApp(const base::FilePath& app_path) {
54 MojoHandle app_handle = MOJO_HANDLE_INVALID;
55 MojoResult result = MojoCreateMessagePipe(&shell_handle_, &app_handle);
56 if (result < MOJO_RESULT_OK) {
57 // Failure..
58 }
59
60 // Launch the app on its own thread.
61 // TODO(beng): Create a unique thread name.
62 thread_.reset(new base::Thread("app_thread"));
63 thread_->Start();
64 thread_->message_loop()->PostTask(
65 FROM_HERE,
66 base::Bind(&LaunchAppOnThread,
67 app_path,
68 app_handle,
69 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
70 base::Bind(&AppContainer::AppCompleted,
71 weak_factory_.GetWeakPtr())));
72
73 const char* hello_msg = "Hello";
74 result = MojoWriteMessage(shell_handle_, hello_msg, strlen(hello_msg)+1,
75 NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE);
76 if (result < MOJO_RESULT_OK) {
77 // Failure..
78 }
79 }
80
81
82 void AppContainer::AppCompleted() {
83 thread_.reset();
84
85 // Probably want to do something more sophisticated here, like notify someone
86 // else to do this.
87 base::MessageLoop::current()->Quit();
88 }
89
90 } // namespace shell
91 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698