Don't add Chromium as a login item

"Background mode" is about allowing background apps to continue running
even when Chromium is closed. What does "closed" mean, though? On
Windows, an app is "closed" if it has no windows open, so on Windows,
background mode keeps the actual chrome.exe running with just an
indication in the system tray.

This has always mapped imperfectly to the Mac, where apps cannot run
without an active Dock icon, yet can remain running without any windows
open. With this mismatch, early on, background mode was implemented on
the Mac to add a login item if an extension was marked as requesting
background mode.

However, using a login item in this way does not significantly improve
the experience of background mode. In addition, the state of the world
has also changed:

- For many years now, macOS has automatically resumed apps that were
running prior to shutdown. This means that the system is, in many
cases, automatically restarting Chromium anyway.

- macOS Ventura adds more restrictions in the area of adding code to
run at startup/login, so this isn't a place that is desirable to be in
anyway.

And finally, given the age of the bug and its number of stars, it's
not clear that this code worked well in the first place.

Given all that, the decision was made to remove the "background mode =
create login item" code on the Mac.

Fixed: 140017
Change-Id: I01b0f20e0bbd3b30bdfd82a9eabfb6ae20437ef0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3997795
Reviewed-by: Devlin Cronin <[email protected]>
Reviewed-by: Mark Mentovai <[email protected]>
Commit-Queue: Avi Drissman <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1066674}
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 67fc241..c6fc5783 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -775,6 +775,15 @@
     "ash.launcher.suggested_content_info_dismissed";
 #endif
 
+#if BUILDFLAG(ENABLE_BACKGROUND_MODE) && BUILDFLAG(IS_MAC)
+// Deprecated 11/2022.
+const char kUserRemovedLoginItem[] = "background_mode.user_removed_login_item";
+const char kChromeCreatedLoginItem[] =
+    "background_mode.chrome_created_login_item";
+const char kMigratedLoginItemPref[] =
+    "background_mode.migrated_login_item_pref";
+#endif
+
 // Register local state used only for migration (clearing or moving to a new
 // key).
 void RegisterLocalStatePrefsForMigration(PrefRegistrySimple* registry) {
@@ -837,6 +846,13 @@
   // Deprecated 09/2022
   registry->RegisterDictionaryPref(kUsersLastInputMethod);
 #endif  // BUILDFLAG(IS_CHROMEOS_ASH)
+
+// Deprecated 11/2022.
+#if BUILDFLAG(ENABLE_BACKGROUND_MODE) && BUILDFLAG(IS_MAC)
+  registry->RegisterBooleanPref(kUserRemovedLoginItem, false);
+  registry->RegisterBooleanPref(kChromeCreatedLoginItem, false);
+  registry->RegisterBooleanPref(kMigratedLoginItemPref, false);
+#endif  // BUILDFLAG(IS_CHROMEOS_ASH)
 }
 
 // Register prefs used only for migration (clearing or moving to a new key).
@@ -1743,6 +1759,13 @@
   local_state->ClearPref(kUsersLastInputMethod);
 #endif  // BUILDFLAG(IS_CHROMEOS_ASH)
 
+#if BUILDFLAG(ENABLE_BACKGROUND_MODE) && BUILDFLAG(IS_MAC)
+  // Added 11/2022.
+  local_state->ClearPref(kUserRemovedLoginItem);
+  local_state->ClearPref(kChromeCreatedLoginItem);
+  local_state->ClearPref(kMigratedLoginItemPref);
+#endif
+
   // Please don't delete the following line. It is used by PRESUBMIT.py.
   // END_MIGRATE_OBSOLETE_LOCAL_STATE_PREFS