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

Side by Side Diff: services/shell/shell.cc

Issue 1921183003: Fixes race in Shell (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge 2 trunk Created 4 years, 7 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 | « services/shell/shell.h ('k') | no next file » | 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 "services/shell/shell.h" 5 #include "services/shell/shell.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 instance->StartWithClient(std::move(client)); 469 instance->StartWithClient(std::move(client));
470 singletons_.insert(kShellName); 470 singletons_.insert(kShellName);
471 shell_connection_.reset(new ShellConnection(this, std::move(request))); 471 shell_connection_.reset(new ShellConnection(this, std::move(request)));
472 472
473 if (catalog) 473 if (catalog)
474 InitCatalog(std::move(catalog)); 474 InitCatalog(std::move(catalog));
475 } 475 }
476 476
477 Shell::~Shell() { 477 Shell::~Shell() {
478 TerminateShellConnections(); 478 TerminateShellConnections();
479 // Terminate any remaining instances.
480 while (!identity_to_instance_.empty())
481 OnInstanceError(identity_to_instance_.begin()->second);
482 identity_to_resolver_.clear();
479 for (auto& runner : native_runners_) 483 for (auto& runner : native_runners_)
480 runner.reset(); 484 runner.reset();
481 } 485 }
482 486
483 void Shell::SetInstanceQuitCallback( 487 void Shell::SetInstanceQuitCallback(
484 base::Callback<void(const Identity&)> callback) { 488 base::Callback<void(const Identity&)> callback) {
485 instance_quit_callback_ = callback; 489 instance_quit_callback_ = callback;
486 } 490 }
487 491
488 void Shell::Connect(std::unique_ptr<ConnectParams> params) { 492 void Shell::Connect(std::unique_ptr<ConnectParams> params) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 instance->StartWithClient(std::move(catalog)); 538 instance->StartWithClient(std::move(catalog));
535 539
536 // TODO(beng): this doesn't work anymore. 540 // TODO(beng): this doesn't work anymore.
537 // Seed the catalog with manifest info for the shell & catalog. 541 // Seed the catalog with manifest info for the shell & catalog.
538 mojom::ShellResolverPtr resolver; 542 mojom::ShellResolverPtr resolver;
539 shell_connection_->connector()->ConnectToInterface(kCatalogName, &resolver); 543 shell_connection_->connector()->ConnectToInterface(kCatalogName, &resolver);
540 resolver->ResolveMojoName(kCatalogName, base::Bind(&EmptyResolverCallback)); 544 resolver->ResolveMojoName(kCatalogName, base::Bind(&EmptyResolverCallback));
541 resolver->ResolveMojoName(kShellName, base::Bind(&EmptyResolverCallback)); 545 resolver->ResolveMojoName(kShellName, base::Bind(&EmptyResolverCallback));
542 } 546 }
543 547
548 mojom::ShellResolver* Shell::GetResolver(const Identity& identity) {
549 auto iter = identity_to_resolver_.find(identity);
550 if (iter != identity_to_resolver_.end())
551 return iter->second.get();
552
553 mojom::ShellResolverPtr resolver_ptr;
554 ConnectToInterface(this, identity, CreateCatalogIdentity(), &resolver_ptr);
555 mojom::ShellResolver* resolver = resolver_ptr.get();
556 identity_to_resolver_[identity] = std::move(resolver_ptr);
557 return resolver;
558 }
559
544 void Shell::TerminateShellConnections() { 560 void Shell::TerminateShellConnections() {
545 Instance* instance = GetExistingInstance(CreateShellIdentity()); 561 Instance* instance = GetExistingInstance(CreateShellIdentity());
546 DCHECK(instance); 562 DCHECK(instance);
547 OnInstanceError(instance); 563 OnInstanceError(instance);
548 } 564 }
549 565
550 void Shell::OnInstanceError(Instance* instance) { 566 void Shell::OnInstanceError(Instance* instance) {
551 const Identity identity = instance->identity(); 567 const Identity identity = instance->identity();
552 // Remove the shell. 568 // Remove the shell.
553 auto it = identity_to_instance_.find(identity); 569 auto it = identity_to_instance_.find(identity);
(...skipping 19 matching lines...) Expand all
573 DCHECK(!client.is_bound() || !identity_to_instance_.count(params->target())); 589 DCHECK(!client.is_bound() || !identity_to_instance_.count(params->target()));
574 590
575 // Connect to an existing matching instance, if possible. 591 // Connect to an existing matching instance, if possible.
576 if (!client.is_bound() && ConnectToExistingInstance(&params)) 592 if (!client.is_bound() && ConnectToExistingInstance(&params))
577 return; 593 return;
578 594
579 // The catalog needs to see the source identity as that of the originating 595 // The catalog needs to see the source identity as that of the originating
580 // app so it loads the correct store. Since the catalog is itself run as root 596 // app so it loads the correct store. Since the catalog is itself run as root
581 // when this re-enters Connect() it'll be handled by 597 // when this re-enters Connect() it'll be handled by
582 // ConnectToExistingInstance(). 598 // ConnectToExistingInstance().
583 mojom::ShellResolverPtr resolver; 599 mojom::ShellResolver* resolver =
584 ConnectToInterface(this, Identity(kShellName, params->target().user_id()), 600 GetResolver(Identity(kShellName, params->target().user_id()));
585 CreateCatalogIdentity(), &resolver);
586 601
587 std::string name = params->target().name(); 602 std::string name = params->target().name();
588 mojom::ShellResolver* resolver_raw = resolver.get(); 603 resolver->ResolveMojoName(
589 resolver_raw->ResolveMojoName(
590 name, base::Bind(&shell::Shell::OnGotResolvedName, 604 name, base::Bind(&shell::Shell::OnGotResolvedName,
591 weak_ptr_factory_.GetWeakPtr(), 605 weak_ptr_factory_.GetWeakPtr(), base::Passed(&params),
592 base::Passed(std::move(resolver)), base::Passed(&params),
593 base::Passed(&client))); 606 base::Passed(&client)));
594 } 607 }
595 608
596 Shell::Instance* Shell::GetExistingInstance(const Identity& identity) const { 609 Shell::Instance* Shell::GetExistingInstance(const Identity& identity) const {
597 const auto& it = identity_to_instance_.find(identity); 610 const auto& it = identity_to_instance_.find(identity);
598 Instance* instance = it != identity_to_instance_.end() ? it->second : nullptr; 611 Instance* instance = it != identity_to_instance_.end() ? it->second : nullptr;
599 if (instance) 612 if (instance)
600 return instance; 613 return instance;
601 614
602 if (singletons_.find(identity.name()) != singletons_.end()) { 615 if (singletons_.find(identity.name()) != singletons_.end()) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 return factory_interface; 691 return factory_interface;
679 } 692 }
680 693
681 void Shell::OnShellClientFactoryLost(const Identity& which) { 694 void Shell::OnShellClientFactoryLost(const Identity& which) {
682 // Remove the mapping. 695 // Remove the mapping.
683 auto it = shell_client_factories_.find(which); 696 auto it = shell_client_factories_.find(which);
684 DCHECK(it != shell_client_factories_.end()); 697 DCHECK(it != shell_client_factories_.end());
685 shell_client_factories_.erase(it); 698 shell_client_factories_.erase(it);
686 } 699 }
687 700
688 void Shell::OnGotResolvedName(mojom::ShellResolverPtr resolver, 701 void Shell::OnGotResolvedName(std::unique_ptr<ConnectParams> params,
689 std::unique_ptr<ConnectParams> params,
690 mojom::ShellClientPtr client, 702 mojom::ShellClientPtr client,
691 mojom::ResolveResultPtr result) { 703 mojom::ResolveResultPtr result) {
692 std::string instance_name = params->target().instance(); 704 std::string instance_name = params->target().instance();
693 if (instance_name == GetNamePath(params->target().name()) && 705 if (instance_name == GetNamePath(params->target().name()) &&
694 result->qualifier != GetNamePath(result->resolved_name)) { 706 result->qualifier != GetNamePath(result->resolved_name)) {
695 instance_name = result->qualifier; 707 instance_name = result->qualifier;
696 } 708 }
697 Identity target(params->target().name(), params->target().user_id(), 709 Identity target(params->target().name(), params->target().user_id(),
698 instance_name); 710 instance_name);
699 params->set_target(target); 711 params->set_target(target);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 void Shell::CleanupRunner(NativeRunner* runner) { 780 void Shell::CleanupRunner(NativeRunner* runner) {
769 for (auto it = native_runners_.begin(); it != native_runners_.end(); ++it) { 781 for (auto it = native_runners_.begin(); it != native_runners_.end(); ++it) {
770 if (it->get() == runner) { 782 if (it->get() == runner) {
771 native_runners_.erase(it); 783 native_runners_.erase(it);
772 return; 784 return;
773 } 785 }
774 } 786 }
775 } 787 }
776 788
777 } // namespace shell 789 } // namespace shell
OLDNEW
« no previous file with comments | « services/shell/shell.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698