--
You received this message because you are subscribed to the Google Groups "content-owners" group.
To unsubscribe from this group and stop receiving emails from it, send an email to content-owner...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/content-owners/CAAHOzFAeyF1daKoYqYH29rBghB6Gi_OZMW%3D9fMad0%2BjWKG-OtQ%40mail.gmail.com.
I think +Lucas Gadani and +John Abd-El-Malek were the last to discuss this in this thread, with subsequent cleanup done in this bug.
On Tue, Dec 15, 2020 at 1:45 PM Alex Moshchuk <ale...@chromium.org> wrote:I think +Lucas Gadani and +John Abd-El-Malek were the last to discuss this in this thread, with subsequent cleanup done in this bug.Thanks!John, do you have a reference to that content change that resulted in a bunch of constness churn?
I'd like to see what sort of change it was and whether both the code before and the code after were logically or physically const. I agree with the desire not to have implementation changes result in large viral constness propagation changes.PK
(What I know so far is that the API used to use const more heavily and significant work was put into removing that, so clearly that was seen as a problem worth engineering effort to solve.)
On Tue, Dec 15, 2020 at 1:52 PM Peter Kasting <pkas...@chromium.org> wrote:On Tue, Dec 15, 2020 at 1:45 PM Alex Moshchuk <ale...@chromium.org> wrote:I think +Lucas Gadani and +John Abd-El-Malek were the last to discuss this in this thread, with subsequent cleanup done in this bug.Thanks!John, do you have a reference to that content change that resulted in a bunch of constness churn?I don't have links since this was 9-10 years ago when we started creating the public API. We got bit in two directions since some interfaces in content/public are implemented inside content while others are implemented by (many) embedders.
--PK
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAAHOzFAK0hB-9Ptcjcb%3DiGzisKUWpvqUEvghzB5CFSMBFLMzxg%40mail.gmail.com.
In some //base APIs what we do when const makes sense on the public API but the impl needs to use non-const state (e.g. a base::Lock) is to make those members "mutable" in the impl (can be accessed from the impl of a const method).
--
You received this message because you are subscribed to the Google Groups "content-owners" group.
To unsubscribe from this group and stop receiving emails from it, send an email to content-owner...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/content-owners/CALhVsw18rHCoE1z604mrsJjniJGiciPLi_fe7WWOB_BBvs41%2Bw%40mail.gmail.com.
Apologies I missed this. I think the background I wrote earlier might not be coming through clearly over email; how about a video chat to go through the issues in high bandwidth?
--
You received this message because you are subscribed to the Google Groups "content-owners" group.
To unsubscribe from this group and stop receiving emails from it, send an email to content-owner...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/content-owners/CAEgCuoHqab1u2KDDwC5SXfFVt6G_9CD%2BPm6xyJemxZvexSCCGg%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CACWgwAb9B%2BDwa50gEnryAtEGQjNoCdYv1FMsHUJ9WaUmTvq-3g%40mail.gmail.com.
As a chromium-downstream perspective, I recall that this rule led to changing the top-level content-client embedder APIs (such as //content/public/browser/content_browser_client.h) to avoid having const-qualified methods. I think that was useful -- it avoided flipping the qualifier back and forth depending on whether there were embedders under // that couldn't make do with a const client method. I think it makes sense to avoid const there and in cases like observer interfaces. Perhaps that was the motivation, but it got extended too widely.
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAAHOzFCe_uRfzzeQ3OELHNZ52C%2ByxXnmF_%3Dg8-aCXwX%3DsrpO-A%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CACWgwAbBOHU67ufo6OautFpUJ-ETDQoAuoLbNkqcx6ONmLoT2g%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "content-owners" group.
To unsubscribe from this group and stop receiving emails from it, send an email to content-owner...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/content-owners/CALHg4nkrE6UF_sqr9SFhSzHLUAP1AhfpOgxLoRzWQb2ADWPNbQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAH%2B8MBY8%2B_4mMB2wiz2LjJAdm3FayasTcjvJ8y21HiKLKJVHqA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/content-owners/CAH%2B8MBY8%2B_4mMB2wiz2LjJAdm3FayasTcjvJ8y21HiKLKJVHqA%40mail.gmail.com.
Getting the most feedback from content owners is best.
I like the idea of making the rules inside and outside content more consistent
I'm hearing from John and Tomasz that it may be worth avoiding const on APIs defined by content and implemented by embedders (e.g., observers), where we should not make assumptions about the embedder. That makes sense to me, though I don't have experience with how other codebases handle that problem.
For APIs implemented by content, we could perhaps start allowing const to allow external const-correct and const-okay code to interact with content without dangerous casts (and to avoid the duplication Alexander mentioned). Peter, would that change be sufficient for most of the problematic cases you've seen?
--
You received this message because you are subscribed to the Google Groups "content-owners" group.
To unsubscribe from this group and stop receiving emails from it, send an email to content-owner...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/content-owners/CAAHOzFDk0uXDZf1avuRwuxYinAaOjfaHwSagKFax5MX4NwNo_g%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/content-owners/CAJ_xCi%3D%3DdViMRdJVuWf8jXF0-rZ0yekE4d4GbrusM9efQ40Ccw%40mail.gmail.com.
I'll also start a bit backwards. For 2), I would expect mostly agreement that we cannot dictate the implementation details of embedders, which means that we cannot use const in those cases. Since I'm making an assumption here, please shout if that is an incorrect one.
About 1). Adding const on an API that is implemented inside //content/ might seem simple on the surface, but I've tried reasoning about at least one existing case and have hard time figuring out whether it is safe or not - RenderFrameHost::GetProcess(). Simple logic tells me it should be safe, but digging into the implementation details ... it isn't so obvious.
Let's continue with the example above and rewind time about a year or so ago, before MBI existed. Let's also assume that RFH::GetProcess() was set to be const. Would it be possible to implement MBI (adding AgentSchedulingGroupHost in the middle) and not be limited by the const-ness? What about MPArch, which we are in the middle of?
Would we put more friction on such big changes by adding the additional constraint of keeping const satisfied when we might actually be changing the assumptions we have made in the past and that const might no longer be correct?
Maybe my C++-fu is weak, maybe there is some magic article that I can read on const that will enlighten me, it may be something else.
But I'm mostly having a hard time with complexity, which is currently exploding in our codebase and adding const to the mix is adding another layer of complexity.
These are my raw thoughts. If we allow const in content, I would like us to have super crisp rules as to when it is ok and when it is not. Unfortunately, I don't know what those rules are. What Peter wrote is way too vague for me and I have a hard time parsing what it means.
The first and third bullets you propose are phrased in terms of what state the method changes or what methods it calls, but that's only true at one point in time. I think we're struggling with the idea of reading it as, "The method changes no object state other than that marked mutable, *and it will never do so in the future.*"
I think the gap here might be our lack of intuition over what shouldn't be const. You pointed out that RenderFrameHost::GetProcess() can't be const because it returns a non-const object, but what would have prevented having a const RenderProcessHost* GetProcess() const method (much like Dave's const WebView* GetWebView() const on RenderFrame here)? Is there something wrong in that case? If that were allowed and we later hypothetically changed RFH::GetProcess() to call SiteInstance::GetProcess() (which creates a process if one is missing), I think it would break the public const API.
This potentially requires updating a lot of caller code, but if the original job was done right, this is code you likely had to update anyway; now the compiler can tell you where it is. (This is a key reason Google and Chromium style guides recommend const APIs and variables where feasible.)
Not to bikeshed over naming, but perhaps SiteInstance::GetOrCreateProcess() would be a name that makes it more obvious that that kind of a method can never be const, and can never be called by a const method.
You may only mark a method const when all of the following apply:* The method changes no object state other than that marked mutable.* The method does not return (directly or via outparam) pointers or references, except to const objects.* The method does not call non-const methods on any other objects.
In APIs implemented by the embedder, is there a difference because they don't have the freedom to update callers inside content when embedder code changes? It seems harder to reason about how an embedder might behave on a callback or observer (since we don't know what they'll need to do), making me suspect we might want fewer consts in those cases. But maybe omitting const is the natural default if we don't know what the embedder will need?
On Mon, May 17, 2021 at 9:55 PM Charlie Reis <cr...@chromium.org> wrote:In APIs implemented by the embedder, is there a difference because they don't have the freedom to update callers inside content when embedder code changes? It seems harder to reason about how an embedder might behave on a callback or observer (since we don't know what they'll need to do), making me suspect we might want fewer consts in those cases. But maybe omitting const is the natural default if we don't know what the embedder will need?Callbacks/observers should almost never be const, because their whole purpose is to change object state/perform some meaningful action in response to an event.
Only when you want to guarantee that firing an action can't have any effect would you make a callback for it const. I can't think of a case like that I've seen in practice.Similarly, in other cases, if a method implemented by an embedder *ought* to allow arbitrary side effects, it shouldn't be const, even if embedders don't do side effects today.
One heuristic is whether you're asking the embedder for something versus telling it about something. Many of the former cases are const; very few of the latter are.
On Mon, May 17, 2021 at 9:55 PM Charlie Reis <cr...@chromium.org> wrote:In APIs implemented by the embedder, is there a difference because they don't have the freedom to update callers inside content when embedder code changes? It seems harder to reason about how an embedder might behave on a callback or observer (since we don't know what they'll need to do), making me suspect we might want fewer consts in those cases. But maybe omitting const is the natural default if we don't know what the embedder will need?Callbacks/observers should almost never be const, because their whole purpose is to change object state/perform some meaningful action in response to an event. Only when you want to guarantee that firing an action can't have any effect would you make a callback for it const. I can't think of a case like that I've seen in practice.
Similarly, in other cases, if a method implemented by an embedder *ought* to allow arbitrary side effects, it shouldn't be const, even if embedders don't do side effects today.One heuristic is whether you're asking the embedder for something versus telling it about something. Many of the former cases are const; very few of the latter are.That's not really a property of embedders vs. other people, though; the same applies to the content layer itself (and any other object/subsystem boundary).So you might make additions to the previous guidance:* The method must not be some kind of callback, observer, or event handler.
* The method must not be plausibly renamable to "GetOrCreateXXX()" or the like.* As a heuristic, the method's primary purpose should be to transfer information from callee to caller, not the other way around.
Thanks!
--PK
You received this message because you are subscribed to the Google Groups "content-owners" group.
To unsubscribe from this group and stop receiving emails from it, send an email to content-owner...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/content-owners/CAAHOzFAdBK6bij%2BuM2sBV%3DCto_kOt%3D2efCpbp6W51uAxHrz%2B6g%40mail.gmail.com.
"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."Separately, I'm not opposed to considering more pros/cons in the future for allowing const on getter APIs implemented by the embedder (e.g., in delegate interfaces, rather than observer interfaces). There are still things I'm learning there, like having const+nonconst overloads is only possible for methods with object return types and not primitive (int/bool/etc) return types, which restricts what an embedder can do for something like int GetFooCount() with no const. In other words, there may be constraints either way (e.g., whether the embedder can use const in their code vs whether the embedder can mutate state in their code). It might be nice to move towards a smaller delta from other style/API rules in general, but there also isn't a rush-- let's start with the easier change above and go from there.
On Tue, May 18, 2021 at 2:24 PM John Abd-El-Malek <j...@chromium.org> wrote:On Tue, May 18, 2021 at 2:19 PM Nasko Oskov <na...@chromium.org> wrote:If folks are ok with these trade offs, I'd be happy with the this guidance:
- const cannot be added on APIs implemented by embedders/outside of content.
- const can only be added on simple getter APIs
This seems like a reasonable starting point, and we can see if it's still negatively impacting src/chrome after? Peter WDYT?Do you have no embedder APIs that are of the form "simple getter on the embedder, for when content/ needs to know something"? Is the information flow only ever one way?I'm thinking of something like "bool IsZoomed()" or "int GetTabCount()" or the like. I don't think it's appropriate to ban const on these simply because they're implemented on the embedder. And because the embedder isn't allowed to make them const, they can't be called on the embedder side by the embedder's own const methods. So you're not achieving an (IMO impossible) goal of "imposing nothing on the embedder". You're imposing non-constness. That was the whole point of raising this thread.
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.