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

Side by Side Diff: services/ui/launcher/launch_instance.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/launch_instance.h ('k') | services/ui/launcher/launcher_app.h » ('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 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"
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/public/c/system/main.h" 12 #include "mojo/public/c/system/main.h"
12 #include "mojo/public/cpp/application/application_impl.h" 13 #include "mojo/public/cpp/application/application_impl.h"
13 #include "mojo/public/cpp/application/connect.h" 14 #include "mojo/public/cpp/application/connect.h"
14 #include "mojo/services/ui/views/interfaces/view_provider.mojom.h" 15 #include "mojo/services/ui/views/interfaces/view_provider.mojom.h"
15 #include "services/ui/launcher/launcher_view_tree.h" 16 #include "services/ui/launcher/launcher_view_tree.h"
16 17
17 namespace launcher { 18 namespace launcher {
18 19
19 LaunchInstance::LaunchInstance(mojo::ApplicationImpl* app_impl, 20 LaunchInstance::LaunchInstance(mojo::ApplicationImpl* app_impl,
20 const std::string& app_url, 21 const std::string& app_url,
22 mojo::gfx::composition::Compositor* compositor,
23 mojo::ui::ViewManager* view_manager,
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 compositor_(compositor),
28 view_manager_(view_manager),
24 shutdown_callback_(shutdown_callback), 29 shutdown_callback_(shutdown_callback),
25 viewport_event_dispatcher_binding_(this) {} 30 viewport_event_dispatcher_binding_(this) {}
26 31
27 LaunchInstance::~LaunchInstance() {} 32 LaunchInstance::~LaunchInstance() {}
28 33
29 void LaunchInstance::Launch() { 34 void LaunchInstance::Launch() {
30 DVLOG(1) << "Launching " << app_url_; 35 DVLOG(1) << "Launching " << app_url_;
31 TRACE_EVENT0("launcher", __func__); 36 TRACE_EVENT0("launcher", __func__);
32 37
33 mojo::ConnectToService(app_impl_->shell(), "mojo:compositor_service",
34 GetProxy(&compositor_));
35 compositor_.set_connection_error_handler(base::Bind(
36 &LaunchInstance::OnCompositorConnectionError, base::Unretained(this)));
37
38 mojo::ConnectToService(app_impl_->shell(), "mojo:view_manager_service",
39 GetProxy(&view_manager_));
40 view_manager_.set_connection_error_handler(base::Bind(
41 &LaunchInstance::OnViewManagerConnectionError, base::Unretained(this)));
42
43 InitViewport(); 38 InitViewport();
44 39
45 mojo::ui::ViewProviderPtr client_view_provider; 40 mojo::ui::ViewProviderPtr client_view_provider;
46 mojo::ConnectToService(app_impl_->shell(), app_url_, 41 mojo::ConnectToService(app_impl_->shell(), app_url_,
47 GetProxy(&client_view_provider)); 42 GetProxy(&client_view_provider));
48 43
49 client_view_provider->CreateView(GetProxy(&client_view_owner_), nullptr, 44 client_view_provider->CreateView(GetProxy(&client_view_owner_), nullptr,
50 nullptr); 45 nullptr);
51 } 46 }
52 47
53 void LaunchInstance::OnCompositorConnectionError() {
54 LOG(ERROR) << "Exiting due to compositor connection error.";
55 shutdown_callback_.Run();
56 }
57
58 void LaunchInstance::OnViewManagerConnectionError() {
59 LOG(ERROR) << "Exiting due to view manager connection error.";
60 shutdown_callback_.Run();
61 }
62
63 void LaunchInstance::InitViewport() { 48 void LaunchInstance::InitViewport() {
64 mojo::ConnectToService(app_impl_->shell(), "mojo:native_viewport_service", 49 mojo::ConnectToService(app_impl_->shell(), "mojo:native_viewport_service",
65 GetProxy(&viewport_)); 50 GetProxy(&viewport_));
66 viewport_.set_connection_error_handler(base::Bind( 51 viewport_.set_connection_error_handler(base::Bind(
67 &LaunchInstance::OnViewportConnectionError, base::Unretained(this))); 52 &LaunchInstance::OnViewportConnectionError, base::Unretained(this)));
68 53
69 mojo::NativeViewportEventDispatcherPtr dispatcher; 54 mojo::NativeViewportEventDispatcherPtr dispatcher;
70 viewport_event_dispatcher_binding_.Bind(GetProxy(&dispatcher)); 55 viewport_event_dispatcher_binding_.Bind(GetProxy(&dispatcher));
71 viewport_->SetEventDispatcher(dispatcher.Pass()); 56 viewport_->SetEventDispatcher(dispatcher.Pass());
72 57
(...skipping 12 matching lines...) Expand all
85 LOG(ERROR) << "Exiting due to viewport connection error."; 70 LOG(ERROR) << "Exiting due to viewport connection error.";
86 shutdown_callback_.Run(); 71 shutdown_callback_.Run();
87 } 72 }
88 73
89 void LaunchInstance::OnViewportCreated(mojo::ViewportMetricsPtr metrics) { 74 void LaunchInstance::OnViewportCreated(mojo::ViewportMetricsPtr metrics) {
90 viewport_->Show(); 75 viewport_->Show();
91 76
92 mojo::ContextProviderPtr context_provider; 77 mojo::ContextProviderPtr context_provider;
93 viewport_->GetContextProvider(GetProxy(&context_provider)); 78 viewport_->GetContextProvider(GetProxy(&context_provider));
94 79
95 view_tree_.reset(new LauncherViewTree(compositor_.get(), view_manager_.get(), 80 view_tree_.reset(new LauncherViewTree(compositor_, view_manager_,
96 context_provider.Pass(), metrics.Pass(), 81 context_provider.Pass(), metrics.Pass(),
97 shutdown_callback_)); 82 shutdown_callback_));
98 view_tree_->SetRoot(client_view_owner_.Pass()); 83 view_tree_->SetRoot(client_view_owner_.Pass());
99 84
100 RequestUpdatedViewportMetrics(); 85 RequestUpdatedViewportMetrics();
101 } 86 }
102 87
103 void LaunchInstance::OnViewportMetricsChanged( 88 void LaunchInstance::OnViewportMetricsChanged(
104 mojo::ViewportMetricsPtr metrics) { 89 mojo::ViewportMetricsPtr metrics) {
105 if (view_tree_) { 90 if (view_tree_) {
106 view_tree_->SetViewportMetrics(metrics.Pass()); 91 view_tree_->SetViewportMetrics(metrics.Pass());
107 RequestUpdatedViewportMetrics(); 92 RequestUpdatedViewportMetrics();
108 } 93 }
109 } 94 }
110 95
111 void LaunchInstance::RequestUpdatedViewportMetrics() { 96 void LaunchInstance::RequestUpdatedViewportMetrics() {
112 viewport_->RequestMetrics(base::Bind( 97 viewport_->RequestMetrics(base::Bind(
113 &LaunchInstance::OnViewportMetricsChanged, base::Unretained(this))); 98 &LaunchInstance::OnViewportMetricsChanged, base::Unretained(this)));
114 } 99 }
115 100
116 void LaunchInstance::OnEvent(mojo::EventPtr event, 101 void LaunchInstance::OnEvent(mojo::EventPtr event,
117 const mojo::Callback<void()>& callback) { 102 const mojo::Callback<void()>& callback) {
118 if (view_tree_) 103 if (view_tree_)
119 view_tree_->DispatchEvent(event.Pass()); 104 view_tree_->DispatchEvent(event.Pass());
120 callback.Run(); 105 callback.Run();
121 } 106 }
122 107
123 } // namespace launcher 108 } // namespace launcher
OLDNEW
« no previous file with comments | « services/ui/launcher/launch_instance.h ('k') | services/ui/launcher/launcher_app.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698