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 import logging | 5 import logging |
6 import re | 6 import re |
7 import socket | 7 import socket |
8 import sys | 8 import sys |
9 | 9 |
10 from telemetry.core import exceptions | 10 from telemetry.core import exceptions |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 return True | 82 return True |
83 | 83 |
84 | 84 |
85 class DevToolsClientBackend(object): | 85 class DevToolsClientBackend(object): |
86 """An object that communicates with Chrome's devtools. | 86 """An object that communicates with Chrome's devtools. |
87 | 87 |
88 This class owns a map of InspectorBackends. It is responsible for creating | 88 This class owns a map of InspectorBackends. It is responsible for creating |
89 them and destroying them. | 89 them and destroying them. |
90 """ | 90 """ |
91 def __init__(self, devtools_port, browser_target, remote_devtools_port, | 91 def __init__(self, devtools_port, browser_target, remote_devtools_port, |
92 app_backend): | 92 app_backend, enable_tracing=True): |
93 """Creates a new DevToolsClientBackend. | 93 """Creates a new DevToolsClientBackend. |
94 | 94 |
95 A DevTools agent must exist on the given devtools_port. | 95 A DevTools agent must exist on the given devtools_port. |
96 | 96 |
97 Args: | 97 Args: |
98 devtools_port: The port to use to connect to DevTools agent. | 98 devtools_port: The port to use to connect to DevTools agent. |
99 remote_devtools_port: In some cases (e.g., app running on | 99 remote_devtools_port: In some cases (e.g., app running on |
100 Android device, devtools_port is the forwarded port on the | 100 Android device, devtools_port is the forwarded port on the |
101 host platform. We also need to know the remote_devtools_port | 101 host platform. We also need to know the remote_devtools_port |
102 so that we can uniquely identify the DevTools agent. | 102 so that we can uniquely identify the DevTools agent. |
103 app_backend: For the app that contains the DevTools agent. | 103 app_backend: For the app that contains the DevTools agent. |
104 """ | 104 """ |
105 self._devtools_port = devtools_port | 105 self._devtools_port = devtools_port |
106 self._browser_target = browser_target or '/devtools/browser' | 106 self._browser_target = browser_target or '/devtools/browser' |
107 self._remote_devtools_port = remote_devtools_port | 107 self._remote_devtools_port = remote_devtools_port |
108 self._devtools_http = devtools_http.DevToolsHttp(devtools_port) | 108 self._devtools_http = devtools_http.DevToolsHttp(devtools_port) |
109 self._browser_inspector_websocket = None | 109 self._browser_inspector_websocket = None |
110 self._tracing_backend = None | 110 self._tracing_backend = None |
111 self._memory_backend = None | 111 self._memory_backend = None |
112 self._system_info_backend = None | 112 self._system_info_backend = None |
113 self._app_backend = app_backend | 113 self._app_backend = app_backend |
114 self._devtools_context_map_backend = _DevToolsContextMapBackend( | 114 self._devtools_context_map_backend = _DevToolsContextMapBackend( |
115 self._app_backend, self) | 115 self._app_backend, self) |
116 self._enable_tracing = enable_tracing | |
116 | 117 |
117 self._tab_ids = None | 118 self._tab_ids = None |
118 | 119 |
119 if not self.supports_tracing: | 120 if not self.supports_tracing: |
120 return | 121 return |
121 chrome_tracing_devtools_manager.RegisterDevToolsClient( | 122 chrome_tracing_devtools_manager.RegisterDevToolsClient( |
122 self, self._app_backend.platform_backend) | 123 self, self._app_backend.platform_backend) |
123 | 124 |
124 # Telemetry has started Chrome tracing if there is trace config, so start | 125 # Telemetry has started Chrome tracing if there is trace config, so start |
125 # tracing on this newly created devtools client if needed. | 126 # tracing on this newly created devtools client if needed. |
(...skipping 11 matching lines...) Expand all Loading... | |
137 self.StartChromeTracing(trace_config) | 138 self.StartChromeTracing(trace_config) |
138 | 139 |
139 @property | 140 @property |
140 def remote_port(self): | 141 def remote_port(self): |
141 return self._remote_devtools_port | 142 return self._remote_devtools_port |
142 | 143 |
143 @property | 144 @property |
144 def supports_tracing(self): | 145 def supports_tracing(self): |
145 if not isinstance(self._app_backend, browser_backend.BrowserBackend): | 146 if not isinstance(self._app_backend, browser_backend.BrowserBackend): |
146 return False | 147 return False |
148 if not self._enable_tracing: | |
nednguyen
2017/08/17 14:16:24
This is a misusage of abstraction. The name of thi
| |
149 return False | |
147 return self._app_backend.supports_tracing | 150 return self._app_backend.supports_tracing |
148 | 151 |
149 @property | 152 @property |
150 def supports_overriding_memory_pressure_notifications(self): | 153 def supports_overriding_memory_pressure_notifications(self): |
151 if not isinstance(self._app_backend, browser_backend.BrowserBackend): | 154 if not isinstance(self._app_backend, browser_backend.BrowserBackend): |
152 return False | 155 return False |
153 return self._app_backend.supports_overriding_memory_pressure_notifications | 156 return self._app_backend.supports_overriding_memory_pressure_notifications |
154 | 157 |
155 | 158 |
156 @property | 159 @property |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
510 context_id) | 513 context_id) |
511 continue | 514 continue |
512 valid_contexts.append(context) | 515 valid_contexts.append(context) |
513 self._contexts = valid_contexts | 516 self._contexts = valid_contexts |
514 | 517 |
515 def Clear(self): | 518 def Clear(self): |
516 for backend in self._inspector_backends_dict.values(): | 519 for backend in self._inspector_backends_dict.values(): |
517 backend.Disconnect() | 520 backend.Disconnect() |
518 self._inspector_backends_dict = {} | 521 self._inspector_backends_dict = {} |
519 self._contexts = None | 522 self._contexts = None |
OLD | NEW |