| OLD | NEW |
| 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/shell.h" | 5 #include "mojo/shell/shell.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 namespace mojo { | 34 namespace mojo { |
| 35 namespace shell { | 35 namespace shell { |
| 36 namespace { | 36 namespace { |
| 37 const char kCatalogName[] = "mojo:catalog"; | 37 const char kCatalogName[] = "mojo:catalog"; |
| 38 const char kShellName[] = "mojo:shell"; | 38 const char kShellName[] = "mojo:shell"; |
| 39 const char kCapabilityClass_UserID[] = "user_id"; | 39 const char kCapabilityClass_UserID[] = "user_id"; |
| 40 const char kCapabilityClass_ClientProcess[] = "client_process"; | 40 const char kCapabilityClass_ClientProcess[] = "client_process"; |
| 41 const char kCapabilityClass_InstanceName[] = "instance_name"; | 41 const char kCapabilityClass_InstanceName[] = "instance_name"; |
| 42 const char kCapabilityClass_AllUsers[] = "all_users"; | 42 const char kCapabilityClass_AllUsers[] = "all_users"; |
| 43 | 43 |
| 44 void EmptyResolverCallback(const String& resolved_name, | 44 void EmptyResolverCallback(mojom::ResolveResultPtr result) {} |
| 45 const String& resolved_instance, | |
| 46 mojom::CapabilitySpecPtr capabilities, | |
| 47 const String& file_url) {} | |
| 48 | 45 |
| 49 } | 46 } |
| 50 | 47 |
| 51 Identity CreateShellIdentity() { | 48 Identity CreateShellIdentity() { |
| 52 return Identity(kShellName, mojom::kRootUserID); | 49 return Identity(kShellName, mojom::kRootUserID); |
| 53 } | 50 } |
| 54 | 51 |
| 55 Identity CreateCatalogIdentity() { | 52 Identity CreateCatalogIdentity() { |
| 56 return Identity(kCatalogName, mojom::kRootUserID); | 53 return Identity(kCatalogName, mojom::kRootUserID); |
| 57 } | 54 } |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 void Shell::OnShellClientFactoryLost(const Identity& which) { | 673 void Shell::OnShellClientFactoryLost(const Identity& which) { |
| 677 // Remove the mapping. | 674 // Remove the mapping. |
| 678 auto it = shell_client_factories_.find(which); | 675 auto it = shell_client_factories_.find(which); |
| 679 DCHECK(it != shell_client_factories_.end()); | 676 DCHECK(it != shell_client_factories_.end()); |
| 680 shell_client_factories_.erase(it); | 677 shell_client_factories_.erase(it); |
| 681 } | 678 } |
| 682 | 679 |
| 683 void Shell::OnGotResolvedName(mojom::ShellResolverPtr resolver, | 680 void Shell::OnGotResolvedName(mojom::ShellResolverPtr resolver, |
| 684 scoped_ptr<ConnectParams> params, | 681 scoped_ptr<ConnectParams> params, |
| 685 mojom::ShellClientPtr client, | 682 mojom::ShellClientPtr client, |
| 686 const String& resolved_name, | 683 mojom::ResolveResultPtr result) { |
| 687 const String& resolved_instance, | |
| 688 mojom::CapabilitySpecPtr capabilities_ptr, | |
| 689 const String& file_url) { | |
| 690 std::string instance_name = params->target().instance(); | 684 std::string instance_name = params->target().instance(); |
| 691 if (instance_name == GetNamePath(params->target().name()) && | 685 if (instance_name == GetNamePath(params->target().name()) && |
| 692 resolved_instance != GetNamePath(resolved_name)) { | 686 result->qualifier != GetNamePath(result->resolved_name)) { |
| 693 instance_name = resolved_instance; | 687 instance_name = result->qualifier; |
| 694 } | 688 } |
| 695 Identity target(params->target().name(), params->target().user_id(), | 689 Identity target(params->target().name(), params->target().user_id(), |
| 696 instance_name); | 690 instance_name); |
| 697 params->set_target(target); | 691 params->set_target(target); |
| 698 | 692 |
| 699 // It's possible that when this manifest request was issued, another one was | 693 // It's possible that when this manifest request was issued, another one was |
| 700 // already in-progress and completed by the time this one did, and so the | 694 // already in-progress and completed by the time this one did, and so the |
| 701 // requested application may already be running. | 695 // requested application may already be running. |
| 702 if (ConnectToExistingInstance(¶ms)) | 696 if (ConnectToExistingInstance(¶ms)) |
| 703 return; | 697 return; |
| 704 | 698 |
| 705 Identity source = params->source(); | 699 Identity source = params->source(); |
| 706 // |capabilities_ptr| can be null when there is no manifest, e.g. for URL | 700 // |capabilities_ptr| can be null when there is no manifest, e.g. for URL |
| 707 // types not resolvable by the resolver. | 701 // types not resolvable by the resolver. |
| 708 CapabilitySpec capabilities = GetPermissiveCapabilities(); | 702 CapabilitySpec capabilities = GetPermissiveCapabilities(); |
| 709 if (!capabilities_ptr.is_null()) | 703 if (!result->capabilities.is_null()) |
| 710 capabilities = capabilities_ptr.To<CapabilitySpec>(); | 704 capabilities = result->capabilities.To<CapabilitySpec>(); |
| 711 | 705 |
| 712 // Clients that request "all_users" class from the shell are allowed to | 706 // Clients that request "all_users" class from the shell are allowed to |
| 713 // field connection requests from any user. They also run with a synthetic | 707 // field connection requests from any user. They also run with a synthetic |
| 714 // user id generated here. The user id provided via Connect() is ignored. | 708 // user id generated here. The user id provided via Connect() is ignored. |
| 715 // Additionally apps with the "all_users" class are not tied to the lifetime | 709 // Additionally apps with the "all_users" class are not tied to the lifetime |
| 716 // of the app that connected to them, instead they are owned by the shell. | 710 // of the app that connected to them, instead they are owned by the shell. |
| 717 Identity source_identity_for_creation; | 711 Identity source_identity_for_creation; |
| 718 if (HasClass(capabilities, kCapabilityClass_AllUsers)) { | 712 if (HasClass(capabilities, kCapabilityClass_AllUsers)) { |
| 719 singletons_.insert(target.name()); | 713 singletons_.insert(target.name()); |
| 720 target.set_user_id(base::GenerateGUID()); | 714 target.set_user_id(base::GenerateGUID()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 738 // Likewise if a ClientProcessConnection was given via Connect(), it | 732 // Likewise if a ClientProcessConnection was given via Connect(), it |
| 739 // provides the ShellClient proxy to use. | 733 // provides the ShellClient proxy to use. |
| 740 instance->StartWithClientProcessConnection( | 734 instance->StartWithClientProcessConnection( |
| 741 std::move(client_process_connection)); | 735 std::move(client_process_connection)); |
| 742 } else { | 736 } else { |
| 743 // Otherwise we create a new ShellClient pipe. | 737 // Otherwise we create a new ShellClient pipe. |
| 744 mojom::ShellClientRequest request = GetProxy(&client); | 738 mojom::ShellClientRequest request = GetProxy(&client); |
| 745 if (LoadWithLoader(target, &request)) { | 739 if (LoadWithLoader(target, &request)) { |
| 746 instance->StartWithClient(std::move(client)); | 740 instance->StartWithClient(std::move(client)); |
| 747 } else { | 741 } else { |
| 748 CHECK(!file_url.is_null() && !capabilities_ptr.is_null()); | 742 CHECK(!result->package_url.is_null() && !result->capabilities.is_null()); |
| 749 | 743 |
| 750 if (target.name() != resolved_name) { | 744 if (target.name() != result->resolved_name) { |
| 751 instance->StartWithClient(std::move(client)); | 745 instance->StartWithClient(std::move(client)); |
| 752 CreateShellClientWithFactory( | 746 Identity factory(result->resolved_name, target.user_id(), |
| 753 source, Identity(resolved_name, target.user_id(), instance_name), | 747 instance_name); |
| 754 target.name(), std::move(request)); | 748 CreateShellClientWithFactory(source, factory, target.name(), |
| 749 std::move(request)); |
| 755 } else { | 750 } else { |
| 756 instance->StartWithFilePath(util::UrlToFilePath(file_url.To<GURL>())); | 751 instance->StartWithFilePath( |
| 752 util::UrlToFilePath(result->package_url.To<GURL>())); |
| 757 } | 753 } |
| 758 } | 754 } |
| 759 } | 755 } |
| 760 | 756 |
| 761 // Now that the instance has a ShellClient, we can connect to it. | 757 // Now that the instance has a ShellClient, we can connect to it. |
| 762 instance->ConnectToClient(std::move(params)); | 758 instance->ConnectToClient(std::move(params)); |
| 763 } | 759 } |
| 764 | 760 |
| 765 bool Shell::LoadWithLoader(const Identity& target, | 761 bool Shell::LoadWithLoader(const Identity& target, |
| 766 mojom::ShellClientRequest* request) { | 762 mojom::ShellClientRequest* request) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 786 for (auto it = native_runners_.begin(); it != native_runners_.end(); ++it) { | 782 for (auto it = native_runners_.begin(); it != native_runners_.end(); ++it) { |
| 787 if (it->get() == runner) { | 783 if (it->get() == runner) { |
| 788 native_runners_.erase(it); | 784 native_runners_.erase(it); |
| 789 return; | 785 return; |
| 790 } | 786 } |
| 791 } | 787 } |
| 792 } | 788 } |
| 793 | 789 |
| 794 } // namespace shell | 790 } // namespace shell |
| 795 } // namespace mojo | 791 } // namespace mojo |
| OLD | NEW |