OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/launch_instance.h" | 5 #include "services/ui/launcher/launch_instance.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "base/command_line.h" | 8 #include "base/command_line.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_split.h" |
9 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
10 #include "mojo/application/application_runner_chromium.h" | 12 #include "mojo/application/application_runner_chromium.h" |
11 #include "mojo/public/c/system/main.h" | 13 #include "mojo/public/c/system/main.h" |
12 #include "mojo/public/cpp/application/application_impl.h" | 14 #include "mojo/public/cpp/application/application_impl.h" |
13 #include "mojo/public/cpp/application/connect.h" | 15 #include "mojo/public/cpp/application/connect.h" |
14 #include "mojo/services/ui/views/interfaces/view_provider.mojom.h" | 16 #include "mojo/services/ui/views/interfaces/view_provider.mojom.h" |
15 #include "services/ui/launcher/launcher_view_tree.h" | 17 #include "services/ui/launcher/launcher_view_tree.h" |
16 | 18 |
17 namespace launcher { | 19 namespace launcher { |
18 | 20 |
19 LaunchInstance::LaunchInstance(mojo::ApplicationImpl* app_impl, | 21 LaunchInstance::LaunchInstance(mojo::ApplicationImpl* app_impl, |
20 const std::string& app_url, | 22 const std::string& app_url, |
| 23 const std::string& view_associate_urls, |
21 const base::Closure& shutdown_callback) | 24 const base::Closure& shutdown_callback) |
22 : app_impl_(app_impl), | 25 : app_impl_(app_impl), |
23 app_url_(app_url), | 26 app_url_(app_url), |
| 27 view_associate_urls_(view_associate_urls), |
24 shutdown_callback_(shutdown_callback), | 28 shutdown_callback_(shutdown_callback), |
25 viewport_event_dispatcher_binding_(this) {} | 29 viewport_event_dispatcher_binding_(this) {} |
26 | 30 |
27 LaunchInstance::~LaunchInstance() {} | 31 LaunchInstance::~LaunchInstance() {} |
28 | 32 |
29 void LaunchInstance::Launch() { | 33 void LaunchInstance::Launch() { |
30 DVLOG(1) << "Launching " << app_url_; | 34 DVLOG(1) << "Launching " << app_url_; |
31 TRACE_EVENT0("launcher", __func__); | 35 TRACE_EVENT0("launcher", __func__); |
32 | 36 |
33 mojo::ConnectToService(app_impl_->shell(), "mojo:compositor_service", | 37 mojo::ConnectToService(app_impl_->shell(), "mojo:compositor_service", |
34 GetProxy(&compositor_)); | 38 GetProxy(&compositor_)); |
35 compositor_.set_connection_error_handler(base::Bind( | 39 compositor_.set_connection_error_handler(base::Bind( |
36 &LaunchInstance::OnCompositorConnectionError, base::Unretained(this))); | 40 &LaunchInstance::OnCompositorConnectionError, base::Unretained(this))); |
37 | 41 |
38 mojo::ConnectToService(app_impl_->shell(), "mojo:view_manager_service", | 42 mojo::ConnectToService(app_impl_->shell(), "mojo:view_manager_service", |
39 GetProxy(&view_manager_)); | 43 GetProxy(&view_manager_)); |
40 view_manager_.set_connection_error_handler(base::Bind( | 44 view_manager_.set_connection_error_handler(base::Bind( |
41 &LaunchInstance::OnViewManagerConnectionError, base::Unretained(this))); | 45 &LaunchInstance::OnViewManagerConnectionError, base::Unretained(this))); |
42 | 46 |
| 47 // Connect to ViewAssociates. |
| 48 std::vector<std::string> associate_urls = SplitString( |
| 49 view_associate_urls_, ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
| 50 if (associate_urls.empty()) { |
| 51 // TODO(jeffbrown): Replace this hardcoded list. |
| 52 associate_urls.push_back("mojo:input_manager_service"); |
| 53 } |
| 54 |
| 55 view_associate_owners_.reserve(associate_urls.size()); |
| 56 |
| 57 for (const auto& url : associate_urls) { |
| 58 // Connect to the ViewAssociate. |
| 59 DVLOG(2) << "Connecting to ViewAssociate " << url; |
| 60 mojo::ui::ViewAssociatePtr view_associate; |
| 61 mojo::ConnectToService(app_impl_->shell(), url, GetProxy(&view_associate)); |
| 62 |
| 63 // Wire up the associate to the ViewManager. |
| 64 mojo::ui::ViewAssociateOwnerPtr view_associate_owner; |
| 65 view_manager_->RegisterViewAssociate(view_associate.Pass(), |
| 66 GetProxy(&view_associate_owner), url); |
| 67 |
| 68 view_associate_owner.set_connection_error_handler( |
| 69 base::Bind(&LaunchInstance::OnViewAssociateConnectionError, |
| 70 base::Unretained(this))); |
| 71 |
| 72 view_associate_owners_.push_back(view_associate_owner.Pass()); |
| 73 } |
| 74 view_manager_->FinishedRegisteringViewAssociates(); |
| 75 |
43 InitViewport(); | 76 InitViewport(); |
44 | 77 |
45 mojo::ui::ViewProviderPtr client_view_provider; | 78 mojo::ui::ViewProviderPtr client_view_provider; |
46 mojo::ConnectToService(app_impl_->shell(), app_url_, | 79 mojo::ConnectToService(app_impl_->shell(), app_url_, |
47 GetProxy(&client_view_provider)); | 80 GetProxy(&client_view_provider)); |
48 | 81 |
49 client_view_provider->CreateView(GetProxy(&client_view_owner_), nullptr, | 82 client_view_provider->CreateView(GetProxy(&client_view_owner_), nullptr, |
50 nullptr); | 83 nullptr); |
51 } | 84 } |
52 | 85 |
| 86 void LaunchInstance::OnViewAssociateConnectionError() { |
| 87 LOG(ERROR) << "Exiting due to view associate connection error."; |
| 88 shutdown_callback_.Run(); |
| 89 }; |
| 90 |
53 void LaunchInstance::OnCompositorConnectionError() { | 91 void LaunchInstance::OnCompositorConnectionError() { |
54 LOG(ERROR) << "Exiting due to compositor connection error."; | 92 LOG(ERROR) << "Exiting due to compositor connection error."; |
55 shutdown_callback_.Run(); | 93 shutdown_callback_.Run(); |
56 } | 94 } |
57 | 95 |
58 void LaunchInstance::OnViewManagerConnectionError() { | 96 void LaunchInstance::OnViewManagerConnectionError() { |
59 LOG(ERROR) << "Exiting due to view manager connection error."; | 97 LOG(ERROR) << "Exiting due to view manager connection error."; |
60 shutdown_callback_.Run(); | 98 shutdown_callback_.Run(); |
61 } | 99 } |
62 | 100 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 152 } |
115 | 153 |
116 void LaunchInstance::OnEvent(mojo::EventPtr event, | 154 void LaunchInstance::OnEvent(mojo::EventPtr event, |
117 const mojo::Callback<void()>& callback) { | 155 const mojo::Callback<void()>& callback) { |
118 if (view_tree_) | 156 if (view_tree_) |
119 view_tree_->DispatchEvent(event.Pass()); | 157 view_tree_->DispatchEvent(event.Pass()); |
120 callback.Run(); | 158 callback.Run(); |
121 } | 159 } |
122 | 160 |
123 } // namespace launcher | 161 } // namespace launcher |
OLD | NEW |