OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2011 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. |
| 4 |
| 5 import json |
| 6 import os |
| 7 |
| 8 def escape_for_quoted_javascript_execution(js): |
| 9 # Poor man's string escape. |
| 10 return js.replace("'", "\\'"); |
| 11 |
| 12 class TimelineModelProxy: |
| 13 def __init__(self, js_executor, shim_id): |
| 14 self._js_executor = js_executor |
| 15 self._shim_id = shim_id |
| 16 |
| 17 # Warning: The JSON serialization process removes cyclic references. |
| 18 # TODO(eatnumber) regenerate these cyclic references on deserialization. |
| 19 def _callModelMethod(self, method_name, *args): |
| 20 result = self._js_executor( |
| 21 """ |
| 22 window.timelineModelShims['%s'].invokeMethod('%s', '%s') |
| 23 """ % ( |
| 24 self._shim_id, |
| 25 escape_for_quoted_javascript_execution(method_name), |
| 26 escape_for_quoted_javascript_execution(json.dumps(args)) |
| 27 ) |
| 28 ) |
| 29 if result["success"]: |
| 30 return result["data"] |
| 31 # TODO(eatnumber) Make these exceptions more reader friendly. |
| 32 raise Exception(result) |
| 33 |
| 34 def __del__(self): |
| 35 self._js_executor( |
| 36 """ |
| 37 window.timelineModelShims['%s'] = undefined; |
| 38 window.domAutomationController.send(''); |
| 39 """ % self._shim_id |
| 40 ) |
| 41 |
| 42 def getAllThreads(self): |
| 43 return self._callModelMethod("getAllThreads") |
| 44 |
| 45 def getAllCpus(self): |
| 46 return self._callModelMethod("getAllCpus") |
| 47 |
| 48 def getAllProcesses(self): |
| 49 return self._callModelMethod("getAllProcesses") |
| 50 |
| 51 def getAllCounters(self): |
| 52 return self._callModelMethod("getAllCounters") |
| 53 |
| 54 def findAllThreadsNamed(self, name): |
| 55 return self._callModelMethod("findAllThreadsNamed", name); |
| 56 |
| 57 # Alias TimelineModel to TimelineModelProxy for convenience. |
| 58 TimelineModel = TimelineModelProxy |
OLD | NEW |