Hello content/ OWNERS,
Summary
- The
const
identifier can be added to simple getter APIs implemented by content. Don‘t add const
to interfaces implemented by the embedder, where we can’t make assumptions about what the embedder needs to implement it.
I propose eliminating this bullet, which would leave content/ governed by the same guidance on `const` as the rest of Chromium (See below). I am not proposing making any systematic implementation changes (e.g. an LSC to change how any APIs use `const`).
Please respond with any feedback you have about this. The remaining message below is just optional additional context.
***
Original motivation for content/ guidance
From jam@: "The motivation [for this guidance] was our repo. Generally we don't care about how our changes affect embedders in other repos... In the beginning of content/chrome split we had const, but would keep having to update many files each time an embedder changed its implementation of a delegate method that couldn't be const anymore. This was sometimes transitive too, e.g. class is calling another class in chrome, and a change there finds that it has to change content api and all the other implementations of that interface... When we added this [guidance] to content/public guidelines there was no chrome-wide guidance [about proper usage of `const`]."
Difference from the rest of Chrome
At this point the rest of Chromium and Blink use consistent guidance that, roughly, boils down to "use `const` to indicate logical constness", where "logically const" effectively means "should be threadsafe unless explicitly annotated otherwise, and should not be able to change the return value of a public const method, or provide the caller with the means to do so (e.g. by vending a pointer-to-non-const)". For the complete guidance, see the following links:
This basically means that, compared to what other Chrome code does, only content/ forbids marking logically const APIs as `const` unless they are simple getters. (On the contrary, Google/Chromium style "strongly encourages" such marking.)
Resulting challenges
Using the terminology of the "Using Const Correctly" doc, content/ is "const okay". This is challenging when hooked to "const correct" code, as it causes viral downgrades of pointers/refs to non-const whenever they'll be used to call such content/ APIs. We have in the past had to remove (semantically correct) `const`s across parts of Chrome due to calling a new content/ API.
We cannot safely address this by `const_cast<>`ing away `const` at content/ boundaries, as it's very easy to introduce silent UB this way.
Having different style rules for different parts of the codebase is also error-prone in both directions.
Known concerns
The primary feedback jam@ shared with me was that changes that merely fiddle with constness are low-value. He was concerned about any rule change here resulting in engineers wasting time "fixing" content/ const-correctness instead of doing something more useful.
I agree that this is not a change worth some sort of LSC to fix. I think it's unlikely any Googlers would take the time to do one. I hope that eliminating this style divergence actually reduces the total number of "fiddle with const" CLs over time (by eliminating a reason to change caller code).
PK