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

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

Issue 2706383002: DO NOT SUBMIT: Show silent service manager failure (Closed)
Patch Set: Created 3 years, 10 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/service_manager/public/cpp/lib/service_context.cc ('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/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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 std::stringstream ss; 205 std::stringstream ss;
206 ss << "Connection InterfaceProviderSpec prevented service: " 206 ss << "Connection InterfaceProviderSpec prevented service: "
207 << params->source().name() << " from binding interface: " 207 << params->source().name() << " from binding interface: "
208 << params->interface_name() << " exposed by: " << identity_.name(); 208 << params->interface_name() << " exposed by: " << identity_.name();
209 LOG(ERROR) << ss.str(); 209 LOG(ERROR) << ss.str();
210 params->bind_interface_callback().Run(mojom::ConnectResult::ACCESS_DENIED, 210 params->bind_interface_callback().Run(mojom::ConnectResult::ACCESS_DENIED,
211 identity_.user_id()); 211 identity_.user_id());
212 return false; 212 return false;
213 } 213 }
214 214
215 LOG(INFO) << "Call callback: " << identity().name();
215 params->bind_interface_callback().Run(mojom::ConnectResult::SUCCEEDED, 216 params->bind_interface_callback().Run(mojom::ConnectResult::SUCCEEDED,
216 identity_.user_id()); 217 identity_.user_id());
217 218
218 pending_service_connections_++; 219 pending_service_connections_++;
220 LOG(INFO) << "iname: " << params->interface_name();
221 auto interface_pipe = params->TakeInterfaceRequestPipe();
222 LOG(INFO) << "ServiceManager::Instance::BindInterface: "
223 << interface_pipe.get().value();
219 service_->OnBindInterface( 224 service_->OnBindInterface(
220 ServiceInfo(params->source(), source_specs), 225 ServiceInfo(params->source(), source_specs),
221 params->interface_name(), 226 params->interface_name(),
222 params->TakeInterfaceRequestPipe(), 227 std::move(interface_pipe),
223 base::Bind(&Instance::OnConnectComplete, base::Unretained(this))); 228 base::Bind(&Instance::OnConnectComplete, base::Unretained(this)));
224 return true; 229 return true;
225 } 230 }
226 231
227 void OnConnectComplete() { 232 void OnConnectComplete() {
233 LOG(INFO) << "OnConnectComplete: " << identity().name();
228 DCHECK_GT(pending_service_connections_, 0); 234 DCHECK_GT(pending_service_connections_, 0);
229 pending_service_connections_--; 235 pending_service_connections_--;
230 } 236 }
231 237
232 void StartWithService(mojom::ServicePtr service) { 238 void StartWithService(mojom::ServicePtr service) {
239 LOG(INFO) << "ServiceManagerInstance::StartWithService: "
240 << identity().name();
233 CHECK(!service_); 241 CHECK(!service_);
234 state_ = State::STARTING; 242 state_ = State::STARTING;
235 service_ = std::move(service); 243 service_ = std::move(service);
236 service_.set_connection_error_handler( 244 service_.set_connection_error_handler(
237 base::Bind(&Instance::OnServiceLost, base::Unretained(this), 245 base::Bind(&Instance::OnServiceLost, base::Unretained(this),
238 service_manager_->GetWeakPtr())); 246 service_manager_->GetWeakPtr()));
239 service_->OnStart(ServiceInfo(identity_, interface_provider_specs_), 247 service_->OnStart(ServiceInfo(identity_, interface_provider_specs_),
240 base::Bind(&Instance::OnStartComplete, 248 base::Bind(&Instance::OnStartComplete,
241 base::Unretained(this))); 249 base::Unretained(this)));
242 } 250 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 params->set_target(target); 349 params->set_target(target);
342 params->set_remote_interfaces(std::move(remote_interfaces)); 350 params->set_remote_interfaces(std::move(remote_interfaces));
343 params->set_connect_callback(callback); 351 params->set_connect_callback(callback);
344 service_manager_->Connect(std::move(params), weak_factory_.GetWeakPtr()); 352 service_manager_->Connect(std::move(params), weak_factory_.GetWeakPtr());
345 } 353 }
346 354
347 void BindInterface(const service_manager::Identity& in_target, 355 void BindInterface(const service_manager::Identity& in_target,
348 const std::string& interface_name, 356 const std::string& interface_name,
349 mojo::ScopedMessagePipeHandle interface_pipe, 357 mojo::ScopedMessagePipeHandle interface_pipe,
350 const BindInterfaceCallback& callback) override { 358 const BindInterfaceCallback& callback) override {
359 LOG_IF(INFO, interface_name == "prefs::mojom::PrefStoreRegistry")
360 << "ServiceManager::Instance::BindInterface";
361 LOG(INFO) << "ServiceManager::BindInterface: "
362 << interface_pipe.get().value();
351 Identity target = in_target; 363 Identity target = in_target;
352 mojom::ConnectResult result = 364 mojom::ConnectResult result =
353 ValidateConnectParams(&target, nullptr, nullptr); 365 ValidateConnectParams(&target, nullptr, nullptr);
354 if (!Succeeded(result)) { 366 if (!Succeeded(result)) {
355 callback.Run(result, mojom::kInheritUserID); 367 callback.Run(result, mojom::kInheritUserID);
356 return; 368 return;
357 } 369 }
358 370
359 std::unique_ptr<ConnectParams> params(new ConnectParams); 371 std::unique_ptr<ConnectParams> params(new ConnectParams);
360 params->set_source(identity_); 372 params->set_source(identity_);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 void PIDAvailable(base::ProcessId pid) { 504 void PIDAvailable(base::ProcessId pid) {
493 if (pid == base::kNullProcessId) { 505 if (pid == base::kNullProcessId) {
494 service_manager_->OnInstanceError(this); 506 service_manager_->OnInstanceError(this);
495 return; 507 return;
496 } 508 }
497 pid_ = pid; 509 pid_ = pid;
498 } 510 }
499 511
500 void OnServiceLost( 512 void OnServiceLost(
501 base::WeakPtr<service_manager::ServiceManager> service_manager) { 513 base::WeakPtr<service_manager::ServiceManager> service_manager) {
514 LOG(INFO) << "ServiceManagerInstance::OnServiceLost: " << identity().name();
502 service_.reset(); 515 service_.reset();
503 OnConnectionLost(service_manager); 516 OnConnectionLost(service_manager);
504 } 517 }
505 518
506 void OnConnectionLost( 519 void OnConnectionLost(
507 base::WeakPtr<service_manager::ServiceManager> service_manager) { 520 base::WeakPtr<service_manager::ServiceManager> service_manager) {
508 // Any time a Connector is lost or we lose the Service connection, it 521 // Any time a Connector is lost or we lose the Service connection, it
509 // may have been the last pipe using this Instance. If so, clean up. 522 // may have been the last pipe using this Instance. If so, clean up.
510 if (service_manager && !service_) { 523 if (service_manager && !service_) {
511 if (connectors_.empty()) 524 if (connectors_.empty())
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 757
745 EraseInstanceIdentity(instance); 758 EraseInstanceIdentity(instance);
746 auto it = instances_.find(instance); 759 auto it = instances_.find(instance);
747 DCHECK(it != instances_.end()); 760 DCHECK(it != instances_.end());
748 761
749 // Deletes |instance|. 762 // Deletes |instance|.
750 instances_.erase(it); 763 instances_.erase(it);
751 } 764 }
752 765
753 void ServiceManager::OnInstanceUnreachable(Instance* instance) { 766 void ServiceManager::OnInstanceUnreachable(Instance* instance) {
767 LOG(INFO) << "ServiceManager::OnInstanceUnreachable: "
768 << instance->identity().name();
754 // If an Instance becomes unreachable, new connection requests for this 769 // If an Instance becomes unreachable, new connection requests for this
755 // identity will elicit a new Instance instantiation. The unreachable instance 770 // identity will elicit a new Instance instantiation. The unreachable instance
756 // remains alive. 771 // remains alive.
757 EraseInstanceIdentity(instance); 772 EraseInstanceIdentity(instance);
758 } 773 }
759 774
760 void ServiceManager::OnInstanceStopped(const Identity& identity) { 775 void ServiceManager::OnInstanceStopped(const Identity& identity) {
761 listeners_.ForAllPtrs([identity](mojom::ServiceManagerListener* listener) { 776 listeners_.ForAllPtrs([identity](mojom::ServiceManagerListener* listener) {
762 listener->OnServiceStopped(identity); 777 listener->OnServiceStopped(identity);
763 }); 778 });
764 if (!instance_quit_callback_.is_null()) 779 if (!instance_quit_callback_.is_null())
765 instance_quit_callback_.Run(identity); 780 instance_quit_callback_.Run(identity);
766 } 781 }
767 782
768 void ServiceManager::Connect(std::unique_ptr<ConnectParams> params, 783 void ServiceManager::Connect(std::unique_ptr<ConnectParams> params,
769 base::WeakPtr<Instance> source_instance) { 784 base::WeakPtr<Instance> source_instance) {
785 LOG_IF(INFO, params->target().name() == "preferences")
786 << "ServiceManager::Connect";
770 TRACE_EVENT_INSTANT1("service_manager", "ServiceManager::Connect", 787 TRACE_EVENT_INSTANT1("service_manager", "ServiceManager::Connect",
771 TRACE_EVENT_SCOPE_THREAD, "original_name", 788 TRACE_EVENT_SCOPE_THREAD, "original_name",
772 params->target().name()); 789 params->target().name());
773 DCHECK(!params->target().name().empty()); 790 DCHECK(!params->target().name().empty());
774 DCHECK(base::IsValidGUID(params->target().user_id())); 791 DCHECK(base::IsValidGUID(params->target().user_id()));
775 DCHECK_NE(mojom::kInheritUserID, params->target().user_id()); 792 DCHECK_NE(mojom::kInheritUserID, params->target().user_id());
776 DCHECK(!params->HasClientProcessInfo() || 793 DCHECK(!params->HasClientProcessInfo() ||
777 !identity_to_instance_.count(params->target())); 794 !identity_to_instance_.count(params->target()));
778 795
779 // Connect to an existing matching instance, if possible. 796 // Connect to an existing matching instance, if possible.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 for (auto& instance : identity_to_instance_) 913 for (auto& instance : identity_to_instance_)
897 instances.push_back(instance.second->CreateRunningServiceInfo()); 914 instances.push_back(instance.second->CreateRunningServiceInfo());
898 listener->OnInit(std::move(instances)); 915 listener->OnInit(std::move(instances));
899 916
900 listeners_.AddPtr(std::move(listener)); 917 listeners_.AddPtr(std::move(listener));
901 } 918 }
902 919
903 void ServiceManager::CreateServiceWithFactory(const Identity& service_factory, 920 void ServiceManager::CreateServiceWithFactory(const Identity& service_factory,
904 const std::string& name, 921 const std::string& name,
905 mojom::ServiceRequest request) { 922 mojom::ServiceRequest request) {
923 LOG_IF(INFO, name == "preferences")
924 << "ServiceManager::CreateServiceWithFactory";
906 mojom::ServiceFactory* factory = GetServiceFactory(service_factory); 925 mojom::ServiceFactory* factory = GetServiceFactory(service_factory);
907 factory->CreateService(std::move(request), name); 926 factory->CreateService(std::move(request), name);
908 } 927 }
909 928
910 mojom::ServiceFactory* ServiceManager::GetServiceFactory( 929 mojom::ServiceFactory* ServiceManager::GetServiceFactory(
911 const Identity& service_factory_identity) { 930 const Identity& service_factory_identity) {
912 auto it = service_factories_.find(service_factory_identity); 931 auto it = service_factories_.find(service_factory_identity);
913 if (it != service_factories_.end()) 932 if (it != service_factories_.end())
914 return it->second.get(); 933 return it->second.get();
915 934
916 Identity source_identity(service_manager::mojom::kServiceName, 935 Identity source_identity(service_manager::mojom::kServiceName,
917 mojom::kInheritUserID); 936 mojom::kInheritUserID);
918 mojom::ServiceFactoryPtr factory; 937 mojom::ServiceFactoryPtr factory;
919 BindInterface(this, source_identity, service_factory_identity, &factory); 938 BindInterface(this, source_identity, service_factory_identity, &factory);
920 mojom::ServiceFactory* factory_interface = factory.get(); 939 mojom::ServiceFactory* factory_interface = factory.get();
921 factory.set_connection_error_handler( 940 factory.set_connection_error_handler(
922 base::Bind(&service_manager::ServiceManager::OnServiceFactoryLost, 941 base::Bind(&service_manager::ServiceManager::OnServiceFactoryLost,
923 weak_ptr_factory_.GetWeakPtr(), service_factory_identity)); 942 weak_ptr_factory_.GetWeakPtr(), service_factory_identity));
924 service_factories_[service_factory_identity] = std::move(factory); 943 service_factories_[service_factory_identity] = std::move(factory);
925 return factory_interface; 944 return factory_interface;
926 } 945 }
927 946
928 void ServiceManager::OnServiceFactoryLost(const Identity& which) { 947 void ServiceManager::OnServiceFactoryLost(const Identity& which) {
948 LOG(INFO) << "ServiceManager::OnServiceFactoryLost";
929 // Remove the mapping. 949 // Remove the mapping.
930 auto it = service_factories_.find(which); 950 auto it = service_factories_.find(which);
931 DCHECK(it != service_factories_.end()); 951 DCHECK(it != service_factories_.end());
932 service_factories_.erase(it); 952 service_factories_.erase(it);
933 } 953 }
934 954
935 void ServiceManager::OnGotResolvedName(std::unique_ptr<ConnectParams> params, 955 void ServiceManager::OnGotResolvedName(std::unique_ptr<ConnectParams> params,
936 bool has_source_instance, 956 bool has_source_instance,
937 base::WeakPtr<Instance> source_instance, 957 base::WeakPtr<Instance> source_instance,
938 mojom::ResolveResultPtr result, 958 mojom::ResolveResultPtr result,
939 mojom::ResolveResultPtr parent) { 959 mojom::ResolveResultPtr parent) {
960 LOG_IF(INFO, params->target().name() == "preferences")
961 << "ServiceManager::OnGotResolvedName";
940 // If this request was originated by a specific Instance and that Instance is 962 // If this request was originated by a specific Instance and that Instance is
941 // no longer around, we ignore this response. 963 // no longer around, we ignore this response.
942 if (has_source_instance && !source_instance) 964 if (has_source_instance && !source_instance)
943 return; 965 return;
944 966
945 // If name resolution failed, we drop the connection. 967 // If name resolution failed, we drop the connection.
946 if (!result) { 968 if (!result) {
947 LOG(ERROR) << "Failed to resolve service name: " << params->target().name(); 969 LOG(ERROR) << "Failed to resolve service name: " << params->target().name();
948 RunCallback(params.get(), mojom::ConnectResult::INVALID_ARGUMENT, ""); 970 RunCallback(params.get(), mojom::ConnectResult::INVALID_ARGUMENT, "");
949 return; 971 return;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 // TODO(beng): There may be some cases where it's valid to have an empty 1031 // TODO(beng): There may be some cases where it's valid to have an empty
1010 // spec, so we should probably include a return value in |result|. 1032 // spec, so we should probably include a return value in |result|.
1011 if (result->interface_provider_specs.empty()) { 1033 if (result->interface_provider_specs.empty()) {
1012 LOG(ERROR) 1034 LOG(ERROR)
1013 << "Error: The catalog was unable to read a manifest for service \"" 1035 << "Error: The catalog was unable to read a manifest for service \""
1014 << result->name << "\"."; 1036 << result->name << "\".";
1015 RunCallback(params.get(), mojom::ConnectResult::ACCESS_DENIED, ""); 1037 RunCallback(params.get(), mojom::ConnectResult::ACCESS_DENIED, "");
1016 return; 1038 return;
1017 } 1039 }
1018 1040
1041 LOG_IF(INFO, params->target().name() == "preferences")
1042 << "parent: " << bool(parent);
1019 if (parent) { 1043 if (parent) {
1020 // This service is provided by another service via a ServiceFactory. 1044 // This service is provided by another service via a ServiceFactory.
1021 std::string target_user_id = target.user_id(); 1045 std::string target_user_id = target.user_id();
1022 std::string factory_instance_name = instance_name; 1046 std::string factory_instance_name = instance_name;
1023 1047
1024 auto spec_iter = parent->interface_provider_specs.find( 1048 auto spec_iter = parent->interface_provider_specs.find(
1025 mojom::kServiceManager_ConnectorSpec); 1049 mojom::kServiceManager_ConnectorSpec);
1026 if (spec_iter != parent->interface_provider_specs.end() && 1050 if (spec_iter != parent->interface_provider_specs.end() &&
1027 HasCapability(spec_iter->second, kCapability_InstancePerChild)) { 1051 HasCapability(spec_iter->second, kCapability_InstancePerChild)) {
1028 // If configured to start a new instance, create a random instance name 1052 // If configured to start a new instance, create a random instance name
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 bool connected = instance->CallOnConnect(&params); 1087 bool connected = instance->CallOnConnect(&params);
1064 DCHECK(connected); 1088 DCHECK(connected);
1065 } 1089 }
1066 } 1090 }
1067 1091
1068 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { 1092 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() {
1069 return weak_ptr_factory_.GetWeakPtr(); 1093 return weak_ptr_factory_.GetWeakPtr();
1070 } 1094 }
1071 1095
1072 } // namespace service_manager 1096 } // namespace service_manager
OLDNEW
« no previous file with comments | « services/service_manager/public/cpp/lib/service_context.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698