Clean up cros_ui.restart() API

cros_ui.restart() took a callable to allow a custom mechanism
for restarting the UI. The only thing using this was passing
in a pyauto method, which was deprecated ages ago. Remove this
but allow instead for the caller to specify that it's OK
for the UI to be down already when calling cros_ui.restart().

BUG=None
TEST=stop ui and then run login_OwnershipRetaken

Change-Id: I78286a5edc777f6a96e2b48e13d386c3a9fd6d0b
Reviewed-on: https://chromium-review.googlesource.com/210054
Tested-by: Chris Masone <cmasone@chromium.org>
Reviewed-by: Richard Barnette <jrbarnette@chromium.org>
Commit-Queue: Chris Masone <cmasone@chromium.org>
diff --git a/client/cros/cros_ui.py b/client/cros/cros_ui.py
index 8aa436d..a060e9a 100644
--- a/client/cros/cros_ui.py
+++ b/client/cros/cros_ui.py
@@ -138,17 +138,18 @@
     return result
 
 
-def restart(impl=None):
+def restart(report_stop_failure=False):
     """Restart the session manager.
 
     - If the user is logged in, the session will be terminated.
+    - If the UI is currently down, just go ahead and bring it up unless the
+      caller has requested that a failure to stop be reported.
     - To ensure all processes are up and ready, this function will wait
       for the login prompt to show up and be marked as visible.
 
-    Args:
-        impl: Method to use to restart the session manager. By
-              default, the session manager is restarted using upstart.
-
+    @param report_stop_failure: False by default, set to True if you care about
+                                the UI being up at the time of call and
+                                successfully torn down by this call.
     """
     state = get_login_prompt_state()
 
@@ -157,11 +158,9 @@
     utils.system('logger "%s"' % UI_RESTART_ATTEMPT_MSG)
 
     try:
-        if impl is not None:
-            impl()
-        elif utils.system('restart ui', ignore_status=True) != 0:
+        if stop(allow_fail=not report_stop_failure) != 0:
             raise error.TestError('Could not stop session')
-
+        start(wait_for_login_prompt=False)
         # Wait for login prompt to appear to indicate that all processes are
         # up and running again.
         wait_for_chrome_ready(state)
diff --git a/client/cros/cros_ui_test.py b/client/cros/cros_ui_test.py
index 2fc2178..afffd21 100644
--- a/client/cros/cros_ui_test.py
+++ b/client/cros/cros_ui_test.py
@@ -427,7 +427,7 @@
         self._save_logs_from_cryptohome()
 
         try:
-            cros_ui.restart(self.pyauto.Logout)
+            cros_ui.restart()
         except:
             self.__perform_ui_diagnostics()
             if not login.wait_for_browser_exit('Chrome crashed during logout'):
diff --git a/client/cros/ownership.py b/client/cros/ownership.py
index d5a5258..cc4c41a 100644
--- a/client/cros/ownership.py
+++ b/client/cros/ownership.py
@@ -87,7 +87,7 @@
     The UI must be stopped while we do this, or the session_manager will
     write the policy and key files out again.
     """
-    cros_ui.stop()
+    cros_ui.stop(allow_fail=not cros_ui.is_up())
     clear_ownership_files_no_restart()
     cros_ui.start()