diff --git a/PRESUBMIT.py b/PRESUBMIT.py index f56ef0fb8d746..389d66d04ee03 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -710,6 +710,14 @@ _BANNED_CPP_FUNCTIONS = ( r'^third_party/blink/renderer/.*\.(cc|h)$', ), ), + ( + 'mojo::DataPipe', + ( + 'mojo::DataPipe is deprecated. Use mojo::CreateDataPipe instead.', + ), + True, + (), + ), ) diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py index 34456b140e909..a650950ca868d 100755 --- a/PRESUBMIT_test.py +++ b/PRESUBMIT_test.py @@ -1772,6 +1772,20 @@ class BannedFunctionCheckTest(unittest.TestCase): self.assertTrue('another/ios_file.mm' in errors[0].message) self.assertTrue('some/mac/file.mm' not in errors[0].message) + def testBannedMojoFunctions(self): + input_api = MockInputApi() + input_api.files = [ + MockFile('some/cpp/problematic/file.cc', + ['mojo::DataPipe();']), + MockFile('some/cpp/ok/file.cc', + ['CreateDataPipe();']), + ] + + errors = PRESUBMIT._CheckNoBannedFunctions(input_api, MockOutputApi()) + self.assertEqual(1, len(errors)) + self.assertTrue('some/cpp/problematic/file.cc' in errors[0].message) + self.assertTrue('some/cpp/ok/file.cc' not in errors[0].message) + class NoProductionCodeUsingTestOnlyFunctionsTest(unittest.TestCase): def testTruePositives(self): diff --git a/mojo/public/cpp/system/data_pipe.h b/mojo/public/cpp/system/data_pipe.h index 205af858aeeac..eb7d6e279adb7 100644 --- a/mojo/public/cpp/system/data_pipe.h +++ b/mojo/public/cpp/system/data_pipe.h @@ -131,16 +131,12 @@ inline MojoResult CreateDataPipe( return rv; } +// DEPRECATED: use |CreateDataPipe| instead. +// +// This class is not safe to use in production code as there is no way for it to +// report failure while creating the pipe and it will CHECK in case of failures. +// // A wrapper class that automatically creates a data pipe and owns both handles. -// -// Note that this class is not safe to use in production code, as there is no -// way for it to report failure while creating the pipe, while in practice -// creating a new data pipe does fail every now and then. Instead just call -// CreateDataPipe directly and check its return value. -// -// TODO(vtl): Make an even more friendly version? (Maybe templatized for a -// particular type instead of some "element"? Maybe functions that take -// vectors?) class MOJO_CPP_SYSTEM_EXPORT DataPipe { public: DataPipe();