Commit 5fc301c
authored
Make
This is a preparation step for removing the Singleton<T> dependency in
config/stats_config_util.cc. The two member fields of
MacStatsConfigUtilImpl were process-global state expressed as instance
state (only one instance has ever existed, courtesy of Singleton<T>):
* config_file_ cached "${user_profile_dir}/.usagestats.db".
SystemUtil::GetUserProfileDirectory() is already called from many
places, so caching its result inside this one class does not buy
much. If profiling shows the call is hot, the right fix is to
memoize it inside SystemUtil so every caller benefits.
* "mutex_" serialized the multi-step file read/write sequence in
"SetEnabled" against concurrent callers. Process-global protection
is what we have had so far, so it is now a "constinit absl::Mutex"
at namespace scope, matching the established pattern in
"base/android_util.cc" and
"renderer/win32/win32_renderer_client.cc".
The class now holds no state, which makes the subsequent "Singleton<T>"
removal mechanical. There is no observable behavioral change in
production.
Note that we have had zero test coverage of MacStatsConfigUtilImpl for
a long time. Filling the gap has been actually difficult in practice
because a naive test would write to "${HOME}/.usagestats.db" and chmod
it, clobbering the developer's real opt-in/out state.
Now that "SystemUtil::SetUserProfileDirectory()" takes effect
immediately inside the implementation, the standard
"TestWithTempUserProfile" fixture is sufficient to redirect the file
into a per-test temp dir.
The new tests cover both branches of the CHANNEL_DEV switch for
MacStatsConfigUtilImpl:
* Stable (!CHANNEL_DEV): default-false when no file exists, the
set/get round-trip for both "true" and "false", and that
"SetEnabled" can overwrite a previously-written value. The last one
is load-bearing because "SetEnabled" chmods the file to read-only
after writing, so a subsequent "SetEnabled" must chmod it back to
writable before truncating; this test exercises that round-trip.
* Dev channel: "IsEnabled" returns "true" regardless of file state,
and "SetEnabled" is a no-op that never creates the file on disk.
PiperOrigin-RevId: 913010829MacStatsConfigUtilImpl stateless (#1496)1 parent b940437 commit 5fc301c
3 files changed
Lines changed: 90 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
139 | 145 | | |
140 | 146 | | |
141 | 147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
152 | 159 | | |
153 | 160 | | |
154 | | - | |
155 | | - | |
156 | 161 | | |
157 | 162 | | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | 163 | | |
163 | 164 | | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | 165 | | |
170 | 166 | | |
171 | 167 | | |
172 | 168 | | |
173 | | - | |
| 169 | + | |
174 | 170 | | |
175 | 171 | | |
176 | | - | |
| 172 | + | |
| 173 | + | |
177 | 174 | | |
178 | 175 | | |
179 | 176 | | |
| |||
197 | 194 | | |
198 | 195 | | |
199 | 196 | | |
200 | | - | |
| 197 | + | |
201 | 198 | | |
202 | 199 | | |
203 | | - | |
204 | | - | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
205 | 203 | | |
206 | | - | |
| 204 | + | |
207 | 205 | | |
208 | 206 | | |
209 | 207 | | |
| |||
212 | 210 | | |
213 | 211 | | |
214 | 212 | | |
215 | | - | |
| 213 | + | |
216 | 214 | | |
217 | 215 | | |
218 | 216 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
41 | 53 | | |
42 | 54 | | |
43 | 55 | | |
| |||
674 | 686 | | |
675 | 687 | | |
676 | 688 | | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
677 | 745 | | |
678 | 746 | | |
679 | 747 | | |
| |||
0 commit comments