| Index: PRESUBMIT.py
|
| diff --git a/PRESUBMIT.py b/PRESUBMIT.py
|
| index 8ec7f5323e1e58ee875963b91ec25c82353f54c5..b3b2606c28788857f555f113cf0c725f341cd55d 100644
|
| --- a/PRESUBMIT.py
|
| +++ b/PRESUBMIT.py
|
| @@ -1282,6 +1282,55 @@ def _CheckNoDeprecatedJS(input_api, output_api):
|
| return results
|
|
|
|
|
| +def _CheckForWeakPtrOrder(input_api, output_api):
|
| + """Check for weakptrfactory order in .h files using ChangedContents."""
|
| + problems = []
|
| + warnings = []
|
| + for f in input_api.AffectedFiles():
|
| + if not f.LocalPath().endswith(('.cc', '.cpp', '.h', '.mm')):
|
| + continue
|
| + contents = f.NewContents()
|
| + weak_ptr_flag = False
|
| + change_line_num = 0
|
| + for line_num, line in f.ChangedContents():
|
| + change_line_num = line_num
|
| + break
|
| + curr_line = 0
|
| + change_flag = False
|
| + for line in contents:
|
| + curr_line += 1
|
| + if (curr_line != change_line_num) and (change_flag != True):
|
| + continue
|
| + else:
|
| + change_flag = True
|
| + if 'base::WeakPtrFactory' in line:
|
| + weak_ptr_flag = True
|
| + continue
|
| + if weak_ptr_flag == True:
|
| + #Checking for commented line
|
| + strip_line = line.strip()
|
| + if strip_line.startswith('//'):
|
| + continue
|
| + #Check for emptyline for skipping
|
| + if (len(line.strip()) == 0):
|
| + continue
|
| + #Check for valid attributes after the WeakPtrFactory pointer
|
| + if input_api.re.search(r'(};|\bDISALLOW_COPY_AND_ASSIGN\b)', line):
|
| + break
|
| + else:
|
| + weak_ptr_flag = False
|
| + problems.append(' %s:%d' % (f.LocalPath(), line_num))
|
| + break
|
| +
|
| + if not problems:
|
| + return []
|
| + return [output_api.PresubmitError(
|
| + 'Member variables should appear before the WeakPtrFactory, to ensure '
|
| + 'that any WeakPtrs to Controller are \ninvalidated before its members '
|
| + 'variable\'s destructors are executed, rendering them invalid.',
|
| + problems)]
|
| +
|
| +
|
| def _CommonChecks(input_api, output_api):
|
| """Checks common to both upload and commit."""
|
| results = []
|
| @@ -1325,6 +1374,7 @@ def _CommonChecks(input_api, output_api):
|
| results.extend(_CheckParseErrors(input_api, output_api))
|
| results.extend(_CheckForIPCRules(input_api, output_api))
|
|
|
| + results.extend(_CheckForWeakPtrOrder(input_api, output_api))
|
| if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
|
| results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
|
| input_api, output_api,
|
|
|