Deprecate Shutdown.ShutdownType metric

This CL is deprecating the ShutdownType metrics and prefs value.
The ShutdownType2 is more reliable and doesn't require the value
to be stored in local_state.

Follow-up on: https://chromium-review.googlesource.com/c/chromium/src/+/4742700

OBSOLETE_HISTOGRAMS="Shutdown Metrics V1 are replaced by Shutdown Metrics V2"

Change-Id: Ic7d5b8293d34d4148d7d56fd45d382516404ca71
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4750201
Reviewed-by: Scott Violet <[email protected]>
Reviewed-by: Luc Nguyen <[email protected]>
Commit-Queue: Etienne Bergeron <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1180308}
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc
index 2911f6b8..b3b7f85 100644
--- a/chrome/browser/chrome_browser_main.cc
+++ b/chrome/browser/chrome_browser_main.cc
@@ -1404,9 +1404,6 @@
   // running.
   browser_process_->PreMainMessageLoopRun();
 
-  // Record last shutdown time into a histogram.
-  browser_shutdown::ReadLastShutdownInfo();
-
 #if BUILDFLAG(IS_WIN)
   // If the command line specifies 'uninstall' then we need to work here
   // unless we detect another chrome browser running.
diff --git a/chrome/browser/lifetime/browser_shutdown.cc b/chrome/browser/lifetime/browser_shutdown.cc
index 6ceb274..4f088f60 100644
--- a/chrome/browser/lifetime/browser_shutdown.cc
+++ b/chrome/browser/lifetime/browser_shutdown.cc
@@ -111,8 +111,6 @@
 }  // namespace
 
 void RegisterPrefs(PrefRegistrySimple* registry) {
-  registry->RegisterIntegerPref(prefs::kShutdownType,
-                                static_cast<int>(ShutdownType::kNotValid));
   registry->RegisterBooleanPref(prefs::kRestartLastSessionOnShutdown, false);
 }
 
@@ -248,12 +246,6 @@
 bool RecordShutdownInfoPrefs() {
   CheckAccessedOnCorrectThread();
   PrefService* prefs = g_browser_process->local_state();
-  if (g_shutdown_type != ShutdownType::kNotValid &&
-      g_shutdown_num_processes > 0) {
-    // Record the shutdown info so that we can put it into a histogram at next
-    // startup.
-    prefs->SetInteger(prefs::kShutdownType, static_cast<int>(g_shutdown_type));
-  }
 
   // Check local state for the restart flag so we can restart the session later.
   bool restart_last_session = false;
@@ -336,17 +328,6 @@
 }
 #endif  // !BUILDFLAG(IS_ANDROID)
 
-void ReadLastShutdownInfo() {
-  PrefService* prefs = g_browser_process->local_state();
-  ShutdownType type =
-      static_cast<ShutdownType>(prefs->GetInteger(prefs::kShutdownType));
-  // clear the prefs immediately so we don't pick them up on a future run
-  prefs->SetInteger(prefs::kShutdownType,
-                    static_cast<int>(ShutdownType::kNotValid));
-
-  base::UmaHistogramEnumeration("Shutdown.ShutdownType", type);
-}
-
 void SetTryingToQuit(bool quitting) {
   CheckAccessedOnCorrectThread();
   g_trying_to_quit = quitting;
diff --git a/chrome/browser/lifetime/browser_shutdown.h b/chrome/browser/lifetime/browser_shutdown.h
index 35990bd..a215406 100644
--- a/chrome/browser/lifetime/browser_shutdown.h
+++ b/chrome/browser/lifetime/browser_shutdown.h
@@ -100,9 +100,6 @@
 void ShutdownPostThreadsStop(RestartMode restart_mode);
 #endif
 
-// Called at startup to create a histogram from our previous shutdown time.
-void ReadLastShutdownInfo();
-
 // There are various situations where the browser process should continue to
 // run after the last browser window has closed - the Mac always continues
 // running until the user explicitly quits, and on Windows/Linux the application
diff --git a/chrome/browser/lifetime/browser_shutdown_browsertest.cc b/chrome/browser/lifetime/browser_shutdown_browsertest.cc
index 817b5c0..3867fb1 100644
--- a/chrome/browser/lifetime/browser_shutdown_browsertest.cc
+++ b/chrome/browser/lifetime/browser_shutdown_browsertest.cc
@@ -81,8 +81,16 @@
   histogram_tester_.ExpectTotalCount("Shutdown.Renderers.Total2", 1);
 }
 
+// Flakes on Mac12.0: https://crbug.com/1259913
+#if BUILDFLAG(IS_MAC)
+#define MAYBE_TwoBrowsersClosingShutdownHistograms \
+  DISABLED_TwoBrowsersClosingShutdownHistograms
+#else
+#define MAYBE_TwoBrowsersClosingShutdownHistograms \
+  TwoBrowsersClosingShutdownHistograms
+#endif
 IN_PROC_BROWSER_TEST_F(BrowserShutdownBrowserTest,
-                       PRE_TwoBrowsersClosingShutdownHistograms) {
+                       MAYBE_TwoBrowsersClosingShutdownHistograms) {
   ASSERT_TRUE(
       ui_test_utils::NavigateToURL(browser(), GURL("browser://version")));
   Browser* browser2 = CreateBrowser(browser()->profile());
@@ -113,21 +121,6 @@
   histogram_tester_.ExpectTotalCount("Shutdown.WindowClose.Time2", 1);
   histogram_tester_.ExpectTotalCount("Shutdown.Renderers.Total2", 1);
 }
-
-// Flakes on Mac12.0: https://crbug.com/1259913
-#if BUILDFLAG(IS_MAC)
-#define MAYBE_TwoBrowsersClosingShutdownHistograms \
-  DISABLED_TwoBrowsersClosingShutdownHistograms
-#else
-#define MAYBE_TwoBrowsersClosingShutdownHistograms \
-  TwoBrowsersClosingShutdownHistograms
-#endif
-IN_PROC_BROWSER_TEST_F(BrowserShutdownBrowserTest,
-                       MAYBE_TwoBrowsersClosingShutdownHistograms) {
-  histogram_tester_.ExpectUniqueSample(
-      "Shutdown.ShutdownType",
-      static_cast<int>(browser_shutdown::ShutdownType::kWindowClose), 1);
-}
 #else
 // On Chrome OS, the shutdown accelerator is handled by Ash and requires
 // confirmation, so Chrome shouldn't try to shut down after it's been hit one
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index befcd701..d09865f 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -956,6 +956,7 @@
 // Deprecated 07/2023.
 const char kShutdownNumProcesses[] = "shutdown.num_processes";
 const char kShutdownNumProcessesSlow[] = "shutdown.num_processes_slow";
+const char kShutdownType[] = "shutdown.type";
 
 // Register local state used only for migration (clearing or moving to a new
 // key).
@@ -1091,6 +1092,7 @@
   // Deprecated 07/2023.
   registry->RegisterIntegerPref(kShutdownNumProcesses, 0);
   registry->RegisterIntegerPref(kShutdownNumProcessesSlow, 0);
+  registry->RegisterIntegerPref(kShutdownType, 0);
 }
 
 // Register prefs used only for migration (clearing or moving to a new key).
@@ -2206,6 +2208,7 @@
   // Added 07/2023.
   local_state->ClearPref(kShutdownNumProcesses);
   local_state->ClearPref(kShutdownNumProcessesSlow);
+  local_state->ClearPref(kShutdownType);
 
   // Please don't delete the following line. It is used by PRESUBMIT.py.
   // END_MIGRATE_OBSOLETE_LOCAL_STATE_PREFS