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

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

Issue 1811483003: Remove support for Root identity singletons and rely on the all_users bit to be set. + test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@54login2
Patch Set: Created 4 years, 9 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/shell.h ('k') | mojo/shell/tests/connect/connect_test_app_manifest.json » ('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/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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 312
313 if (!(*client_process_connection)->shell_client.is_valid() || 313 if (!(*client_process_connection)->shell_client.is_valid() ||
314 !(*client_process_connection)->pid_receiver_request.is_valid()) { 314 !(*client_process_connection)->pid_receiver_request.is_valid()) {
315 LOG(ERROR) << "Error: must supply both shell_client AND " 315 LOG(ERROR) << "Error: must supply both shell_client AND "
316 << "pid_receiver_request when sending " 316 << "pid_receiver_request when sending "
317 << "client_process_connection."; 317 << "client_process_connection.";
318 callback.Run(mojom::ConnectResult::INVALID_ARGUMENT, 318 callback.Run(mojom::ConnectResult::INVALID_ARGUMENT,
319 mojom::kInheritUserID, mojom::kInvalidInstanceID); 319 mojom::kInheritUserID, mojom::kInvalidInstanceID);
320 return false; 320 return false;
321 } 321 }
322 if (shell_->GetExistingOrRootInstance(target)) { 322 if (shell_->GetExistingInstance(target)) {
323 LOG(ERROR) << "Error: Cannot client process matching existing identity:" 323 LOG(ERROR) << "Error: Cannot client process matching existing identity:"
324 << "Name: " << target.name() << " User: " << target.user_id() 324 << "Name: " << target.name() << " User: " << target.user_id()
325 << " Instance: " << target.instance(); 325 << " Instance: " << target.instance();
326 callback.Run(mojom::ConnectResult::INVALID_ARGUMENT, 326 callback.Run(mojom::ConnectResult::INVALID_ARGUMENT,
327 mojom::kInheritUserID, mojom::kInvalidInstanceID); 327 mojom::kInheritUserID, mojom::kInvalidInstanceID);
328 return false; 328 return false;
329 } 329 }
330 } 330 }
331 return true; 331 return true;
332 } 332 }
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 mojom::ShellResolver* resolver_raw = resolver.get(); 553 mojom::ShellResolver* resolver_raw = resolver.get();
554 resolver_raw->ResolveMojoName( 554 resolver_raw->ResolveMojoName(
555 name, 555 name,
556 base::Bind(&Shell::OnGotResolvedName, weak_ptr_factory_.GetWeakPtr(), 556 base::Bind(&Shell::OnGotResolvedName, weak_ptr_factory_.GetWeakPtr(),
557 base::Passed(std::move(resolver)), base::Passed(&params), 557 base::Passed(std::move(resolver)), base::Passed(&params),
558 base::Passed(&client))); 558 base::Passed(&client)));
559 } 559 }
560 560
561 Shell::Instance* Shell::GetExistingInstance(const Identity& identity) const { 561 Shell::Instance* Shell::GetExistingInstance(const Identity& identity) const {
562 const auto& it = identity_to_instance_.find(identity); 562 const auto& it = identity_to_instance_.find(identity);
563 return it != identity_to_instance_.end() ? it->second : nullptr; 563 Instance* instance = it != identity_to_instance_.end() ? it->second : nullptr;
564 } 564 if (instance)
565 return instance;
565 566
566 Shell::Instance* Shell::GetExistingOrRootInstance( 567 if (singletons_.find(identity.name()) != singletons_.end()) {
567 const Identity& identity) const { 568 for (auto entry : identity_to_instance_) {
568 Instance* instance = GetExistingInstance(identity); 569 if (entry.first.name() == identity.name() &&
569 if (!instance) { 570 entry.first.instance() == identity.instance()) {
570 if (singletons_.find(identity.name()) != singletons_.end()) { 571 return entry.second;
571 for (auto entry : identity_to_instance_) {
572 if (entry.first.name() == identity.name() &&
573 entry.first.instance() == identity.instance()) {
574 return entry.second;
575 }
576 } 572 }
577 } 573 }
578
579 Identity root_identity = identity;
580 root_identity.set_user_id(mojom::kRootUserID);
581 instance = GetExistingInstance(root_identity);
582 } 574 }
583 return instance; 575 return nullptr;
584 } 576 }
585 577
586 void Shell::NotifyPIDAvailable(uint32_t id, base::ProcessId pid) { 578 void Shell::NotifyPIDAvailable(uint32_t id, base::ProcessId pid) {
587 instance_listeners_.ForAllPtrs([id, pid](mojom::InstanceListener* listener) { 579 instance_listeners_.ForAllPtrs([id, pid](mojom::InstanceListener* listener) {
588 listener->InstancePIDAvailable(id, pid); 580 listener->InstancePIDAvailable(id, pid);
589 }); 581 });
590 } 582 }
591 583
592 bool Shell::ConnectToExistingInstance(scoped_ptr<ConnectParams>* params) { 584 bool Shell::ConnectToExistingInstance(scoped_ptr<ConnectParams>* params) {
593 Instance* instance = GetExistingOrRootInstance((*params)->target()); 585 Instance* instance = GetExistingInstance((*params)->target());
594 if (instance) 586 if (instance)
595 instance->ConnectToClient(std::move(*params)); 587 instance->ConnectToClient(std::move(*params));
596 return !!instance; 588 return !!instance;
597 } 589 }
598 590
599 Shell::Instance* Shell::CreateInstance(const Identity& target, 591 Shell::Instance* Shell::CreateInstance(const Identity& target,
600 const CapabilitySpec& spec) { 592 const CapabilitySpec& spec) {
601 CHECK(target.user_id() != mojom::kInheritUserID); 593 CHECK(target.user_id() != mojom::kInheritUserID);
602 Instance* instance = new Instance(this, target, spec); 594 Instance* instance = new Instance(this, target, spec);
603 DCHECK(identity_to_instance_.find(target) == 595 DCHECK(identity_to_instance_.find(target) ==
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 for (auto it = native_runners_.begin(); it != native_runners_.end(); ++it) { 740 for (auto it = native_runners_.begin(); it != native_runners_.end(); ++it) {
749 if (it->get() == runner) { 741 if (it->get() == runner) {
750 native_runners_.erase(it); 742 native_runners_.erase(it);
751 return; 743 return;
752 } 744 }
753 } 745 }
754 } 746 }
755 747
756 } // namespace shell 748 } // namespace shell
757 } // namespace mojo 749 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/shell.h ('k') | mojo/shell/tests/connect/connect_test_app_manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698