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

Side by Side 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: Created 5 years, 2 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Top-level presubmit script for Chromium media component. 5 """Top-level presubmit script for Chromium media component.
6 6
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into depot_tools. 8 for more details about the presubmit API built into depot_tools.
9 """ 9 """
10 10
11 import re
12 import string
13
14 # Well-defined simple classes containing only <= 4 ints, or <= 2 floats.
15 BASE_TIME_TYPES = [
16 'base::Time',
17 'base::TimeDelta',
18 'base::TimeTicks',
19 ]
20
21 PASS_BY_VALUE_RE = re.compile(r'\bconst (%s)&' %
sandersd (OOO until July 31) 2015/10/20 21:01:03 This should be BASE_TIME_TYPES_RE to match.
mcasas 2016/04/01 21:34:39 Done.
22 string.join(BASE_TIME_TYPES, '|'))
23
11 def _FilterFile(affected_file): 24 def _FilterFile(affected_file):
12 """Return true if the file could contain code requiring a presubmit check.""" 25 """Return true if the file could contain code requiring a presubmit check."""
13 return affected_file.LocalPath().endswith( 26 return affected_file.LocalPath().endswith(
14 ('.h', '.cc', '.cpp', '.cxx', '.mm')) 27 ('.h', '.cc', '.cpp', '.cxx', '.mm'))
15 28
16 29
17 def _CheckForUseOfWrongClock(input_api, output_api): 30 def _CheckForUseOfWrongClock(input_api, output_api):
18 """Make sure new lines of media code don't use a clock susceptible to skew.""" 31 """Make sure new lines of media code don't use a clock susceptible to skew."""
19 32
20 # Regular expression that should detect any explicit references to the 33 # Regular expression that should detect any explicit references to the
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 'UMA_HISTOGRAM_ENUMERATION reports in src/media/ are expected to adhere\n' 165 'UMA_HISTOGRAM_ENUMERATION reports in src/media/ are expected to adhere\n'
153 'to the following guidelines:\n' 166 'to the following guidelines:\n'
154 ' - The max value (3rd argument) should be an enum value equal to the\n' 167 ' - The max value (3rd argument) should be an enum value equal to the\n'
155 ' last valid value, e.g. FOO_MAX = LAST_VALID_FOO.\n' 168 ' last valid value, e.g. FOO_MAX = LAST_VALID_FOO.\n'
156 ' - 1 must be added to that max value.\n' 169 ' - 1 must be added to that max value.\n'
157 'Contact rileya@chromium.org if you have questions.' , problems)] 170 'Contact rileya@chromium.org if you have questions.' , problems)]
158 171
159 return [] 172 return []
160 173
161 174
175 def _CheckPassByValue(input_api, output_api):
176 """Check that base::Time and derived classes are passed by value, and not by
177 const reference """
178
179 problems = []
180
181 for f in input_api.AffectedSourceFiles(_FilterFile):
182 for line_number, line in f.ChangedContents():
183 if PASS_BY_VALUE_RE.search(line):
184 problems.append('%s:%d' % (f, line_number))
185
186 if problems:
187 return [output_api.PresubmitError(
188 'base::Time and derived classes should be passed by value and not by\n'
189 'const ref, see base/time/time.h for more information.', problems)]
190 return []
191
192
162 def _CheckChange(input_api, output_api): 193 def _CheckChange(input_api, output_api):
163 results = [] 194 results = []
164 results.extend(_CheckForUseOfWrongClock(input_api, output_api)) 195 results.extend(_CheckForUseOfWrongClock(input_api, output_api))
165 results.extend(_CheckForMessageLoopProxy(input_api, output_api)) 196 results.extend(_CheckForMessageLoopProxy(input_api, output_api))
197 results.extend(_CheckPassByValue(input_api, output_api))
166 results.extend(_CheckForHistogramOffByOne(input_api, output_api)) 198 results.extend(_CheckForHistogramOffByOne(input_api, output_api))
167 return results 199 return results
168 200
169 201
170 def CheckChangeOnUpload(input_api, output_api): 202 def CheckChangeOnUpload(input_api, output_api):
171 return _CheckChange(input_api, output_api) 203 return _CheckChange(input_api, output_api)
172 204
173 205
174 def CheckChangeOnCommit(input_api, output_api): 206 def CheckChangeOnCommit(input_api, output_api):
175 return _CheckChange(input_api, output_api) 207 return _CheckChange(input_api, output_api)
OLDNEW
« 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