Skip to content

Commit

Permalink
Add a presubmit to find new uses of the old callback system.
Browse files Browse the repository at this point in the history
BUG=none
TEST=edit files locally, add random references to the old callback system, and run presubmit.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111729 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
dcheng@chromium.org committed Nov 28, 2011
1 parent 0633e31 commit ecdf8ea
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,36 @@ def _CheckNoFRIEND_TEST(input_api, output_api):
'FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))]


def _CheckNoNewOldCallback(input_api, output_api):
"""Checks to make sure we don't introduce new uses of old callbacks."""

def HasOldCallbackKeywords(line):
"""Returns True if a line of text contains keywords that indicate the use
of the old callback system.
"""
return ('NewRunnableMethod' in line or
'NewRunnableFunction' in line or
'NewCallback' in line or
input_api.re.search(r'\bCallback\d<', line) or
input_api.re.search(r'\bpublic Task\b', line) or
'public CancelableTask' in line)

problems = []
file_filter = lambda f: f.LocalPath().endswith(('.cc', '.h'))
for f in input_api.AffectedFiles(file_filter=file_filter):
if not any(HasOldCallbackKeywords(line) for line in f.NewContents()):
continue
for line_num, line in f.ChangedContents():
if HasOldCallbackKeywords(line):
problems.append(' %s:%d' % (f.LocalPath(), line_num))

if not problems:
return []
return [output_api.PresubmitPromptWarning('The old callback system is '
'deprecated. If possible, use base::Bind and base::Callback instead.\n' +
'\n'.join(problems))]


def _CommonChecks(input_api, output_api):
"""Checks common to both upload and commit."""
results = []
Expand All @@ -191,6 +221,7 @@ def _CommonChecks(input_api, output_api):
results.extend(_CheckNoNewWStrings(input_api, output_api))
results.extend(_CheckNoDEPSGIT(input_api, output_api))
results.extend(_CheckNoFRIEND_TEST(input_api, output_api))
results.extend(_CheckNoNewOldCallback(input_api, output_api))
return results


Expand Down

0 comments on commit ecdf8ea

Please sign in to comment.