Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ index 0000000000000..c191fb3963968
+}
+
+void SyncDefaultTheme(PrefService* pref_service) {
+ // BrowserOS: If the user is using a system theme (GTK on Linux), do not
+ // overwrite it with the default BrowserOS value.
+ if (pref_service->GetBoolean(::prefs::kUsesSystemTheme)) {
+ return;
+ }
Comment on lines +68 to +70
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Potential crash on non-Linux platforms

::prefs::kUsesSystemTheme is a Linux-specific preference in Chromium. On macOS and Windows, this preference is typically not registered. Calling pref_service->GetBoolean() on an unregistered preference is a CHECK failure in debug builds and undefined behavior in release builds.

Since SyncDefaultTheme appears to be called cross-platform, this guard should be wrapped in a Linux build flag, or a safer FindPreference pattern (matching the existing pattern used for kUserColor below) should be used:

Suggested change
+ if (pref_service->GetBoolean(::prefs::kUsesSystemTheme)) {
+ return;
+ }
// BrowserOS: If the user is using a system theme (GTK on Linux), do not
// overwrite it with the default BrowserOS value.
#if BUILDFLAG(IS_LINUX)
if (pref_service->GetBoolean(::prefs::kUsesSystemTheme)) {
return;
}
#endif

Alternatively, mirror the safer pattern already used in this function:

  const PrefService::Preference* system_theme_pref =
      pref_service->FindPreference(::prefs::kUsesSystemTheme);
  if (system_theme_pref && system_theme_pref->GetValue()->GetBool()) {
    return;
  }
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/browseros/chromium_patches/chrome/browser/browseros/core/browseros_prefs.cc
Line: 68-70

Comment:
**Potential crash on non-Linux platforms**

`::prefs::kUsesSystemTheme` is a Linux-specific preference in Chromium. On macOS and Windows, this preference is typically not registered. Calling `pref_service->GetBoolean()` on an unregistered preference is a `CHECK` failure in debug builds and undefined behavior in release builds.

Since `SyncDefaultTheme` appears to be called cross-platform, this guard should be wrapped in a Linux build flag, or a safer `FindPreference` pattern (matching the existing pattern used for `kUserColor` below) should be used:

```suggestion
  // BrowserOS: If the user is using a system theme (GTK on Linux), do not
  // overwrite it with the default BrowserOS value.
#if BUILDFLAG(IS_LINUX)
  if (pref_service->GetBoolean(::prefs::kUsesSystemTheme)) {
    return;
  }
#endif

```

Alternatively, mirror the safer pattern already used in this function:

```cpp
  const PrefService::Preference* system_theme_pref =
      pref_service->FindPreference(::prefs::kUsesSystemTheme);
  if (system_theme_pref && system_theme_pref->GetValue()->GetBool()) {
    return;
  }
```

How can I resolve this? If you propose a fix, please make it concise.

+
+ const PrefService::Preference* user_color_pref =
+ pref_service->FindPreference(::prefs::kUserColor);
+ if (user_color_pref && user_color_pref->IsDefaultValue()) {
Expand Down
Loading