Skip to content

Commit 8afabae

Browse files
tsepezchromeos-ci-prod
authored andcommitted
Mark many more base/ accessors as lifetime bound
Bug: 375244062 Change-Id: I8aabba49af73c64f282e51e7ae99d036274f16b7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5959167 Commit-Queue: Tom Sepez <[email protected]> Reviewed-by: Daniel Cheng <[email protected]> Cr-Commit-Position: refs/heads/main@{#1374042} CrOS-Libchrome-Original-Commit: 04e98bf9e13012fda48001096174a4500ff27866
1 parent 8117c34 commit 8afabae

40 files changed

+148
-87
lines changed

base/containers/intrusive_heap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,8 @@ class WithHeapHandle : public InternalHeapHandleStorage {
729729
WithHeapHandle& operator=(const WithHeapHandle&) = delete;
730730
WithHeapHandle& operator=(WithHeapHandle&& other) = default;
731731

732-
T& value() { return value_; }
733-
const T& value() const { return value_; }
732+
T& value() LIFETIME_BOUND { return value_; }
733+
const T& value() const LIFETIME_BOUND { return value_; }
734734

735735
// Utility functions.
736736
void swap(WithHeapHandle& other) noexcept;

base/debug/allocation_trace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class BASE_EXPORT OperationRecord {
6666
// Number of allocated bytes. Returns 0 for free operations.
6767
size_t GetSize() const;
6868
// The stacktrace as taken by the Initialize*-functions.
69-
const StackTraceContainer& GetStackTrace() const;
69+
const StackTraceContainer& GetStackTrace() const LIFETIME_BOUND;
7070

7171
// Initialize the record with data for another operation. Data from any
7272
// previous operation will be silently overwritten. These functions are

base/files/file_path.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
#include <vector>
110110

111111
#include "base/base_export.h"
112+
#include "base/compiler_specific.h"
112113
#include "base/trace_event/base_tracing_forward.h"
113114
#include "build/build_config.h"
114115

@@ -217,7 +218,7 @@ class BASE_EXPORT FilePath {
217218
return path_ < that.path_;
218219
}
219220

220-
const StringType& value() const { return path_; }
221+
const StringType& value() const LIFETIME_BOUND { return path_; }
221222

222223
[[nodiscard]] bool empty() const { return path_.empty(); }
223224

base/files/important_file_writer.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <string_view>
1212

1313
#include "base/base_export.h"
14+
#include "base/compiler_specific.h"
1415
#include "base/files/file_path.h"
1516
#include "base/functional/callback.h"
1617
#include "base/memory/raw_ptr.h"
@@ -103,7 +104,7 @@ class BASE_EXPORT ImportantFileWriter {
103104
// of destruction.
104105
~ImportantFileWriter();
105106

106-
const FilePath& path() const { return path_; }
107+
const FilePath& path() const LIFETIME_BOUND { return path_; }
107108

108109
// Returns true if there is a scheduled write pending which has not yet
109110
// been started.
@@ -155,10 +156,12 @@ class BASE_EXPORT ImportantFileWriter {
155156
}
156157

157158
private:
158-
const OneShotTimer& timer() const {
159+
const OneShotTimer& timer() const LIFETIME_BOUND {
160+
return timer_override_ ? *timer_override_ : timer_;
161+
}
162+
OneShotTimer& timer() LIFETIME_BOUND {
159163
return timer_override_ ? *timer_override_ : timer_;
160164
}
161-
OneShotTimer& timer() { return timer_override_ ? *timer_override_ : timer_; }
162165

163166
// Same as WriteNow() but it uses a promise-like signature that allows running
164167
// custom logic in the background sequence.

base/files/safe_base_name.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <optional>
99

1010
#include "base/base_export.h"
11+
#include "base/compiler_specific.h"
1112
#include "base/files/file_path.h"
1213

1314
namespace base {
@@ -30,11 +31,13 @@ class BASE_EXPORT SafeBaseName {
3031

3132
// Same as above, but takes a StringPieceType for convenience.
3233
static std::optional<SafeBaseName> Create(FilePath::StringPieceType);
33-
const FilePath& path() const { return path_; }
34+
const FilePath& path() const LIFETIME_BOUND { return path_; }
3435

3536
// Convenience functions.
3637
const std::string AsUTF8Unsafe() const { return path_.AsUTF8Unsafe(); }
37-
const FilePath::StringType& value() const { return path_.value(); }
38+
const FilePath::StringType& value() const LIFETIME_BOUND {
39+
return path_.value();
40+
}
3841
[[nodiscard]] bool empty() const { return path_.empty(); }
3942

4043
bool operator==(const SafeBaseName& that) const;

base/files/scoped_temp_dir.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// intervening calls to Delete or Take, or the calls will fail.
1919

2020
#include "base/base_export.h"
21+
#include "base/compiler_specific.h"
2122
#include "base/files/file_path.h"
2223

2324
namespace base {
@@ -53,7 +54,7 @@ class BASE_EXPORT ScopedTempDir {
5354

5455
// Returns the path to the created directory. Call one of the
5556
// CreateUniqueTempDir* methods before getting the path.
56-
const FilePath& GetPath() const;
57+
const FilePath& GetPath() const LIFETIME_BOUND;
5758

5859
// Returns true if path_ is non-empty and exists.
5960
bool IsValid() const;

base/memory/discardable_shared_memory.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <stddef.h>
99

1010
#include "base/base_export.h"
11+
#include "base/compiler_specific.h"
1112
#include "base/containers/span.h"
1213
#include "base/dcheck_is_on.h"
1314
#include "base/memory/shared_memory_mapping.h"
@@ -91,7 +92,7 @@ class BASE_EXPORT DiscardableSharedMemory {
9192
// Returns an ID for the shared memory region. This is ID of the mapped region
9293
// consistent across all processes and is valid as long as the region is not
9394
// unmapped.
94-
const UnguessableToken& mapped_id() const {
95+
const UnguessableToken& mapped_id() const LIFETIME_BOUND {
9596
return shared_memory_mapping_.guid();
9697
}
9798

base/memory/platform_shared_memory_region.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <optional>
1111

1212
#include "base/base_export.h"
13+
#include "base/compiler_specific.h"
1314
#include "base/containers/span.h"
1415
#include "base/gtest_prod_util.h"
1516
#include "base/memory/platform_shared_memory_handle.h"
@@ -203,7 +204,7 @@ class BASE_EXPORT PlatformSharedMemoryRegion {
203204
// created by calling |MapAt()| above.
204205
static void Unmap(span<uint8_t> mapping, SharedMemoryMapper* mapper);
205206

206-
const UnguessableToken& GetGUID() const { return guid_; }
207+
const UnguessableToken& GetGUID() const LIFETIME_BOUND { return guid_; }
207208

208209
size_t GetSize() const { return size_; }
209210

base/memory/protected_memory.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
#include "base/bits.h"
8686
#include "base/check.h"
8787
#include "base/check_op.h"
88+
#include "base/compiler_specific.h"
8889
#include "base/gtest_prod_util.h"
8990
#include "base/memory/page_size.h"
9091
#include "base/memory/protected_memory_buildflags.h"
@@ -191,8 +192,8 @@ class ProtectedDataHolder {
191192
public:
192193
consteval ProtectedDataHolder() = default;
193194

194-
T& GetReference() { return *GetPointer(); }
195-
const T& GetReference() const { return *GetPointer(); }
195+
T& GetReference() LIFETIME_BOUND { return *GetPointer(); }
196+
const T& GetReference() const LIFETIME_BOUND { return *GetPointer(); }
196197

197198
T* GetPointer() {
198199
CHECK(constructed_);

base/memory/read_only_shared_memory_region.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
#ifndef BASE_MEMORY_READ_ONLY_SHARED_MEMORY_REGION_H_
66
#define BASE_MEMORY_READ_ONLY_SHARED_MEMORY_REGION_H_
77

8+
#include <stdint.h>
9+
810
#include "base/base_export.h"
911
#include "base/check.h"
1012
#include "base/check_op.h"
13+
#include "base/compiler_specific.h"
1114
#include "base/memory/platform_shared_memory_region.h"
1215
#include "base/memory/shared_memory_mapping.h"
1316

14-
#include <stdint.h>
15-
1617
namespace base {
1718

1819
struct MappedReadOnlyRegion;
@@ -107,7 +108,7 @@ class BASE_EXPORT ReadOnlySharedMemoryRegion {
107108
}
108109

109110
// Returns 128-bit GUID of the region.
110-
const UnguessableToken& GetGUID() const {
111+
const UnguessableToken& GetGUID() const LIFETIME_BOUND {
111112
DCHECK(IsValid());
112113
return handle_.GetGUID();
113114
}

0 commit comments

Comments
 (0)