| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Thanks. String changes look good, but Gemini noted a problem on the forward declaration.
Change-Id: I39d938185c3810502e3050d91b251fd87578bd89Please associate changes with a bug whenever possible, which is useful for context and for grouping together related CLs.
static base::FilePath GenerateTracingFilePath(std::string_view basename);Gemini noted a concern with this return type:
Return-by-Value with Forward Declaration
Issue: You cannot return a class by value if the compiler only sees a forward
declaration. The compiler needs the full definition of base::FilePath to
determine the return value's size and layout at the call site for any file
that includes this header.
Remediation: Revert the removal of #include "base/files/file_path.h" in
tracing_controller_android.h. Forward declarations are only suitable for
pointers or references.
It appears the compiler didn't complain, but Gemini confirmed it's still an issue:
1. Self-Contained Headers
Chromium follows the Google C++ Style Guide
(https://google.github.io/styleguide/cppguide.html#Self_contained_Headers),
which requires headers to be "self-contained." This means any file including
tracing_controller_android.h should be able to use its public API without
having to manually include additional dependencies.
Because GenerateTracingFilePath returns a base::FilePath by value, any caller
of this method will immediately encounter a compilation error unless they also
include base/files/file_path.h. By removing the include from the header, you
are offloading the "cost" of the include to every single call site, which
often results in more maintenance overhead and less readable code.
2. When to Forward Declare
The general rule in Chromium (and modern C++) is:
* Forward declare when the type is only used as a pointer or reference.
* Include when the type is used by value (as a member variable or a return
value), because the compiler needs to know the object's size and layout to
generate code at the call site.
Analysis of this Specific Case
In your patch, you actually had to add #include "base/files/file_path.h" to
startup_tracing_controller.cc precisely because the forward declaration in the
header was insufficient for the call site.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
LGTM, ideally once a bug number is added.
static base::FilePath GenerateTracingFilePath(std::string_view basename);Conflicting style guides are fun. Given "You can and should use forward declarations for most types passed or returned by value, reference, or pointer" from that link, this seems to be an approved case.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +2 |
Please associate changes with a bug whenever possible, which is useful for context and for grouping together related CLs.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
2 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
[Tracing] Modernize string handling and header hygiene
- Update TracingControllerAndroid::GenerateTracingFilePath to take a
std::string_view instead of const std::string&.
- Improve header hygiene in tracing_controller_android.h by using a
forward declaration for base::FilePath and moving the include to the
implementation.
- Update StartupTracingController to use std::string_view for basename
handling and std::move for property setters.
These changes reduce unnecessary string copies and improve compilation
times by pruning header dependencies.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |