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

Side by Side Diff: mojo/shell/public/cpp/lib/application_impl.cc

Issue 1675083002: Rename ApplicationDelegate to ShellClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@delegate
Patch Set: . Created 4 years, 10 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <algorithm> 5 #include <algorithm>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "mojo/converters/network/network_type_converters.h" 10 #include "mojo/converters/network/network_type_converters.h"
11 #include "mojo/public/cpp/bindings/interface_ptr.h" 11 #include "mojo/public/cpp/bindings/interface_ptr.h"
12 #include "mojo/public/cpp/environment/logging.h" 12 #include "mojo/public/cpp/environment/logging.h"
13 #include "mojo/shell/public/cpp/application_delegate.h"
14 #include "mojo/shell/public/cpp/application_impl.h" 13 #include "mojo/shell/public/cpp/application_impl.h"
15 #include "mojo/shell/public/cpp/lib/service_registry.h" 14 #include "mojo/shell/public/cpp/lib/service_registry.h"
15 #include "mojo/shell/public/cpp/shell_client.h"
16 16
17 namespace mojo { 17 namespace mojo {
18 18
19 namespace { 19 namespace {
20 20
21 void DefaultTerminationClosure() { 21 void DefaultTerminationClosure() {
22 if (base::MessageLoop::current() && 22 if (base::MessageLoop::current() &&
23 base::MessageLoop::current()->is_running()) 23 base::MessageLoop::current()->is_running())
24 base::MessageLoop::current()->QuitWhenIdle(); 24 base::MessageLoop::current()->QuitWhenIdle();
25 } 25 }
26 26
27 } // namespace 27 } // namespace
28 28
29 ApplicationImpl::ConnectParams::ConnectParams(const std::string& url) 29 ApplicationImpl::ConnectParams::ConnectParams(const std::string& url)
30 : ConnectParams(URLRequest::From(url)) {} 30 : ConnectParams(URLRequest::From(url)) {}
31 ApplicationImpl::ConnectParams::ConnectParams(URLRequestPtr request) 31 ApplicationImpl::ConnectParams::ConnectParams(URLRequestPtr request)
32 : request_(std::move(request)), 32 : request_(std::move(request)),
33 filter_(shell::mojom::CapabilityFilter::New()) { 33 filter_(shell::mojom::CapabilityFilter::New()) {
34 filter_->filter.mark_non_null(); 34 filter_->filter.mark_non_null();
35 } 35 }
36 ApplicationImpl::ConnectParams::~ConnectParams() {} 36 ApplicationImpl::ConnectParams::~ConnectParams() {}
37 37
38 ApplicationImpl::ApplicationImpl( 38 ApplicationImpl::ApplicationImpl(
39 ApplicationDelegate* delegate, 39 ShellClient* client,
40 InterfaceRequest<shell::mojom::Application> request) 40 InterfaceRequest<shell::mojom::Application> request)
41 : ApplicationImpl(delegate, 41 : ApplicationImpl(client,
42 std::move(request), 42 std::move(request),
43 base::Bind(&DefaultTerminationClosure)) {} 43 base::Bind(&DefaultTerminationClosure)) {}
44 44
45 ApplicationImpl::ApplicationImpl( 45 ApplicationImpl::ApplicationImpl(
46 ApplicationDelegate* delegate, 46 ShellClient* client,
47 InterfaceRequest<shell::mojom::Application> request, 47 InterfaceRequest<shell::mojom::Application> request,
48 const Closure& termination_closure) 48 const Closure& termination_closure)
49 : delegate_(delegate), 49 : client_(client),
50 binding_(this, std::move(request)), 50 binding_(this, std::move(request)),
51 termination_closure_(termination_closure), 51 termination_closure_(termination_closure),
52 app_lifetime_helper_(this), 52 app_lifetime_helper_(this),
53 quit_requested_(false), 53 quit_requested_(false),
54 weak_factory_(this) {} 54 weak_factory_(this) {}
55 55
56 ApplicationImpl::~ApplicationImpl() { 56 ApplicationImpl::~ApplicationImpl() {
57 app_lifetime_helper_.OnQuit(); 57 app_lifetime_helper_.OnQuit();
58 } 58 }
59 59
60 void ApplicationImpl::WaitForInitialize() { 60 void ApplicationImpl::WaitForInitialize() {
61 DCHECK(!shell_.is_bound()); 61 DCHECK(!shell_.is_bound());
62 binding_.WaitForIncomingMethodCall(); 62 binding_.WaitForIncomingMethodCall();
63 } 63 }
64 64
65 scoped_ptr<ApplicationConnection> ApplicationImpl::ConnectToApplication( 65 scoped_ptr<Connection> ApplicationImpl::ConnectToApplication(
66 const std::string& url) { 66 const std::string& url) {
67 ConnectParams params(url); 67 ConnectParams params(url);
68 params.set_filter(CreatePermissiveCapabilityFilter()); 68 params.set_filter(CreatePermissiveCapabilityFilter());
69 return ConnectToApplication(&params); 69 return ConnectToApplication(&params);
70 } 70 }
71 71
72 scoped_ptr<ApplicationConnection> 72 scoped_ptr<Connection> ApplicationImpl::ConnectToApplication(
73 ApplicationImpl::ConnectToApplication(ConnectParams* params) { 73 ConnectParams* params) {
74 if (!shell_) 74 if (!shell_)
75 return nullptr; 75 return nullptr;
76 DCHECK(params); 76 DCHECK(params);
77 URLRequestPtr request = params->TakeRequest(); 77 URLRequestPtr request = params->TakeRequest();
78 ServiceProviderPtr local_services; 78 ServiceProviderPtr local_services;
79 InterfaceRequest<ServiceProvider> local_request = GetProxy(&local_services); 79 InterfaceRequest<ServiceProvider> local_request = GetProxy(&local_services);
80 ServiceProviderPtr remote_services; 80 ServiceProviderPtr remote_services;
81 std::string application_url = request->url.To<std::string>(); 81 std::string application_url = request->url.To<std::string>();
82 // We allow all interfaces on outgoing connections since we are presumably in 82 // We allow all interfaces on outgoing connections since we are presumably in
83 // a position to know who we're talking to. 83 // a position to know who we're talking to.
(...skipping 27 matching lines...) Expand all
111 111
112 scoped_ptr<AppRefCount> ApplicationImpl::CreateAppRefCount() { 112 scoped_ptr<AppRefCount> ApplicationImpl::CreateAppRefCount() {
113 return app_lifetime_helper_.CreateAppRefCount(); 113 return app_lifetime_helper_.CreateAppRefCount();
114 } 114 }
115 115
116 void ApplicationImpl::Initialize(shell::mojom::ShellPtr shell, 116 void ApplicationImpl::Initialize(shell::mojom::ShellPtr shell,
117 const mojo::String& url, 117 const mojo::String& url,
118 uint32_t id) { 118 uint32_t id) {
119 shell_ = std::move(shell); 119 shell_ = std::move(shell);
120 shell_.set_connection_error_handler([this]() { OnConnectionError(); }); 120 shell_.set_connection_error_handler([this]() { OnConnectionError(); });
121 delegate_->Initialize(this, url, id); 121 client_->Initialize(this, url, id);
122 } 122 }
123 123
124 void ApplicationImpl::AcceptConnection( 124 void ApplicationImpl::AcceptConnection(
125 const String& requestor_url, 125 const String& requestor_url,
126 uint32_t requestor_id, 126 uint32_t requestor_id,
127 InterfaceRequest<ServiceProvider> services, 127 InterfaceRequest<ServiceProvider> services,
128 ServiceProviderPtr exposed_services, 128 ServiceProviderPtr exposed_services,
129 Array<String> allowed_interfaces, 129 Array<String> allowed_interfaces,
130 const String& url) { 130 const String& url) {
131 scoped_ptr<ApplicationConnection> registry(new internal::ServiceRegistry( 131 scoped_ptr<Connection> registry(new internal::ServiceRegistry(
132 url, requestor_url, requestor_id, std::move(exposed_services), 132 url, requestor_url, requestor_id, std::move(exposed_services),
133 std::move(services), allowed_interfaces.To<std::set<std::string>>())); 133 std::move(services), allowed_interfaces.To<std::set<std::string>>()));
134 if (!delegate_->AcceptConnection(registry.get())) 134 if (!client_->AcceptConnection(registry.get()))
135 return; 135 return;
136 136
137 // If we were quitting because we thought there were no more services for this 137 // If we were quitting because we thought there were no more services for this
138 // app in use, then that has changed so cancel the quit request. 138 // app in use, then that has changed so cancel the quit request.
139 if (quit_requested_) 139 if (quit_requested_)
140 quit_requested_ = false; 140 quit_requested_ = false;
141 141
142 incoming_connections_.push_back(std::move(registry)); 142 incoming_connections_.push_back(std::move(registry));
143 } 143 }
144 144
145 void ApplicationImpl::OnQuitRequested(const Callback<void(bool)>& callback) { 145 void ApplicationImpl::OnQuitRequested(const Callback<void(bool)>& callback) {
146 // If by the time we got the reply from the shell, more requests had come in 146 // If by the time we got the reply from the shell, more requests had come in
147 // then we don't want to quit the app anymore so we return false. Otherwise 147 // then we don't want to quit the app anymore so we return false. Otherwise
148 // |quit_requested_| is true so we tell the shell to proceed with the quit. 148 // |quit_requested_| is true so we tell the shell to proceed with the quit.
149 callback.Run(quit_requested_); 149 callback.Run(quit_requested_);
150 if (quit_requested_) 150 if (quit_requested_)
151 QuitNow(); 151 QuitNow();
152 } 152 }
153 153
154 void ApplicationImpl::OnConnectionError() { 154 void ApplicationImpl::OnConnectionError() {
155 base::WeakPtr<ApplicationImpl> ptr(weak_factory_.GetWeakPtr()); 155 base::WeakPtr<ApplicationImpl> ptr(weak_factory_.GetWeakPtr());
156 156
157 // We give the delegate notice first, since it might want to do something on 157 // We give the client notice first, since it might want to do something on
158 // shell connection errors other than immediate termination of the run 158 // shell connection errors other than immediate termination of the run
159 // loop. The application might want to continue servicing connections other 159 // loop. The application might want to continue servicing connections other
160 // than the one to the shell. 160 // than the one to the shell.
161 bool quit_now = delegate_->ShellConnectionLost(); 161 bool quit_now = client_->ShellConnectionLost();
162 if (quit_now) 162 if (quit_now)
163 QuitNow(); 163 QuitNow();
164 if (!ptr) 164 if (!ptr)
165 return; 165 return;
166 shell_ = nullptr; 166 shell_ = nullptr;
167 } 167 }
168 168
169 void ApplicationImpl::QuitNow() { 169 void ApplicationImpl::QuitNow() {
170 delegate_->Quit(); 170 client_->Quit();
171 termination_closure_.Run(); 171 termination_closure_.Run();
172 } 172 }
173 173
174 void ApplicationImpl::UnbindConnections( 174 void ApplicationImpl::UnbindConnections(
175 InterfaceRequest<shell::mojom::Application>* application_request, 175 InterfaceRequest<shell::mojom::Application>* application_request,
176 shell::mojom::ShellPtr* shell) { 176 shell::mojom::ShellPtr* shell) {
177 *application_request = binding_.Unbind(); 177 *application_request = binding_.Unbind();
178 shell->Bind(shell_.PassInterface()); 178 shell->Bind(shell_.PassInterface());
179 } 179 }
180 180
181 shell::mojom::CapabilityFilterPtr CreatePermissiveCapabilityFilter() { 181 shell::mojom::CapabilityFilterPtr CreatePermissiveCapabilityFilter() {
182 shell::mojom::CapabilityFilterPtr filter( 182 shell::mojom::CapabilityFilterPtr filter(
183 shell::mojom::CapabilityFilter::New()); 183 shell::mojom::CapabilityFilter::New());
184 Array<String> all_interfaces; 184 Array<String> all_interfaces;
185 all_interfaces.push_back("*"); 185 all_interfaces.push_back("*");
186 filter->filter.insert("*", std::move(all_interfaces)); 186 filter->filter.insert("*", std::move(all_interfaces));
187 return filter; 187 return filter;
188 } 188 }
189 189
190 } // namespace mojo 190 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/public/cpp/lib/application_delegate.cc ('k') | mojo/shell/public/cpp/lib/application_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698