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

Unified Diff: mojo/shell/in_process_native_runner.cc

Issue 1049993002: Get mojo_shell building inside chromium checkout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix presubmit Created 5 years, 9 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
« no previous file with comments | « mojo/shell/in_process_native_runner.h ('k') | mojo/shell/in_process_native_runner_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/shell/in_process_native_runner.cc
diff --git a/mojo/shell/in_process_native_runner.cc b/mojo/shell/in_process_native_runner.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7431fe02dc045cef9795445cd81ad0bf41e6ed39
--- /dev/null
+++ b/mojo/shell/in_process_native_runner.cc
@@ -0,0 +1,72 @@
+// 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 "mojo/shell/in_process_native_runner.h"
+
+#include "base/bind.h"
+#include "base/callback_helpers.h"
+#include "base/location.h"
+#include "base/message_loop/message_loop_proxy.h"
+#include "base/threading/platform_thread.h"
+#include "mojo/shell/native_application_support.h"
+
+namespace mojo {
+namespace shell {
+
+InProcessNativeRunner::InProcessNativeRunner(Context* context)
+ : cleanup_(NativeApplicationCleanup::DONT_DELETE), app_library_(nullptr) {
+}
+
+InProcessNativeRunner::~InProcessNativeRunner() {
+ // It is important to let the thread exit before unloading the DSO (when
+ // app_library_ is destructed), because the library may have registered
+ // thread-local data and destructors to run on thread termination.
+ if (thread_) {
+ DCHECK(thread_->HasBeenStarted());
+ DCHECK(!thread_->HasBeenJoined());
+ thread_->Join();
+ }
+}
+
+void InProcessNativeRunner::Start(
+ const base::FilePath& app_path,
+ NativeApplicationCleanup cleanup,
+ InterfaceRequest<Application> application_request,
+ const base::Closure& app_completed_callback) {
+ app_path_ = app_path;
+ cleanup_ = cleanup;
+
+ DCHECK(!application_request_.is_pending());
+ application_request_ = application_request.Pass();
+
+ DCHECK(app_completed_callback_runner_.is_null());
+ app_completed_callback_runner_ =
+ base::Bind(&base::TaskRunner::PostTask, base::MessageLoopProxy::current(),
+ FROM_HERE, app_completed_callback);
+
+ DCHECK(!thread_);
+ thread_.reset(new base::DelegateSimpleThread(this, "app_thread"));
+ thread_->Start();
+}
+
+void InProcessNativeRunner::Run() {
+ DVLOG(2) << "Loading/running Mojo app in process from library: "
+ << app_path_.value()
+ << " thread id=" << base::PlatformThread::CurrentId();
+
+ // TODO(vtl): ScopedNativeLibrary doesn't have a .get() method!
+ base::NativeLibrary app_library = LoadNativeApplication(app_path_, cleanup_);
+ app_library_.Reset(app_library);
+ RunNativeApplication(app_library, application_request_.Pass());
+ app_completed_callback_runner_.Run();
+ app_completed_callback_runner_.Reset();
+}
+
+scoped_ptr<NativeRunner> InProcessNativeRunnerFactory::Create(
+ const Options& options) {
+ return make_scoped_ptr(new InProcessNativeRunner(context_));
+}
+
+} // namespace shell
+} // namespace mojo
« no previous file with comments | « mojo/shell/in_process_native_runner.h ('k') | mojo/shell/in_process_native_runner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698