| Index: tools/metrics/actions/extract_actions.py
|
| diff --git a/tools/metrics/actions/extract_actions.py b/tools/metrics/actions/extract_actions.py
|
| index efb23b7402295fbe793973f7de33d3eee343b746..042775e1b8d9dd538d5e309de9e0fdc99cd716fa 100755
|
| --- a/tools/metrics/actions/extract_actions.py
|
| +++ b/tools/metrics/actions/extract_actions.py
|
| @@ -57,8 +57,26 @@ USER_METRICS_ACTION_RE = re.compile(r"""
|
| """,
|
| re.VERBOSE | re.DOTALL # Verbose syntax and makes . also match new lines.
|
| )
|
| +USER_METRICS_ACTION_RE_JS = re.compile(r"""
|
| + chrome\.send # Start of function call.
|
| + \( # Opening parenthesis.
|
| + \s* # Any amount of whitespace, including new lines.
|
| + # WebUI message handled by CoreOptionsHandler.
|
| + 'coreOptionsUserMetricsAction'
|
| + , # Separator after first parameter.
|
| + \s* # Any amount of whitespace, including new lines.
|
| + \[ # Opening bracket for arguments for C++ function.
|
| + \s* # Any amount of whitespace, including new lines.
|
| + (.+?) # A sequence of characters for the param.
|
| + \s* # Any amount of whitespace, including new lines.
|
| + \] # Closing bracket.
|
| + \s* # Any amount of whitespace, including new lines.
|
| + \) # Closing parenthesis.
|
| + """,
|
| + re.VERBOSE | re.DOTALL # Verbose syntax and makes . also match new lines.
|
| +)
|
| COMPUTED_ACTION_RE = re.compile(r'RecordComputedAction')
|
| -QUOTED_STRING_RE = re.compile(r'\"(.+?)\"')
|
| +QUOTED_STRING_RE = re.compile(r"""('[^']+'|"[^"]+")$""")
|
|
|
| # Files that are known to use content::RecordComputedAction(), which means
|
| # they require special handling code in this script.
|
| @@ -318,10 +336,11 @@ class InvalidStatementException(Exception):
|
| class ActionNameFinder:
|
| """Helper class to find action names in source code file."""
|
|
|
| - def __init__(self, path, contents):
|
| + def __init__(self, path, contents, action_re):
|
| self.__path = path
|
| self.__pos = 0
|
| self.__contents = contents
|
| + self.__action_re = action_re
|
|
|
| def FindNextAction(self):
|
| """Finds the next action name in the file.
|
| @@ -333,15 +352,20 @@ class ActionNameFinder:
|
| and could not be parsed. There may still be more actions in the file,
|
| so FindNextAction() can continue to be called to find following ones.
|
| """
|
| - match = USER_METRICS_ACTION_RE.search(self.__contents, pos=self.__pos)
|
| + match = self.__action_re.search(self.__contents, pos=self.__pos)
|
| if not match:
|
| return None
|
| match_start = match.start()
|
| self.__pos = match.end()
|
| +
|
| match = QUOTED_STRING_RE.match(match.group(1))
|
| if not match:
|
| + if self.__action_re == USER_METRICS_ACTION_RE_JS:
|
| + return None
|
| self._RaiseException(match_start, self.__pos)
|
| - return match.group(1)
|
| +
|
| + # Remove surrounding quotation marks.
|
| + return match.group(1)[1:-1]
|
|
|
| def _RaiseException(self, match_start, match_end):
|
| """Raises an InvalidStatementException for the specified code range."""
|
| @@ -363,7 +387,14 @@ def GrepForActions(path, actions):
|
| global number_of_files_total
|
| number_of_files_total = number_of_files_total + 1
|
|
|
| - finder = ActionNameFinder(path, open(path).read())
|
| + # Check the extension, using the regular expression for C++ syntax by default.
|
| + ext = os.path.splitext(path)[1].lower()
|
| + if ext == '.js':
|
| + action_re = USER_METRICS_ACTION_RE_JS
|
| + else:
|
| + action_re = USER_METRICS_ACTION_RE
|
| +
|
| + finder = ActionNameFinder(path, open(path).read(), action_re)
|
| while True:
|
| try:
|
| action_name = finder.FindNextAction()
|
| @@ -373,6 +404,9 @@ def GrepForActions(path, actions):
|
| except InvalidStatementException, e:
|
| logging.warning(str(e))
|
|
|
| + if action_re != USER_METRICS_ACTION_RE:
|
| + return
|
| +
|
| line_number = 0
|
| for line in open(path):
|
| line_number = line_number + 1
|
| @@ -487,6 +521,7 @@ def AddWebUIActions(actions):
|
| resources_root = os.path.join(REPOSITORY_ROOT, 'chrome', 'browser',
|
| 'resources')
|
| WalkDirectory(resources_root, actions, ('.html'), GrepForWebUIActions)
|
| + WalkDirectory(resources_root, actions, ('.js'), GrepForActions)
|
|
|
| def AddHistoryPageActions(actions):
|
| """Add actions that are used in History page.
|
|
|