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

Side by Side Diff: services/ui/launcher/launcher_app.cc

Issue 1949233002: Create a RegisterViewAssociate method in ViewManager (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: add tests to mojo tests Created 4 years, 7 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
« no previous file with comments | « services/ui/launcher/launcher_app.h ('k') | services/ui/view_manager/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "services/ui/launcher/launcher_app.h" 5 #include "services/ui/launcher/launcher_app.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/string_split.h"
9 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
10 #include "mojo/application/application_runner_chromium.h" 11 #include "mojo/application/application_runner_chromium.h"
11 #include "mojo/common/tracing_impl.h" 12 #include "mojo/common/tracing_impl.h"
12 #include "mojo/public/c/system/main.h" 13 #include "mojo/public/c/system/main.h"
13 #include "mojo/public/cpp/application/application_impl.h" 14 #include "mojo/public/cpp/application/application_impl.h"
15 #include "mojo/public/cpp/application/connect.h"
14 #include "mojo/public/cpp/application/service_provider_impl.h" 16 #include "mojo/public/cpp/application/service_provider_impl.h"
15 17
16 namespace launcher { 18 namespace launcher {
17 19
18 LauncherApp::LauncherApp() : app_impl_(nullptr), next_id_(0u) {} 20 LauncherApp::LauncherApp() : app_impl_(nullptr), next_id_(0u) {}
19 21
20 LauncherApp::~LauncherApp() {} 22 LauncherApp::~LauncherApp() {}
21 23
22 void LauncherApp::Initialize(mojo::ApplicationImpl* app_impl) { 24 void LauncherApp::Initialize(mojo::ApplicationImpl* app_impl) {
23 app_impl_ = app_impl; 25 app_impl_ = app_impl;
24 26
25 auto command_line = base::CommandLine::ForCurrentProcess(); 27 auto command_line = base::CommandLine::ForCurrentProcess();
26 command_line->InitFromArgv(app_impl_->args()); 28 command_line->InitFromArgv(app_impl_->args());
27 logging::LoggingSettings settings; 29 logging::LoggingSettings settings;
28 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; 30 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
29 logging::InitLogging(settings); 31 logging::InitLogging(settings);
30 32
31 tracing_.Initialize(app_impl_); 33 tracing_.Initialize(app_impl_);
32 TRACE_EVENT0("launcher", __func__); 34 TRACE_EVENT0("launcher", __func__);
33 35
36 InitCompositor();
37 InitViewManager();
38 InitViewAssociates(command_line->GetSwitchValueASCII("view_associate_urls"));
39
34 for (size_t i = 0; i < command_line->GetArgs().size(); ++i) { 40 for (size_t i = 0; i < command_line->GetArgs().size(); ++i) {
35 Launch(command_line->GetArgs()[i]); 41 Launch(command_line->GetArgs()[i]);
36 } 42 }
37 } 43 }
38 44
45 void LauncherApp::InitCompositor() {
46 mojo::ConnectToService(app_impl_->shell(), "mojo:compositor_service",
47 GetProxy(&compositor_));
48 compositor_.set_connection_error_handler(base::Bind(
49 &LauncherApp::OnCompositorConnectionError, base::Unretained(this)));
50 }
51
52 void LauncherApp::InitViewManager() {
53 mojo::ConnectToService(app_impl_->shell(), "mojo:view_manager_service",
54 GetProxy(&view_manager_));
55 view_manager_.set_connection_error_handler(base::Bind(
56 &LauncherApp::OnViewManagerConnectionError, base::Unretained(this)));
57 }
58
59 void LauncherApp::InitViewAssociates(
60 const std::string& associate_urls_command_line_param) {
61 // Build up the list of ViewAssociates we are going to start
62 auto associate_urls =
63 SplitString(associate_urls_command_line_param, ",", base::KEEP_WHITESPACE,
64 base::SPLIT_WANT_ALL);
65
66 // If there's nothing we got from the command line, use our own list
67 if (associate_urls.empty()) {
68 // TODO(jeffbrown): Replace this hardcoded list.
69 associate_urls.push_back("mojo:input_manager_service");
70 }
71
72 view_associate_owners_.reserve(associate_urls.size());
73
74 // Connect to ViewAssociates.
75 for (const auto& url : associate_urls) {
76 // Connect to the ViewAssociate.
77 DVLOG(2) << "Connecting to ViewAssociate " << url;
78 mojo::ui::ViewAssociatePtr view_associate;
79 mojo::ConnectToService(app_impl_->shell(), url, GetProxy(&view_associate));
80
81 // Wire up the associate to the ViewManager.
82 mojo::ui::ViewAssociateOwnerPtr view_associate_owner;
83 view_manager_->RegisterViewAssociate(view_associate.Pass(),
84 GetProxy(&view_associate_owner), url);
85
86 view_associate_owner.set_connection_error_handler(base::Bind(
87 &LauncherApp::OnViewAssociateConnectionError, base::Unretained(this)));
88
89 view_associate_owners_.push_back(view_associate_owner.Pass());
90 }
91 view_manager_->FinishedRegisteringViewAssociates();
92 }
93
39 bool LauncherApp::ConfigureIncomingConnection( 94 bool LauncherApp::ConfigureIncomingConnection(
40 mojo::ServiceProviderImpl* service_provider_impl) { 95 mojo::ServiceProviderImpl* service_provider_impl) {
41 // Only present the launcher interface to the shell. 96 // Only present the launcher interface to the shell.
42 if (service_provider_impl->connection_context().remote_url.empty()) { 97 if (service_provider_impl->connection_context().remote_url.empty()) {
43 service_provider_impl->AddService<Launcher>( 98 service_provider_impl->AddService<Launcher>(
44 [this](const mojo::ConnectionContext& connection_context, 99 [this](const mojo::ConnectionContext& connection_context,
45 mojo::InterfaceRequest<Launcher> launcher_request) { 100 mojo::InterfaceRequest<Launcher> launcher_request) {
46 bindings_.AddBinding(this, launcher_request.Pass()); 101 bindings_.AddBinding(this, launcher_request.Pass());
47 }); 102 });
48 } 103 }
49 return true; 104 return true;
50 } 105 }
51 106
52 void LauncherApp::Launch(const mojo::String& application_url) { 107 void LauncherApp::Launch(const mojo::String& application_url) {
53 uint32_t next_id = next_id_++; 108 uint32_t next_id = next_id_++;
54 std::unique_ptr<LaunchInstance> instance(new LaunchInstance( 109 std::unique_ptr<LaunchInstance> instance(new LaunchInstance(
55 app_impl_, application_url, base::Bind(&LauncherApp::OnLaunchTermination, 110 app_impl_, application_url, compositor_.get(), view_manager_.get(),
56 base::Unretained(this), next_id))); 111 base::Bind(&LauncherApp::OnLaunchTermination, base::Unretained(this),
112 next_id)));
57 instance->Launch(); 113 instance->Launch();
58 launch_instances_.emplace(next_id, std::move(instance)); 114 launch_instances_.emplace(next_id, std::move(instance));
59 } 115 }
60 116
61 void LauncherApp::OnLaunchTermination(uint32_t id) { 117 void LauncherApp::OnLaunchTermination(uint32_t id) {
62 launch_instances_.erase(id); 118 launch_instances_.erase(id);
63 if (launch_instances_.empty()) { 119 if (launch_instances_.empty()) {
64 app_impl_->Terminate(); 120 app_impl_->Terminate();
65 } 121 }
66 } 122 }
67 123
124 void LauncherApp::OnCompositorConnectionError() {
125 LOG(ERROR) << "Exiting due to compositor connection error.";
126 app_impl_->Terminate();
127 }
128
129 void LauncherApp::OnViewManagerConnectionError() {
130 LOG(ERROR) << "Exiting due to view manager connection error.";
131 app_impl_->Terminate();
132 }
133
134 void LauncherApp::OnViewAssociateConnectionError() {
135 LOG(ERROR) << "Exiting due to view associate connection error.";
136 app_impl_->Terminate();
137 };
138
68 } // namespace launcher 139 } // namespace launcher
OLDNEW
« no previous file with comments | « services/ui/launcher/launcher_app.h ('k') | services/ui/view_manager/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698