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

Side by Side Diff: breakpad.py

Issue 9145001: Make sure that direct call to SendStack() doesn't send a stack trace for non googler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 8 years, 11 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
« no previous file with comments | « no previous file | tests/breakpad_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 """Breakpad for Python. 5 """Breakpad for Python.
6 6
7 Sends a notification when a process stops on an exception. 7 Sends a notification when a process stops on an exception.
8 8
9 It is only enabled when all these conditions are met: 9 It is only enabled when all these conditions are met:
10 1. hostname finishes with '.google.com' or 'chromium.org' 10 1. hostname finishes with '.google.com' or 'chromium.org'
(...skipping 15 matching lines...) Expand all
26 # Configure these values. 26 # Configure these values.
27 DEFAULT_URL = 'https://chromium-status.appspot.com' 27 DEFAULT_URL = 'https://chromium-status.appspot.com'
28 28
29 # Global variable to prevent double registration. 29 # Global variable to prevent double registration.
30 _REGISTERED = False 30 _REGISTERED = False
31 31
32 _TIME_STARTED = time.time() 32 _TIME_STARTED = time.time()
33 33
34 _HOST_NAME = socket.getfqdn() 34 _HOST_NAME = socket.getfqdn()
35 35
36 # Skip unit tests and we don't want anything from non-googler.
37 IS_ENABLED = (
38 not 'test' in getattr(sys.modules['__main__'], '__file__', '') and
39 not 'NO_BREAKPAD' in os.environ and
40 _HOST_NAME.endswith(('.google.com', '.chromium.org')))
41
36 42
37 def post(url, params): 43 def post(url, params):
38 """HTTP POST with timeout when it's supported.""" 44 """HTTP POST with timeout when it's supported."""
39 kwargs = {} 45 kwargs = {}
40 if (sys.version_info[0] * 10 + sys.version_info[1]) >= 26: 46 if (sys.version_info[0] * 10 + sys.version_info[1]) >= 26:
41 kwargs['timeout'] = 4 47 kwargs['timeout'] = 4
42 request = urllib2.urlopen(url, urllib.urlencode(params), **kwargs) 48 request = urllib2.urlopen(url, urllib.urlencode(params), **kwargs)
43 out = request.read() 49 out = request.read()
44 request.close() 50 request.close()
45 return out 51 return out
(...skipping 22 matching lines...) Expand all
68 out += '\nread(): %s' % e.read() 74 out += '\nread(): %s' % e.read()
69 if hasattr(e, 'info') and callable(e.info): 75 if hasattr(e, 'info') and callable(e.info):
70 out += '\ninfo(): %s' % e.info() 76 out += '\ninfo(): %s' % e.info()
71 except Exception: 77 except Exception:
72 pass 78 pass
73 return out 79 return out
74 80
75 81
76 def SendStack(last_tb, stack, url=None, maxlen=50): 82 def SendStack(last_tb, stack, url=None, maxlen=50):
77 """Sends the stack trace to the breakpad server.""" 83 """Sends the stack trace to the breakpad server."""
84 if not IS_ENABLED:
85 # Make sure to not send anything for non googler.
86 return
78 if not url: 87 if not url:
79 url = DEFAULT_URL + '/breakpad' 88 url = DEFAULT_URL + '/breakpad'
80 print 'Sending crash report ...' 89 print 'Sending crash report ...'
81 try: 90 try:
82 params = { 91 params = {
83 'args': sys.argv, 92 'args': sys.argv,
84 'stack': stack[0:4096], 93 'stack': stack[0:4096],
85 'user': getpass.getuser(), 94 'user': getpass.getuser(),
86 'exception': FormatException(last_tb), 95 'exception': FormatException(last_tb),
87 'host': _HOST_NAME, 96 'host': _HOST_NAME,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 135
127 def Register(): 136 def Register():
128 """Registers the callback at exit. Calling it multiple times is no-op.""" 137 """Registers the callback at exit. Calling it multiple times is no-op."""
129 global _REGISTERED 138 global _REGISTERED
130 if _REGISTERED: 139 if _REGISTERED:
131 return 140 return
132 _REGISTERED = True 141 _REGISTERED = True
133 atexit.register(CheckForException) 142 atexit.register(CheckForException)
134 143
135 144
136 # Skip unit tests and we don't want anything from non-googler. 145 if IS_ENABLED:
137 if (not 'test' in getattr(sys.modules['__main__'], '__file__', '') and
138 not 'NO_BREAKPAD' in os.environ and
139 (_HOST_NAME.endswith('.google.com') or
140 _HOST_NAME.endswith('.chromium.org'))):
141 Register() 146 Register()
142 147
143 # Uncomment this line if you want to test it out. 148 # Uncomment this line if you want to test it out.
144 #Register() 149 #Register()
OLDNEW
« no previous file with comments | « no previous file | tests/breakpad_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698