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
3 # found in the LICENSE file.
5 # A singleton map from platform backends to maps of uniquely-identifying
6 # remote port (which may be the same as local port) to DevToolsClientBackend.
7 # There is no guarantee that the devtools agent is still alive.
8 _platform_backends_to_devtools_clients_maps
= {}
11 def _RemoveStaleDevToolsClient(platform_backend
):
12 """Removes DevTools clients that are no longer connectable."""
13 devtools_clients_map
= _platform_backends_to_devtools_clients_maps
.get(
15 devtools_clients_map
= {
17 for port
, client
in devtools_clients_map
.iteritems()
20 _platform_backends_to_devtools_clients_maps
[platform_backend
] = (
24 def RegisterDevToolsClient(devtools_client_backend
, platform_backend
):
25 """Register DevTools client
27 This should only be called from DevToolsClientBackend when it is initialized.
29 remote_port
= str(devtools_client_backend
.remote_port
)
30 if platform_backend
not in _platform_backends_to_devtools_clients_maps
:
31 _platform_backends_to_devtools_clients_maps
[platform_backend
] = {}
32 devtools_clients_map
= (
33 _platform_backends_to_devtools_clients_maps
[platform_backend
])
34 devtools_clients_map
[remote_port
] = devtools_client_backend
37 def IsSupported(platform_backend
):
38 _RemoveStaleDevToolsClient(platform_backend
)
39 devtools_clients_map
= _platform_backends_to_devtools_clients_maps
.get(
41 for _
, devtools_client
in devtools_clients_map
.iteritems():
42 if devtools_client
.IsChromeTracingSupported():
47 def GetDevToolsClients(platform_backend
):
48 """Get DevTools clients including the ones that are no longer connectable."""
49 devtools_clients_map
= _platform_backends_to_devtools_clients_maps
.get(
51 if not devtools_clients_map
:
53 return devtools_clients_map
.values()
55 def GetActiveDevToolsClients(platform_backend
):
56 """Get DevTools clients that are still connectable."""
57 _RemoveStaleDevToolsClient(platform_backend
)
58 return GetDevToolsClients(platform_backend
)