Browse Source

Make sure that direct call to SendStack() doesn't send a stack trace for non googler

I don't want to receive them even in the case of a direct call to SendStack().

R=dpranke@chromium.org
BUG=
TEST=


Review URL: http://codereview.chromium.org/9145001

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@117039 0039d316-1c4b-4281-b951-d872f2087c98
maruel@chromium.org 13 năm trước cách đây
mục cha
commit
18878421ec
2 tập tin đã thay đổi với 17 bổ sung9 xóa
  1. 11 6
      breakpad.py
  2. 6 3
      tests/breakpad_unittest.py

+ 11 - 6
breakpad.py

@@ -1,4 +1,4 @@
-# Copyright (c) 2011 The Chromium Authors. All rights reserved.
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 # found in the LICENSE file.
 
 
@@ -33,6 +33,12 @@ _TIME_STARTED = time.time()
 
 
 _HOST_NAME = socket.getfqdn()
 _HOST_NAME = socket.getfqdn()
 
 
+# Skip unit tests and we don't want anything from non-googler.
+IS_ENABLED = (
+    not 'test' in getattr(sys.modules['__main__'], '__file__', '') and
+    not 'NO_BREAKPAD' in os.environ and
+    _HOST_NAME.endswith(('.google.com', '.chromium.org')))
+
 
 
 def post(url, params):
 def post(url, params):
   """HTTP POST with timeout when it's supported."""
   """HTTP POST with timeout when it's supported."""
@@ -75,6 +81,9 @@ def FormatException(e):
 
 
 def SendStack(last_tb, stack, url=None, maxlen=50):
 def SendStack(last_tb, stack, url=None, maxlen=50):
   """Sends the stack trace to the breakpad server."""
   """Sends the stack trace to the breakpad server."""
+  if not IS_ENABLED:
+    # Make sure to not send anything for non googler.
+    return
   if not url:
   if not url:
     url = DEFAULT_URL + '/breakpad'
     url = DEFAULT_URL + '/breakpad'
   print 'Sending crash report ...'
   print 'Sending crash report ...'
@@ -133,11 +142,7 @@ def Register():
   atexit.register(CheckForException)
   atexit.register(CheckForException)
 
 
 
 
-# Skip unit tests and we don't want anything from non-googler.
-if (not 'test' in getattr(sys.modules['__main__'], '__file__', '') and
-    not 'NO_BREAKPAD' in os.environ and
-    (_HOST_NAME.endswith('.google.com') or
-     _HOST_NAME.endswith('.chromium.org'))):
+if IS_ENABLED:
   Register()
   Register()
 
 
 # Uncomment this line if you want to test it out.
 # Uncomment this line if you want to test it out.

+ 6 - 3
tests/breakpad_unittest.py

@@ -1,5 +1,5 @@
 #!/usr/bin/env python
 #!/usr/bin/env python
-# Copyright (c) 2011 The Chromium Authors. All rights reserved.
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 # found in the LICENSE file.
 
 
@@ -23,20 +23,23 @@ class Breakpad(SuperMoxTestBase):
     self.mox.StubOutWithMock(breakpad.getpass, 'getuser')
     self.mox.StubOutWithMock(breakpad.getpass, 'getuser')
     self.mox.StubOutWithMock(breakpad.urllib2, 'urlopen')
     self.mox.StubOutWithMock(breakpad.urllib2, 'urlopen')
     breakpad._HOST_NAME = 'bozo'
     breakpad._HOST_NAME = 'bozo'
+    self.assertEquals(False, breakpad.IS_ENABLED)
+    breakpad.IS_ENABLED = True
     self._old_sys_argv = breakpad.sys.argv
     self._old_sys_argv = breakpad.sys.argv
     breakpad.sys.argv = ['my_test']
     breakpad.sys.argv = ['my_test']
     self._old_sys_version = breakpad.sys.version
     self._old_sys_version = breakpad.sys.version
     breakpad.sys.version = 'random python'
     breakpad.sys.version = 'random python'
 
 
   def tearDown(self):
   def tearDown(self):
+    breakpad.IS_ENABLED = False
     breakpad.sys.version = self._old_sys_version
     breakpad.sys.version = self._old_sys_version
     breakpad.sys.argv = self._old_sys_argv
     breakpad.sys.argv = self._old_sys_argv
     super(Breakpad, self).tearDown()
     super(Breakpad, self).tearDown()
 
 
   def testMembersChanged(self):
   def testMembersChanged(self):
     members = [
     members = [
-        'CheckForException', 'DEFAULT_URL', 'FormatException', 'Register',
-        'SendProfiling', 'SendStack',
+        'CheckForException', 'DEFAULT_URL', 'FormatException', 'IS_ENABLED',
+        'Register', 'SendProfiling', 'SendStack',
         'atexit', 'getpass', 'os', 'post', 'socket', 'sys', 'time', 'traceback',
         'atexit', 'getpass', 'os', 'post', 'socket', 'sys', 'time', 'traceback',
         'urllib', 'urllib2',
         'urllib', 'urllib2',
     ]
     ]