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

Unified Diff: third_party/mojo/src/mojo/public/python/mojo_bindings/reflection.py

Issue 910883002: Update mojo sdk to rev 8af2ccff2eee4bfca1043015abee30482a030b30 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Apply 9f87aeadbda22441b7d469e596f7bd7d0d73e2a8 (https://codereview.chromium.org/908973002/) Created 5 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 side-by-side diff with in-line comments
Download patch
Index: third_party/mojo/src/mojo/public/python/mojo_bindings/reflection.py
diff --git a/third_party/mojo/src/mojo/public/python/mojo_bindings/reflection.py b/third_party/mojo/src/mojo/public/python/mojo_bindings/reflection.py
index 7b8edf6819c3209a0df49c4ea3d8ed1a14834029..35b8ff294a16019dc07e16d1d59ea23e6083d457 100644
--- a/third_party/mojo/src/mojo/public/python/mojo_bindings/reflection.py
+++ b/third_party/mojo/src/mojo/public/python/mojo_bindings/reflection.py
@@ -146,7 +146,6 @@ class MojoInterfaceType(type):
class MyInterface(object):
__metaclass__ = MojoInterfaceType
DESCRIPTOR = {
- 'client': MyInterfaceClient,
'methods': [
{
'name': 'FireAndForget',
@@ -181,13 +180,10 @@ class MojoInterfaceType(type):
methods = [_MethodDescriptor(x) for x in descriptor.get('methods', [])]
for method in methods:
dictionary[method.name] = _NotImplemented
- client_class_getter = descriptor.get('client', None)
fully_qualified_name = descriptor['fully_qualified_name']
- interface_manager = InterfaceManager(fully_qualified_name, methods,
- client_class_getter)
+ interface_manager = InterfaceManager(fully_qualified_name, methods)
dictionary.update({
- 'client': None,
'manager': None,
'_interface_manager': interface_manager,
})
@@ -244,24 +240,13 @@ class InterfaceManager(object):
over a pipe.
"""
- def __init__(self, name, methods, client_class_getter):
+ def __init__(self, name, methods):
self.name = name
self.methods = methods
self.interface_class = None
- self._client_class_getter = client_class_getter
- self._client_manager = None
- self._client_manager_computed = False
self._proxy_class = None
self._stub_class = None
- @property
- def client_manager(self):
- if not self._client_manager_computed:
- self._client_manager_computed = True
- if self._client_class_getter:
- self._client_manager = self._client_class_getter().manager
- return self._client_manager
-
def Proxy(self, handle):
router = messaging.Router(handle)
error_handler = _ProxyErrorHandler()
@@ -282,9 +267,6 @@ class InterfaceManager(object):
retainer.release()
error_handler.AddCallback(Cleanup)
- if self.client_manager:
- impl.client = self.client_manager._InternalProxy(router, error_handler)
-
# Give an instance manager to the implementation to allow it to close
# the connection.
impl.manager = InstanceManager(router, error_handler)
@@ -292,15 +274,14 @@ class InterfaceManager(object):
router.Start()
def _InternalProxy(self, router, error_handler):
+ if error_handler is None:
+ error_handler = _ProxyErrorHandler()
+
if not self._proxy_class:
dictionary = {
'__module__': __name__,
'__init__': _ProxyInit,
}
- if self.client_manager:
- dictionary['client'] = property(_ProxyGetClient, _ProxySetClient)
- dictionary['manager'] = None
- dictionary['_client_manager'] = self.client_manager
for method in self.methods:
dictionary[method.name] = _ProxyMethodCall(method)
self._proxy_class = type('%sProxy' % self.name,
@@ -335,15 +316,18 @@ class InstanceManager(object):
def __init__(self, router, error_handler):
self._router = router
self._error_handler = error_handler
+ assert self._error_handler is not None
def Close(self):
+ self._error_handler.OnClose()
self._router.Close()
def PassMessagePipe(self):
+ self._error_handler.OnClose()
return self._router.PassMessagePipe()
def AddOnErrorCallback(self, callback):
- self._error_handler.AddCallback(lambda _: callback())
+ self._error_handler.AddCallback(lambda _: callback(), False)
class _MethodDescriptor(object):
@@ -373,21 +357,32 @@ def _ConstructParameterStruct(descriptor, name, suffix):
class _ProxyErrorHandler(messaging.ConnectionErrorHandler):
def __init__(self):
messaging.ConnectionErrorHandler.__init__(self)
- self._callbacks = set()
+ self._callbacks = dict()
def OnError(self, result):
+ if self._callbacks is None:
+ return
exception = messaging.MessagingException('Mojo error: %d' % result)
- for callback in list(self._callbacks):
+ for (callback, _) in self._callbacks.iteritems():
callback(exception)
self._callbacks = None
- def AddCallback(self, callback):
+ def OnClose(self):
+ if self._callbacks is None:
+ return
+ exception = messaging.MessagingException('Router has been closed.')
+ for (callback, call_on_close) in self._callbacks.iteritems():
+ if call_on_close:
+ callback(exception)
+ self._callbacks = None
+
+ def AddCallback(self, callback, call_on_close=True):
if self._callbacks is not None:
- self._callbacks.add(callback)
+ self._callbacks[callback] = call_on_close
def RemoveCallback(self, callback):
if self._callbacks:
- self._callbacks.remove(callback)
+ del self._callbacks[callback]
class _Retainer(object):
@@ -457,19 +452,6 @@ def _StructNe(self, other):
def _ProxyInit(self, router, error_handler):
self._router = router
self._error_handler = error_handler
- self._client = None
-
-
-# pylint: disable=W0212
-def _ProxyGetClient(self):
- return self._client
-
-
-# pylint: disable=W0212
-def _ProxySetClient(self, client):
- self._client = client
- stub = self._client_manager._Stub(client)
- self._router.SetIncomingMessageReceiver(stub)
# pylint: disable=W0212
« no previous file with comments | « third_party/mojo/src/mojo/public/mojo_application.gni ('k') | third_party/mojo/src/mojo/public/tools/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698