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

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

Issue 2179023004: Make Service own ServiceContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 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/service_manager.h ('k') | services/shell/tests/connect/connect_test_app.cc » ('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 "services/shell/service_manager.h" 5 #include "services/shell/service_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 CHECK_NE(mojom::kInvalidInstanceID, id); 406 CHECK_NE(mojom::kInvalidInstanceID, id);
407 return id; 407 return id;
408 } 408 }
409 409
410 void PIDAvailable(base::ProcessId pid) { 410 void PIDAvailable(base::ProcessId pid) {
411 if (pid == base::kNullProcessId) { 411 if (pid == base::kNullProcessId) {
412 service_manager_->OnInstanceError(this); 412 service_manager_->OnInstanceError(this);
413 return; 413 return;
414 } 414 }
415 pid_ = pid; 415 pid_ = pid;
416 service_manager_->NotifyPIDAvailable(id_, pid_); 416 service_manager_->NotifyPIDAvailable(identity_, pid_);
417 } 417 }
418 418
419 void OnServiceLost(base::WeakPtr<shell::ServiceManager> service_manager) { 419 void OnServiceLost(base::WeakPtr<shell::ServiceManager> service_manager) {
420 service_.reset(); 420 service_.reset();
421 OnConnectionLost(service_manager); 421 OnConnectionLost(service_manager);
422 } 422 }
423 423
424 void OnConnectionLost(base::WeakPtr<shell::ServiceManager> service_manager) { 424 void OnConnectionLost(base::WeakPtr<shell::ServiceManager> service_manager) {
425 // Any time a Connector is lost or we lose the Service connection, it 425 // Any time a Connector is lost or we lose the Service connection, it
426 // may have been the last pipe using this Instance. If so, clean up. 426 // may have been the last pipe using this Instance. If so, clean up.
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 Instance* instance = GetExistingInstance(CreateServiceManagerIdentity()); 587 Instance* instance = GetExistingInstance(CreateServiceManagerIdentity());
588 DCHECK(instance); 588 DCHECK(instance);
589 OnInstanceError(instance); 589 OnInstanceError(instance);
590 } 590 }
591 591
592 void ServiceManager::OnInstanceError(Instance* instance) { 592 void ServiceManager::OnInstanceError(Instance* instance) {
593 const Identity identity = instance->identity(); 593 const Identity identity = instance->identity();
594 // Remove the Service Manager. 594 // Remove the Service Manager.
595 auto it = identity_to_instance_.find(identity); 595 auto it = identity_to_instance_.find(identity);
596 DCHECK(it != identity_to_instance_.end()); 596 DCHECK(it != identity_to_instance_.end());
597 int id = instance->id();
598 identity_to_instance_.erase(it); 597 identity_to_instance_.erase(it);
599 listeners_.ForAllPtrs([this, id](mojom::ServiceManagerListener* listener) { 598 listeners_.ForAllPtrs(
600 listener->OnServiceStopped(id); 599 [this, identity](mojom::ServiceManagerListener* listener) {
601 }); 600 listener->OnServiceStopped(mojom::Identity::From(identity));
601 });
602 delete instance; 602 delete instance;
603 if (!instance_quit_callback_.is_null()) 603 if (!instance_quit_callback_.is_null())
604 instance_quit_callback_.Run(identity); 604 instance_quit_callback_.Run(identity);
605 } 605 }
606 606
607 void ServiceManager::Connect(std::unique_ptr<ConnectParams> params, 607 void ServiceManager::Connect(std::unique_ptr<ConnectParams> params,
608 mojom::ServicePtr service) { 608 mojom::ServicePtr service) {
609 TRACE_EVENT_INSTANT1("mojo_shell", "ServiceManager::Connect", 609 TRACE_EVENT_INSTANT1("mojo_shell", "ServiceManager::Connect",
610 TRACE_EVENT_SCOPE_THREAD, "original_name", 610 TRACE_EVENT_SCOPE_THREAD, "original_name",
611 params->target().name()); 611 params->target().name());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 for (auto entry : identity_to_instance_) { 643 for (auto entry : identity_to_instance_) {
644 if (entry.first.name() == identity.name() && 644 if (entry.first.name() == identity.name() &&
645 entry.first.instance() == identity.instance()) { 645 entry.first.instance() == identity.instance()) {
646 return entry.second; 646 return entry.second;
647 } 647 }
648 } 648 }
649 } 649 }
650 return nullptr; 650 return nullptr;
651 } 651 }
652 652
653 void ServiceManager::NotifyPIDAvailable(uint32_t id, base::ProcessId pid) { 653 void ServiceManager::NotifyPIDAvailable(const Identity& identity,
654 listeners_.ForAllPtrs([id, pid](mojom::ServiceManagerListener* listener) { 654 base::ProcessId pid) {
655 listener->OnServiceStarted(id, pid); 655 listeners_.ForAllPtrs(
656 }); 656 [identity, pid](mojom::ServiceManagerListener* listener) {
657 listener->OnServiceStarted(mojom::Identity::From(identity), pid);
658 });
657 } 659 }
658 660
659 bool ServiceManager::ConnectToExistingInstance( 661 bool ServiceManager::ConnectToExistingInstance(
660 std::unique_ptr<ConnectParams>* params) { 662 std::unique_ptr<ConnectParams>* params) {
661 Instance* instance = GetExistingInstance((*params)->target()); 663 Instance* instance = GetExistingInstance((*params)->target());
662 return !!instance && instance->ConnectToService(params); 664 return !!instance && instance->ConnectToService(params);
663 } 665 }
664 666
665 ServiceManager::Instance* ServiceManager::CreateInstance( 667 ServiceManager::Instance* ServiceManager::CreateInstance(
666 const Identity& source, 668 const Identity& source,
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 // Now that the instance has a Service, we can connect to it. 800 // Now that the instance has a Service, we can connect to it.
799 bool connected = instance->ConnectToService(&params); 801 bool connected = instance->ConnectToService(&params);
800 DCHECK(connected); 802 DCHECK(connected);
801 } 803 }
802 804
803 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { 805 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() {
804 return weak_ptr_factory_.GetWeakPtr(); 806 return weak_ptr_factory_.GetWeakPtr();
805 } 807 }
806 808
807 } // namespace shell 809 } // namespace shell
OLDNEW
« no previous file with comments | « services/shell/service_manager.h ('k') | services/shell/tests/connect/connect_test_app.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698