Commit 5b1c7e5f authored by erikchen's avatar erikchen Committed by Commit bot

Telemetry: Removed unused code from InspectorWebsocket.

The will_close_handler parameter of RegisterDomain is never used.

Review URL: https://codereview.chromium.org/945193002

Cr-Commit-Position: refs/heads/master@{#317640}
parent 7e20e761
...@@ -211,10 +211,7 @@ class InspectorBackend(object): ...@@ -211,10 +211,7 @@ class InspectorBackend(object):
if res['method'] == 'HeapProfiler.addHeapSnapshotChunk': if res['method'] == 'HeapProfiler.addHeapSnapshotChunk':
snapshot.append(res['params']['chunk']) snapshot.append(res['params']['chunk'])
def OnClose(): self._websocket.RegisterDomain('HeapProfiler', OnNotification)
pass
self._websocket.RegisterDomain('HeapProfiler', OnNotification, OnClose)
self._websocket.SyncRequest({'method': 'Page.getResourceTree'}, timeout) self._websocket.SyncRequest({'method': 'Page.getResourceTree'}, timeout)
self._websocket.SyncRequest({'method': 'Debugger.enable'}, timeout) self._websocket.SyncRequest({'method': 'Debugger.enable'}, timeout)
......
...@@ -6,10 +6,7 @@ ...@@ -6,10 +6,7 @@
class InspectorConsole(object): class InspectorConsole(object):
def __init__(self, inspector_websocket): def __init__(self, inspector_websocket):
self._inspector_websocket = inspector_websocket self._inspector_websocket = inspector_websocket
self._inspector_websocket.RegisterDomain( self._inspector_websocket.RegisterDomain('Console', self._OnNotification)
'Console',
self._OnNotification,
self._OnClose)
self._message_output_stream = None self._message_output_stream = None
self._last_message = None self._last_message = None
self._console_enabled = False self._console_enabled = False
...@@ -31,9 +28,6 @@ class InspectorConsole(object): ...@@ -31,9 +28,6 @@ class InspectorConsole(object):
self._message_output_stream.write( self._message_output_stream.write(
'%s\n' % self._last_message) '%s\n' % self._last_message)
def _OnClose(self):
pass
# False positive in PyLint 0.25.1: http://www.logilab.org/89092 # False positive in PyLint 0.25.1: http://www.logilab.org/89092
@property @property
def message_output_stream(self): # pylint: disable=E0202 def message_output_stream(self): # pylint: disable=E0202
......
...@@ -12,17 +12,11 @@ class InspectorMemory(object): ...@@ -12,17 +12,11 @@ class InspectorMemory(object):
def __init__(self, inspector_websocket): def __init__(self, inspector_websocket):
self._inspector_websocket = inspector_websocket self._inspector_websocket = inspector_websocket
self._inspector_websocket.RegisterDomain( self._inspector_websocket.RegisterDomain('Memory', self._OnNotification)
'Memory',
self._OnNotification,
self._OnClose)
def _OnNotification(self, msg): def _OnNotification(self, msg):
pass pass
def _OnClose(self):
pass
def GetDOMCounters(self, timeout): def GetDOMCounters(self, timeout):
"""Retrieves DOM element counts. """Retrieves DOM element counts.
......
...@@ -143,8 +143,7 @@ class InspectorNetwork(object): ...@@ -143,8 +143,7 @@ class InspectorNetwork(object):
self.ClearResponseData() self.ClearResponseData()
self._inspector_websocket.RegisterDomain( self._inspector_websocket.RegisterDomain(
'Network', 'Network',
self._OnNetworkNotification, self._OnNetworkNotification)
self._OnClose)
request = { request = {
'method': 'Network.enable' 'method': 'Network.enable'
} }
...@@ -199,9 +198,6 @@ class InspectorNetwork(object): ...@@ -199,9 +198,6 @@ class InspectorNetwork(object):
def HTTPResponseServedFromCache(self, request_id): def HTTPResponseServedFromCache(self, request_id):
return request_id and request_id in self._served_from_cache return request_id and request_id in self._served_from_cache
def _OnClose(self):
pass
@property @property
def timeline_recorder(self): def timeline_recorder(self):
if not self._timeline_recorder: if not self._timeline_recorder:
......
...@@ -11,10 +11,7 @@ from telemetry.image_processing import image_util ...@@ -11,10 +11,7 @@ from telemetry.image_processing import image_util
class InspectorPage(object): class InspectorPage(object):
def __init__(self, inspector_websocket, timeout=60): def __init__(self, inspector_websocket, timeout=60):
self._inspector_websocket = inspector_websocket self._inspector_websocket = inspector_websocket
self._inspector_websocket.RegisterDomain( self._inspector_websocket.RegisterDomain('Page', self._OnNotification)
'Page',
self._OnNotification,
self._OnClose)
self._navigation_pending = False self._navigation_pending = False
self._navigation_url = '' # Support for legacy backends. self._navigation_url = '' # Support for legacy backends.
...@@ -45,9 +42,6 @@ class InspectorPage(object): ...@@ -45,9 +42,6 @@ class InspectorPage(object):
# WaitForNavigate call. # WaitForNavigate call.
self._navigation_pending = False self._navigation_pending = False
def _OnClose(self):
pass
def _SetScriptToEvaluateOnCommit(self, source): def _SetScriptToEvaluateOnCommit(self, source):
existing_source = (self._script_to_evaluate_on_commit and existing_source = (self._script_to_evaluate_on_commit and
self._script_to_evaluate_on_commit['source']) self._script_to_evaluate_on_commit['source'])
......
...@@ -7,10 +7,7 @@ from telemetry.core import exceptions ...@@ -7,10 +7,7 @@ from telemetry.core import exceptions
class InspectorRuntime(object): class InspectorRuntime(object):
def __init__(self, inspector_websocket): def __init__(self, inspector_websocket):
self._inspector_websocket = inspector_websocket self._inspector_websocket = inspector_websocket
self._inspector_websocket.RegisterDomain( self._inspector_websocket.RegisterDomain('Runtime', self._OnNotification)
'Runtime',
self._OnNotification,
self._OnClose)
self._contexts_enabled = False self._contexts_enabled = False
self._max_context_id = None self._max_context_id = None
...@@ -20,9 +17,6 @@ class InspectorRuntime(object): ...@@ -20,9 +17,6 @@ class InspectorRuntime(object):
self._max_context_id = max(self._max_context_id, self._max_context_id = max(self._max_context_id,
msg['params']['context']['id']) msg['params']['context']['id'])
def _OnClose(self):
pass
def Execute(self, expr, context_id, timeout): def Execute(self, expr, context_id, timeout):
self.Evaluate(expr + '; 0;', context_id, timeout) self.Evaluate(expr + '; 0;', context_id, timeout)
......
...@@ -11,10 +11,6 @@ import time ...@@ -11,10 +11,6 @@ import time
from telemetry.core.backends.chrome_inspector import websocket from telemetry.core.backends.chrome_inspector import websocket
_DomainHandler = collections.namedtuple(
'DomainHandler', ['notification_handler', 'will_close_handler'])
class DispatchNotificationsUntilDoneTimeoutException(Exception): class DispatchNotificationsUntilDoneTimeoutException(Exception):
"""Exception that can be thrown from DispatchNotificationsUntilDone to """Exception that can be thrown from DispatchNotificationsUntilDone to
indicate timeout exception of the function. indicate timeout exception of the function.
...@@ -42,8 +38,7 @@ class InspectorWebsocket(object): ...@@ -42,8 +38,7 @@ class InspectorWebsocket(object):
self._all_data_received = False self._all_data_received = False
self._domain_handlers = {} self._domain_handlers = {}
def RegisterDomain( def RegisterDomain(self, domain_name, notification_handler):
self, domain_name, notification_handler, will_close_handler=None):
"""Registers a given domain for handling notification methods. """Registers a given domain for handling notification methods.
When used as handler for DispatchNotificationsUntilDone, When used as handler for DispatchNotificationsUntilDone,
...@@ -55,10 +50,7 @@ class InspectorWebsocket(object): ...@@ -55,10 +50,7 @@ class InspectorWebsocket(object):
if msg['method'] == 'Console.messageAdded': if msg['method'] == 'Console.messageAdded':
print msg['params']['message'] print msg['params']['message']
return True return True
def OnConsoleClose(self): inspector_backend.RegisterDomain('Console', OnConsoleNotification)
pass
inspector_backend.RegisterDomain(
'Console', OnConsoleNotification, OnConsoleClose)
Args: Args:
domain_name: The devtools domain name. E.g., 'Tracing', 'Memory', 'Page'. domain_name: The devtools domain name. E.g., 'Tracing', 'Memory', 'Page'.
...@@ -67,16 +59,14 @@ class InspectorWebsocket(object): ...@@ -67,16 +59,14 @@ class InspectorWebsocket(object):
(via DispatchNotifications and DispatchNotificationsUntilDone). (via DispatchNotifications and DispatchNotificationsUntilDone).
The handler accepts a single paramater: the JSON object representing The handler accepts a single paramater: the JSON object representing
the notification. the notification.
will_close_handler: Handler to be called from Disconnect().
""" """
assert domain_name not in self._domain_handlers assert domain_name not in self._domain_handlers
self._domain_handlers[domain_name] = _DomainHandler( self._domain_handlers[domain_name] = notification_handler
notification_handler, will_close_handler)
def UnregisterDomain(self, domain_name): def UnregisterDomain(self, domain_name):
"""Unregisters a previously registered domain.""" """Unregisters a previously registered domain."""
assert domain_name in self._domain_handlers assert domain_name in self._domain_handlers
self._domain_handlers.pop(domain_name) del self._domain_handlers[domain_name]
def Connect(self, url, timeout=10): def Connect(self, url, timeout=10):
assert not self._socket assert not self._socket
...@@ -85,14 +75,7 @@ class InspectorWebsocket(object): ...@@ -85,14 +75,7 @@ class InspectorWebsocket(object):
self._next_request_id = 0 self._next_request_id = 0
def Disconnect(self): def Disconnect(self):
"""Disconnects the inspector websocket. """Disconnects the inspector websocket."""
All existing domain handlers will also be unregistered.
"""
for _, handler in self._domain_handlers.items():
if handler.will_close_handler:
handler.will_close_handler()
if self._socket: if self._socket:
self._socket.close() self._socket.close()
self._socket = None self._socket = None
...@@ -177,7 +160,7 @@ class InspectorWebsocket(object): ...@@ -177,7 +160,7 @@ class InspectorWebsocket(object):
dot_pos = mname.find('.') dot_pos = mname.find('.')
domain_name = mname[:dot_pos] domain_name = mname[:dot_pos]
if domain_name in self._domain_handlers: if domain_name in self._domain_handlers:
return self._domain_handlers[domain_name].notification_handler(result) return self._domain_handlers[domain_name](result)
logging.warn('Unhandled inspector message: %s', result) logging.warn('Unhandled inspector message: %s', result)
return False return False
...@@ -66,7 +66,7 @@ class InspectorWebsocketUnittest(unittest.TestCase): ...@@ -66,7 +66,7 @@ class InspectorWebsocketUnittest(unittest.TestCase):
def OnTestEvent(result): def OnTestEvent(result):
results.append(result) results.append(result)
inspector.RegisterDomain('Test', OnTestEvent, _DoNothingHandler) inspector.RegisterDomain('Test', OnTestEvent)
fake_socket.AddResponse('{"method": "Test.foo"}', 5) fake_socket.AddResponse('{"method": "Test.foo"}', 5)
inspector.DispatchNotifications() inspector.DispatchNotifications()
self.assertEqual(1, len(results)) self.assertEqual(1, len(results))
...@@ -83,7 +83,7 @@ class InspectorWebsocketUnittest(unittest.TestCase): ...@@ -83,7 +83,7 @@ class InspectorWebsocketUnittest(unittest.TestCase):
def OnTestEvent(result): def OnTestEvent(result):
results.append(result) results.append(result)
inspector.RegisterDomain('Test', OnTestEvent, _DoNothingHandler) inspector.RegisterDomain('Test', OnTestEvent)
fake_socket.AddResponse('{"method": "Test.foo"}', 11) fake_socket.AddResponse('{"method": "Test.foo"}', 11)
with self.assertRaises( with self.assertRaises(
websocket.WebSocketTimeoutException): websocket.WebSocketTimeoutException):
...@@ -100,7 +100,7 @@ class InspectorWebsocketUnittest(unittest.TestCase): ...@@ -100,7 +100,7 @@ class InspectorWebsocketUnittest(unittest.TestCase):
def OnTestEvent(result): def OnTestEvent(result):
results.append(result) results.append(result)
inspector.RegisterDomain('Test', OnTestEvent, _DoNothingHandler) inspector.RegisterDomain('Test', OnTestEvent)
# The third call to socket.recv() will take 15 seconds without any data # The third call to socket.recv() will take 15 seconds without any data
# received, hence the below call will raise a # received, hence the below call will raise a
# DispatchNotificationsUntilDoneTimeoutException. # DispatchNotificationsUntilDoneTimeoutException.
...@@ -124,7 +124,7 @@ class InspectorWebsocketUnittest(unittest.TestCase): ...@@ -124,7 +124,7 @@ class InspectorWebsocketUnittest(unittest.TestCase):
results.append(result) results.append(result)
return len(results) > 2 return len(results) > 2
inspector.RegisterDomain('Test', OnTestEvent, _DoNothingHandler) inspector.RegisterDomain('Test', OnTestEvent)
# Even though it takes 70 seconds to receive all the data, the call below # Even though it takes 70 seconds to receive all the data, the call below
# will succeed since there are no interval which the previous data package # will succeed since there are no interval which the previous data package
# received and the next failed data receiving attempt was greater than # received and the next failed data receiving attempt was greater than
...@@ -150,7 +150,7 @@ class InspectorWebsocketUnittest(unittest.TestCase): ...@@ -150,7 +150,7 @@ class InspectorWebsocketUnittest(unittest.TestCase):
def OnTestEvent(result): def OnTestEvent(result):
results.append(result) results.append(result)
inspector.RegisterDomain('Test', OnTestEvent, _DoNothingHandler) inspector.RegisterDomain('Test', OnTestEvent)
fake_socket.AddResponse('{"method": "Test.foo"}', 5) fake_socket.AddResponse('{"method": "Test.foo"}', 5)
fake_socket.AddResponse('{"method": "Test.bar"}', 16) fake_socket.AddResponse('{"method": "Test.bar"}', 16)
fake_socket.AddResponse('{"method": "Test.baz"}', 20) fake_socket.AddResponse('{"method": "Test.baz"}', 20)
...@@ -170,8 +170,8 @@ class InspectorWebsocketUnittest(unittest.TestCase): ...@@ -170,8 +170,8 @@ class InspectorWebsocketUnittest(unittest.TestCase):
def OnTestEvent(result): def OnTestEvent(result):
results.append(result) results.append(result)
inspector.RegisterDomain('Test', OnTestEvent, _DoNothingHandler) inspector.RegisterDomain('Test', OnTestEvent)
inspector.RegisterDomain('Test2', OnTestEvent, _DoNothingHandler) inspector.RegisterDomain('Test2', OnTestEvent)
inspector.UnregisterDomain('Test') inspector.UnregisterDomain('Test')
fake_socket.AddResponse('{"method": "Test.foo"}', 5) fake_socket.AddResponse('{"method": "Test.foo"}', 5)
...@@ -189,21 +189,3 @@ class InspectorWebsocketUnittest(unittest.TestCase): ...@@ -189,21 +189,3 @@ class InspectorWebsocketUnittest(unittest.TestCase):
error_handler=_ReraiseExceptionErrorHandler) error_handler=_ReraiseExceptionErrorHandler)
with self.assertRaises(AssertionError): with self.assertRaises(AssertionError):
inspector.UnregisterDomain('Test') inspector.UnregisterDomain('Test')
def testRegisterDomainWillCloseHandler(self):
inspector = inspector_websocket.InspectorWebsocket(
error_handler=_ReraiseExceptionErrorHandler)
results = []
def OnClose():
results.append(1)
results2 = []
def OnClose2():
results2.append(1)
inspector.RegisterDomain('Test', _DoNothingHandler, OnClose)
inspector.RegisterDomain('Test2', _DoNothingHandler, OnClose2)
inspector.RegisterDomain('Test3', _DoNothingHandler)
inspector.Disconnect()
self.assertEqual(1, len(results))
self.assertEqual(1, len(results2))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment