forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PRESUBMIT.py
6935 lines (6183 loc) · 268 KB
/
PRESUBMIT.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2012 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Top-level presubmit script for Chromium.
See https://www.chromium.org/developers/how-tos/depottools/presubmit-scripts/
for more details about the presubmit API built into depot_tools.
"""
from typing import Callable
from typing import Optional
from typing import Sequence
from dataclasses import dataclass
PRESUBMIT_VERSION = '2.0.0'
# This line is 'magic' in that git-cl looks for it to decide whether to
# use Python3 instead of Python2 when running the code in this file.
USE_PYTHON3 = True
_EXCLUDED_PATHS = (
# Generated file
(r"chrome/android/webapk/shell_apk/src/org/chromium"
r"/webapk/lib/runtime_library/IWebApkApi.java"),
# File needs to write to stdout to emulate a tool it's replacing.
r"chrome/updater/mac/keystone/ksadmin.mm",
# Generated file.
(r"^components/variations/proto/devtools/"
r"client_variations.js"),
# These are video files, not typescript.
r"^media/test/data/.*.ts",
r"^native_client_sdksrc/build_tools/make_rules.py",
r"^native_client_sdk/src/build_tools/make_simple.py",
r"^native_client_sdk/src/tools/.*.mk",
r"^net/tools/spdyshark/.*",
r"^skia/.*",
r"^third_party/blink/.*",
r"^third_party/breakpad/.*",
# sqlite is an imported third party dependency.
r"^third_party/sqlite/.*",
r"^v8/.*",
r".*MakeFile$",
r".+_autogen\.h$",
r".+_pb2(_grpc)?\.py$",
r".+/pnacl_shim\.c$",
r"^gpu/config/.*_list_json\.cc$",
r"tools/md_browser/.*\.css$",
# Test pages for Maps telemetry tests.
r"tools/perf/page_sets/maps_perf_test.*",
# Test pages for WebRTC telemetry tests.
r"tools/perf/page_sets/webrtc_cases.*",
# Test file compared with generated output.
r"tools/polymer/tests/html_to_wrapper/.*.html.ts$",
)
_EXCLUDED_SET_NO_PARENT_PATHS = (
# It's for historical reasons that blink isn't a top level directory, where
# it would be allowed to have "set noparent" to avoid top level owners
# accidentally +1ing changes.
'third_party/blink/OWNERS',
)
# Fragment of a regular expression that matches C++ and Objective-C++
# implementation files.
_IMPLEMENTATION_EXTENSIONS = r'\.(cc|cpp|cxx|mm)$'
# Fragment of a regular expression that matches C++ and Objective-C++
# header files.
_HEADER_EXTENSIONS = r'\.(h|hpp|hxx)$'
# Paths with sources that don't use //base.
_NON_BASE_DEPENDENT_PATHS = (
r"^chrome/browser/browser_switcher/bho/",
r"^tools/win/",
)
# Regular expression that matches code only used for test binaries
# (best effort).
_TEST_CODE_EXCLUDED_PATHS = (
r'.*/(fake_|test_|mock_).+%s' % _IMPLEMENTATION_EXTENSIONS,
r'.+_test_(base|support|util)%s' % _IMPLEMENTATION_EXTENSIONS,
# Test suite files, like:
# foo_browsertest.cc
# bar_unittest_mac.cc (suffix)
# baz_unittests.cc (plural)
r'.+_(api|browser|eg|int|perf|pixel|unit|ui)?test(s)?(_[a-z]+)?%s' %
_IMPLEMENTATION_EXTENSIONS,
r'.+_(fuzz|fuzzer)(_[a-z]+)?%s' % _IMPLEMENTATION_EXTENSIONS,
r'.+sync_service_impl_harness%s' % _IMPLEMENTATION_EXTENSIONS,
r'.*/(test|tool(s)?)/.*',
# content_shell is used for running content_browsertests.
r'content/shell/.*',
# Web test harness.
r'content/web_test/.*',
# Non-production example code.
r'mojo/examples/.*',
# Launcher for running iOS tests on the simulator.
r'testing/iossim/iossim\.mm$',
# EarlGrey app side code for tests.
r'ios/.*_app_interface\.mm$',
# Views Examples code
r'ui/views/examples/.*',
# Chromium Codelab
r'codelabs/*'
)
_THIRD_PARTY_EXCEPT_BLINK = 'third_party/(?!blink/)'
_TEST_ONLY_WARNING = (
'You might be calling functions intended only for testing from\n'
'production code. If you are doing this from inside another method\n'
'named as *ForTesting(), then consider exposing things to have tests\n'
'make that same call directly.\n'
'If that is not possible, you may put a comment on the same line with\n'
' // IN-TEST \n'
'to tell the PRESUBMIT script that the code is inside a *ForTesting()\n'
'method and can be ignored. Do not do this inside production code.\n'
'The android-binary-size trybot will block if the method exists in the\n'
'release apk.')
@dataclass
class BanRule:
# String pattern. If the pattern begins with a slash, the pattern will be
# treated as a regular expression instead.
pattern: str
# Explanation as a sequence of strings. Each string in the sequence will be
# printed on its own line.
explanation: Sequence[str]
# Whether or not to treat this ban as a fatal error. If unspecified,
# defaults to true.
treat_as_error: Optional[bool] = None
# Paths that should be excluded from the ban check. Each string is a regular
# expression that will be matched against the path of the file being checked
# relative to the root of the source tree.
excluded_paths: Optional[Sequence[str]] = None
_BANNED_JAVA_IMPORTS : Sequence[BanRule] = (
BanRule(
'import java.net.URI;',
(
'Use org.chromium.url.GURL instead of java.net.URI, where possible.',
),
excluded_paths=(
(r'net/android/javatests/src/org/chromium/net/'
'AndroidProxySelectorTest\.java'),
r'components/cronet/',
r'third_party/robolectric/local/',
),
),
BanRule(
'import android.annotation.TargetApi;',
(
'Do not use TargetApi, use @androidx.annotation.RequiresApi instead. '
'RequiresApi ensures that any calls are guarded by the appropriate '
'SDK_INT check. See https://crbug.com/1116486.',
),
),
BanRule(
'import androidx.test.rule.UiThreadTestRule;',
(
'Do not use UiThreadTestRule, just use '
'@org.chromium.base.test.UiThreadTest on test methods that should run '
'on the UI thread. See https://crbug.com/1111893.',
),
),
BanRule(
'import androidx.test.annotation.UiThreadTest;',
('Do not use androidx.test.annotation.UiThreadTest, use '
'org.chromium.base.test.UiThreadTest instead. See '
'https://crbug.com/1111893.',
),
),
BanRule(
'import androidx.test.rule.ActivityTestRule;',
(
'Do not use ActivityTestRule, use '
'org.chromium.base.test.BaseActivityTestRule instead.',
),
excluded_paths=(
'components/cronet/',
),
),
BanRule(
'import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;',
(
'Do not use VectorDrawableCompat, use getResources().getDrawable() to '
'avoid extra indirections. Please also add trace event as the call '
'might take more than 20 ms to complete.',
),
),
)
_BANNED_JAVA_FUNCTIONS : Sequence[BanRule] = (
BanRule(
'StrictMode.allowThreadDiskReads()',
(
'Prefer using StrictModeContext.allowDiskReads() to using StrictMode '
'directly.',
),
False,
),
BanRule(
'StrictMode.allowThreadDiskWrites()',
(
'Prefer using StrictModeContext.allowDiskWrites() to using StrictMode '
'directly.',
),
False,
),
BanRule(
'.waitForIdleSync()',
(
'Do not use waitForIdleSync as it masks underlying issues. There is '
'almost always something else you should wait on instead.',
),
False,
),
BanRule(
r'/(?<!\bsuper\.)(?<!\bIntent )\bregisterReceiver\(',
(
'Do not call android.content.Context.registerReceiver (or an override) '
'directly. Use one of the wrapper methods defined in '
'org.chromium.base.ContextUtils, such as '
'registerProtectedBroadcastReceiver, '
'registerExportedBroadcastReceiver, or '
'registerNonExportedBroadcastReceiver. See their documentation for '
'which one to use.',
),
True,
excluded_paths=(
r'.*Test[^a-z]',
r'third_party/',
'base/android/java/src/org/chromium/base/ContextUtils.java',
'chromecast/browser/android/apk/src/org/chromium/chromecast/shell/BroadcastReceiverScope.java',
),
),
BanRule(
r'/(?:extends|new)\s*(?:android.util.)?Property<[A-Za-z.]+,\s*(?:Integer|Float)>',
(
'Do not use Property<..., Integer|Float>, but use FloatProperty or '
'IntProperty because it will avoid unnecessary autoboxing of '
'primitives.',
),
),
BanRule(
'requestLayout()',
(
'Layouts can be expensive. Prefer using ViewUtils.requestLayout(), '
'which emits a trace event with additional information to help with '
'scroll jank investigations. See http://crbug.com/1354176.',
),
False,
excluded_paths=(
'ui/android/java/src/org/chromium/ui/base/ViewUtils.java',
),
),
BanRule(
'Profile.getLastUsedRegularProfile()',
(
'Prefer passing in the Profile reference instead of relying on the '
'static getLastUsedRegularProfile() call. Only top level entry points '
'(e.g. Activities) should call this method. Otherwise, the Profile '
'should either be passed in explicitly or retreived from an existing '
'entity with a reference to the Profile (e.g. WebContents).',
),
False,
excluded_paths=(
r'.*Test[A-Z]?.*\.java',
),
),
BanRule(
r'/(ResourcesCompat|getResources\(\))\.getDrawable\(\)',
(
'getDrawable() can be expensive. If you have a lot of calls to '
'GetDrawable() or your code may introduce janks, please put your calls '
'inside a trace().',
),
False,
excluded_paths=(
r'.*Test[A-Z]?.*\.java',
),
),
BanRule(
r'/RecordHistogram\.getHistogram(ValueCount|TotalCount|Samples)ForTesting\(',
(
'Raw histogram counts are easy to misuse; for example they don\'t reset '
'between batched tests. Use HistogramWatcher to check histogram records instead.',
),
False,
excluded_paths=(
'base/android/javatests/src/org/chromium/base/metrics/RecordHistogramTest.java',
'base/test/android/javatests/src/org/chromium/base/test/util/HistogramWatcher.java',
),
),
)
_BANNED_JAVASCRIPT_FUNCTIONS : Sequence [BanRule] = (
BanRule(
r'/\bchrome\.send\b',
(
'The use of chrome.send is disallowed in Chrome (context: https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/security/handling-messages-from-web-content.md).',
'Please use mojo instead for new webuis. https://docs.google.com/document/d/1RF-GSUoveYa37eoyZ9EhwMtaIwoW7Z88pIgNZ9YzQi4/edit#heading=h.gkk22wgk6wff',
),
True,
(
r'^(?!ash\/webui).+',
# TODO(crbug.com/1385601): pre-existing violations still need to be
# cleaned up.
'ash/webui/common/resources/cr.m.js',
'ash/webui/common/resources/multidevice_setup/multidevice_setup_browser_proxy.js',
'ash/webui/common/resources/quick_unlock/lock_screen_constants.js',
'ash/webui/common/resources/smb_shares/smb_browser_proxy.js',
'ash/webui/connectivity_diagnostics/resources/connectivity_diagnostics.js',
'ash/webui/diagnostics_ui/resources/diagnostics_browser_proxy.ts',
'ash/webui/multidevice_debug/resources/logs.js',
'ash/webui/multidevice_debug/resources/webui.js',
'ash/webui/projector_app/resources/annotator/trusted/annotator_browser_proxy.js',
'ash/webui/projector_app/resources/app/trusted/projector_browser_proxy.js',
'ash/webui/scanning/resources/scanning_browser_proxy.js',
),
),
)
_BANNED_OBJC_FUNCTIONS : Sequence[BanRule] = (
BanRule(
'addTrackingRect:',
(
'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is'
'prohibited. Please use CrTrackingArea instead.',
'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
),
False,
),
BanRule(
r'/NSTrackingArea\W',
(
'The use of NSTrackingAreas is prohibited. Please use CrTrackingArea',
'instead.',
'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
),
False,
),
BanRule(
'convertPointFromBase:',
(
'The use of -[NSView convertPointFromBase:] is almost certainly wrong.',
'Please use |convertPoint:(point) fromView:nil| instead.',
'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
),
True,
),
BanRule(
'convertPointToBase:',
(
'The use of -[NSView convertPointToBase:] is almost certainly wrong.',
'Please use |convertPoint:(point) toView:nil| instead.',
'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
),
True,
),
BanRule(
'convertRectFromBase:',
(
'The use of -[NSView convertRectFromBase:] is almost certainly wrong.',
'Please use |convertRect:(point) fromView:nil| instead.',
'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
),
True,
),
BanRule(
'convertRectToBase:',
(
'The use of -[NSView convertRectToBase:] is almost certainly wrong.',
'Please use |convertRect:(point) toView:nil| instead.',
'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
),
True,
),
BanRule(
'convertSizeFromBase:',
(
'The use of -[NSView convertSizeFromBase:] is almost certainly wrong.',
'Please use |convertSize:(point) fromView:nil| instead.',
'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
),
True,
),
BanRule(
'convertSizeToBase:',
(
'The use of -[NSView convertSizeToBase:] is almost certainly wrong.',
'Please use |convertSize:(point) toView:nil| instead.',
'http://dev.chromium.org/developers/coding-style/cocoa-dos-and-donts',
),
True,
),
BanRule(
r"/\s+UTF8String\s*]",
(
'The use of -[NSString UTF8String] is dangerous as it can return null',
'even if |canBeConvertedToEncoding:NSUTF8StringEncoding| returns YES.',
'Please use |SysNSStringToUTF8| instead.',
),
True,
),
BanRule(
r'__unsafe_unretained',
(
'The use of __unsafe_unretained is almost certainly wrong, unless',
'when interacting with NSFastEnumeration or NSInvocation.',
'Please use __weak in files build with ARC, nothing otherwise.',
),
False,
),
BanRule(
'freeWhenDone:NO',
(
'The use of "freeWhenDone:NO" with the NoCopy creation of ',
'Foundation types is prohibited.',
),
True,
),
)
_BANNED_IOS_OBJC_FUNCTIONS = (
BanRule(
r'/\bTEST[(]',
(
'TEST() macro should not be used in Objective-C++ code as it does not ',
'drain the autorelease pool at the end of the test. Use TEST_F() ',
'macro instead with a fixture inheriting from PlatformTest (or a ',
'typedef).'
),
True,
),
BanRule(
r'/\btesting::Test\b',
(
'testing::Test should not be used in Objective-C++ code as it does ',
'not drain the autorelease pool at the end of the test. Use ',
'PlatformTest instead.'
),
True,
),
BanRule(
' systemImageNamed:',
(
'+[UIImage systemImageNamed:] should not be used to create symbols.',
'Instead use a wrapper defined in:',
'ios/chrome/browser/ui/icons/symbol_helpers.h'
),
True,
excluded_paths=(
'ios/chrome/browser/shared/ui/symbols/symbol_helpers.mm',
'ios/chrome/search_widget_extension/',
),
),
)
_BANNED_IOS_EGTEST_FUNCTIONS : Sequence[BanRule] = (
BanRule(
r'/\bEXPECT_OCMOCK_VERIFY\b',
(
'EXPECT_OCMOCK_VERIFY should not be used in EarlGrey tests because ',
'it is meant for GTests. Use [mock verify] instead.'
),
True,
),
)
_BANNED_CPP_FUNCTIONS : Sequence[BanRule] = (
BanRule(
r'/\busing namespace ',
(
'Using directives ("using namespace x") are banned by the Google Style',
'Guide ( http://google.github.io/styleguide/cppguide.html#Namespaces ).',
'Explicitly qualify symbols or use using declarations ("using x::foo").',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
),
# Make sure that gtest's FRIEND_TEST() macro is not used; the
# FRIEND_TEST_ALL_PREFIXES() macro from base/gtest_prod_util.h should be
# used instead since that allows for FLAKY_ and DISABLED_ prefixes.
BanRule(
'FRIEND_TEST(',
(
'Chromium code should not use gtest\'s FRIEND_TEST() macro. Include',
'base/gtest_prod_util.h and use FRIEND_TEST_ALL_PREFIXES() instead.',
),
False,
(),
),
BanRule(
'setMatrixClip',
(
'Overriding setMatrixClip() is prohibited; ',
'the base function is deprecated. ',
),
True,
(),
),
BanRule(
'SkRefPtr',
(
'The use of SkRefPtr is prohibited. ',
'Please use sk_sp<> instead.'
),
True,
(),
),
BanRule(
'SkAutoRef',
(
'The indirect use of SkRefPtr via SkAutoRef is prohibited. ',
'Please use sk_sp<> instead.'
),
True,
(),
),
BanRule(
'SkAutoTUnref',
(
'The use of SkAutoTUnref is dangerous because it implicitly ',
'converts to a raw pointer. Please use sk_sp<> instead.'
),
True,
(),
),
BanRule(
'SkAutoUnref',
(
'The indirect use of SkAutoTUnref through SkAutoUnref is dangerous ',
'because it implicitly converts to a raw pointer. ',
'Please use sk_sp<> instead.'
),
True,
(),
),
BanRule(
r'/HANDLE_EINTR\(.*close',
(
'HANDLE_EINTR(close) is invalid. If close fails with EINTR, the file',
'descriptor will be closed, and it is incorrect to retry the close.',
'Either call close directly and ignore its return value, or wrap close',
'in IGNORE_EINTR to use its return value. See http://crbug.com/269623'
),
True,
(),
),
BanRule(
r'/IGNORE_EINTR\((?!.*close)',
(
'IGNORE_EINTR is only valid when wrapping close. To wrap other system',
'calls, use HANDLE_EINTR. See http://crbug.com/269623',
),
True,
(
# Files that #define IGNORE_EINTR.
r'^base/posix/eintr_wrapper\.h$',
r'^ppapi/tests/test_broker\.cc$',
),
),
BanRule(
r'/v8::Extension\(',
(
'Do not introduce new v8::Extensions into the code base, use',
'gin::Wrappable instead. See http://crbug.com/334679',
),
True,
(
r'extensions/renderer/safe_builtins\.*',
),
),
BanRule(
'#pragma comment(lib,',
(
'Specify libraries to link with in build files and not in the source.',
),
True,
(
r'^base/third_party/symbolize/.*',
r'^third_party/abseil-cpp/.*',
),
),
BanRule(
r'/base::SequenceChecker\b',
(
'Consider using SEQUENCE_CHECKER macros instead of the class directly.',
),
False,
(),
),
BanRule(
r'/base::ThreadChecker\b',
(
'Consider using THREAD_CHECKER macros instead of the class directly.',
),
False,
(),
),
BanRule(
r'/\b(?!(Sequenced|SingleThread))\w*TaskRunner::(GetCurrentDefault|CurrentDefaultHandle)',
(
'It is not allowed to call these methods from the subclasses ',
'of Sequenced or SingleThread task runners.',
),
True,
(),
),
BanRule(
r'/(Time(|Delta|Ticks)|ThreadTicks)::FromInternalValue|ToInternalValue',
(
'base::TimeXXX::FromInternalValue() and ToInternalValue() are',
'deprecated (http://crbug.com/634507). Please avoid converting away',
'from the Time types in Chromium code, especially if any math is',
'being done on time values. For interfacing with platform/library',
'APIs, use FromMicroseconds() or InMicroseconds(), or one of the other',
'type converter methods instead. For faking TimeXXX values (for unit',
'testing only), use TimeXXX() + Microseconds(N). For',
'other use cases, please contact base/time/OWNERS.',
),
False,
(),
),
BanRule(
'CallJavascriptFunctionUnsafe',
(
"Don't use CallJavascriptFunctionUnsafe() in new code. Instead, use",
'AllowJavascript(), OnJavascriptAllowed()/OnJavascriptDisallowed(),',
'and CallJavascriptFunction(). See https://goo.gl/qivavq.',
),
False,
(
r'^content/browser/webui/web_ui_impl\.(cc|h)$',
r'^content/public/browser/web_ui\.h$',
r'^content/public/test/test_web_ui\.(cc|h)$',
),
),
BanRule(
'leveldb::DB::Open',
(
'Instead of leveldb::DB::Open() use leveldb_env::OpenDB() from',
'third_party/leveldatabase/env_chromium.h. It exposes databases to',
"Chrome's tracing, making their memory usage visible.",
),
True,
(
r'^third_party/leveldatabase/.*\.(cc|h)$',
),
),
BanRule(
'leveldb::NewMemEnv',
(
'Instead of leveldb::NewMemEnv() use leveldb_chrome::NewMemEnv() from',
'third_party/leveldatabase/leveldb_chrome.h. It exposes environments',
"to Chrome's tracing, making their memory usage visible.",
),
True,
(
r'^third_party/leveldatabase/.*\.(cc|h)$',
),
),
BanRule(
'RunLoop::QuitCurrent',
(
'Please migrate away from RunLoop::QuitCurrent*() methods. Use member',
'methods of a specific RunLoop instance instead.',
),
False,
(),
),
BanRule(
'base::ScopedMockTimeMessageLoopTaskRunner',
(
'ScopedMockTimeMessageLoopTaskRunner is deprecated. Prefer',
'TaskEnvironment::TimeSource::MOCK_TIME. There are still a',
'few cases that may require a ScopedMockTimeMessageLoopTaskRunner',
'(i.e. mocking the main MessageLoopForUI in browser_tests), but check',
'with gab@ first if you think you need it)',
),
False,
(),
),
BanRule(
'std::regex',
(
'Using std::regex adds unnecessary binary size to Chrome. Please use',
're2::RE2 instead (crbug.com/755321)',
),
True,
# Abseil's benchmarks never linked into chrome.
['third_party/abseil-cpp/.*_benchmark.cc'],
),
BanRule(
r'/\bstd::sto(i|l|ul|ll|ull)\b',
(
'std::sto{i,l,ul,ll,ull}() use exceptions to communicate results. ',
'Use base::StringTo[U]Int[64]() instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
),
BanRule(
r'/\bstd::sto(f|d|ld)\b',
(
'std::sto{f,d,ld}() use exceptions to communicate results. ',
'For locale-independent values, e.g. reading numbers from disk',
'profiles, use base::StringToDouble().',
'For user-visible values, parse using ICU.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
),
BanRule(
r'/\bstd::to_string\b',
(
'std::to_string() is locale dependent and slower than alternatives.',
'For locale-independent strings, e.g. writing numbers to disk',
'profiles, use base::NumberToString().',
'For user-visible strings, use base::FormatNumber() and',
'the related functions in base/i18n/number_formatting.h.',
),
False, # Only a warning since it is already used.
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
),
BanRule(
r'/\bstd::shared_ptr\b',
(
'std::shared_ptr is banned. Use scoped_refptr instead.',
),
True,
[
# Needed for interop with third-party library.
'^third_party/blink/renderer/core/typed_arrays/array_buffer/' +
'array_buffer_contents\.(cc|h)',
'^third_party/blink/renderer/bindings/core/v8/' +
'v8_wasm_response_extensions.cc',
'^gin/array_buffer\.(cc|h)',
'^chrome/services/sharing/nearby/',
# Needed for interop with third-party library libunwindstack.
'^base/profiler/libunwindstack_unwinder_android\.(cc|h)',
# Needed for interop with third-party boringssl cert verifier
'^third_party/boringssl/',
'^net/cert/',
'^net/tools/cert_verify_tool/',
'^services/cert_verifier/',
'^components/certificate_transparency/',
'^components/media_router/common/providers/cast/certificate/',
# gRPC provides some C++ libraries that use std::shared_ptr<>.
'^chromeos/ash/services/libassistant/grpc/',
'^chromecast/cast_core/grpc',
'^chromecast/cast_core/runtime/browser',
'^ios/chrome/test/earl_grey/chrome_egtest_plugin_client\.(mm|h)',
# Fuchsia provides C++ libraries that use std::shared_ptr<>.
'^base/fuchsia/.*\.(cc|h)',
'.*fuchsia.*test\.(cc|h)',
# Needed for clang plugin tests
'^tools/clang/plugins/tests/',
_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders.
),
BanRule(
r'/\bstd::weak_ptr\b',
(
'std::weak_ptr is banned. Use base::WeakPtr instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders.
),
BanRule(
r'/\blong long\b',
(
'long long is banned. Use [u]int64_t instead.',
),
False, # Only a warning since it is already used.
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
),
BanRule(
r'/\b(absl|std)::any\b',
(
'{absl,std}::any are banned due to incompatibility with the component ',
'build.',
),
True,
# Not an error in third party folders, though it probably should be :)
[_THIRD_PARTY_EXCEPT_BLINK],
),
BanRule(
r'/\bstd::bind\b',
(
'std::bind() is banned because of lifetime risks. Use ',
'base::Bind{Once,Repeating}() instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders.
),
BanRule(
(
r'/\bstd::(?:'
r'linear_congruential_engine|mersenne_twister_engine|'
r'subtract_with_carry_engine|discard_block_engine|'
r'independent_bits_engine|shuffle_order_engine|'
r'minstd_rand0?|mt19937(_64)?|ranlux(24|48)(_base)?|knuth_b|'
r'default_random_engine|'
r'random_device|'
r'seed_seq'
r')\b'
),
(
'STL random number engines and generators are banned. Use the ',
'helpers in base/rand_util.h instead, e.g. base::RandBytes() or ',
'base::RandomBitGenerator.'
),
True,
[
# Not an error in third_party folders.
_THIRD_PARTY_EXCEPT_BLINK,
# Various tools which build outside of Chrome.
r'testing/libfuzzer',
r'tools/android/io_benchmark/',
# Fuzzers are allowed to use standard library random number generators
# since fuzzing speed + reproducibility is important.
r'tools/ipc_fuzzer/',
r'.+_fuzzer\.cc$',
r'.+_fuzzertest\.cc$',
# TODO(https://crbug.com/1380528): These are all unsanctioned uses of
# the standard library's random number generators, and should be
# migrated to the //base equivalent.
r'ash/ambient/model/ambient_topic_queue\.cc',
r'base/allocator/partition_allocator/partition_alloc_unittest\.cc',
r'base/ranges/algorithm_unittest\.cc',
r'base/test/launcher/test_launcher\.cc',
r'cc/metrics/video_playback_roughness_reporter_unittest\.cc',
r'chrome/browser/apps/app_service/metrics/website_metrics\.cc',
r'chrome/browser/ash/power/auto_screen_brightness/monotone_cubic_spline_unittest\.cc',
r'chrome/browser/ash/printing/zeroconf_printer_detector_unittest\.cc',
r'chrome/browser/nearby_sharing/contacts/nearby_share_contact_manager_impl_unittest\.cc',
r'chrome/browser/nearby_sharing/contacts/nearby_share_contacts_sorter_unittest\.cc',
r'chrome/browser/privacy_budget/mesa_distribution_unittest\.cc',
r'chrome/browser/web_applications/test/web_app_test_utils\.cc',
r'chrome/browser/web_applications/test/web_app_test_utils\.cc',
r'chrome/browser/win/conflicts/module_blocklist_cache_util_unittest\.cc',
r'chrome/chrome_cleaner/logging/detailed_info_sampler\.cc',
r'chromeos/ash/components/memory/userspace_swap/swap_storage_unittest\.cc',
r'chromeos/ash/components/memory/userspace_swap/userspace_swap\.cc',
r'components/metrics/metrics_state_manager\.cc',
r'components/omnibox/browser/history_quick_provider_performance_unittest\.cc',
r'components/zucchini/disassembler_elf_unittest\.cc',
r'content/browser/webid/federated_auth_request_impl\.cc',
r'content/browser/webid/federated_auth_request_impl\.cc',
r'media/cast/test/utility/udp_proxy\.h',
r'sql/recover_module/module_unittest\.cc',
],
),
BanRule(
r'/\b(absl,std)::bind_front\b',
(
'{absl,std}::bind_front() are banned. Use base::Bind{Once,Repeating}() '
'instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders.
),
BanRule(
r'/\bABSL_FLAG\b',
(
'ABSL_FLAG is banned. Use base::CommandLine instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders.
),
BanRule(
r'/\babsl::c_',
(
'Abseil container utilities are banned. Use base/ranges/algorithm.h ',
'instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders.
),
BanRule(
r'/\babsl::FunctionRef\b',
(
'absl::FunctionRef is banned. Use base::FunctionRef instead.',
),
True,
[
# base::Bind{Once,Repeating} references absl::FunctionRef to disallow
# interoperability.
r'^base/functional/bind_internal\.h',
# base::FunctionRef is implemented on top of absl::FunctionRef.
r'^base/functional/function_ref.*\..+',
# Not an error in third_party folders.
_THIRD_PARTY_EXCEPT_BLINK,
],
),
BanRule(
r'/\babsl::(Insecure)?BitGen\b',
(
'absl random number generators are banned. Use the helpers in '
'base/rand_util.h instead, e.g. base::RandBytes() or ',
'base::RandomBitGenerator.'
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders.
),
BanRule(
r'/(\babsl::Span\b|#include <span>)',
(
'absl::Span is banned and <span> is not allowed yet ',
'(https://crbug.com/1414652). Use base::span instead.',
),
True,
[
# Needed to use QUICHE API.
r'services/network/web_transport\.cc',
# Not an error in third_party folders.
_THIRD_PARTY_EXCEPT_BLINK
],
),
BanRule(
r'/\babsl::StatusOr\b',
(
'absl::StatusOr is banned. Use base::expected instead.',
),
True,
[
# Needed to use liburlpattern API.
r'third_party/blink/renderer/core/url_pattern/.*',
r'third_party/blink/renderer/modules/manifest/manifest_parser\.cc',
# Not an error in third_party folders.
_THIRD_PARTY_EXCEPT_BLINK
],
),
BanRule(
r'/\babsl::StrFormat\b',
(
'absl::StrFormat() is not allowed yet (https://crbug.com/1371963). ',
'Use base::StringPrintf() instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders.
),
BanRule(
r'/\babsl::string_view\b',
(
'absl::string_view is a legacy spelling of std::string_view, which is ',
'not allowed yet (https://crbug.com/691162). Use base::StringPiece ',
'instead, unless std::string_view is needed to use with an external ',
'API.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Don't warn in third_party folders.
),
BanRule(
r'/\bstd::(u16)?string_view\b',
(
'std::[u16]string_view is not yet allowed (crbug.com/691162). Use ',
'base::StringPiece[16] instead, unless std::[u16]string_view is ',
'needed to use an external API.',
),
True,
[
# Needed to implement and test std::string_view interoperability.
r'base/strings/string_piece.*',
# Needed to use re2::RE2 regular expression library.
r'third_party/blink/common/interest_group/ad_display_size_utils.cc',
# Needed to use liburlpattern API.
r'third_party/blink/renderer/core/url_pattern/.*',
r'third_party/blink/renderer/modules/manifest/manifest_parser\.cc',
# Needed to use QUICHE API.
r'net/quic/.*',
r'net/spdy/.*',
r'net/test/embedded_test_server/.*',
r'net/third_party/quiche/.*',
r'services/network/web_transport\.cc',
# This code is in the process of being extracted into an external
# library, where //base will be unavailable.
r'net/cert/pki/.*',
r'net/der/.*',
# Needed to use APIs from the above.
r'net/cert/.*',
# Not an error in third_party folders.
_THIRD_PARTY_EXCEPT_BLINK
],
),
BanRule(
r'/\babsl::(StrSplit|StrJoin|StrCat|StrAppend|Substitute|StrContains)\b',
(
'Abseil string utilities are banned. Use base/strings instead.',
),
True,
[_THIRD_PARTY_EXCEPT_BLINK], # Not an error in third_party folders.