| 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 "services/service_manager/service_manager.h" | 5 #include "services/service_manager/service_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "services/service_manager/public/cpp/service_context.h" | 27 #include "services/service_manager/public/cpp/service_context.h" |
| 28 #include "services/service_manager/public/interfaces/connector.mojom.h" | 28 #include "services/service_manager/public/interfaces/connector.mojom.h" |
| 29 #include "services/service_manager/public/interfaces/service.mojom.h" | 29 #include "services/service_manager/public/interfaces/service.mojom.h" |
| 30 #include "services/service_manager/public/interfaces/service_manager.mojom.h" | 30 #include "services/service_manager/public/interfaces/service_manager.mojom.h" |
| 31 | 31 |
| 32 namespace service_manager { | 32 namespace service_manager { |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 const char kCatalogName[] = "service:catalog"; | 36 const char kCatalogName[] = "service:catalog"; |
| 37 const char kServiceManagerName[] = "service:shell"; | 37 const char kServiceManagerName[] = "service:service_manager"; |
| 38 const char kCapabilityClass_UserID[] = "shell:user_id"; | 38 const char kCapabilityClass_UserID[] = "service_manager:user_id"; |
| 39 const char kCapabilityClass_ClientProcess[] = "shell:client_process"; | 39 const char kCapabilityClass_ClientProcess[] = "service_manager:client_process"; |
| 40 const char kCapabilityClass_InstanceName[] = "shell:instance_name"; | 40 const char kCapabilityClass_InstanceName[] = "service_manager:instance_name"; |
| 41 const char kCapabilityClass_AllUsers[] = "shell:all_users"; | 41 const char kCapabilityClass_AllUsers[] = "service_manager:all_users"; |
| 42 const char kCapabilityClass_ExplicitClass[] = "shell:explicit_class"; | 42 const char kCapabilityClass_ExplicitClass[] = "service_manager:explicit_class"; |
| 43 const char kCapabilityClass_ServiceManager[] = "shell:service_manager"; | 43 const char kCapabilityClass_ServiceManager[] = |
| 44 "service_manager:service_manager"; |
| 44 | 45 |
| 45 } // namespace | 46 } // namespace |
| 46 | 47 |
| 47 Identity CreateServiceManagerIdentity() { | 48 Identity CreateServiceManagerIdentity() { |
| 48 return Identity(kServiceManagerName, mojom::kRootUserID); | 49 return Identity(kServiceManagerName, mojom::kRootUserID); |
| 49 } | 50 } |
| 50 | 51 |
| 51 Identity CreateCatalogIdentity() { | 52 Identity CreateCatalogIdentity() { |
| 52 return Identity(kCatalogName, mojom::kRootUserID); | 53 return Identity(kCatalogName, mojom::kRootUserID); |
| 53 } | 54 } |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 328 |
| 328 bool ValidateClientProcessConnection( | 329 bool ValidateClientProcessConnection( |
| 329 mojom::ClientProcessConnectionPtr* client_process_connection, | 330 mojom::ClientProcessConnectionPtr* client_process_connection, |
| 330 const Identity& target, | 331 const Identity& target, |
| 331 const ConnectCallback& callback) { | 332 const ConnectCallback& callback) { |
| 332 if (!client_process_connection->is_null()) { | 333 if (!client_process_connection->is_null()) { |
| 333 if (!HasClass(capability_spec_, kCapabilityClass_ClientProcess)) { | 334 if (!HasClass(capability_spec_, kCapabilityClass_ClientProcess)) { |
| 334 LOG(ERROR) << "Instance: " << identity_.name() << " attempting " | 335 LOG(ERROR) << "Instance: " << identity_.name() << " attempting " |
| 335 << "to register an instance for a process it created for " | 336 << "to register an instance for a process it created for " |
| 336 << "target: " << target.name() << " without the " | 337 << "target: " << target.name() << " without the " |
| 337 << "service:shell{client_process} capability class."; | 338 << "service:service_manager{client_process} capability " |
| 339 << "class."; |
| 338 callback.Run(mojom::ConnectResult::ACCESS_DENIED, | 340 callback.Run(mojom::ConnectResult::ACCESS_DENIED, |
| 339 mojom::kInheritUserID); | 341 mojom::kInheritUserID); |
| 340 return false; | 342 return false; |
| 341 } | 343 } |
| 342 | 344 |
| 343 if (!(*client_process_connection)->service.is_valid() || | 345 if (!(*client_process_connection)->service.is_valid() || |
| 344 !(*client_process_connection)->pid_receiver_request.is_valid()) { | 346 !(*client_process_connection)->pid_receiver_request.is_valid()) { |
| 345 LOG(ERROR) << "Must supply both service AND " | 347 LOG(ERROR) << "Must supply both service AND " |
| 346 << "pid_receiver_request when sending " | 348 << "pid_receiver_request when sending " |
| 347 << "client_process_connection."; | 349 << "client_process_connection."; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 362 } | 364 } |
| 363 | 365 |
| 364 bool ValidateCapabilities(const Identity& target, | 366 bool ValidateCapabilities(const Identity& target, |
| 365 const ConnectCallback& callback) { | 367 const ConnectCallback& callback) { |
| 366 // TODO(beng): Need to do the following additional policy validation of | 368 // TODO(beng): Need to do the following additional policy validation of |
| 367 // whether this instance is allowed to connect using: | 369 // whether this instance is allowed to connect using: |
| 368 // - a non-null client_process_connection. | 370 // - a non-null client_process_connection. |
| 369 if (target.user_id() != identity_.user_id() && | 371 if (target.user_id() != identity_.user_id() && |
| 370 target.user_id() != mojom::kRootUserID && | 372 target.user_id() != mojom::kRootUserID && |
| 371 !HasClass(capability_spec_, kCapabilityClass_UserID)) { | 373 !HasClass(capability_spec_, kCapabilityClass_UserID)) { |
| 372 LOG(ERROR) << "Instance: " << identity_.name() << " running as: " | 374 LOG(ERROR) << "Instance: " << identity_.name() |
| 373 << identity_.user_id() << " attempting to connect to: " | 375 << " running as: " << identity_.user_id() |
| 374 << target.name() << " as: " << target.user_id() << " without " | 376 << " attempting to connect to: " << target.name() |
| 375 << " the service:shell{user_id} capability class."; | 377 << " as: " << target.user_id() << " without " |
| 378 << " the service:service_manager{user_id} capability class."; |
| 376 callback.Run(mojom::ConnectResult::ACCESS_DENIED, | 379 callback.Run(mojom::ConnectResult::ACCESS_DENIED, |
| 377 mojom::kInheritUserID); | 380 mojom::kInheritUserID); |
| 378 return false; | 381 return false; |
| 379 } | 382 } |
| 380 if (!target.instance().empty() && | 383 if (!target.instance().empty() && |
| 381 target.instance() != GetNamePath(target.name()) && | 384 target.instance() != GetNamePath(target.name()) && |
| 382 !HasClass(capability_spec_, kCapabilityClass_InstanceName)) { | 385 !HasClass(capability_spec_, kCapabilityClass_InstanceName)) { |
| 383 LOG(ERROR) << "Instance: " << identity_.name() << " attempting to " | 386 LOG(ERROR) << "Instance: " << identity_.name() << " attempting to " |
| 384 << "connect to " << target.name() << " using Instance name: " | 387 << "connect to " << target.name() |
| 385 << target.instance() << " without the " | 388 << " using Instance name: " << target.instance() |
| 386 << "service:shell{instance_name} capability class."; | 389 << " without the " |
| 390 << "service:service_manager{instance_name} capability class."; |
| 387 callback.Run(mojom::ConnectResult::ACCESS_DENIED, mojom::kInheritUserID); | 391 callback.Run(mojom::ConnectResult::ACCESS_DENIED, mojom::kInheritUserID); |
| 388 return false; | 392 return false; |
| 389 | 393 |
| 390 } | 394 } |
| 391 | 395 |
| 392 if (allow_any_application_ || | 396 if (allow_any_application_ || |
| 393 capability_spec_.required.find(target.name()) != | 397 capability_spec_.required.find(target.name()) != |
| 394 capability_spec_.required.end()) { | 398 capability_spec_.required.end()) { |
| 395 return true; | 399 return true; |
| 396 } | 400 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 std::unique_ptr<NativeRunnerFactory> native_runner_factory, | 498 std::unique_ptr<NativeRunnerFactory> native_runner_factory, |
| 495 mojom::ServicePtr catalog) | 499 mojom::ServicePtr catalog) |
| 496 : native_runner_factory_(std::move(native_runner_factory)), | 500 : native_runner_factory_(std::move(native_runner_factory)), |
| 497 weak_ptr_factory_(this) { | 501 weak_ptr_factory_(this) { |
| 498 mojom::ServicePtr service; | 502 mojom::ServicePtr service; |
| 499 mojom::ServiceRequest request = mojo::GetProxy(&service); | 503 mojom::ServiceRequest request = mojo::GetProxy(&service); |
| 500 | 504 |
| 501 CapabilitySpec spec; | 505 CapabilitySpec spec; |
| 502 spec.provided[kCapabilityClass_ServiceManager].insert( | 506 spec.provided[kCapabilityClass_ServiceManager].insert( |
| 503 "service_manager::mojom::ServiceManager"); | 507 "service_manager::mojom::ServiceManager"); |
| 504 spec.required["*"].insert("shell:service_factory"); | 508 spec.required["*"].insert("service_manager:service_factory"); |
| 505 spec.required["service:catalog"].insert("shell:resolver"); | 509 spec.required["service:catalog"].insert("service_manager:resolver"); |
| 506 | 510 |
| 507 service_manager_instance_ = | 511 service_manager_instance_ = |
| 508 CreateInstance(Identity(), CreateServiceManagerIdentity(), spec); | 512 CreateInstance(Identity(), CreateServiceManagerIdentity(), spec); |
| 509 service_manager_instance_->StartWithService(std::move(service)); | 513 service_manager_instance_->StartWithService(std::move(service)); |
| 510 singletons_.insert(kServiceManagerName); | 514 singletons_.insert(kServiceManagerName); |
| 511 service_context_.reset(new ServiceContext(this, std::move(request))); | 515 service_context_.reset(new ServiceContext(this, std::move(request))); |
| 512 | 516 |
| 513 if (catalog) | 517 if (catalog) |
| 514 InitCatalog(std::move(catalog)); | 518 InitCatalog(std::move(catalog)); |
| 515 } | 519 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 | 581 |
| 578 //////////////////////////////////////////////////////////////////////////////// | 582 //////////////////////////////////////////////////////////////////////////////// |
| 579 // ServiceManager, private: | 583 // ServiceManager, private: |
| 580 | 584 |
| 581 void ServiceManager::InitCatalog(mojom::ServicePtr catalog) { | 585 void ServiceManager::InitCatalog(mojom::ServicePtr catalog) { |
| 582 // TODO(beng): It'd be great to build this from the manifest, however there's | 586 // TODO(beng): It'd be great to build this from the manifest, however there's |
| 583 // a bit of a chicken-and-egg problem. | 587 // a bit of a chicken-and-egg problem. |
| 584 CapabilitySpec spec; | 588 CapabilitySpec spec; |
| 585 spec.provided["app"].insert("filesystem::mojom::Directory"); | 589 spec.provided["app"].insert("filesystem::mojom::Directory"); |
| 586 spec.provided["catalog:catalog"].insert("catalog::mojom::Catalog"); | 590 spec.provided["catalog:catalog"].insert("catalog::mojom::Catalog"); |
| 587 spec.provided["shell:resolver"].insert("service_manager::mojom::Resolver"); | 591 spec.provided["service_manager:resolver"].insert( |
| 592 "service_manager::mojom::Resolver"); |
| 588 spec.provided["control"].insert("catalog::mojom::CatalogControl"); | 593 spec.provided["control"].insert("catalog::mojom::CatalogControl"); |
| 589 Instance* instance = CreateInstance( | 594 Instance* instance = CreateInstance( |
| 590 CreateServiceManagerIdentity(), CreateCatalogIdentity(), spec); | 595 CreateServiceManagerIdentity(), CreateCatalogIdentity(), spec); |
| 591 singletons_.insert(kCatalogName); | 596 singletons_.insert(kCatalogName); |
| 592 instance->StartWithService(std::move(catalog)); | 597 instance->StartWithService(std::move(catalog)); |
| 593 } | 598 } |
| 594 | 599 |
| 595 mojom::Resolver* ServiceManager::GetResolver(const Identity& identity) { | 600 mojom::Resolver* ServiceManager::GetResolver(const Identity& identity) { |
| 596 auto iter = identity_to_resolver_.find(identity); | 601 auto iter = identity_to_resolver_.find(identity); |
| 597 if (iter != identity_to_resolver_.end()) | 602 if (iter != identity_to_resolver_.end()) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 listeners_.ForAllPtrs([identity](mojom::ServiceManagerListener* listener) { | 640 listeners_.ForAllPtrs([identity](mojom::ServiceManagerListener* listener) { |
| 636 listener->OnServiceStopped(identity); | 641 listener->OnServiceStopped(identity); |
| 637 }); | 642 }); |
| 638 if (!instance_quit_callback_.is_null()) | 643 if (!instance_quit_callback_.is_null()) |
| 639 instance_quit_callback_.Run(identity); | 644 instance_quit_callback_.Run(identity); |
| 640 } | 645 } |
| 641 | 646 |
| 642 void ServiceManager::Connect(std::unique_ptr<ConnectParams> params, | 647 void ServiceManager::Connect(std::unique_ptr<ConnectParams> params, |
| 643 mojom::ServicePtr service, | 648 mojom::ServicePtr service, |
| 644 base::WeakPtr<Instance> source_instance) { | 649 base::WeakPtr<Instance> source_instance) { |
| 645 TRACE_EVENT_INSTANT1("mojo_shell", "ServiceManager::Connect", | 650 TRACE_EVENT_INSTANT1("service_manager", "ServiceManager::Connect", |
| 646 TRACE_EVENT_SCOPE_THREAD, "original_name", | 651 TRACE_EVENT_SCOPE_THREAD, "original_name", |
| 647 params->target().name()); | 652 params->target().name()); |
| 648 DCHECK(IsValidName(params->target().name())); | 653 DCHECK(IsValidName(params->target().name())); |
| 649 DCHECK(base::IsValidGUID(params->target().user_id())); | 654 DCHECK(base::IsValidGUID(params->target().user_id())); |
| 650 DCHECK_NE(mojom::kInheritUserID, params->target().user_id()); | 655 DCHECK_NE(mojom::kInheritUserID, params->target().user_id()); |
| 651 DCHECK(!service.is_bound() || !identity_to_instance_.count(params->target())); | 656 DCHECK(!service.is_bound() || !identity_to_instance_.count(params->target())); |
| 652 | 657 |
| 653 // Connect to an existing matching instance, if possible. | 658 // Connect to an existing matching instance, if possible. |
| 654 if (!service.is_bound() && ConnectToExistingInstance(¶ms)) | 659 if (!service.is_bound() && ConnectToExistingInstance(¶ms)) |
| 655 return; | 660 return; |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 // Now that the instance has a Service, we can connect to it. | 881 // Now that the instance has a Service, we can connect to it. |
| 877 bool connected = instance->ConnectToService(¶ms); | 882 bool connected = instance->ConnectToService(¶ms); |
| 878 DCHECK(connected); | 883 DCHECK(connected); |
| 879 } | 884 } |
| 880 | 885 |
| 881 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { | 886 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { |
| 882 return weak_ptr_factory_.GetWeakPtr(); | 887 return weak_ptr_factory_.GetWeakPtr(); |
| 883 } | 888 } |
| 884 | 889 |
| 885 } // namespace service_manager | 890 } // namespace service_manager |
| OLD | NEW |