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

Side by Side Diff: tools/telemetry/telemetry/inspector_console.py

Issue 12278015: [Telemetry] Reorganize everything. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Re-add shebangs. Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (c) 2012 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 import json
5 import logging
6
7 class InspectorConsole(object):
8 def __init__(self, inspector_backend):
9 self._inspector_backend = inspector_backend
10 self._inspector_backend.RegisterDomain(
11 'Console',
12 self._OnNotification,
13 self._OnClose)
14 self._message_output_stream = None
15 self._last_message = None
16 self._console_enabled = False
17
18 def _OnNotification(self, msg):
19 logging.debug('Notification: %s', json.dumps(msg, indent=2))
20 if msg['method'] == 'Console.messageAdded':
21 self._last_message = 'At %s:%i: %s' % (
22 msg['params']['message']['url'],
23 msg['params']['message']['line'],
24 msg['params']['message']['text'])
25 if self._message_output_stream:
26 self._message_output_stream.write(
27 '%s\n' % self._last_message)
28
29 elif msg['method'] == 'Console.messageRepeatCountUpdated':
30 if self._message_output_stream:
31 self._message_output_stream.write(
32 '%s\n' % self._last_message)
33
34 def _OnClose(self):
35 pass
36
37 # False positive in PyLint 0.25.1: http://www.logilab.org/89092
38 @property
39 def message_output_stream(self): # pylint: disable=E0202
40 return self._message_output_stream
41
42 @message_output_stream.setter
43 def message_output_stream(self, stream): # pylint: disable=E0202
44 self._message_output_stream = stream
45 self._UpdateConsoleEnabledState()
46
47 def _UpdateConsoleEnabledState(self):
48 enabled = self._message_output_stream != None
49 if enabled == self._console_enabled:
50 return
51
52 if enabled:
53 method_name = 'enable'
54 else:
55 method_name = 'disable'
56 self._inspector_backend.SyncRequest({
57 'method': 'Console.%s' % method_name
58 })
59 self._console_enabled = enabled
OLDNEW
« no previous file with comments | « tools/telemetry/telemetry/inspector_backend.py ('k') | tools/telemetry/telemetry/inspector_console_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698