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

Side by Side Diff: mojo/shell/application_manager.cc

Issue 1354043002: Revert of Some more minor cleanup to ApplicationManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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 | « mojo/shell/application_manager.h ('k') | mojo/shell/application_manager_unittest.cc » ('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 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 "mojo/shell/application_manager.h" 5 #include "mojo/shell/application_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 ApplicationManager::ApplicationManager( 53 ApplicationManager::ApplicationManager(
54 scoped_ptr<PackageManager> package_manager) 54 scoped_ptr<PackageManager> package_manager)
55 : package_manager_(package_manager.Pass()), 55 : package_manager_(package_manager.Pass()),
56 content_handler_id_counter_(0u), 56 content_handler_id_counter_(0u),
57 weak_ptr_factory_(this) { 57 weak_ptr_factory_(this) {
58 package_manager_->SetApplicationManager(this); 58 package_manager_->SetApplicationManager(this);
59 } 59 }
60 60
61 ApplicationManager::~ApplicationManager() { 61 ApplicationManager::~ApplicationManager() {
62 IdentityToContentHandlerMap identity_to_content_handler( 62 URLToContentHandlerMap url_to_content_handler(url_to_content_handler_);
63 identity_to_content_handler_); 63 for (auto& pair : url_to_content_handler)
64 for (auto& pair : identity_to_content_handler)
65 pair.second->CloseConnection(); 64 pair.second->CloseConnection();
66 TerminateShellConnections(); 65 TerminateShellConnections();
67 STLDeleteValues(&url_to_loader_); 66 STLDeleteValues(&url_to_loader_);
68 } 67 }
69 68
70 void ApplicationManager::TerminateShellConnections() { 69 void ApplicationManager::TerminateShellConnections() {
71 STLDeleteValues(&identity_to_instance_); 70 STLDeleteValues(&identity_to_instance_);
72 } 71 }
73 72
74 void ApplicationManager::ConnectToApplication( 73 void ApplicationManager::ConnectToApplication(
74 ApplicationInstance* originator,
75 URLRequestPtr app_url_request,
76 const std::string& qualifier,
77 InterfaceRequest<ServiceProvider> services,
78 ServiceProviderPtr exposed_services,
79 const CapabilityFilter& filter,
80 const base::Closure& on_application_end,
81 const Shell::ConnectToApplicationCallback& connect_callback) {
82 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams);
83 params->SetOriginatorInfo(originator);
84 params->SetURLInfo(app_url_request.Pass());
85 params->set_qualifier(qualifier);
86 params->set_services(services.Pass());
87 params->set_exposed_services(exposed_services.Pass());
88 params->set_filter(filter);
89 params->set_on_application_end(on_application_end);
90 params->set_connect_callback(connect_callback);
91
92 ConnectToApplication(params.Pass());
93 }
94
95 void ApplicationManager::ConnectToApplication(
75 scoped_ptr<ConnectToApplicationParams> params) { 96 scoped_ptr<ConnectToApplicationParams> params) {
76 GURL original_url = params->app_url(); 97 GURL original_url = params->app_url();
77 URLRequestPtr original_url_request = params->TakeAppURLRequest(); 98 URLRequestPtr original_url_request = params->TakeAppURLRequest();
78 99
79 TRACE_EVENT_INSTANT1("mojo_shell", "ApplicationManager::ConnectToApplication", 100 TRACE_EVENT_INSTANT1("mojo_shell", "ApplicationManager::ConnectToApplication",
80 TRACE_EVENT_SCOPE_THREAD, "original_url", 101 TRACE_EVENT_SCOPE_THREAD, "original_url",
81 original_url.spec()); 102 original_url.spec());
82 DCHECK(original_url.is_valid()); 103 DCHECK(original_url.is_valid());
83 DCHECK(original_url_request); 104 DCHECK(original_url_request);
84 105
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 return true; 141 return true;
121 } 142 }
122 143
123 void ApplicationManager::ConnectToApplicationWithLoader( 144 void ApplicationManager::ConnectToApplicationWithLoader(
124 scoped_ptr<ConnectToApplicationParams>* params, 145 scoped_ptr<ConnectToApplicationParams>* params,
125 const GURL& resolved_url, 146 const GURL& resolved_url,
126 ApplicationLoader* loader) { 147 ApplicationLoader* loader) {
127 if (!(*params)->app_url().SchemeIs("mojo")) 148 if (!(*params)->app_url().SchemeIs("mojo"))
128 (*params)->SetURLInfo(resolved_url); 149 (*params)->SetURLInfo(resolved_url);
129 150
130 loader->Load(resolved_url, CreateInstance(params->Pass(), nullptr)); 151 loader->Load(resolved_url, RegisterInstance(params->Pass(), nullptr));
131 } 152 }
132 153
133 InterfaceRequest<Application> ApplicationManager::CreateInstance( 154 InterfaceRequest<Application> ApplicationManager::RegisterInstance(
134 scoped_ptr<ConnectToApplicationParams> params, 155 scoped_ptr<ConnectToApplicationParams> params,
135 ApplicationInstance** resulting_instance) { 156 ApplicationInstance** resulting_instance) {
136 Identity app_identity(params->app_url(), params->qualifier()); 157 Identity app_identity(params->app_url(), params->qualifier());
137 158
138 ApplicationPtr application; 159 ApplicationPtr application;
139 InterfaceRequest<Application> application_request = GetProxy(&application); 160 InterfaceRequest<Application> application_request = GetProxy(&application);
140 ApplicationInstance* instance = new ApplicationInstance( 161 ApplicationInstance* instance = new ApplicationInstance(
141 application.Pass(), this, params->originator_identity(), app_identity, 162 application.Pass(), this, params->originator_identity(), app_identity,
142 params->filter(), Shell::kInvalidContentHandlerID, 163 params->filter(), Shell::kInvalidContentHandlerID,
143 params->on_application_end()); 164 params->on_application_end());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 218
198 Identity originator_identity = params->originator_identity(); 219 Identity originator_identity = params->originator_identity();
199 CapabilityFilter originator_filter = params->originator_filter(); 220 CapabilityFilter originator_filter = params->originator_filter();
200 CapabilityFilter filter = params->filter(); 221 CapabilityFilter filter = params->filter();
201 GURL app_url = params->app_url(); 222 GURL app_url = params->app_url();
202 std::string qualifier = params->qualifier(); 223 std::string qualifier = params->qualifier();
203 Shell::ConnectToApplicationCallback connect_callback = 224 Shell::ConnectToApplicationCallback connect_callback =
204 params->connect_callback(); 225 params->connect_callback();
205 params->set_connect_callback(EmptyConnectCallback()); 226 params->set_connect_callback(EmptyConnectCallback());
206 ApplicationInstance* app = nullptr; 227 ApplicationInstance* app = nullptr;
207 InterfaceRequest<Application> request(CreateInstance(params.Pass(), &app)); 228 InterfaceRequest<Application> request(RegisterInstance(params.Pass(), &app));
208 229
209 230
210 GURL content_handler_url; 231 GURL content_handler_url;
211 URLResponsePtr new_response; 232 URLResponsePtr new_response;
212 if (package_manager_->HandleWithContentHandler(fetcher.get(), 233 if (package_manager_->HandleWithContentHandler(fetcher.get(),
213 app_url, 234 app_url,
214 blocking_pool_, 235 blocking_pool_,
215 &new_response, 236 &new_response,
216 &content_handler_url, 237 &content_handler_url,
217 &qualifier)) { 238 &qualifier)) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 const Identity& originator_identity, 292 const Identity& originator_identity,
272 const CapabilityFilter& originator_filter, 293 const CapabilityFilter& originator_filter,
273 const GURL& content_handler_url, 294 const GURL& content_handler_url,
274 const std::string& qualifier, 295 const std::string& qualifier,
275 const CapabilityFilter& filter, 296 const CapabilityFilter& filter,
276 const Shell::ConnectToApplicationCallback& connect_callback, 297 const Shell::ConnectToApplicationCallback& connect_callback,
277 ApplicationInstance* app, 298 ApplicationInstance* app,
278 InterfaceRequest<Application> application_request, 299 InterfaceRequest<Application> application_request,
279 URLResponsePtr url_response) { 300 URLResponsePtr url_response) {
280 ContentHandlerConnection* connection = nullptr; 301 ContentHandlerConnection* connection = nullptr;
281 Identity content_handler_identity(content_handler_url, qualifier); 302 std::pair<GURL, std::string> key(content_handler_url, qualifier);
282 // TODO(beng): Figure out the extent to which capability filter should be 303 // TODO(beng): Figure out the extent to which capability filter should be
283 // factored into handler identity. 304 // factored into handler identity.
284 IdentityToContentHandlerMap::iterator iter = 305 URLToContentHandlerMap::iterator iter = url_to_content_handler_.find(key);
285 identity_to_content_handler_.find(content_handler_identity); 306 if (iter != url_to_content_handler_.end()) {
286 if (iter != identity_to_content_handler_.end()) {
287 connection = iter->second; 307 connection = iter->second;
288 } else { 308 } else {
289 connection = new ContentHandlerConnection( 309 connection = new ContentHandlerConnection(
290 this, originator_identity, originator_filter, content_handler_url, 310 this, originator_identity, originator_filter, content_handler_url,
291 qualifier, filter, ++content_handler_id_counter_); 311 qualifier, filter, ++content_handler_id_counter_);
292 identity_to_content_handler_[content_handler_identity] = connection; 312 url_to_content_handler_[key] = connection;
293 } 313 }
294 314
295 app->set_requesting_content_handler_id(connection->id()); 315 app->set_requesting_content_handler_id(connection->id());
296 connection->content_handler()->StartApplication(application_request.Pass(), 316 connection->content_handler()->StartApplication(application_request.Pass(),
297 url_response.Pass()); 317 url_response.Pass());
298 connect_callback.Run(connection->id()); 318 connect_callback.Run(connection->id());
299 } 319 }
300 320
301 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, 321 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader,
302 const GURL& url) { 322 const GURL& url) {
(...skipping 20 matching lines...) Expand all
323 DCHECK(it != identity_to_instance_.end()); 343 DCHECK(it != identity_to_instance_.end());
324 delete it->second; 344 delete it->second;
325 identity_to_instance_.erase(it); 345 identity_to_instance_.erase(it);
326 if (!on_application_end.is_null()) 346 if (!on_application_end.is_null())
327 on_application_end.Run(); 347 on_application_end.Run();
328 } 348 }
329 349
330 void ApplicationManager::OnContentHandlerConnectionClosed( 350 void ApplicationManager::OnContentHandlerConnectionClosed(
331 ContentHandlerConnection* content_handler) { 351 ContentHandlerConnection* content_handler) {
332 // Remove the mapping to the content handler. 352 // Remove the mapping to the content handler.
333 auto it = identity_to_content_handler_.find( 353 auto it = url_to_content_handler_.find(
334 Identity(content_handler->content_handler_url(), 354 std::make_pair(content_handler->content_handler_url(),
335 content_handler->content_handler_qualifier())); 355 content_handler->content_handler_qualifier()));
336 DCHECK(it != identity_to_content_handler_.end()); 356 DCHECK(it != url_to_content_handler_.end());
337 identity_to_content_handler_.erase(it); 357 url_to_content_handler_.erase(it);
338 } 358 }
339 359
340 void ApplicationManager::CleanupRunner(NativeRunner* runner) { 360 void ApplicationManager::CleanupRunner(NativeRunner* runner) {
341 native_runners_.erase( 361 native_runners_.erase(
342 std::find(native_runners_.begin(), native_runners_.end(), runner)); 362 std::find(native_runners_.begin(), native_runners_.end(), runner));
343 } 363 }
344 364
365 ScopedMessagePipeHandle ApplicationManager::ConnectToServiceByName(
366 const GURL& application_url,
367 const std::string& interface_name) {
368 ServiceProviderPtr services;
369 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams);
370 params->SetURLInfo(application_url);
371 params->set_services(GetProxy(&services));
372 params->set_filter(GetPermissiveCapabilityFilter());
373 ConnectToApplication(params.Pass());
374 MessagePipe pipe;
375 services->ConnectToService(interface_name, pipe.handle1.Pass());
376 return pipe.handle0.Pass();
377 }
378
345 Shell::ConnectToApplicationCallback EmptyConnectCallback() { 379 Shell::ConnectToApplicationCallback EmptyConnectCallback() {
346 return base::Bind(&OnEmptyOnConnectCallback); 380 return base::Bind(&OnEmptyOnConnectCallback);
347 } 381 }
348 382
349 } // namespace shell 383 } // namespace shell
350 } // namespace mojo 384 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/application_manager.h ('k') | mojo/shell/application_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698