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

Side by Side Diff: telemetry/telemetry/internal/backends/chrome_inspector/inspector_backend.py

Issue 3013243002: Refactor websocket connections logic with devtool Storage domain to a separate class (Closed)
Patch Set: Created 3 years, 3 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
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 import functools 5 import functools
6 import logging 6 import logging
7 import socket 7 import socket
8 import sys 8 import sys
9 9
10 from py_trace_event import trace_event 10 from py_trace_event import trace_event
11 11
12 from telemetry.core import exceptions 12 from telemetry.core import exceptions
13 from telemetry import decorators 13 from telemetry import decorators
14 from telemetry.internal.backends.chrome_inspector import devtools_http 14 from telemetry.internal.backends.chrome_inspector import devtools_http
15 from telemetry.internal.backends.chrome_inspector import inspector_console 15 from telemetry.internal.backends.chrome_inspector import inspector_console
16 from telemetry.internal.backends.chrome_inspector import inspector_memory 16 from telemetry.internal.backends.chrome_inspector import inspector_memory
17 from telemetry.internal.backends.chrome_inspector import inspector_page 17 from telemetry.internal.backends.chrome_inspector import inspector_page
18 from telemetry.internal.backends.chrome_inspector import inspector_runtime 18 from telemetry.internal.backends.chrome_inspector import inspector_runtime
19 from telemetry.internal.backends.chrome_inspector import inspector_storage
19 from telemetry.internal.backends.chrome_inspector import inspector_websocket 20 from telemetry.internal.backends.chrome_inspector import inspector_websocket
20 from telemetry.internal.backends.chrome_inspector import websocket 21 from telemetry.internal.backends.chrome_inspector import websocket
21 from telemetry.util import js_template 22 from telemetry.util import js_template
22 23
23 import py_utils 24 import py_utils
24 25
25 26
26 def _HandleInspectorWebSocketExceptions(func): 27 def _HandleInspectorWebSocketExceptions(func):
27 """Decorator for converting inspector_websocket exceptions. 28 """Decorator for converting inspector_websocket exceptions.
28 29
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 self._context = context 65 self._context = context
65 66
66 logging.debug('InspectorBackend._Connect() to %s', self.debugger_url) 67 logging.debug('InspectorBackend._Connect() to %s', self.debugger_url)
67 try: 68 try:
68 self._websocket.Connect(self.debugger_url, timeout) 69 self._websocket.Connect(self.debugger_url, timeout)
69 self._console = inspector_console.InspectorConsole(self._websocket) 70 self._console = inspector_console.InspectorConsole(self._websocket)
70 self._memory = inspector_memory.InspectorMemory(self._websocket) 71 self._memory = inspector_memory.InspectorMemory(self._websocket)
71 self._page = inspector_page.InspectorPage( 72 self._page = inspector_page.InspectorPage(
72 self._websocket, timeout=timeout) 73 self._websocket, timeout=timeout)
73 self._runtime = inspector_runtime.InspectorRuntime(self._websocket) 74 self._runtime = inspector_runtime.InspectorRuntime(self._websocket)
75 self._storage = inspector_storage.InspectorStorage(self._websocket)
74 except (websocket.WebSocketException, exceptions.TimeoutException, 76 except (websocket.WebSocketException, exceptions.TimeoutException,
75 py_utils.TimeoutException) as e: 77 py_utils.TimeoutException) as e:
76 self._ConvertExceptionFromInspectorWebsocket(e) 78 self._ConvertExceptionFromInspectorWebsocket(e)
77 79
78 def Disconnect(self): 80 def Disconnect(self):
79 """Disconnects the inspector websocket. 81 """Disconnects the inspector websocket.
80 82
81 This method intentionally leaves the self._websocket object around, so that 83 This method intentionally leaves the self._websocket object around, so that
82 future calls it to it will fail with a relevant error. 84 future calls it to it will fail with a relevant error.
83 """ 85 """
(...skipping 17 matching lines...) Expand all
101 return self._devtools_client.GetUrl(self.id) 103 return self._devtools_client.GetUrl(self.id)
102 104
103 @property 105 @property
104 def id(self): # pylint: disable=invalid-name 106 def id(self): # pylint: disable=invalid-name
105 return self._context['id'] 107 return self._context['id']
106 108
107 @property 109 @property
108 def debugger_url(self): 110 def debugger_url(self):
109 return self._context['webSocketDebuggerUrl'] 111 return self._context['webSocketDebuggerUrl']
110 112
113 def ClearDataForOrigin(self, url, timeout):
114 self._storage.ClearDataForOrigin(url, timeout)
115
111 def GetWebviewInspectorBackends(self): 116 def GetWebviewInspectorBackends(self):
112 """Returns a list of InspectorBackend instances associated with webviews. 117 """Returns a list of InspectorBackend instances associated with webviews.
113 118
114 Raises: 119 Raises:
115 devtools_http.DevToolsClientConnectionError 120 devtools_http.DevToolsClientConnectionError
116 """ 121 """
117 inspector_backends = [] 122 inspector_backends = []
118 devtools_context_map = self._devtools_client.GetUpdatedInspectableContexts() 123 devtools_context_map = self._devtools_client.GetUpdatedInspectableContexts()
119 for context in devtools_context_map.contexts: 124 for context in devtools_context_map.contexts:
120 if context['type'] == 'webview': 125 if context['type'] == 'webview':
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 error.AddDebuggingMessage(msg) 507 error.AddDebuggingMessage(msg)
503 error.AddDebuggingMessage('Debugger url: %s' % self.debugger_url) 508 error.AddDebuggingMessage('Debugger url: %s' % self.debugger_url)
504 509
505 @_HandleInspectorWebSocketExceptions 510 @_HandleInspectorWebSocketExceptions
506 def _EvaluateJavaScript(self, expression, context_id, timeout): 511 def _EvaluateJavaScript(self, expression, context_id, timeout):
507 return self._runtime.Evaluate(expression, context_id, timeout) 512 return self._runtime.Evaluate(expression, context_id, timeout)
508 513
509 @_HandleInspectorWebSocketExceptions 514 @_HandleInspectorWebSocketExceptions
510 def CollectGarbage(self): 515 def CollectGarbage(self):
511 self._page.CollectGarbage() 516 self._page.CollectGarbage()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698