Chromium Code Reviews| 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, uuid): | |
|
nduca
2012/07/20 07:13:13
uuid -> something more obvious. decorator_id, if t
| |
| 14 self._js_executor = js_executor | |
| 15 self._uuid = uuid | |
| 16 | |
| 17 # Do note that the JSON serialization process removes cyclic references. | |
|
nduca
2012/07/20 07:13:13
# NB: The json serialization process ..., or
# Wa
| |
| 18 # TODO(eatnumber) regenerate these cyclic references on deserialization. | |
| 19 def _callModelMethod(self, method_name, *args): | |
| 20 result = self._js_executor.ExecuteJavascript( | |
| 21 """ | |
| 22 window.timelineModelDecorators['%s'].invokeOnTimelineModel('%s', '%s') | |
| 23 """ % ( | |
| 24 self._uuid, | |
| 25 escape_for_quoted_javascript_execution(method_name), | |
| 26 escape_for_quoted_javascript_execution(json.dumps(args)) | |
| 27 ) | |
| 28 ) | |
| 29 if( result["success"] ): | |
|
nduca
2012/07/20 07:13:13
python style
if x:
never
if (x):
| |
| 30 return result["data"] | |
| 31 # TODO(eatnumber) Make these exceptions more reader friendly | |
|
nduca
2012/07/20 07:13:13
Comments end with periods because they are complet
| |
| 32 raise Exception(result) | |
| 33 | |
| 34 def getAllThreads(self): | |
| 35 return self._callModelMethod("getAllThreads") | |
| 36 | |
| 37 def getAllCpus(self): | |
| 38 return self._callModelMethod("getAllCpus") | |
| 39 | |
| 40 def getAllProcesses(self): | |
| 41 return self._callModelMethod("getAllProcesses") | |
| 42 | |
| 43 def getAllCounters(self): | |
| 44 return self._callModelMethod("getAllCounters") | |
| 45 | |
| 46 def findAllThreadsNamed(self, name): | |
| 47 return self._callModelMethod("findAllThreadsNamed", name); | |
| 48 | |
| 49 # Alias TimelineModel to TimelineModelProxy for convenience | |
| 50 TimelineModel = TimelineModelProxy | |
| OLD | NEW |