Various upgrade_util improvements.

- upgrade_util.{cc,h} and friends are now only included in the build for
  relevant platforms (desktop Chrome).
- upgrade_util::SetNewCommandLine now explicitly takes ownership of its
  argument.
- A test seam has been added to RelaunchChromeBrowser. Tests may now
  specify a callback to be run when relaunch takes place.
- Unexpected calls to RelaunchChromeBrowser in browser_tests and friends
  now cause test failures (they previously attempted to launch Chrome).
- ScopedRelaunchChromeBrowserOverride is now available for tests of
  scenarios that involved RelaunchChromeBrowser.

BUG=958893,989468

Change-Id: I8620e2bbe56e282934b94b3ea2ae52ef32f9d04a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1736707
Auto-Submit: Greg Thompson <[email protected]>
Reviewed-by: Gabriel Charette <[email protected]>
Reviewed-by: Marc Treib <[email protected]>
Commit-Queue: Greg Thompson <[email protected]>
Cr-Commit-Position: refs/heads/master@{#685466}
diff --git a/chrome/browser/first_run/upgrade_util.h b/chrome/browser/first_run/upgrade_util.h
index 93e1c6d..859b9a09 100644
--- a/chrome/browser/first_run/upgrade_util.h
+++ b/chrome/browser/first_run/upgrade_util.h
@@ -5,16 +5,15 @@
 #ifndef CHROME_BROWSER_FIRST_RUN_UPGRADE_UTIL_H_
 #define CHROME_BROWSER_FIRST_RUN_UPGRADE_UTIL_H_
 
+#include <memory>
+
+#include "base/callback_forward.h"
 #include "build/build_config.h"
 
 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
 #error Not used on Android or ChromeOS
 #endif
 
-#if defined(OS_WIN)
-#include <string>
-#endif
-
 namespace base {
 class CommandLine;
 }
@@ -27,10 +26,12 @@
 
 #if !defined(OS_MACOSX)
 
-void SetNewCommandLine(base::CommandLine* new_command_line);
+// Sets a command line to be used to relaunch the browser upon exit.
+void SetNewCommandLine(std::unique_ptr<base::CommandLine> new_command_line);
 
-// Launches a new instance of the browser if the current instance in persistent
-// mode an upgrade is detected.
+// Launches a new instance of the browser using a command line previously
+// provided to SetNewCommandLine. This is typically used to finalize an in-use
+// update that was detected while the browser was in persistent mode.
 void RelaunchChromeBrowserWithNewCommandLineIfNeeded();
 
 // Windows:
@@ -42,6 +43,15 @@
 
 #endif  // !defined(OS_MACOSX)
 
+using RelaunchChromeBrowserCallback =
+    base::RepeatingCallback<bool(const base::CommandLine&)>;
+
+// Sets |callback| to be run to process a RelaunchChromeBrowser request. This
+// is a test seam for whole-browser tests. See
+// ScopedRelaunchChromeBrowserOverride for convenience.
+RelaunchChromeBrowserCallback SetRelaunchChromeBrowserCallbackForTesting(
+    RelaunchChromeBrowserCallback callback);
+
 }  // namespace upgrade_util
 
 #endif  // CHROME_BROWSER_FIRST_RUN_UPGRADE_UTIL_H_