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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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/trace_event/trace_event.h"
6 #include "mojo/application/application_runner_chromium.h"
7 #include "mojo/common/tracing_impl.h"
8 #include "mojo/public/c/system/main.h"
9 #include "mojo/public/cpp/application/application_connection.h"
10 #include "mojo/public/cpp/application/application_impl.h"
11 #include "mojo/services/surfaces/cpp/surfaces_utils.h"
12 #include "mojo/services/surfaces/interfaces/quads.mojom.h"
13 #include "services/ui/launcher/launcher_app.h"
14 #include "services/ui/launcher/launcher_view_tree.h"
15
16 namespace launcher {
17
18 LauncherApp::LauncherApp()
19 : app_impl_(nullptr), viewport_event_dispatcher_binding_(this) {}
20
21 LauncherApp::~LauncherApp() {}
22
23 void LauncherApp::Initialize(mojo::ApplicationImpl* app) {
24 app_impl_ = app;
25 tracing_.Initialize(app);
26 TRACE_EVENT0("launcher", __func__);
27
28 if (app->args().size() != 2) {
29 LOG(ERROR) << "Invalid arguments.\n\n"
30 "Usage: mojo_shell \"mojo:launcher <app url>\"";
31 app->Terminate();
32 return;
33 }
34
35 InitViewport();
36 LaunchClient(app->args()[1]);
37 }
38
39 void LauncherApp::InitViewport() {
40 app_impl_->ConnectToService("mojo:native_viewport_service",
41 &viewport_service_);
42 viewport_service_.set_connection_error_handler(base::Bind(
43 &LauncherApp::OnViewportConnectionError, base::Unretained(this)));
44
45 mojo::NativeViewportEventDispatcherPtr dispatcher;
46 viewport_event_dispatcher_binding_.Bind(GetProxy(&dispatcher));
47 viewport_service_->SetEventDispatcher(dispatcher.Pass());
48
49 // Match the Nexus 5 aspect ratio initially.
50 auto size = mojo::Size::New();
51 size->width = 320;
52 size->height = 640;
53
54 auto requested_configuration = mojo::SurfaceConfiguration::New();
55 viewport_service_->Create(
56 size.Clone(), requested_configuration.Pass(),
57 base::Bind(&LauncherApp::OnViewportCreated, base::Unretained(this)));
58 }
59
60 void LauncherApp::OnViewportConnectionError() {
61 LOG(ERROR) << "Exiting due to viewport connection error.";
62 app_impl_->Terminate();
63 }
64
65 void LauncherApp::OnViewportCreated(mojo::ViewportMetricsPtr metrics) {
66 viewport_service_->Show();
67 mojo::ContextProviderPtr context_provider;
68 viewport_service_->GetContextProvider(GetProxy(&context_provider));
69
70 mojo::DisplayFactoryPtr display_factory;
71 app_impl_->ConnectToService("mojo:surfaces_service", &display_factory);
72
73 mojo::DisplayPtr display;
74 display_factory->Create(context_provider.Pass(), nullptr, GetProxy(&display));
75
76 view_tree_.reset(
77 new LauncherViewTree(app_impl_, display.Pass(), metrics.Pass()));
78 UpdateClientView();
79 RequestUpdatedViewportMetrics();
80 }
81
82 void LauncherApp::OnViewportMetricsChanged(mojo::ViewportMetricsPtr metrics) {
83 if (view_tree_) {
84 view_tree_->SetViewportMetrics(metrics.Pass());
85 RequestUpdatedViewportMetrics();
86 }
87 }
88
89 void LauncherApp::RequestUpdatedViewportMetrics() {
90 viewport_service_->RequestMetrics(base::Bind(
91 &LauncherApp::OnViewportMetricsChanged, base::Unretained(this)));
92 }
93
94 void LauncherApp::OnEvent(mojo::EventPtr event,
95 const mojo::Callback<void()>& callback) {
96 if (view_tree_)
97 view_tree_->DispatchEvent(event.Pass());
98 callback.Run();
99 }
100
101 void LauncherApp::LaunchClient(std::string app_url) {
102 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
103
104 app_impl_->ConnectToService(app_url, &client_view_provider_);
105 client_view_provider_.set_connection_error_handler(base::Bind(
106 &LauncherApp::OnClientConnectionError, base::Unretained(this)));
107
108 client_view_provider_->CreateView(
109 nullptr, nullptr,
110 base::Bind(&LauncherApp::OnClientViewCreated, base::Unretained(this)));
111 }
112
113 void LauncherApp::OnClientConnectionError() {
114 LOG(ERROR) << "Exiting due to client application connection error.";
115 app_impl_->Terminate();
116 }
117
118 void LauncherApp::OnClientViewCreated(mojo::ui::ViewTokenPtr view_token) {
119 client_view_token_ = view_token.Pass();
120 UpdateClientView();
121 }
122
123 void LauncherApp::UpdateClientView() {
124 if (view_tree_)
125 view_tree_->SetRoot(client_view_token_.Clone());
126 }
127
128 } // namespace launcher
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698