[ios] Remove the dependency to base/ files in closure.h [chromium/src : main]

0 views
Skip to first unread message

Asami Doi (Gerrit)

unread,
Feb 12, 2026, 11:34:56 AM (13 days ago) Feb 12
to Justin Novosad, chromium...@chromium.org, ios-revie...@chromium.org, ios-r...@chromium.org, marq+...@chromium.org
Attention needed from Justin Novosad

Asami Doi added 1 comment

File ios/chrome/test/swift_interop/closure/closure.h
Line 36, Patchset 3: int ref_count_ = 1;
Asami Doi . unresolved

We need a manual counting mechanism for `ClosureProvider` because we can't inherit `base::RefCounted<>`. It would be nice if we have a better way.

Open in Gerrit

Related details

Attention is currently required from:
  • Justin Novosad
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Iad6e31cf07560cc2b326e5aa23db19d474263bbf
Gerrit-Change-Number: 7572162
Gerrit-PatchSet: 5
Gerrit-Owner: Asami Doi <asam...@chromium.org>
Gerrit-Reviewer: Justin Novosad <ju...@chromium.org>
Gerrit-Attention: Justin Novosad <ju...@chromium.org>
Gerrit-Comment-Date: Thu, 12 Feb 2026 16:34:41 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Justin Novosad (Gerrit)

unread,
Feb 12, 2026, 2:52:50 PM (12 days ago) Feb 12
to Asami Doi, chromium...@chromium.org, ios-revie...@chromium.org, ios-r...@chromium.org, marq+...@chromium.org
Attention needed from Asami Doi

Justin Novosad added 2 comments

Patchset-level comments
File-level comment, Patchset 5 (Latest):
Justin Novosad . unresolved

This is interesting, but I think it's too much red tape. We should see what it looks like if we used `std::function`. If that is nice and clean, then we could use simpler shims that wrap base::RepeatingCallback objects inside std::function objects. `std::function` is banned in Chromium (see: https://chromium.googlesource.com/chromium/src/+/main/styleguide/c++/c++-features.md#std_function-banned ). However, I think that a base::RepeatingCallback wrapped in an std::function for the purpose of binding with swift may be an acceptable exception to the ban. We should try that to see what it looks like. If it's way better, then we should ask c...@chromium.org for further guidance, and request possible amendments to the style guide.

File ios/chrome/test/swift_interop/closure/closure.cc
Line 55, Patchset 5 (Latest):void Release_ClosureProvider(ClosureProvider* provider) {
Justin Novosad . unresolved

This is not thread safe. Have you tried using std::shared_ptr?

Open in Gerrit

Related details

Attention is currently required from:
  • Asami Doi
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Iad6e31cf07560cc2b326e5aa23db19d474263bbf
Gerrit-Change-Number: 7572162
Gerrit-PatchSet: 5
Gerrit-Owner: Asami Doi <asam...@chromium.org>
Gerrit-Reviewer: Justin Novosad <ju...@chromium.org>
Gerrit-Attention: Asami Doi <asam...@chromium.org>
Gerrit-Comment-Date: Thu, 12 Feb 2026 19:52:46 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Justin Novosad (Gerrit)

unread,
Feb 12, 2026, 2:56:54 PM (12 days ago) Feb 12
to Asami Doi, chromium...@chromium.org, ios-revie...@chromium.org, ios-r...@chromium.org, marq+...@chromium.org
Attention needed from Asami Doi

Justin Novosad added 1 comment

File ios/chrome/test/swift_interop/closure/closure.cc
Line 55, Patchset 5 (Latest):void Release_ClosureProvider(ClosureProvider* provider) {
Justin Novosad . unresolved

This is not thread safe. Have you tried using std::shared_ptr?

Justin Novosad

Perhaps it's okay to not be thread safe if this pattern is guaranteed to yield a non-Sendable closure on the swift side.

Open in Gerrit

Related details

Attention is currently required from:
  • Asami Doi
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Iad6e31cf07560cc2b326e5aa23db19d474263bbf
Gerrit-Change-Number: 7572162
Gerrit-PatchSet: 5
Gerrit-Owner: Asami Doi <asam...@chromium.org>
Gerrit-Reviewer: Justin Novosad <ju...@chromium.org>
Gerrit-Attention: Asami Doi <asam...@chromium.org>
Gerrit-Comment-Date: Thu, 12 Feb 2026 19:56:48 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Justin Novosad <ju...@chromium.org>
satisfied_requirement
unsatisfied_requirement
open
diffy

Asami Doi (Gerrit)

unread,
Feb 13, 2026, 9:50:57 AM (12 days ago) Feb 13
to Justin Novosad, chromium...@chromium.org, ios-revie...@chromium.org, ios-r...@chromium.org, marq+...@chromium.org
Attention needed from Justin Novosad

Asami Doi added 1 comment

Patchset-level comments
File-level comment, Patchset 5:
Justin Novosad . unresolved

This is interesting, but I think it's too much red tape. We should see what it looks like if we used `std::function`. If that is nice and clean, then we could use simpler shims that wrap base::RepeatingCallback objects inside std::function objects. `std::function` is banned in Chromium (see: https://chromium.googlesource.com/chromium/src/+/main/styleguide/c++/c++-features.md#std_function-banned ). However, I think that a base::RepeatingCallback wrapped in an std::function for the purpose of binding with swift may be an acceptable exception to the ban. We should try that to see what it looks like. If it's way better, then we should ask c...@chromium.org for further guidance, and request possible amendments to the style guide.

Asami Doi

I have tried to use `std::function`. The diff is here:
https://chromium-review.googlesource.com/c/chromium/src/+/7572162/5..6

That allows us to call directly a closure by `closure()` in Swift the code becomes simpler.

I'll ask c...@chromium.org if we can accept the exception if the latest CL looks better.

Open in Gerrit

Related details

Attention is currently required from:
  • Justin Novosad
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Iad6e31cf07560cc2b326e5aa23db19d474263bbf
Gerrit-Change-Number: 7572162
Gerrit-PatchSet: 6
Gerrit-Owner: Asami Doi <asam...@chromium.org>
Gerrit-Reviewer: Justin Novosad <ju...@chromium.org>
Gerrit-Attention: Justin Novosad <ju...@chromium.org>
Gerrit-Comment-Date: Fri, 13 Feb 2026 14:50:45 +0000
satisfied_requirement
unsatisfied_requirement
open
diffy

Justin Novosad (Gerrit)

unread,
Feb 13, 2026, 10:56:27 AM (12 days ago) Feb 13
to Asami Doi, chromium...@chromium.org, ios-revie...@chromium.org, ios-r...@chromium.org, marq+...@chromium.org
Attention needed from Asami Doi

Justin Novosad added 3 comments

File ios/chrome/test/swift_interop/closure/closure.h
Line 36, Patchset 3: int ref_count_ = 1;
Asami Doi . unresolved

We need a manual counting mechanism for `ClosureProvider` because we can't inherit `base::RefCounted<>`. It would be nice if we have a better way.

Justin Novosad

There's probably a better way, but it's outside the scope of the CL to investigate that.

File ios/chrome/test/swift_interop/closure/closure.cc
Line 21, Patchset 6:std::function<void()> ClosureProvider::GetRepeatingClosure() {
Justin Novosad . unresolved

This is great, but I feel the wrapping should be defined in a re-usable generic way. You could use variadic templates for this

Something like this (I did not try, may have gotten syntax details wrong):

```
namespace swift_helpers {

template<ReturnVal, typename... Args>
std::function<ReturnVal(Args)> AsStdFunction(base::RepeatingCallback<ReturnVal(Args)> cb) {
return [cb](Args... args) { cb.run(args...); }
}
template<ReturnVal, typename... Args>
std::function<ReturnVal(Args)> AsStdFunction(base::OnceCallback<ReturnVal(Args)> cb) {
auto shared_cb = std::make_shared<base::OnceClosure>(std::move(cb));
return [shared_cb](Args... args) mutable {
if (!shared_cb->is_null()) {
std::move(*shared_cb).Run(args...);
}
}
}

}
```

Line 40, Patchset 6: }
Justin Novosad . unresolved

Nice workaround!

Have you tried finding a way to export a std::function as a move-only type?

On the swift side, closest the equivalent of of R-value references is 'consuming' arguments. There may be a way of leveraging that to ensure that once callbacks can only be invoked once from the swift side.

Alternately, if we can't provide compile-time guarantees that the swift code can only call the callback once (or if we want to solve that problem later), then there should at least be a run-time check. There could be a `CHECK` statement, or perhaps an `else` clause that calls `base::debug::DumpWuithoutCrashing` when `shared_cb` is null.

Open in Gerrit

Related details

Attention is currently required from:
  • Asami Doi
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Iad6e31cf07560cc2b326e5aa23db19d474263bbf
Gerrit-Change-Number: 7572162
Gerrit-PatchSet: 7
Gerrit-Owner: Asami Doi <asam...@chromium.org>
Gerrit-Reviewer: Justin Novosad <ju...@chromium.org>
Gerrit-Attention: Asami Doi <asam...@chromium.org>
Gerrit-Comment-Date: Fri, 13 Feb 2026 15:56:22 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Asami Doi <asam...@chromium.org>
satisfied_requirement
unsatisfied_requirement
open
diffy

Asami Doi (Gerrit)

unread,
Feb 16, 2026, 11:39:38 AM (9 days ago) Feb 16
to Chromium LUCI CQ, Justin Novosad, chromium...@chromium.org, ios-revie...@chromium.org, ios-r...@chromium.org, marq+...@chromium.org
Attention needed from Justin Novosad

Asami Doi added 5 comments

Patchset-level comments
File-level comment, Patchset 12 (Latest):
Asami Doi . resolved

Thanks for the comments. PTAL.

File ios/chrome/test/swift_interop/closure/closure.h
Line 36, Patchset 3: int ref_count_ = 1;
Asami Doi . resolved

We need a manual counting mechanism for `ClosureProvider` because we can't inherit `base::RefCounted<>`. It would be nice if we have a better way.

Justin Novosad

There's probably a better way, but it's outside the scope of the CL to investigate that.

Asami Doi

I've wrapped ref_count_ with std::atomic. The unsafe thread issue is solved. I'll improve this part in another CL.

File ios/chrome/test/swift_interop/closure/closure.cc
Line 21, Patchset 6:std::function<void()> ClosureProvider::GetRepeatingClosure() {
Justin Novosad . resolved

This is great, but I feel the wrapping should be defined in a re-usable generic way. You could use variadic templates for this

Something like this (I did not try, may have gotten syntax details wrong):

```
namespace swift_helpers {

template<ReturnVal, typename... Args>
std::function<ReturnVal(Args)> AsStdFunction(base::RepeatingCallback<ReturnVal(Args)> cb) {
return [cb](Args... args) { cb.run(args...); }
}
template<ReturnVal, typename... Args>
std::function<ReturnVal(Args)> AsStdFunction(base::OnceCallback<ReturnVal(Args)> cb) {
auto shared_cb = std::make_shared<base::OnceClosure>(std::move(cb));
return [shared_cb](Args... args) mutable {
if (!shared_cb->is_null()) {
std::move(*shared_cb).Run(args...);
}
}
}

}
```

Asami Doi

Thank you for the suggestion. I've implemented the generic ToStdFunction templates using variadic arguments as suggested. This handles both RepeatingCallback and OnceCallback (with the shared_ptr workaround and CHECK safety).

Line 40, Patchset 6: }
Justin Novosad . resolved

Nice workaround!

Have you tried finding a way to export a std::function as a move-only type?

On the swift side, closest the equivalent of of R-value references is 'consuming' arguments. There may be a way of leveraging that to ensure that once callbacks can only be invoked once from the swift side.

Alternately, if we can't provide compile-time guarantees that the swift code can only call the callback once (or if we want to solve that problem later), then there should at least be a run-time check. There could be a `CHECK` statement, or perhaps an `else` clause that calls `base::debug::DumpWuithoutCrashing` when `shared_cb` is null.

Asami Doi

Thanks for the suggestion. I don't find the way to export std::function as a move-only type. I have tried to mark it with the annotation (`__attribute__((swift_attr("~Copyable")))`) but it doesn't work as intended.

I've added a CHECK(!shared_cb->is_null()) inside the lambda. This ensures a crash if the Swift code attempts to invoke the OnceClosure more than once.

Line 55, Patchset 5:void Release_ClosureProvider(ClosureProvider* provider) {
Justin Novosad . resolved

This is not thread safe. Have you tried using std::shared_ptr?

Justin Novosad

Perhaps it's okay to not be thread safe if this pattern is guaranteed to yield a non-Sendable closure on the swift side.

Asami Doi

I have tried to return std::shared_ptr<ClosureProvider> from MakeForSwift() but it didn't work well.
Instead, I wrap ref_count_ with std::atomic.

Open in Gerrit

Related details

Attention is currently required from:
  • Justin Novosad
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Iad6e31cf07560cc2b326e5aa23db19d474263bbf
Gerrit-Change-Number: 7572162
Gerrit-PatchSet: 12
Gerrit-Owner: Asami Doi <asam...@chromium.org>
Gerrit-Reviewer: Asami Doi <asam...@chromium.org>
Gerrit-Reviewer: Justin Novosad <ju...@chromium.org>
Gerrit-Attention: Justin Novosad <ju...@chromium.org>
Gerrit-Comment-Date: Mon, 16 Feb 2026 16:39:26 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Justin Novosad <ju...@chromium.org>
Comment-In-Reply-To: Asami Doi <asam...@chromium.org>
satisfied_requirement
unsatisfied_requirement
open
diffy

Sylvain Defresne (Gerrit)

unread,
Feb 18, 2026, 9:16:50 AM (7 days ago) Feb 18
to Asami Doi, Chromium LUCI CQ, Justin Novosad, chromium...@chromium.org, ios-revie...@chromium.org, ios-r...@chromium.org, marq+...@chromium.org
Attention needed from Asami Doi and Justin Novosad

Sylvain Defresne added 1 comment

File ios/chrome/test/swift_interop/closure/closure.h
Line 20, Patchset 13 (Latest): std::function<void()> GetRepeatingClosure();
Sylvain Defresne . unresolved
Open in Gerrit

Related details

Attention is currently required from:
  • Asami Doi
  • Justin Novosad
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Iad6e31cf07560cc2b326e5aa23db19d474263bbf
Gerrit-Change-Number: 7572162
Gerrit-PatchSet: 13
Gerrit-Owner: Asami Doi <asam...@chromium.org>
Gerrit-Reviewer: Asami Doi <asam...@chromium.org>
Gerrit-Reviewer: Justin Novosad <ju...@chromium.org>
Gerrit-CC: Sylvain Defresne <sdef...@chromium.org>
Gerrit-Attention: Justin Novosad <ju...@chromium.org>
Gerrit-Attention: Asami Doi <asam...@chromium.org>
Gerrit-Comment-Date: Wed, 18 Feb 2026 14:16:33 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Asami Doi (Gerrit)

unread,
Feb 18, 2026, 9:51:42 AM (7 days ago) Feb 18
to Sylvain Defresne, Chromium LUCI CQ, Justin Novosad, chromium...@chromium.org, ios-revie...@chromium.org, ios-r...@chromium.org, marq+...@chromium.org
Attention needed from Justin Novosad and Sylvain Defresne

Asami Doi added 1 comment

File ios/chrome/test/swift_interop/closure/closure.h
Line 20, Patchset 13 (Latest): std::function<void()> GetRepeatingClosure();
Sylvain Defresne . unresolved

`std::function<...>` is banned in Chromium code.

https://chromium.googlesource.com/chromium/src/+/main/styleguide/c++/c++-features.md#std_function-banned

Asami Doi

Yes, so I'll ask c...@chromium.org if we can accept using std::function for the C++/Swift interop case as an exception once the CL becomes stable.

Open in Gerrit

Related details

Attention is currently required from:
  • Justin Novosad
  • Sylvain Defresne
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Iad6e31cf07560cc2b326e5aa23db19d474263bbf
Gerrit-Change-Number: 7572162
Gerrit-PatchSet: 13
Gerrit-Owner: Asami Doi <asam...@chromium.org>
Gerrit-Reviewer: Asami Doi <asam...@chromium.org>
Gerrit-Reviewer: Justin Novosad <ju...@chromium.org>
Gerrit-CC: Sylvain Defresne <sdef...@chromium.org>
Gerrit-Attention: Justin Novosad <ju...@chromium.org>
Gerrit-Attention: Sylvain Defresne <sdef...@chromium.org>
Gerrit-Comment-Date: Wed, 18 Feb 2026 14:51:30 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Sylvain Defresne <sdef...@chromium.org>
satisfied_requirement
unsatisfied_requirement
open
diffy

Justin Novosad (Gerrit)

unread,
Feb 18, 2026, 10:02:47 AM (7 days ago) Feb 18
to Asami Doi, Sylvain Defresne, Chromium LUCI CQ, chromium...@chromium.org, ios-revie...@chromium.org, ios-r...@chromium.org, marq+...@chromium.org
Attention needed from Asami Doi and Sylvain Defresne

Justin Novosad added 2 comments

File ios/chrome/test/swift_interop/closure/closure.cc
Line 15, Patchset 13 (Latest):template <typename ReturnVal, typename... Args>
std::function<ReturnVal(Args...)> ToStdFunction(
base::RepeatingCallback<ReturnVal(Args...)> cb) {
return [cb = std::move(cb)](Args... args) -> ReturnVal {
return cb.Run(std::forward<Args>(args)...);
};
}

template <typename ReturnVal, typename... Args>
std::function<ReturnVal(Args...)> ToStdFunction(
base::OnceCallback<ReturnVal(Args...)> cb) {
using CallbackType = base::OnceCallback<ReturnVal(Args...)>;
// std::function requires its target to be copyable.
// By wrapping the base::OnceCallback in a std::shared_ptr, the lambda
// captures the pointer instead of the callback itself.
auto shared_cb = std::make_shared<CallbackType>(std::move(cb));

// The mutable keyword allows to move a value.
return [shared_cb](Args... args) mutable -> ReturnVal {
CHECK(shared_cb && !shared_cb->is_null())
<< "OnceCallback invoked more than once from Swift.";
return std::move(*shared_cb).Run(std::forward<Args>(args)...);
};
}
Justin Novosad . unresolved

Excellent!

Now can we move these to a header somewhere since this is re-usable code that we'll eventually want to use in the product (not just in tests).

Justin Novosad . resolved

Nice workaround!

Have you tried finding a way to export a std::function as a move-only type?

On the swift side, closest the equivalent of of R-value references is 'consuming' arguments. There may be a way of leveraging that to ensure that once callbacks can only be invoked once from the swift side.

Alternately, if we can't provide compile-time guarantees that the swift code can only call the callback once (or if we want to solve that problem later), then there should at least be a run-time check. There could be a `CHECK` statement, or perhaps an `else` clause that calls `base::debug::DumpWuithoutCrashing` when `shared_cb` is null.

Asami Doi

Thanks for the suggestion. I don't find the way to export std::function as a move-only type. I have tried to mark it with the annotation (`__attribute__((swift_attr("~Copyable")))`) but it doesn't work as intended.

I've added a CHECK(!shared_cb->is_null()) inside the lambda. This ensures a crash if the Swift code attempts to invoke the OnceClosure more than once.

Justin Novosad

I think this could be solved by using a type with a deleted copy constructor, but I'm not sure what exact incantaion will work well with interop. We can revisit this in a follow-up CL.

Open in Gerrit

Related details

Attention is currently required from:
  • Asami Doi
  • Sylvain Defresne
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Iad6e31cf07560cc2b326e5aa23db19d474263bbf
Gerrit-Change-Number: 7572162
Gerrit-PatchSet: 13
Gerrit-Owner: Asami Doi <asam...@chromium.org>
Gerrit-Reviewer: Asami Doi <asam...@chromium.org>
Gerrit-Reviewer: Justin Novosad <ju...@chromium.org>
Gerrit-CC: Sylvain Defresne <sdef...@chromium.org>
Gerrit-Attention: Asami Doi <asam...@chromium.org>
Gerrit-Attention: Sylvain Defresne <sdef...@chromium.org>
Gerrit-Comment-Date: Wed, 18 Feb 2026 15:02:37 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Justin Novosad (Gerrit)

unread,
Feb 18, 2026, 10:08:48 AM (7 days ago) Feb 18
to Asami Doi, Sylvain Defresne, Chromium LUCI CQ, chromium...@chromium.org, ios-revie...@chromium.org, ios-r...@chromium.org, marq+...@chromium.org
Attention needed from Asami Doi and Sylvain Defresne

Justin Novosad added 1 comment

File ios/chrome/test/swift_interop/closure/closure.h
Line 20, Patchset 13 (Latest): std::function<void()> GetRepeatingClosure();
Sylvain Defresne . unresolved

`std::function<...>` is banned in Chromium code.

https://chromium.googlesource.com/chromium/src/+/main/styleguide/c++/c++-features.md#std_function-banned

Asami Doi

Yes, so I'll ask c...@chromium.org if we can accept using std::function for the C++/Swift interop case as an exception once the CL becomes stable.

Justin Novosad

I think we've converged enough at this point to loop in C++ style owners. I think the main point we need to make here is that we're not using std::function on its own. We're using it as a wrapper to transport base::{Repeating|Once}Callback objects across the C++-to-swift boundary. This way, we continue to benefit from the safety features built into the base callback types.

Gerrit-Comment-Date: Wed, 18 Feb 2026 15:08:42 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Asami Doi <asam...@chromium.org>
Comment-In-Reply-To: Sylvain Defresne <sdef...@chromium.org>
satisfied_requirement
unsatisfied_requirement
open
diffy

Asami Doi (Gerrit)

unread,
Feb 19, 2026, 9:34:28 AM (6 days ago) Feb 19
to Sylvain Defresne, Chromium LUCI CQ, Justin Novosad, chromium...@chromium.org, ios-revie...@chromium.org, ios-r...@chromium.org, marq+...@chromium.org
Attention needed from Justin Novosad and Sylvain Defresne

Asami Doi added 2 comments

File ios/chrome/test/swift_interop/closure/closure.h
Line 20, Patchset 13: std::function<void()> GetRepeatingClosure();
Sylvain Defresne . unresolved

`std::function<...>` is banned in Chromium code.

https://chromium.googlesource.com/chromium/src/+/main/styleguide/c++/c++-features.md#std_function-banned

Asami Doi

Yes, so I'll ask c...@chromium.org if we can accept using std::function for the C++/Swift interop case as an exception once the CL becomes stable.

Justin Novosad

I think we've converged enough at this point to loop in C++ style owners. I think the main point we need to make here is that we're not using std::function on its own. We're using it as a wrapper to transport base::{Repeating|Once}Callback objects across the C++-to-swift boundary. This way, we continue to benefit from the safety features built into the base callback types.

Asami Doi

I have sent an email to c...@chromium.org with you in CC. Let's wait for their feedback.

File ios/chrome/test/swift_interop/closure/closure.cc
Line 15, Patchset 13:template <typename ReturnVal, typename... Args>

std::function<ReturnVal(Args...)> ToStdFunction(
base::RepeatingCallback<ReturnVal(Args...)> cb) {
return [cb = std::move(cb)](Args... args) -> ReturnVal {
return cb.Run(std::forward<Args>(args)...);
};
}

template <typename ReturnVal, typename... Args>
std::function<ReturnVal(Args...)> ToStdFunction(
base::OnceCallback<ReturnVal(Args...)> cb) {
using CallbackType = base::OnceCallback<ReturnVal(Args...)>;
// std::function requires its target to be copyable.
// By wrapping the base::OnceCallback in a std::shared_ptr, the lambda
// captures the pointer instead of the callback itself.
auto shared_cb = std::make_shared<CallbackType>(std::move(cb));

// The mutable keyword allows to move a value.
return [shared_cb](Args... args) mutable -> ReturnVal {
CHECK(shared_cb && !shared_cb->is_null())
<< "OnceCallback invoked more than once from Swift.";
return std::move(*shared_cb).Run(std::forward<Args>(args)...);
};
}
Justin Novosad . resolved

Excellent!

Now can we move these to a header somewhere since this is re-usable code that we'll eventually want to use in the product (not just in tests).

Asami Doi

I have added swift_callback_helpers.h under base/apple.

Open in Gerrit

Related details

Attention is currently required from:
  • Justin Novosad
  • Sylvain Defresne
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Iad6e31cf07560cc2b326e5aa23db19d474263bbf
Gerrit-Change-Number: 7572162
Gerrit-PatchSet: 14
Gerrit-Owner: Asami Doi <asam...@chromium.org>
Gerrit-Reviewer: Asami Doi <asam...@chromium.org>
Gerrit-Reviewer: Justin Novosad <ju...@chromium.org>
Gerrit-CC: Sylvain Defresne <sdef...@chromium.org>
Gerrit-Attention: Justin Novosad <ju...@chromium.org>
Gerrit-Attention: Sylvain Defresne <sdef...@chromium.org>
Gerrit-Comment-Date: Thu, 19 Feb 2026 14:34:15 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Justin Novosad <ju...@chromium.org>
satisfied_requirement
unsatisfied_requirement
open
diffy

Asami Doi (Gerrit)

unread,
Feb 24, 2026, 8:09:53 AM (18 hours ago) Feb 24
to Nico Weber, Sylvain Defresne, Chromium LUCI CQ, Justin Novosad, chromium...@chromium.org, ios-revie...@chromium.org, ios-r...@chromium.org, marq+...@chromium.org
Attention needed from Justin Novosad, Nico Weber and Sylvain Defresne

Asami Doi voted and added 2 comments

Votes added by Asami Doi

Commit-Queue+1

2 comments

Patchset-level comments
File-level comment, Patchset 19 (Latest):
Asami Doi . resolved

Can you review this CL? Thank you.

File ios/chrome/test/swift_interop/closure/closure.h
Line 20, Patchset 13: std::function<void()> GetRepeatingClosure();
Sylvain Defresne . resolved

`std::function<...>` is banned in Chromium code.

https://chromium.googlesource.com/chromium/src/+/main/styleguide/c++/c++-features.md#std_function-banned

Asami Doi

Yes, so I'll ask c...@chromium.org if we can accept using std::function for the C++/Swift interop case as an exception once the CL becomes stable.

Justin Novosad

I think we've converged enough at this point to loop in C++ style owners. I think the main point we need to make here is that we're not using std::function on its own. We're using it as a wrapper to transport base::{Repeating|Once}Callback objects across the C++-to-swift boundary. This way, we continue to benefit from the safety features built into the base callback types.

Asami Doi

I have sent an email to c...@chromium.org with you in CC. Let's wait for their feedback.

Asami Doi

The usage of std::function can be accepted in this limited scope. https://groups.google.com/a/chromium.org/g/cxx/c/dj6q-e4wXPc

I have added the exception to PRESUBMIT.py.

Open in Gerrit

Related details

Attention is currently required from:
  • Justin Novosad
  • Nico Weber
  • Sylvain Defresne
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Iad6e31cf07560cc2b326e5aa23db19d474263bbf
Gerrit-Change-Number: 7572162
Gerrit-PatchSet: 19
Gerrit-Owner: Asami Doi <asam...@chromium.org>
Gerrit-Reviewer: Asami Doi <asam...@chromium.org>
Gerrit-Reviewer: Justin Novosad <ju...@chromium.org>
Gerrit-Reviewer: Nico Weber <tha...@chromium.org>
Gerrit-Reviewer: Sylvain Defresne <sdef...@chromium.org>
Gerrit-Attention: Justin Novosad <ju...@chromium.org>
Gerrit-Attention: Nico Weber <tha...@chromium.org>
Gerrit-Attention: Sylvain Defresne <sdef...@chromium.org>
Gerrit-Comment-Date: Tue, 24 Feb 2026 13:09:41 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Justin Novosad (Gerrit)

unread,
Feb 24, 2026, 10:41:47 AM (16 hours ago) Feb 24
to Asami Doi, Nico Weber, Sylvain Defresne, Chromium LUCI CQ, chromium...@chromium.org, ios-revie...@chromium.org, ios-r...@chromium.org, marq+...@chromium.org
Attention needed from Asami Doi, Nico Weber and Sylvain Defresne

Justin Novosad voted and added 2 comments

Votes added by Justin Novosad

Code-Review+1

2 comments

File base/apple/swift_callback_helpers.h
Line 13, Patchset 19 (Latest):template <typename ReturnVal, typename... Args>
Justin Novosad . unresolved

Add comments that explain how and when to use these helpers.

File ios/chrome/test/swift_interop/closure/closure_xctest.swift
Line 41, Patchset 19 (Latest): closure()
Justin Novosad . unresolved

The fact that we can get rid of RunCxxClosure is fantastic.

Open in Gerrit

Related details

Attention is currently required from:
  • Asami Doi
  • Nico Weber
  • Sylvain Defresne
Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Owners
    • requirement satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: Iad6e31cf07560cc2b326e5aa23db19d474263bbf
    Gerrit-Change-Number: 7572162
    Gerrit-PatchSet: 19
    Gerrit-Owner: Asami Doi <asam...@chromium.org>
    Gerrit-Reviewer: Asami Doi <asam...@chromium.org>
    Gerrit-Reviewer: Justin Novosad <ju...@chromium.org>
    Gerrit-Reviewer: Nico Weber <tha...@chromium.org>
    Gerrit-Reviewer: Sylvain Defresne <sdef...@chromium.org>
    Gerrit-Attention: Nico Weber <tha...@chromium.org>
    Gerrit-Attention: Asami Doi <asam...@chromium.org>
    Gerrit-Attention: Sylvain Defresne <sdef...@chromium.org>
    Gerrit-Comment-Date: Tue, 24 Feb 2026 15:41:42 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Nico Weber (Gerrit)

    unread,
    Feb 24, 2026, 10:45:24 AM (16 hours ago) Feb 24
    to Asami Doi, Nico Weber, Justin Novosad, Sylvain Defresne, Chromium LUCI CQ, chromium...@chromium.org, ios-revie...@chromium.org, ios-r...@chromium.org, marq+...@chromium.org
    Attention needed from Asami Doi and Sylvain Defresne

    Nico Weber voted and added 3 comments

    Votes added by Nico Weber

    Code-Review+1

    3 comments

    Patchset-level comments
    Nico Weber . resolved

    lg once junov is happy

    File base/apple/swift_callback_helpers.h
    Line 13, Patchset 19 (Latest):template <typename ReturnVal, typename... Args>
    Justin Novosad . unresolved

    Add comments that explain how and when to use these helpers.

    Nico Weber

    +1

    Line 11, Patchset 19 (Latest):namespace swift_helpers {
    Nico Weber . resolved

    Probably should be base::swift_helpers if you want to put this in base (?)

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Asami Doi
    • Sylvain Defresne
    Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Owners
    • requirement satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: Iad6e31cf07560cc2b326e5aa23db19d474263bbf
    Gerrit-Change-Number: 7572162
    Gerrit-PatchSet: 19
    Gerrit-Owner: Asami Doi <asam...@chromium.org>
    Gerrit-Reviewer: Asami Doi <asam...@chromium.org>
    Gerrit-Reviewer: Justin Novosad <ju...@chromium.org>
    Gerrit-Reviewer: Nico Weber <tha...@chromium.org>
    Gerrit-Reviewer: Sylvain Defresne <sdef...@chromium.org>
    Gerrit-Attention: Asami Doi <asam...@chromium.org>
    Gerrit-Attention: Sylvain Defresne <sdef...@chromium.org>
    Gerrit-Comment-Date: Tue, 24 Feb 2026 15:45:17 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Comment-In-Reply-To: Justin Novosad <ju...@chromium.org>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Enrique Cab (Gerrit)

    unread,
    Feb 24, 2026, 12:12:56 PM (14 hours ago) Feb 24
    to Asami Doi, Nico Weber, Justin Novosad, Sylvain Defresne, Chromium LUCI CQ, chromium...@chromium.org, ios-revie...@chromium.org, ios-r...@chromium.org, marq+...@chromium.org
    Attention needed from Asami Doi and Sylvain Defresne

    Enrique Cab added 2 comments

    File base/apple/swift_callback_helpers.h
    Line 13, Patchset 19:template <typename ReturnVal, typename... Args>
    Justin Novosad . resolved

    Add comments that explain how and when to use these helpers.

    Nico Weber

    +1

    Enrique Cab

    Done

    File ios/chrome/test/swift_interop/closure/closure_xctest.swift
    Line 41, Patchset 19: closure()
    Justin Novosad . resolved

    The fact that we can get rid of RunCxxClosure is fantastic.

    Enrique Cab

    Marked as resolved.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Asami Doi
    • Sylvain Defresne
    Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Owners
    • requirement satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: Iad6e31cf07560cc2b326e5aa23db19d474263bbf
    Gerrit-Change-Number: 7572162
    Gerrit-PatchSet: 21
    Gerrit-Owner: Asami Doi <asam...@chromium.org>
    Gerrit-Reviewer: Asami Doi <asam...@chromium.org>
    Gerrit-Reviewer: Justin Novosad <ju...@chromium.org>
    Gerrit-Reviewer: Nico Weber <tha...@chromium.org>
    Gerrit-Reviewer: Sylvain Defresne <sdef...@chromium.org>
    Gerrit-CC: Enrique Cab <mirror...@gmail.com>
    Gerrit-Attention: Asami Doi <asam...@chromium.org>
    Gerrit-Attention: Sylvain Defresne <sdef...@chromium.org>
    Gerrit-Comment-Date: Tue, 24 Feb 2026 17:12:50 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Nico Weber <tha...@chromium.org>
    Comment-In-Reply-To: Justin Novosad <ju...@chromium.org>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Asami Doi (Gerrit)

    unread,
    Feb 24, 2026, 1:23:32 PM (13 hours ago) Feb 24
    to Enrique Cab, Nico Weber, Justin Novosad, Sylvain Defresne, Chromium LUCI CQ, chromium...@chromium.org, ios-revie...@chromium.org, ios-r...@chromium.org, marq+...@chromium.org
    Attention needed from Enrique Cab and Sylvain Defresne

    Asami Doi added 3 comments

    File base/apple/swift_callback_helpers.h
    Line 13, Patchset 19:template <typename ReturnVal, typename... Args>
    Justin Novosad . resolved

    Add comments that explain how and when to use these helpers.

    Nico Weber

    +1

    Asami Doi

    Done

    Line 11, Patchset 19:namespace swift_helpers {
    Nico Weber . resolved

    Probably should be base::swift_helpers if you want to put this in base (?)

    Asami Doi

    I have added `namespace base`. We can move this file to a different directory in a follow-up CL if we find a better place.

    File ios/chrome/test/swift_interop/closure/closure_xctest.swift
    Justin Novosad . resolved

    The fact that we can get rid of RunCxxClosure is fantastic.

    Asami Doi

    Yes, it's much simpler. Thank you.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Enrique Cab
    • Sylvain Defresne
    Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Owners
    • requirement satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: Iad6e31cf07560cc2b326e5aa23db19d474263bbf
    Gerrit-Change-Number: 7572162
    Gerrit-PatchSet: 22
    Gerrit-Owner: Asami Doi <asam...@chromium.org>
    Gerrit-Reviewer: Asami Doi <asam...@chromium.org>
    Gerrit-Reviewer: Justin Novosad <ju...@chromium.org>
    Gerrit-Reviewer: Nico Weber <tha...@chromium.org>
    Gerrit-Reviewer: Sylvain Defresne <sdef...@chromium.org>
    Gerrit-CC: Enrique Cab <mirror...@gmail.com>
    Gerrit-Attention: Enrique Cab <mirror...@gmail.com>
    Gerrit-Attention: Sylvain Defresne <sdef...@chromium.org>
    Gerrit-Comment-Date: Tue, 24 Feb 2026 18:23:14 +0000
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages