| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 """Python implementation of the ServiceProvider interface.""" | 5 """Python implementation of the ServiceProvider interface.""" |
| 6 | 6 |
| 7 import logging | 7 import logging |
| 8 | 8 |
| 9 import service_provider_mojom | 9 import service_provider_mojom |
| 10 | 10 |
| 11 class ServiceProviderImpl(service_provider_mojom.ServiceProvider): | 11 class ServiceProviderImpl(service_provider_mojom.ServiceProvider): |
| 12 def __init__(self, provider): | 12 def __init__(self, provider): |
| 13 self._provider = provider | 13 self._provider = provider |
| 14 self._name_to_service_connector = {} | 14 self._name_to_service_connector = {} |
| 15 | 15 |
| 16 def AddService(self, service_class): | 16 def AddService(self, service_class, service_name=None): |
| 17 self._name_to_service_connector[service_class.manager.name] = service_class | 17 if service_name is None: |
| 18 service_name = service_class.manager.service_name |
| 19 if service_name is None: |
| 20 logging.error("No ServiceName specified for %s." % service_class.__name__) |
| 21 return |
| 22 self._name_to_service_connector[service_name] = service_class |
| 18 | 23 |
| 19 def ConnectToService(self, interface_name, pipe): | 24 def ConnectToService(self, interface_name, pipe): |
| 20 if interface_name in self._name_to_service_connector: | 25 if interface_name in self._name_to_service_connector: |
| 21 service = self._name_to_service_connector[interface_name] | 26 service = self._name_to_service_connector[interface_name] |
| 22 service.manager.Bind(service(), pipe) | 27 service.manager.Bind(service(), pipe) |
| 23 else: | 28 else: |
| 24 logging.error("Unable to find service " + interface_name) | 29 logging.error("Unable to find service " + interface_name) |
| OLD | NEW |