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

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

Issue 1354003002: Make CapabilityFilter be part of Identity (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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 68 }
69 69
70 void ApplicationManager::TerminateShellConnections() { 70 void ApplicationManager::TerminateShellConnections() {
71 STLDeleteValues(&identity_to_instance_); 71 STLDeleteValues(&identity_to_instance_);
72 } 72 }
73 73
74 void ApplicationManager::ConnectToApplication( 74 void ApplicationManager::ConnectToApplication(
75 scoped_ptr<ConnectToApplicationParams> params) { 75 scoped_ptr<ConnectToApplicationParams> params) {
76 TRACE_EVENT_INSTANT1("mojo_shell", "ApplicationManager::ConnectToApplication", 76 TRACE_EVENT_INSTANT1("mojo_shell", "ApplicationManager::ConnectToApplication",
77 TRACE_EVENT_SCOPE_THREAD, "original_url", 77 TRACE_EVENT_SCOPE_THREAD, "original_url",
78 params->app_url().spec()); 78 params->target().url().spec());
79 DCHECK(params->app_url().is_valid()); 79 DCHECK(params->target().url().is_valid());
80 80
81 // Connect to an existing matching instance, if possible. 81 // Connect to an existing matching instance, if possible.
82 if (ConnectToRunningApplication(&params)) 82 if (ConnectToRunningApplication(&params))
83 return; 83 return;
84 84
85 ApplicationLoader* loader = GetLoaderForURL(params->app_url()); 85 ApplicationLoader* loader = GetLoaderForURL(params->target().url());
86 if (loader) { 86 if (loader) {
87 GURL url = params->app_url(); 87 GURL url = params->target().url();
88 loader->Load(url, CreateInstance(params.Pass(), nullptr)); 88 loader->Load(url, CreateInstance(params.Pass(), nullptr));
89 return; 89 return;
90 } 90 }
91 91
92 URLRequestPtr original_url_request = params->TakeAppURLRequest(); 92 URLRequestPtr original_url_request = params->TakeTargetURLRequest();
93 auto callback = 93 auto callback =
94 base::Bind(&ApplicationManager::HandleFetchCallback, 94 base::Bind(&ApplicationManager::HandleFetchCallback,
95 weak_ptr_factory_.GetWeakPtr(), base::Passed(&params)); 95 weak_ptr_factory_.GetWeakPtr(), base::Passed(&params));
96 package_manager_->FetchRequest(original_url_request.Pass(), callback); 96 package_manager_->FetchRequest(original_url_request.Pass(), callback);
97 } 97 }
98 98
99 bool ApplicationManager::ConnectToRunningApplication( 99 bool ApplicationManager::ConnectToRunningApplication(
100 scoped_ptr<ConnectToApplicationParams>* params) { 100 scoped_ptr<ConnectToApplicationParams>* params) {
101 ApplicationInstance* instance = GetApplicationInstance( 101 ApplicationInstance* instance = GetApplicationInstance((*params)->target());
102 Identity((*params)->app_url(), (*params)->qualifier()));
103 if (!instance) 102 if (!instance)
104 return false; 103 return false;
105 104
106 instance->ConnectToClient(params->Pass()); 105 instance->ConnectToClient(params->Pass());
107 return true; 106 return true;
108 } 107 }
109 108
110 InterfaceRequest<Application> ApplicationManager::CreateInstance( 109 InterfaceRequest<Application> ApplicationManager::CreateInstance(
111 scoped_ptr<ConnectToApplicationParams> params, 110 scoped_ptr<ConnectToApplicationParams> params,
112 ApplicationInstance** resulting_instance) { 111 ApplicationInstance** resulting_instance) {
113 Identity app_identity(params->app_url(), params->qualifier()); 112 Identity target_id = params->target();
114
115 ApplicationPtr application; 113 ApplicationPtr application;
116 InterfaceRequest<Application> application_request = GetProxy(&application); 114 InterfaceRequest<Application> application_request = GetProxy(&application);
117 ApplicationInstance* instance = new ApplicationInstance( 115 ApplicationInstance* instance = new ApplicationInstance(
118 application.Pass(), this, params->originator_identity(), app_identity, 116 application.Pass(), this, target_id, Shell::kInvalidContentHandlerID,
119 params->filter(), Shell::kInvalidContentHandlerID,
120 params->on_application_end()); 117 params->on_application_end());
121 DCHECK(identity_to_instance_.find(app_identity) == 118 DCHECK(identity_to_instance_.find(target_id) ==
122 identity_to_instance_.end()); 119 identity_to_instance_.end());
123 identity_to_instance_[app_identity] = instance; 120 identity_to_instance_[target_id] = instance;
124 instance->InitializeApplication(); 121 instance->InitializeApplication();
125 instance->ConnectToClient(params.Pass()); 122 instance->ConnectToClient(params.Pass());
126 if (resulting_instance) 123 if (resulting_instance)
127 *resulting_instance = instance; 124 *resulting_instance = instance;
128 return application_request.Pass(); 125 return application_request.Pass();
129 } 126 }
130 127
131 ApplicationInstance* ApplicationManager::GetApplicationInstance( 128 ApplicationInstance* ApplicationManager::GetApplicationInstance(
132 const Identity& identity) const { 129 const Identity& identity) const {
133 const auto& it = identity_to_instance_.find(identity); 130 const auto& it = identity_to_instance_.find(identity);
(...skipping 12 matching lines...) Expand all
146 GURL redirect_url = fetcher->GetRedirectURL(); 143 GURL redirect_url = fetcher->GetRedirectURL();
147 if (!redirect_url.is_empty()) { 144 if (!redirect_url.is_empty()) {
148 // And around we go again... Whee! 145 // And around we go again... Whee!
149 // TODO(sky): this loses the original URL info. 146 // TODO(sky): this loses the original URL info.
150 URLRequestPtr new_request = URLRequest::New(); 147 URLRequestPtr new_request = URLRequest::New();
151 new_request->url = redirect_url.spec(); 148 new_request->url = redirect_url.spec();
152 HttpHeaderPtr header = HttpHeader::New(); 149 HttpHeaderPtr header = HttpHeader::New();
153 header->name = "Referer"; 150 header->name = "Referer";
154 header->value = fetcher->GetRedirectReferer().spec(); 151 header->value = fetcher->GetRedirectReferer().spec();
155 new_request->headers.push_back(header.Pass()); 152 new_request->headers.push_back(header.Pass());
156 params->SetURLInfo(new_request.Pass()); 153 params->SetTargetURLRequest(new_request.Pass());
157 ConnectToApplication(params.Pass()); 154 ConnectToApplication(params.Pass());
158 return; 155 return;
159 } 156 }
160 157
161 // We already checked if the application was running before we fetched it, but 158 // We already checked if the application was running before we fetched it, but
162 // it might have started while the fetch was outstanding. We don't want to 159 // it might have started while the fetch was outstanding. We don't want to
163 // have two copies of the app running, so check again. 160 // have two copies of the app running, so check again.
164 if (ConnectToRunningApplication(&params)) 161 if (ConnectToRunningApplication(&params))
165 return; 162 return;
166 163
167 Identity originator_identity = params->originator_identity(); 164 Identity source = params->source();
168 CapabilityFilter originator_filter = params->originator_filter(); 165 Identity target = params->target();
169 CapabilityFilter filter = params->filter();
170 GURL app_url = params->app_url();
171 std::string qualifier = params->qualifier();
172 Shell::ConnectToApplicationCallback connect_callback = 166 Shell::ConnectToApplicationCallback connect_callback =
173 params->connect_callback(); 167 params->connect_callback();
174 params->set_connect_callback(EmptyConnectCallback()); 168 params->set_connect_callback(EmptyConnectCallback());
175 ApplicationInstance* app = nullptr; 169 ApplicationInstance* app = nullptr;
176 InterfaceRequest<Application> request(CreateInstance(params.Pass(), &app)); 170 InterfaceRequest<Application> request(CreateInstance(params.Pass(), &app));
177 171
178 172
179 GURL content_handler_url; 173 GURL content_handler_url;
180 URLResponsePtr new_response; 174 URLResponsePtr new_response;
175 std::string qualifier;
181 if (package_manager_->HandleWithContentHandler(fetcher.get(), 176 if (package_manager_->HandleWithContentHandler(fetcher.get(),
182 app_url, 177 target.url(),
183 blocking_pool_, 178 blocking_pool_,
184 &new_response, 179 &new_response,
185 &content_handler_url, 180 &content_handler_url,
186 &qualifier)) { 181 &qualifier)) {
187 LoadWithContentHandler(originator_identity, originator_filter, 182 Identity content_handler(content_handler_url, qualifier, target.filter());
188 content_handler_url, qualifier, filter, 183 LoadWithContentHandler(source, content_handler, connect_callback, app,
189 connect_callback, app, request.Pass(), 184 request.Pass(), new_response.Pass());
190 new_response.Pass());
191 } else { 185 } else {
192 // TODO(erg): Have a better way of switching the sandbox on. For now, switch 186 // TODO(erg): Have a better way of switching the sandbox on. For now, switch
193 // it on hard coded when we're using some of the sandboxable core services. 187 // it on hard coded when we're using some of the sandboxable core services.
194 bool start_sandboxed = false; 188 bool start_sandboxed = false;
195 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 189 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
196 switches::kMojoNoSandbox)) { 190 switches::kMojoNoSandbox)) {
197 if (app_url == GURL("mojo://core_services/") && qualifier == "Core") 191 start_sandboxed = (target.url() == GURL("mojo://core_services/") &&
198 start_sandboxed = true; 192 target.qualifier() == "Core") ||
199 else if (app_url == GURL("mojo://html_viewer/")) 193 target.url() == GURL("mojo://html_viewer/");
200 start_sandboxed = true;
201 } 194 }
202 195
203 connect_callback.Run(Shell::kInvalidContentHandlerID); 196 connect_callback.Run(Shell::kInvalidContentHandlerID);
204 197
205 fetcher->AsPath(blocking_pool_, 198 fetcher->AsPath(blocking_pool_,
206 base::Bind(&ApplicationManager::RunNativeApplication, 199 base::Bind(&ApplicationManager::RunNativeApplication,
207 weak_ptr_factory_.GetWeakPtr(), 200 weak_ptr_factory_.GetWeakPtr(),
208 base::Passed(request.Pass()), start_sandboxed, 201 base::Passed(request.Pass()), start_sandboxed,
209 base::Passed(fetcher.Pass()))); 202 base::Passed(fetcher.Pass())));
210 } 203 }
(...skipping 19 matching lines...) Expand all
230 TRACE_EVENT1("mojo_shell", "ApplicationManager::RunNativeApplication", "path", 223 TRACE_EVENT1("mojo_shell", "ApplicationManager::RunNativeApplication", "path",
231 path.AsUTF8Unsafe()); 224 path.AsUTF8Unsafe());
232 NativeRunner* runner = native_runner_factory_->Create().release(); 225 NativeRunner* runner = native_runner_factory_->Create().release();
233 native_runners_.push_back(runner); 226 native_runners_.push_back(runner);
234 runner->Start(path, start_sandboxed, application_request.Pass(), 227 runner->Start(path, start_sandboxed, application_request.Pass(),
235 base::Bind(&ApplicationManager::CleanupRunner, 228 base::Bind(&ApplicationManager::CleanupRunner,
236 weak_ptr_factory_.GetWeakPtr(), runner)); 229 weak_ptr_factory_.GetWeakPtr(), runner));
237 } 230 }
238 231
239 void ApplicationManager::LoadWithContentHandler( 232 void ApplicationManager::LoadWithContentHandler(
240 const Identity& originator_identity, 233 const Identity& source,
241 const CapabilityFilter& originator_filter, 234 const Identity& content_handler,
242 const GURL& content_handler_url,
243 const std::string& qualifier,
244 const CapabilityFilter& filter,
245 const Shell::ConnectToApplicationCallback& connect_callback, 235 const Shell::ConnectToApplicationCallback& connect_callback,
246 ApplicationInstance* app, 236 ApplicationInstance* app,
247 InterfaceRequest<Application> application_request, 237 InterfaceRequest<Application> application_request,
248 URLResponsePtr url_response) { 238 URLResponsePtr url_response) {
249 ContentHandlerConnection* connection = nullptr; 239 ContentHandlerConnection* connection = nullptr;
250 Identity content_handler_identity(content_handler_url, qualifier);
251 // TODO(beng): Figure out the extent to which capability filter should be 240 // TODO(beng): Figure out the extent to which capability filter should be
252 // factored into handler identity. 241 // factored into handler identity.
253 IdentityToContentHandlerMap::iterator iter = 242 IdentityToContentHandlerMap::iterator iter =
254 identity_to_content_handler_.find(content_handler_identity); 243 identity_to_content_handler_.find(content_handler);
255 if (iter != identity_to_content_handler_.end()) { 244 if (iter != identity_to_content_handler_.end()) {
256 connection = iter->second; 245 connection = iter->second;
257 } else { 246 } else {
258 connection = new ContentHandlerConnection( 247 connection = new ContentHandlerConnection(
259 this, originator_identity, originator_filter, content_handler_url, 248 this, source, content_handler, ++content_handler_id_counter_);
260 qualifier, filter, ++content_handler_id_counter_); 249 identity_to_content_handler_[content_handler] = connection;
261 identity_to_content_handler_[content_handler_identity] = connection;
262 } 250 }
263 251
264 app->set_requesting_content_handler_id(connection->id()); 252 app->set_requesting_content_handler_id(connection->id());
265 connection->content_handler()->StartApplication(application_request.Pass(), 253 connection->content_handler()->StartApplication(application_request.Pass(),
266 url_response.Pass()); 254 url_response.Pass());
267 connect_callback.Run(connection->id()); 255 connect_callback.Run(connection->id());
268 } 256 }
269 257
270 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, 258 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader,
271 const GURL& url) { 259 const GURL& url) {
(...skipping 20 matching lines...) Expand all
292 DCHECK(it != identity_to_instance_.end()); 280 DCHECK(it != identity_to_instance_.end());
293 delete it->second; 281 delete it->second;
294 identity_to_instance_.erase(it); 282 identity_to_instance_.erase(it);
295 if (!on_application_end.is_null()) 283 if (!on_application_end.is_null())
296 on_application_end.Run(); 284 on_application_end.Run();
297 } 285 }
298 286
299 void ApplicationManager::OnContentHandlerConnectionClosed( 287 void ApplicationManager::OnContentHandlerConnectionClosed(
300 ContentHandlerConnection* content_handler) { 288 ContentHandlerConnection* content_handler) {
301 // Remove the mapping to the content handler. 289 // Remove the mapping to the content handler.
302 auto it = identity_to_content_handler_.find( 290 auto it = identity_to_content_handler_.find(content_handler->identity());
303 Identity(content_handler->content_handler_url(),
304 content_handler->content_handler_qualifier()));
305 DCHECK(it != identity_to_content_handler_.end()); 291 DCHECK(it != identity_to_content_handler_.end());
306 identity_to_content_handler_.erase(it); 292 identity_to_content_handler_.erase(it);
307 } 293 }
308 294
309 void ApplicationManager::CleanupRunner(NativeRunner* runner) { 295 void ApplicationManager::CleanupRunner(NativeRunner* runner) {
310 native_runners_.erase( 296 native_runners_.erase(
311 std::find(native_runners_.begin(), native_runners_.end(), runner)); 297 std::find(native_runners_.begin(), native_runners_.end(), runner));
312 } 298 }
313 299
314 Shell::ConnectToApplicationCallback EmptyConnectCallback() { 300 Shell::ConnectToApplicationCallback EmptyConnectCallback() {
315 return base::Bind(&OnEmptyOnConnectCallback); 301 return base::Bind(&OnEmptyOnConnectCallback);
316 } 302 }
317 303
318 } // namespace shell 304 } // namespace shell
319 } // namespace mojo 305 } // 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