| 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/public/cpp/service_context.h" | 5 #include "services/service_manager/public/cpp/service_context.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 void ServiceContext::DestroyService() { | 73 void ServiceContext::DestroyService() { |
| 74 QuitNow(); | 74 QuitNow(); |
| 75 service_.reset(); | 75 service_.reset(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 //////////////////////////////////////////////////////////////////////////////// | 78 //////////////////////////////////////////////////////////////////////////////// |
| 79 // ServiceContext, mojom::Service implementation: | 79 // ServiceContext, mojom::Service implementation: |
| 80 | 80 |
| 81 void ServiceContext::OnStart(const ServiceInfo& info, | 81 void ServiceContext::OnStart(const ServiceInfo& info, |
| 82 const OnStartCallback& callback) { | 82 const OnStartCallback& callback) { |
| 83 service_started_ = true; | |
| 84 local_info_ = info; | 83 local_info_ = info; |
| 85 callback.Run(std::move(pending_connector_request_), | 84 callback.Run(std::move(pending_connector_request_), |
| 86 mojo::MakeRequest(&service_control_)); | 85 mojo::MakeRequest(&service_control_)); |
| 87 | 86 |
| 88 service_->set_context(this); | 87 service_->set_context(this); |
| 89 service_->OnStart(); | 88 service_->OnStart(); |
| 90 } | 89 } |
| 91 | 90 |
| 92 void ServiceContext::OnConnect( | 91 void ServiceContext::OnConnect( |
| 93 const ServiceInfo& source_info, | 92 const ServiceInfo& source_info, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 133 |
| 135 InterfaceRegistry* raw_registry = registry.get(); | 134 InterfaceRegistry* raw_registry = registry.get(); |
| 136 registry->AddConnectionLostClosure(base::Bind( | 135 registry->AddConnectionLostClosure(base::Bind( |
| 137 &ServiceContext::OnRegistryConnectionError, base::Unretained(this), | 136 &ServiceContext::OnRegistryConnectionError, base::Unretained(this), |
| 138 raw_registry)); | 137 raw_registry)); |
| 139 connection_interface_registries_.insert( | 138 connection_interface_registries_.insert( |
| 140 std::make_pair(raw_registry, std::move(registry))); | 139 std::make_pair(raw_registry, std::move(registry))); |
| 141 } | 140 } |
| 142 | 141 |
| 143 void ServiceContext::OnConnectionError() { | 142 void ServiceContext::OnConnectionError() { |
| 144 if (!service_started_) { | |
| 145 // The pipe was broken before we even received OnStart(). | |
| 146 service_->set_context(this); | |
| 147 service_->OnStartFailed(); | |
| 148 return; | |
| 149 } | |
| 150 | |
| 151 // Note that the Service doesn't technically have to quit now, it may live | 143 // Note that the Service doesn't technically have to quit now, it may live |
| 152 // on to service existing connections. All existing Connectors however are | 144 // on to service existing connections. All existing Connectors however are |
| 153 // invalid. | 145 // invalid. |
| 154 service_quit_ = service_->OnStop(); | 146 service_quit_ = service_->OnStop(); |
| 155 if (service_quit_) { | 147 if (service_quit_) { |
| 156 QuitNow(); | 148 QuitNow(); |
| 157 // NOTE: This call may delete |this|, so don't access any ServiceContext | 149 // NOTE: This call may delete |this|, so don't access any ServiceContext |
| 158 // state beyond this point. | 150 // state beyond this point. |
| 159 return; | 151 return; |
| 160 } | 152 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 174 } | 166 } |
| 175 | 167 |
| 176 void ServiceContext::DestroyConnectionInterfaceRegistry( | 168 void ServiceContext::DestroyConnectionInterfaceRegistry( |
| 177 InterfaceRegistry* registry) { | 169 InterfaceRegistry* registry) { |
| 178 auto it = connection_interface_registries_.find(registry); | 170 auto it = connection_interface_registries_.find(registry); |
| 179 CHECK(it != connection_interface_registries_.end()); | 171 CHECK(it != connection_interface_registries_.end()); |
| 180 connection_interface_registries_.erase(it); | 172 connection_interface_registries_.erase(it); |
| 181 } | 173 } |
| 182 | 174 |
| 183 } // namespace service_manager | 175 } // namespace service_manager |
| OLD | NEW |