Replace BrowserProces::AddRefModule/RemoveModule by ScopedKeepAlive

Uses ScopedKeepAlive for Browser and menus, and remove references
to other separate counters to keep Chrome alive. KeepAliveRegistry
should now be the source of truth to look up what is keeping the
browser process running.

Doing so breaks many assumptions from the unit and browser tests,
so most changes are to fix them.

BUG=587926

Review URL: https://codereview.chromium.org/1803143002

Cr-Commit-Position: refs/heads/master@{#381938}
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index 07f98719..e62dd47 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -62,6 +62,8 @@
 #include "chrome/browser/infobars/infobar_service.h"
 #include "chrome/browser/lifetime/application_lifetime.h"
 #include "chrome/browser/lifetime/keep_alive_registry.h"
+#include "chrome/browser/lifetime/keep_alive_types.h"
+#include "chrome/browser/lifetime/scoped_keep_alive.h"
 #include "chrome/browser/memory/tab_manager_web_contents_data.h"
 #include "chrome/browser/notifications/notification_ui_manager.h"
 #include "chrome/browser/pepper_broker_infobar_delegate.h"
@@ -938,6 +940,14 @@
   signin_view_controller_.ShowModalSyncConfirmationDialog(this);
 }
 
+void Browser::RegisterKeepAlive() {
+  keep_alive_.reset(new ScopedKeepAlive(KeepAliveOrigin::BROWSER,
+                                        KeepAliveRestartOption::DISABLED));
+}
+void Browser::UnregisterKeepAlive() {
+  keep_alive_.reset();
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 // Browser, PageNavigator implementation: