Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Unified Diff: media/PRESUBMIT.py

Issue 1407093002: media/PRESUBMIT.py: adding CheckPassByValue for base::Time and derived classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: PASS_BY_VALUE_RE--> BASE_TIME_TYPES_RE Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/PRESUBMIT.py
diff --git a/media/PRESUBMIT.py b/media/PRESUBMIT.py
index d87000bcc96d997f3ac684c54923c342e5446d21..02bd02bf01b13a3588e909b9ac1ea54eb4b71d68 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.
+BASE_TIME_TYPES = [
+ 'base::Time',
+ 'base::TimeDelta',
+ 'base::TimeTicks',
+]
+
+BASE_TIME_TYPES_RE = re.compile(r'\bconst (%s)&' %
+ string.join(BASE_TIME_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 BASE_TIME_TYPES_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))
results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api)
return results
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698