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

Unified Diff: PRESUBMIT.py

Issue 669853003: Adding presubmit check for WeakPtrFactory in the code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed indentation issues Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | PRESUBMIT_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: PRESUBMIT.py
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 444f5bb7212946a52549e20d2aa00093f78686b9..3cdce9e7db9ae696581cd857f1716fbc5f7ffbee 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -1274,6 +1274,55 @@ def _CheckForOverrideAndFinalRules(input_api, output_api):
problems)]
+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'))):
M-A Ruel 2014/10/22 18:02:40 if not f.LocalPath().endswith(('.cc', '.cpp', '.h'
MRV 2014/10/23 03:06:31 Done.
+ 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 = []
@@ -1316,7 +1365,7 @@ def _CommonChecks(input_api, output_api):
results.extend(_CheckParseErrors(input_api, output_api))
results.extend(_CheckForIPCRules(input_api, output_api))
results.extend(_CheckForOverrideAndFinalRules(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,
« no previous file with comments | « no previous file | PRESUBMIT_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698