Chromium Code Reviews| Index: media/PRESUBMIT.py |
| diff --git a/media/PRESUBMIT.py b/media/PRESUBMIT.py |
| index feba2f719a5c6fe3c35fdb514af8fb5ef61cbbd4..2774b11bcc6a44488f66c8a6e1c8287784761036 100644 |
| --- a/media/PRESUBMIT.py |
| +++ b/media/PRESUBMIT.py |
| @@ -8,6 +8,19 @@ See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| for more details about the presubmit API built into depot_tools. |
| """ |
| +import re |
| +import string |
| + |
| +# Well-defined simple classes containing only <= 4 ints, or <= 2 floats. |
| +PASS_BY_VALUE_TYPES = [ |
|
sandersd (OOO until July 31)
2015/10/20 00:29:08
Based on the message I'd rename this as BASE_TIME_
mcasas
2015/10/20 00:32:21
Done.
|
| + 'base::Time', |
| + 'base::TimeDelta', |
| + 'base::TimeTicks', |
| +] |
| + |
| +PASS_BY_VALUE_RE = re.compile(r'\bconst +' + '(%s)&' % |
|
sandersd (OOO until July 31)
2015/10/20 00:29:08
Something's gone wrong here, should be:
re.compil
mcasas
2015/10/20 00:32:21
Done.
|
| + string.join(PASS_BY_VALUE_TYPES, '|')) |
| + |
| def _FilterFile(affected_file): |
| """Return true if the file could contain code requiring a presubmit check.""" |
| return affected_file.LocalPath().endswith( |
| @@ -159,10 +172,29 @@ def _CheckForHistogramOffByOne(input_api, output_api): |
| return [] |
| +def _CheckPassByValue(input_api, output_api): |
| + """Check that base::Time and derived classes are passed by value, and not by |
| + const reference """ |
| + |
| + problems = [] |
| + |
| + for f in input_api.AffectedSourceFiles(_FilterFile): |
| + for line_number, line in f.ChangedContents(): |
| + if PASS_BY_VALUE_RE.search(line): |
| + problems.append('%s:%d' % (f, line_number)) |
| + |
| + if problems: |
| + return [output_api.PresubmitError( |
| + 'base::Time and derived classes should be passed by value and not by\n' |
| + 'const ref, see base/time/time.h for more information.', problems)] |
| + return [] |
| + |
| + |
| def _CheckChange(input_api, output_api): |
| results = [] |
| results.extend(_CheckForUseOfWrongClock(input_api, output_api)) |
| results.extend(_CheckForMessageLoopProxy(input_api, output_api)) |
| + results.extend(_CheckPassByValue(input_api, output_api)) |
| results.extend(_CheckForHistogramOffByOne(input_api, output_api)) |
| return results |