Index: services/shell/shell.cc |
diff --git a/services/shell/shell.cc b/services/shell/shell.cc |
index a542ae4769e481d48514d785e9650414d4d09d3a..35049dd41f30873ef65a2161d14f8a1c5f548fde 100644 |
--- a/services/shell/shell.cc |
+++ b/services/shell/shell.cc |
@@ -120,8 +120,10 @@ |
allow_any_application_(capability_spec.required.count("*") == 1), |
pid_receiver_binding_(this), |
weak_factory_(this) { |
- if (identity_.name() == kShellName) |
+ if (identity_.name() == kShellName || |
+ shell_->GetLoaderForName(identity_.name())) { |
pid_ = base::Process::Current().Pid(); |
+ } |
DCHECK_NE(mojom::kInvalidInstanceID, id_); |
} |
@@ -458,6 +460,7 @@ |
Shell::~Shell() { |
TerminateShellConnections(); |
+ STLDeleteValues(&name_to_loader_); |
for (auto& runner : native_runners_) |
runner.reset(); |
} |
@@ -484,6 +487,14 @@ |
Connect(std::move(params), std::move(client)); |
return request; |
+} |
+ |
+void Shell::SetLoaderForName(std::unique_ptr<Loader> loader, |
+ const std::string& name) { |
+ auto it = name_to_loader_.find(name); |
+ if (it != name_to_loader_.end()) |
+ delete it->second; |
+ name_to_loader_[name] = loader.release(); |
} |
//////////////////////////////////////////////////////////////////////////////// |
@@ -726,22 +737,42 @@ |
} else { |
// Otherwise we create a new ShellClient pipe. |
mojom::ShellClientRequest request = GetProxy(&client); |
- CHECK(!result->package_url.is_null() && !result->capabilities.is_null()); |
- |
- if (target.name() != result->resolved_name) { |
+ if (LoadWithLoader(target, &request)) { |
instance->StartWithClient(std::move(client)); |
- Identity factory(result->resolved_name, target.user_id(), |
- instance_name); |
- CreateShellClientWithFactory(factory, target.name(), |
- std::move(request)); |
} else { |
- instance->StartWithFilePath( |
- mojo::util::UrlToFilePath(result->package_url.To<GURL>())); |
+ CHECK(!result->package_url.is_null() && !result->capabilities.is_null()); |
+ |
+ if (target.name() != result->resolved_name) { |
+ instance->StartWithClient(std::move(client)); |
+ Identity factory(result->resolved_name, target.user_id(), |
+ instance_name); |
+ CreateShellClientWithFactory(factory, target.name(), |
+ std::move(request)); |
+ } else { |
+ instance->StartWithFilePath( |
+ mojo::util::UrlToFilePath(result->package_url.To<GURL>())); |
+ } |
} |
} |
// Now that the instance has a ShellClient, we can connect to it. |
instance->ConnectToClient(std::move(params)); |
+} |
+ |
+bool Shell::LoadWithLoader(const Identity& target, |
+ mojom::ShellClientRequest* request) { |
+ Loader* loader = GetLoaderForName(target.name()); |
+ if (!loader) |
+ return false; |
+ loader->Load(target.name(), std::move(*request)); |
+ return true; |
+} |
+ |
+Loader* Shell::GetLoaderForName(const std::string& name) { |
+ auto name_it = name_to_loader_.find(name); |
+ if (name_it != name_to_loader_.end()) |
+ return name_it->second; |
+ return default_loader_.get(); |
} |
base::WeakPtr<Shell> Shell::GetWeakPtr() { |