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

Unified Diff: services/ui/launcher/launcher_app.cc

Issue 1404423007: mozart: Initial commit of the launcher. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: applied review comments Created 5 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: services/ui/launcher/launcher_app.cc
diff --git a/services/ui/launcher/launcher_app.cc b/services/ui/launcher/launcher_app.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c2865fb1cd60ab7dea98b52c3a2a2adeff8904d5
--- /dev/null
+++ b/services/ui/launcher/launcher_app.cc
@@ -0,0 +1,128 @@
+// Copyright 2015 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/trace_event/trace_event.h"
+#include "mojo/application/application_runner_chromium.h"
+#include "mojo/common/tracing_impl.h"
+#include "mojo/public/c/system/main.h"
+#include "mojo/public/cpp/application/application_connection.h"
+#include "mojo/public/cpp/application/application_impl.h"
+#include "mojo/services/surfaces/cpp/surfaces_utils.h"
+#include "mojo/services/surfaces/interfaces/quads.mojom.h"
+#include "services/ui/launcher/launcher_app.h"
+#include "services/ui/launcher/launcher_view_tree.h"
+
+namespace launcher {
+
+LauncherApp::LauncherApp()
+ : app_impl_(nullptr), viewport_event_dispatcher_binding_(this) {}
+
+LauncherApp::~LauncherApp() {}
+
+void LauncherApp::Initialize(mojo::ApplicationImpl* app) {
+ app_impl_ = app;
+ tracing_.Initialize(app);
+ TRACE_EVENT0("launcher", __func__);
+
+ if (app->args().size() != 2) {
+ LOG(ERROR) << "Invalid arguments.\n\n"
+ "Usage: mojo_shell \"mojo:launcher <app url>\"";
+ app->Terminate();
+ return;
+ }
+
+ InitViewport();
+ LaunchClient(app->args()[1]);
+}
+
+void LauncherApp::InitViewport() {
+ app_impl_->ConnectToService("mojo:native_viewport_service",
+ &viewport_service_);
+ viewport_service_.set_connection_error_handler(base::Bind(
+ &LauncherApp::OnViewportConnectionError, base::Unretained(this)));
+
+ mojo::NativeViewportEventDispatcherPtr dispatcher;
+ viewport_event_dispatcher_binding_.Bind(GetProxy(&dispatcher));
+ viewport_service_->SetEventDispatcher(dispatcher.Pass());
+
+ // Match the Nexus 5 aspect ratio initially.
+ auto size = mojo::Size::New();
+ size->width = 320;
+ size->height = 640;
+
+ auto requested_configuration = mojo::SurfaceConfiguration::New();
+ viewport_service_->Create(
+ size.Clone(), requested_configuration.Pass(),
+ base::Bind(&LauncherApp::OnViewportCreated, base::Unretained(this)));
+}
+
+void LauncherApp::OnViewportConnectionError() {
+ LOG(ERROR) << "Exiting due to viewport connection error.";
+ app_impl_->Terminate();
+}
+
+void LauncherApp::OnViewportCreated(mojo::ViewportMetricsPtr metrics) {
+ viewport_service_->Show();
+ mojo::ContextProviderPtr context_provider;
+ viewport_service_->GetContextProvider(GetProxy(&context_provider));
+
+ mojo::DisplayFactoryPtr display_factory;
+ app_impl_->ConnectToService("mojo:surfaces_service", &display_factory);
+
+ mojo::DisplayPtr display;
+ display_factory->Create(context_provider.Pass(), nullptr, GetProxy(&display));
+
+ view_tree_.reset(
+ new LauncherViewTree(app_impl_, display.Pass(), metrics.Pass()));
+ UpdateClientView();
+ RequestUpdatedViewportMetrics();
+}
+
+void LauncherApp::OnViewportMetricsChanged(mojo::ViewportMetricsPtr metrics) {
+ if (view_tree_) {
+ view_tree_->SetViewportMetrics(metrics.Pass());
+ RequestUpdatedViewportMetrics();
+ }
+}
+
+void LauncherApp::RequestUpdatedViewportMetrics() {
+ viewport_service_->RequestMetrics(base::Bind(
+ &LauncherApp::OnViewportMetricsChanged, base::Unretained(this)));
+}
+
+void LauncherApp::OnEvent(mojo::EventPtr event,
+ const mojo::Callback<void()>& callback) {
+ if (view_tree_)
+ view_tree_->DispatchEvent(event.Pass());
+ callback.Run();
+}
+
+void LauncherApp::LaunchClient(std::string app_url) {
+ LOG(INFO) << "Launching " << app_url << " with Mozart...";
jamesr 2015/10/27 23:01:35 VLOG(). this is just going to annoy everyone as is
jeffbrown 2015/10/27 23:31:38 I was thinking of the launcher as a command-line t
+
+ app_impl_->ConnectToService(app_url, &client_view_provider_);
+ client_view_provider_.set_connection_error_handler(base::Bind(
+ &LauncherApp::OnClientConnectionError, base::Unretained(this)));
+
+ client_view_provider_->CreateView(
+ nullptr, nullptr,
+ base::Bind(&LauncherApp::OnClientViewCreated, base::Unretained(this)));
+}
+
+void LauncherApp::OnClientConnectionError() {
+ LOG(ERROR) << "Exiting due to client application connection error.";
+ app_impl_->Terminate();
+}
+
+void LauncherApp::OnClientViewCreated(mojo::ui::ViewTokenPtr view_token) {
+ client_view_token_ = view_token.Pass();
+ UpdateClientView();
+}
+
+void LauncherApp::UpdateClientView() {
+ if (view_tree_)
+ view_tree_->SetRoot(client_view_token_.Clone());
+}
+
+} // namespace launcher

Powered by Google App Engine
This is Rietveld 408576698