| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 const String& resolved_instance, | 44 const String& resolved_instance, |
| 45 mojom::CapabilitySpecPtr capabilities, | 45 mojom::CapabilitySpecPtr capabilities, |
| 46 const String& file_url) {} | 46 const String& file_url) {} |
| 47 | 47 |
| 48 } | 48 } |
| 49 | 49 |
| 50 Identity CreateShellIdentity() { | 50 Identity CreateShellIdentity() { |
| 51 return Identity(kShellName, mojom::kRootUserID); | 51 return Identity(kShellName, mojom::kRootUserID); |
| 52 } | 52 } |
| 53 | 53 |
| 54 Identity CreateCatalogIdentity() { |
| 55 return Identity(kCatalogName, mojom::kRootUserID); |
| 56 } |
| 57 |
| 54 CapabilitySpec GetPermissiveCapabilities() { | 58 CapabilitySpec GetPermissiveCapabilities() { |
| 55 CapabilitySpec capabilities; | 59 CapabilitySpec capabilities; |
| 56 CapabilityRequest spec; | 60 CapabilityRequest spec; |
| 57 spec.interfaces.insert("*"); | 61 spec.interfaces.insert("*"); |
| 58 capabilities.required["*"] = spec; | 62 capabilities.required["*"] = spec; |
| 59 return capabilities; | 63 return capabilities; |
| 60 } | 64 } |
| 61 | 65 |
| 62 CapabilityRequest GetCapabilityRequest(const CapabilitySpec& source_spec, | 66 CapabilityRequest GetCapabilityRequest(const CapabilitySpec& source_spec, |
| 63 const Identity& target) { | 67 const Identity& target) { |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 } | 485 } |
| 482 } | 486 } |
| 483 DCHECK(instance); | 487 DCHECK(instance); |
| 484 return instance->AcceptConnection(connection); | 488 return instance->AcceptConnection(connection); |
| 485 } | 489 } |
| 486 | 490 |
| 487 //////////////////////////////////////////////////////////////////////////////// | 491 //////////////////////////////////////////////////////////////////////////////// |
| 488 // Shell, private: | 492 // Shell, private: |
| 489 | 493 |
| 490 void Shell::InitCatalog(mojom::ShellClientPtr catalog) { | 494 void Shell::InitCatalog(mojom::ShellClientPtr catalog) { |
| 491 Identity identity(kCatalogName, mojom::kRootUserID); | 495 CreateInstance(CreateCatalogIdentity(), CapabilitySpec(), std::move(catalog)); |
| 492 CreateInstance(identity, CapabilitySpec(), std::move(catalog)); | |
| 493 shell_connection_->connector()->ConnectToInterface( | |
| 494 kCatalogName, &shell_resolver_); | |
| 495 | 496 |
| 497 // TODO(beng): this doesn't work anymore. |
| 496 // Seed the catalog with manifest info for the shell & catalog. | 498 // Seed the catalog with manifest info for the shell & catalog. |
| 497 shell_resolver_->ResolveMojoName( | 499 mojo::shell::mojom::ShellResolverPtr resolver; |
| 498 kCatalogName, base::Bind(&EmptyResolverCallback)); | 500 shell_connection_->connector()->ConnectToInterface(kCatalogName, &resolver); |
| 499 shell_resolver_->ResolveMojoName( | 501 resolver->ResolveMojoName(kCatalogName, base::Bind(&EmptyResolverCallback)); |
| 500 kShellName, base::Bind(&EmptyResolverCallback)); | 502 resolver->ResolveMojoName(kShellName, base::Bind(&EmptyResolverCallback)); |
| 501 } | 503 } |
| 502 | 504 |
| 503 void Shell::TerminateShellConnections() { | 505 void Shell::TerminateShellConnections() { |
| 504 STLDeleteValues(&identity_to_instance_); | 506 STLDeleteValues(&identity_to_instance_); |
| 505 } | 507 } |
| 506 | 508 |
| 507 void Shell::OnInstanceError(Instance* instance) { | 509 void Shell::OnInstanceError(Instance* instance) { |
| 508 const Identity identity = instance->identity(); | 510 const Identity identity = instance->identity(); |
| 509 // Remove the shell. | 511 // Remove the shell. |
| 510 auto it = identity_to_instance_.find(identity); | 512 auto it = identity_to_instance_.find(identity); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 526 params->target().name()); | 528 params->target().name()); |
| 527 DCHECK(IsValidName(params->target().name())); | 529 DCHECK(IsValidName(params->target().name())); |
| 528 DCHECK(base::IsValidGUID(params->target().user_id())); | 530 DCHECK(base::IsValidGUID(params->target().user_id())); |
| 529 DCHECK_NE(mojom::kInheritUserID, params->target().user_id()); | 531 DCHECK_NE(mojom::kInheritUserID, params->target().user_id()); |
| 530 DCHECK(!client.is_bound() || !identity_to_instance_.count(params->target())); | 532 DCHECK(!client.is_bound() || !identity_to_instance_.count(params->target())); |
| 531 | 533 |
| 532 // Connect to an existing matching instance, if possible. | 534 // Connect to an existing matching instance, if possible. |
| 533 if (!client.is_bound() && ConnectToExistingInstance(¶ms)) | 535 if (!client.is_bound() && ConnectToExistingInstance(¶ms)) |
| 534 return; | 536 return; |
| 535 | 537 |
| 538 // The catalog needs to see the source identity as that of the originating |
| 539 // app so it loads the correct store. Since the catalog is itself run as root |
| 540 // when this re-enters Connect() it'll be handled by |
| 541 // ConnectToExistingInstance(). |
| 542 mojom::ShellResolverPtr resolver; |
| 543 ConnectToInterface(this, Identity(kShellName, params->target().user_id()), |
| 544 CreateCatalogIdentity(), &resolver); |
| 545 |
| 536 std::string name = params->target().name(); | 546 std::string name = params->target().name(); |
| 537 shell_resolver_->ResolveMojoName( | 547 mojom::ShellResolver* resolver_raw = resolver.get(); |
| 548 resolver_raw->ResolveMojoName( |
| 538 name, | 549 name, |
| 539 base::Bind(&Shell::OnGotResolvedName, | 550 base::Bind(&Shell::OnGotResolvedName, weak_ptr_factory_.GetWeakPtr(), |
| 540 weak_ptr_factory_.GetWeakPtr(), base::Passed(¶ms), | 551 base::Passed(std::move(resolver)), base::Passed(¶ms), |
| 541 base::Passed(&client))); | 552 base::Passed(&client))); |
| 542 } | 553 } |
| 543 | 554 |
| 544 Shell::Instance* Shell::GetExistingInstance(const Identity& identity) const { | 555 Shell::Instance* Shell::GetExistingInstance(const Identity& identity) const { |
| 545 const auto& it = identity_to_instance_.find(identity); | 556 const auto& it = identity_to_instance_.find(identity); |
| 546 return it != identity_to_instance_.end() ? it->second : nullptr; | 557 return it != identity_to_instance_.end() ? it->second : nullptr; |
| 547 } | 558 } |
| 548 | 559 |
| 549 Shell::Instance* Shell::GetExistingOrRootInstance( | 560 Shell::Instance* Shell::GetExistingOrRootInstance( |
| 550 const Identity& identity) const { | 561 const Identity& identity) const { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 return factory_interface; | 636 return factory_interface; |
| 626 } | 637 } |
| 627 | 638 |
| 628 void Shell::OnShellClientFactoryLost(const Identity& which) { | 639 void Shell::OnShellClientFactoryLost(const Identity& which) { |
| 629 // Remove the mapping. | 640 // Remove the mapping. |
| 630 auto it = shell_client_factories_.find(which); | 641 auto it = shell_client_factories_.find(which); |
| 631 DCHECK(it != shell_client_factories_.end()); | 642 DCHECK(it != shell_client_factories_.end()); |
| 632 shell_client_factories_.erase(it); | 643 shell_client_factories_.erase(it); |
| 633 } | 644 } |
| 634 | 645 |
| 635 void Shell::OnGotResolvedName(scoped_ptr<ConnectParams> params, | 646 void Shell::OnGotResolvedName(mojom::ShellResolverPtr resolver, |
| 647 scoped_ptr<ConnectParams> params, |
| 636 mojom::ShellClientPtr client, | 648 mojom::ShellClientPtr client, |
| 637 const String& resolved_name, | 649 const String& resolved_name, |
| 638 const String& resolved_instance, | 650 const String& resolved_instance, |
| 639 mojom::CapabilitySpecPtr capabilities_ptr, | 651 mojom::CapabilitySpecPtr capabilities_ptr, |
| 640 const String& file_url) { | 652 const String& file_url) { |
| 641 std::string instance_name = params->target().instance(); | 653 std::string instance_name = params->target().instance(); |
| 642 if (instance_name == GetNamePath(params->target().name()) && | 654 if (instance_name == GetNamePath(params->target().name()) && |
| 643 resolved_instance != GetNamePath(resolved_name)) { | 655 resolved_instance != GetNamePath(resolved_name)) { |
| 644 instance_name = resolved_instance; | 656 instance_name = resolved_instance; |
| 645 } | 657 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 for (auto it = native_runners_.begin(); it != native_runners_.end(); ++it) { | 732 for (auto it = native_runners_.begin(); it != native_runners_.end(); ++it) { |
| 721 if (it->get() == runner) { | 733 if (it->get() == runner) { |
| 722 native_runners_.erase(it); | 734 native_runners_.erase(it); |
| 723 return; | 735 return; |
| 724 } | 736 } |
| 725 } | 737 } |
| 726 } | 738 } |
| 727 | 739 |
| 728 } // namespace shell | 740 } // namespace shell |
| 729 } // namespace mojo | 741 } // namespace mojo |
| OLD | NEW |