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

Unified Diff: mojo/shell/app_container.cc

Issue 72123002: Work in progress for end-to-end bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add base dep for sample_app 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
« mojo/shell/app_container.h ('K') | « mojo/shell/app_container.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/shell/app_container.cc
diff --git a/mojo/shell/app_container.cc b/mojo/shell/app_container.cc
index 221c871c1f99cb5dc7e2e96e794eba53b7b83555..6699b1a833887e42938d48af66d36204b05397e6 100644
--- a/mojo/shell/app_container.cc
+++ b/mojo/shell/app_container.cc
@@ -23,38 +23,9 @@ typedef MojoResult (*MojoMainFunction)(mojo::Handle pipe);
namespace mojo {
namespace shell {
-void LaunchAppOnThread(
- const base::FilePath& app_path,
- Handle app_handle_raw) {
- base::ScopedClosureRunner app_deleter(
- base::Bind(base::IgnoreResult(&base::DeleteFile), app_path, false));
- ScopedHandle app_handle(app_handle_raw);
-
- base::ScopedNativeLibrary app_library(
- base::LoadNativeLibrary(app_path, NULL));
- if (!app_library.is_valid()) {
- LOG(ERROR) << "Failed to load library: " << app_path.value().c_str();
- return;
- }
-
- MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>(
- app_library.GetFunctionPointer("MojoMain"));
- if (!main_function) {
- LOG(ERROR) << "Entrypoint MojoMain not found.";
- return;
- }
-
- MojoResult result = main_function(app_handle.get());
- if (result < MOJO_RESULT_OK) {
- LOG(ERROR) << "MojoMain returned an error: " << result;
- return;
- }
-
- LOG(INFO) << "MojoMain succeeded: " << result;
-}
-
AppContainer::AppContainer(Context* context)
: context_(context),
+ app_handle_raw_(mojo::kInvalidHandle),
weak_factory_(this) {
}
@@ -67,40 +38,64 @@ void AppContainer::Load(const GURL& app_url) {
void AppContainer::DidCompleteLoad(const GURL& app_url,
const base::FilePath& app_path) {
- Handle app_handle;
- MojoResult result = CreateMessagePipe(&shell_handle_, &app_handle);
+ Handle shell_handle;
+ MojoResult result = CreateMessagePipe(&shell_handle, &app_handle_raw_);
if (result < MOJO_RESULT_OK) {
// Failure..
}
+ hello_world_service_.reset(
+ new examples::HelloWorldServiceImpl(shell_handle));
+
// Launch the app on its own thread.
// TODO(beng): Create a unique thread name.
- thread_.reset(new base::Thread("app_thread"));
+ app_path_ = app_path;
+ ack_closure_ =
+ base::Bind(&AppContainer::AppCompleted, weak_factory_.GetWeakPtr());
+ thread_.reset(new base::DelegateSimpleThread(this, "app_thread"));
thread_->Start();
- thread_->message_loop_proxy()->PostTaskAndReply(
- FROM_HERE,
- base::Bind(&LaunchAppOnThread, app_path, app_handle),
- base::Bind(&AppContainer::AppCompleted, weak_factory_.GetWeakPtr()));
-
- const char* hello_msg = "Hello";
- result = WriteMessage(shell_handle_, hello_msg,
- static_cast<uint32_t>(strlen(hello_msg)+1),
- NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE);
- if (result < MOJO_RESULT_OK) {
- // Failure..
- }
// TODO(beng): This should be created on demand by the NativeViewportService
// when it is retrieved by the app.
- native_viewport_controller_.reset(
- new services::NativeViewportController(context_, shell_handle_));
+ // native_viewport_controller_.reset(
+ // new services::NativeViewportController(context_, shell_handle_));
+}
+
+void AppContainer::Run() {
+ base::ScopedClosureRunner app_deleter(
+ base::Bind(base::IgnoreResult(&base::DeleteFile), app_path_, false));
+ ScopedHandle app_handle(app_handle_raw_);
+
+ base::ScopedNativeLibrary app_library(
+ base::LoadNativeLibrary(app_path_, NULL));
+ if (!app_library.is_valid()) {
+ LOG(ERROR) << "Failed to load library: " << app_path_.value().c_str();
+ return;
+ }
+
+ MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>(
+ app_library.GetFunctionPointer("MojoMain"));
+ if (!main_function) {
+ LOG(ERROR) << "Entrypoint MojoMain not found.";
+ return;
+ }
+
+ MojoResult result = main_function(app_handle.get());
+ if (result < MOJO_RESULT_OK) {
+ LOG(ERROR) << "MojoMain returned an error: " << result;
+ return;
+ }
+ LOG(INFO) << "MojoMain succeeded: " << result;
+ context_->task_runners()->ui_runner()->PostTask(FROM_HERE, ack_closure_);
}
void AppContainer::AppCompleted() {
- native_viewport_controller_->Close();
+ hello_world_service_.reset();
+ // TODO(aa): This code gets replaced once we have a service manager.
+ // native_viewport_controller_->Close();
+ thread_->Join();
thread_.reset();
- Close(shell_handle_);
}
} // namespace shell
« mojo/shell/app_container.h ('K') | « mojo/shell/app_container.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698