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

Unified Diff: PRESUBMIT.py

Issue 1276523003: Don't trigger HW acceleration from Toasts on low-end devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Enhance PRESUBMIT message Created 5 years, 4 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 | chrome/android/java/src/org/chromium/chrome/browser/ChromeTabbedActivity.java » ('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 520642ea664fab16705f539995d8eebc408076bb..cd183fcd9182db21a8d759576eef69410dccc5c3 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -1312,6 +1312,40 @@ def _CheckJavaStyle(input_api, output_api):
black_list=_EXCLUDED_PATHS + input_api.DEFAULT_BLACK_LIST)
+def _CheckAndroidToastUsage(input_api, output_api):
+ """Checks that Chromium code uses org.chromium.ui.widget.Toast
+ instead of android.widget.Toast (Chromium Toast doesn't force hardware
+ acceleration on low-end devices, saving memory).
+ """
+ toast_import_pattern = input_api.re.compile(
+ r'^import android\.widget\.Toast;$')
+
+ import_errors = []
+
+ sources = lambda x: input_api.FilterSourceFile(x, white_list=(r'.*\.java$',))
+ for f in input_api.AffectedSourceFiles(sources):
+ for line_num, line in f.ChangedContents():
+ if toast_import_pattern.search(line):
+ import_errors.append("%s:%d" % (f.LocalPath(), line_num))
+
+ results = []
+ if import_errors:
+ results.append(output_api.PresubmitPromptWarning(
+ '"android.widget.Toast" usage is detected. Android toasts use hardware'
Dmitry Skiba 2015/08/11 23:49:50 Example output: ** Presubmit Warnings ** "android
+ ' acceleration, and can be\ncostly on low-end devices. If your code'
+ ' triggers toasts on low-end devices (especially during\nnormal'
+ ' browsing workflow), you should use "org.chromium.ui.widget.Toast"'
+ ' instead.\n'
+ "You don't need to bother if toast is shown only from an activity that"
+ ' is hardware accelerated\n(e.g. Preferences) or the one that is not'
+ ' visible to the end user (e.g. ChromeShellActivity).\n'
+ 'In any case, feel free to contact dskiba@chromium.org if you have any'
+ ' questions or concerns.',
+ import_errors))
+
+ return results
+
+
def _CheckAndroidCrLogUsage(input_api, output_api):
"""Checks that new logs using org.chromium.base.Log:
- Are using 'TAG' as variable name for the tags (warn)
@@ -1530,6 +1564,7 @@ def _AndroidSpecificOnUploadChecks(input_api, output_api):
"""Groups checks that target android code."""
results = []
results.extend(_CheckAndroidCrLogUsage(input_api, output_api))
+ results.extend(_CheckAndroidToastUsage(input_api, output_api))
return results
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/ChromeTabbedActivity.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698