Files
Michael Froman 75e67d6a88 Bug 1952339 - Vendor libwebrtc from 7f6b0f35c0
Upstream commit: https://webrtc.googlesource.com/src/+/7f6b0f35c0812b04e1860c026ecae231304842af
    Reland "IWYU stats related files"

    This is a reland of commit 48f271fba90d4a6d8699e813cd049014de502523

    Original change's description:
    > IWYU stats related files
    >
    > caused Chromium compile failures:
    >   https://chromium-review.googlesource.com/c/chromium/src/+/6289230
    >
    > BUG=webrtc:42226242
    >
    > Change-Id: I6a5179638e23bf94326b3f8948a167c20f66591a
    > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/378180
    > Reviewed-by: Harald Alvestrand <hta@webrtc.org>
    > Commit-Queue: Philipp Hancke <phancke@meta.com>
    > Reviewed-by: Henrik Boström <hbos@webrtc.org>
    > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
    > Cr-Commit-Position: refs/heads/main@{#43989}

    Bug: webrtc:42226242
    Change-Id: Ibc72f027d22aa071138ae82c31287389c131b4a3
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/379120
    Reviewed-by: Björn Terelius <terelius@webrtc.org>
    Reviewed-by: Harald Alvestrand <hta@webrtc.org>
    Reviewed-by: Henrik Boström <hbos@webrtc.org>
    Commit-Queue: Philipp Hancke <phancke@meta.com>
    Cr-Commit-Position: refs/heads/main@{#44009}

Differential Revision: https://phabricator.services.mozilla.com/D244020
2025-03-07 18:01:13 -06:00
..

How to write code in the api/ directory

Mostly, just follow the regular style guide, but:

  • Note that api/ code is not exempt from the “.h and .cc files come in pairs” rule, so if you declare something in api/path/to/foo.h, it should be defined in api/path/to/foo.cc.
  • Headers in api/ should, if possible, not #include headers outside api/. Its not always possible to avoid this, but be aware that it adds to a small mountain of technical debt that were trying to shrink.
  • .cc files in api/, on the other hand, are free to #include headers outside api/.
  • Avoid structs in api, prefer classes.

The preferred way for api/ code to access non-api/ code is to call it from a .cc file, so that users of our API headers wont transitively #include non-public headers.

For headers in api/ that need to refer to non-public types, forward declarations are often a lesser evil than including non-public header files. The usual rules still apply, though.

.cc files in api/ should preferably be kept reasonably small. If a substantial implementation is needed, consider putting it with our non-public code, and just call it from the api/ .cc file.

Avoid defining api with structs as it makes harder for the api to evolve. Your struct may gain invariant, or change how it represents data. Evolving struct from the api is particular challenging as it is designed to be used in other code bases and thus needs to be updated independetly from its usage. Class with accessors and setters makes such migration safer. See Google C++ style guide for more.

If you need to evolve existent struct in api, prefer first to convert it into a class.