Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import json | |
| 6 import sys | |
| 7 | |
| 8 from metrics import Metric | |
| 9 from telemetry.page import page_test | |
| 10 from telemetry.value import scalar | |
| 11 | |
| 12 | |
| 13 class KeychainMetric(Metric): | |
| 14 """KeychainMetric gathers keychain statistics from the browser object. | |
| 15 | |
| 16 This includes the number of times that the keychain was accessed. | |
| 17 """ | |
| 18 | |
| 19 DISPLAY_NAME = 'OSX_Keychain_Access' | |
| 20 HISTOGRAM_NAME = 'OSX.Keychain.Access' | |
| 21 MAX_KEYCHAIN_ACCESS_COUNT = 10 | |
| 22 | |
| 23 @classmethod | |
| 24 def CustomizeBrowserOptions(cls, options): | |
| 25 """Adds a browser argument that allows for the collection of keychain | |
| 26 metrics.""" | |
| 27 options.AppendExtraBrowserArgs(['--enable-stats-collection-bindings']) | |
| 28 | |
| 29 @staticmethod | |
| 30 def GetKeychainAccessCount(tab): | |
|
dtu
2014/12/05 01:12:54
telemetry.value.histogram_util.GetHistogramSum
erikchen
2014/12/08 23:41:25
Done.
| |
| 31 """Retrieves the number of times that the keychain was accessed since the | |
| 32 browser was started.""" | |
| 33 get_histogram_js = 'statsCollectionController.getBrowserHistogram("%s")' | |
| 34 | |
| 35 result = tab.EvaluateJavaScript(get_histogram_js % | |
| 36 KeychainMetric.HISTOGRAM_NAME) | |
| 37 result = json.loads(result) | |
| 38 | |
| 39 access_count = 0 | |
| 40 if result: | |
| 41 access_count = result['sum'] | |
| 42 return access_count | |
| 43 | |
| 44 def AddResults(self, tab, results): | |
| 45 """Adds the number of times that the keychain was accessed to |results|.""" | |
| 46 access_count = KeychainMetric.GetKeychainAccessCount(tab) | |
| 47 results.AddValue(scalar.ScalarValue( | |
| 48 results.current_page, KeychainMetric.DISPLAY_NAME, 'count', | |
| 49 access_count)) | |
| 50 if access_count > KeychainMetric.MAX_KEYCHAIN_ACCESS_COUNT: | |
|
tonyg
2014/12/05 03:12:03
Correct me if I'm mistaken, but didn't we land on
erikchen
2014/12/08 23:41:25
Yup, removed this line.
| |
| 51 raise page_test.Failure('Keychain accessed too many times ({0}).'. | |
| 52 format(KeychainMetric.MAX_KEYCHAIN_ACCESS_COUNT)) | |
| 53 | |
| 54 @staticmethod | |
| 55 def ShouldCollectKeychainMetrics(): | |
|
dtu
2014/12/05 01:12:54
Since all callers are going to check ShouldCollect
erikchen
2014/12/08 23:41:25
Hm. You're right.
I moved the logic into this fil
dtu
2014/12/09 00:25:03
Makes sense.
| |
| 56 """Whether Chrome collects Keychain metrics on the OS.""" | |
| 57 return sys.platform == 'darwin' | |
| OLD | NEW |