OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import logging |
5 import sys | 6 import sys |
6 | 7 |
7 from metrics import Metric | 8 from metrics import Metric |
| 9 from telemetry.util.mac import keychain_helper |
8 from telemetry.value import histogram_util | 10 from telemetry.value import histogram_util |
9 from telemetry.value import scalar | 11 from telemetry.value import scalar |
10 | 12 |
11 | 13 |
12 class KeychainMetric(Metric): | 14 class KeychainMetric(Metric): |
13 """KeychainMetric gathers keychain statistics from the browser object. | 15 """KeychainMetric gathers keychain statistics from the browser object. |
14 | 16 |
15 This includes the number of times that the keychain was accessed. | 17 This includes the number of times that the keychain was accessed. |
16 """ | 18 """ |
17 | 19 |
18 DISPLAY_NAME = 'OSX_Keychain_Access' | 20 DISPLAY_NAME = 'OSX_Keychain_Access' |
19 HISTOGRAM_NAME = 'OSX.Keychain.Access' | 21 HISTOGRAM_NAME = 'OSX.Keychain.Access' |
20 | 22 |
| 23 @staticmethod |
| 24 def _CheckKeychainConfiguration(): |
| 25 """ |
| 26 On OSX, it is possible for a misconfigured keychain to cause the |
| 27 Telemetry tests to stall. This method confirms that the keychain is in a |
| 28 sane state that will not cause this behavior. Three conditions are checked: |
| 29 - The keychain is unlocked. |
| 30 - The keychain will not auto-lock after a period of time. |
| 31 - The ACLs are correctly configured on the relevant keychain items. |
| 32 """ |
| 33 warning_suffix = ('which will cause some Telemetry tests to stall when run' |
| 34 ' on a headless machine (e.g. perf bot).') |
| 35 if keychain_helper.IsKeychainLocked(): |
| 36 logging.warning('The default keychain is locked, %s', warning_suffix) |
| 37 |
| 38 if keychain_helper.DoesKeychainHaveTimeout(): |
| 39 logging.warning('The default keychain is configured to automatically' |
| 40 ' lock itself have a period of time, %s', warning_suffix) |
| 41 |
| 42 chrome_acl_configured = (keychain_helper. |
| 43 IsKeychainConfiguredForBotsWithChrome()) |
| 44 chromium_acl_configured = (keychain_helper. |
| 45 IsKeychainConfiguredForBotsWithChromium()) |
| 46 acl_warning = ('A commonly used %s key stored in the default keychain does' |
| 47 ' not give decryption access to all applications, %s') |
| 48 if not chrome_acl_configured: |
| 49 logging.warning(acl_warning, 'Chrome', warning_suffix) |
| 50 if not chromium_acl_configured: |
| 51 logging.warning(acl_warning, 'Chromium', warning_suffix) |
| 52 |
21 @classmethod | 53 @classmethod |
22 def CustomizeBrowserOptions(cls, options): | 54 def CustomizeBrowserOptions(cls, options): |
23 """Adds a browser argument that allows for the collection of keychain | 55 """Adds a browser argument that allows for the collection of keychain |
24 metrics. Has no effect on non-Mac platforms.""" | 56 metrics. Has no effect on non-Mac platforms.""" |
25 if sys.platform != 'darwin': | 57 if sys.platform != 'darwin': |
26 return | 58 return |
27 | 59 |
| 60 KeychainMetric._CheckKeychainConfiguration() |
| 61 |
28 options.AppendExtraBrowserArgs(['--enable-stats-collection-bindings']) | 62 options.AppendExtraBrowserArgs(['--enable-stats-collection-bindings']) |
29 | 63 |
30 def AddResults(self, tab, results): | 64 def AddResults(self, tab, results): |
31 """Adds the number of times that the keychain was accessed to |results|. | 65 """Adds the number of times that the keychain was accessed to |results|. |
32 Has no effect on non-Mac platforms.""" | 66 Has no effect on non-Mac platforms.""" |
33 if sys.platform != 'darwin': | 67 if sys.platform != 'darwin': |
34 return | 68 return |
35 | 69 |
36 access_count = histogram_util.GetHistogramSum( | 70 access_count = histogram_util.GetHistogramSum( |
37 histogram_util.BROWSER_HISTOGRAM, KeychainMetric.HISTOGRAM_NAME, tab) | 71 histogram_util.BROWSER_HISTOGRAM, KeychainMetric.HISTOGRAM_NAME, tab) |
38 results.AddValue(scalar.ScalarValue( | 72 results.AddValue(scalar.ScalarValue( |
39 results.current_page, KeychainMetric.DISPLAY_NAME, 'count', | 73 results.current_page, KeychainMetric.DISPLAY_NAME, 'count', |
40 access_count)) | 74 access_count)) |
OLD | NEW |