Revert "Restore web app windows when session restore is enabled."

This partially reverts commit 9aa56a4612d13c491e60c9500915dbda2ac9f2a1.

Although this fixes issue 938759, it introduces issue 953965 which is not easily fixed.
I'll add more detail on the right fix in issue 938759.

The piece that ensures the default browser prompt isn't shown in an app window
is kept as this is still useful.

Original change's description:
> Restore web app windows when session restore is enabled.
>
> App windows are currently only restored through session restore when
> Chrome is restarted on Chrome OS.
>
> This CL includes standalone web app windows on other desktop platforms
> in session restore. This ensures that when Chrome is quit with web apps
> open, those web apps will be reopened if the user has opted into
> "continue where I left off" upon restarting. Session service tests are
> updated to account for this change in behaviour.
>
> The default browser prompt is also updated to ensure it never shows in
> an app window (which may now be the "last active" browser object at
> startup depending on the order in which the windows are restored).
>
> BUG=938759
>
> Change-Id: I4f0927e03b3c472f67e8dbee81233d6b453a7d68
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1504477
> Commit-Queue: Dominick Ng <dominickn@chromium.org>
> Reviewed-by: Tommy Martino <tmartino@chromium.org>
> Reviewed-by: Chris Hamilton <chrisha@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#639187}

TBR=chrisha@chromium.org,tmartino@chromium.org,dominickn@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 938759
Change-Id: I72534ece9254656c92bfb634bc1a464311e4146f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1657508
Reviewed-by: Dominick Ng <dominickn@chromium.org>
Reviewed-by: Chris Hamilton <chrisha@chromium.org>
Reviewed-by: Raymes Khoury <raymes@chromium.org>
Commit-Queue: Raymes Khoury <raymes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#669551}
diff --git a/chrome/browser/sessions/session_service.cc b/chrome/browser/sessions/session_service.cc
index e4aef68..180b188 100644
--- a/chrome/browser/sessions/session_service.cc
+++ b/chrome/browser/sessions/session_service.cc
@@ -40,7 +40,6 @@
 #include "chrome/browser/ui/startup/startup_browser_creator.h"
 #include "chrome/browser/ui/tabs/tab_group_id.h"
 #include "chrome/browser/ui/tabs/tab_strip_model.h"
-#include "chrome/browser/web_applications/components/web_app_helpers.h"
 #include "components/sessions/content/content_serialized_navigation_builder.h"
 #include "components/sessions/core/session_command.h"
 #include "components/sessions/core/session_constants.h"
@@ -68,18 +67,6 @@
 // Every kWritesPerReset commands triggers recreating the file.
 static const int kWritesPerReset = 250;
 
-namespace {
-
-SessionService::AppType AppTypeForAppName(const std::string& app_name) {
-  if (!web_app::GetAppIdFromApplicationName(app_name).empty())
-    return SessionService::TYPE_WEB_APP;
-  if (!app_name.empty())
-    return SessionService::TYPE_CHROME_APP;
-  return SessionService::TYPE_NORMAL;
-}
-
-}  // namespace
-
 // SessionService -------------------------------------------------------------
 
 SessionService::SessionService(Profile* profile)
@@ -265,8 +252,9 @@
     return;
 
   RestoreIfNecessary(std::vector<GURL>(), browser);
-  SetWindowType(browser->session_id(), browser->type(),
-                AppTypeForAppName(browser->app_name()));
+  SetWindowType(browser->session_id(),
+                browser->type(),
+                browser->is_app() ? TYPE_APP : TYPE_NORMAL);
   SetWindowAppName(browser->session_id(), browser->app_name());
 }
 
@@ -585,17 +573,13 @@
 bool SessionService::ShouldRestoreWindowOfType(
     sessions::SessionWindow::WindowType window_type,
     AppType app_type) const {
-  if (window_type == sessions::SessionWindow::TYPE_POPUP) {
 #if defined(OS_CHROMEOS)
-    // Chrome App popups are only restored on Chrome OS.
-    if (app_type == TYPE_CHROME_APP)
-      return true;
+  // Restore app popups for ChromeOS alone.
+  if (window_type == sessions::SessionWindow::TYPE_POPUP &&
+      app_type == TYPE_APP)
+    return true;
 #endif
 
-    // Web App popups are restored on all platforms.
-    if (app_type == TYPE_WEB_APP)
-      return true;
-  }
   return window_type == sessions::SessionWindow::TYPE_TABBED;
 }
 
@@ -605,7 +589,8 @@
   while (i != window_list->end()) {
     sessions::SessionWindow* window = i->get();
     if (!ShouldRestoreWindowOfType(window->type,
-                                   AppTypeForAppName(window->app_name))) {
+                                   window->app_name.empty() ? TYPE_NORMAL :
+                                                              TYPE_APP)) {
       i = window_list->erase(i);
     } else {
       ++i;
@@ -920,7 +905,7 @@
     return false;
   }
   return ShouldRestoreWindowOfType(WindowTypeForBrowserType(browser->type()),
-                                   AppTypeForAppName(browser->app_name()));
+                                   browser->is_app() ? TYPE_APP : TYPE_NORMAL);
 }
 
 void SessionService::MaybeDeleteSessionOnlyData() {
diff --git a/chrome/browser/sessions/session_service.h b/chrome/browser/sessions/session_service.h
index f4b2daef..d571e543 100644
--- a/chrome/browser/sessions/session_service.h
+++ b/chrome/browser/sessions/session_service.h
@@ -68,13 +68,7 @@
  public:
   // Used to distinguish an application from a ordinary content window.
   enum AppType {
-    // Chrome Apps.
-    TYPE_CHROME_APP,
-
-    // Web Apps.
-    TYPE_WEB_APP,
-
-    // Not an app.
+    TYPE_APP,
     TYPE_NORMAL
   };
 
diff --git a/chrome/browser/sessions/session_service_unittest.cc b/chrome/browser/sessions/session_service_unittest.cc
index 89eef28..b88bdd8 100644
--- a/chrome/browser/sessions/session_service_unittest.cc
+++ b/chrome/browser/sessions/session_service_unittest.cc
@@ -29,7 +29,6 @@
 #include "chrome/browser/profiles/profile_attributes_storage.h"
 #include "chrome/browser/profiles/profile_manager.h"
 #include "chrome/browser/sessions/session_service_test_helper.h"
-#include "chrome/browser/web_applications/components/web_app_helpers.h"
 #include "chrome/common/chrome_paths.h"
 #include "chrome/common/url_constants.h"
 #include "chrome/test/base/browser_with_test_window_test.h"
@@ -173,58 +172,6 @@
     UpdateNavigation(window2_id, tab2_id, *nav2, true);
   }
 
-  void TestAppRestore(const std::string& app_name,
-                      SessionService::AppType app_type) {
-    SessionID window2_id = SessionID::NewUnique();
-    SessionID tab_id = SessionID::NewUnique();
-    SessionID tab2_id = SessionID::NewUnique();
-    ASSERT_NE(window2_id, window_id);
-
-    service()->SetWindowType(window2_id, Browser::TYPE_POPUP, app_type);
-    service()->SetWindowBounds(window2_id, window_bounds,
-                               ui::SHOW_STATE_NORMAL);
-    service()->SetWindowAppName(window2_id, app_name);
-
-    SerializedNavigationEntry nav1 =
-        SerializedNavigationEntryTestHelper::CreateNavigation(
-            "http://google.com", "abc");
-    SerializedNavigationEntry nav2 =
-        SerializedNavigationEntryTestHelper::CreateNavigation(
-            "http://google2.com", "abcd");
-
-    helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
-    UpdateNavigation(window_id, tab_id, nav1, true);
-
-    helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false);
-    UpdateNavigation(window2_id, tab2_id, nav2, true);
-
-    std::vector<std::unique_ptr<sessions::SessionWindow>> windows;
-    ReadWindows(&windows, NULL);
-
-    ASSERT_EQ(2U, windows.size());
-    int tabbed_index =
-        windows[0]->type == sessions::SessionWindow::TYPE_TABBED ? 0 : 1;
-    int app_index = tabbed_index == 0 ? 1 : 0;
-    ASSERT_EQ(0, windows[tabbed_index]->selected_tab_index);
-    ASSERT_EQ(window_id, windows[tabbed_index]->window_id);
-    ASSERT_EQ(1U, windows[tabbed_index]->tabs.size());
-
-    sessions::SessionTab* tab = windows[tabbed_index]->tabs[0].get();
-    helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab);
-    helper_.AssertNavigationEquals(nav1, tab->navigations[0]);
-
-    ASSERT_EQ(0, windows[app_index]->selected_tab_index);
-    ASSERT_EQ(window2_id, windows[app_index]->window_id);
-    ASSERT_EQ(1U, windows[app_index]->tabs.size());
-    ASSERT_TRUE(windows[app_index]->type ==
-                sessions::SessionWindow::TYPE_POPUP);
-    ASSERT_EQ(app_name, windows[app_index]->app_name);
-
-    tab = windows[app_index]->tabs[0].get();
-    helper_.AssertTabEquals(window2_id, tab2_id, 0, 0, 1, *tab);
-    helper_.AssertNavigationEquals(nav2, tab->navigations[0]);
-  }
-
   SessionService* service() { return helper_.service(); }
 
   const gfx::Rect window_bounds;
@@ -610,19 +557,59 @@
   EXPECT_EQ(sessions::SessionWindow::TYPE_TABBED, windows_list[0]->type);
 }
 
-// Makes sure we track Web Apps on all platforms. Don't test on OS X since web
-// apps on that platform require a shim on disk to open in windows.
-#if !defined(OS_MACOSX)
-TEST_F(SessionServiceTest, RestoreWebApps) {
-  TestAppRestore(web_app::GenerateApplicationNameFromAppId("TestAppId"),
-                 SessionService::TYPE_WEB_APP);
-}
-#endif  // defined(OS_MACOSX)
+#if defined (OS_CHROMEOS)
+// Makes sure we track apps. Only applicable on chromeos.
+TEST_F(SessionServiceTest, RestoreApp) {
+  SessionID window2_id = SessionID::NewUnique();
+  SessionID tab_id = SessionID::NewUnique();
+  SessionID tab2_id = SessionID::NewUnique();
+  ASSERT_NE(window2_id, window_id);
 
-#if defined(OS_CHROMEOS)
-// Makes sure we track Chrome Apps on Chrome OS.
-TEST_F(SessionServiceTest, RestoreChromeApps) {
-  TestAppRestore("TestAppName", SessionService::TYPE_CHROME_APP);
+  service()->SetWindowType(window2_id,
+                           Browser::TYPE_POPUP,
+                           SessionService::TYPE_APP);
+  service()->SetWindowBounds(window2_id,
+                             window_bounds,
+                             ui::SHOW_STATE_NORMAL);
+  service()->SetWindowAppName(window2_id, "TestApp");
+
+  SerializedNavigationEntry nav1 =
+      SerializedNavigationEntryTestHelper::CreateNavigation(
+          "http://google.com", "abc");
+  SerializedNavigationEntry nav2 =
+      SerializedNavigationEntryTestHelper::CreateNavigation(
+          "http://google2.com", "abcd");
+
+  helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
+  UpdateNavigation(window_id, tab_id, nav1, true);
+
+  helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false);
+  UpdateNavigation(window2_id, tab2_id, nav2, true);
+
+  std::vector<std::unique_ptr<sessions::SessionWindow>> windows;
+  ReadWindows(&windows, NULL);
+
+  ASSERT_EQ(2U, windows.size());
+  int tabbed_index = windows[0]->type == sessions::SessionWindow::TYPE_TABBED ?
+      0 : 1;
+  int app_index = tabbed_index == 0 ? 1 : 0;
+  ASSERT_EQ(0, windows[tabbed_index]->selected_tab_index);
+  ASSERT_EQ(window_id, windows[tabbed_index]->window_id);
+  ASSERT_EQ(1U, windows[tabbed_index]->tabs.size());
+
+  sessions::SessionTab* tab = windows[tabbed_index]->tabs[0].get();
+  helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab);
+  helper_.AssertNavigationEquals(nav1, tab->navigations[0]);
+
+  ASSERT_EQ(0, windows[app_index]->selected_tab_index);
+  ASSERT_EQ(window2_id, windows[app_index]->window_id);
+  ASSERT_EQ(1U, windows[app_index]->tabs.size());
+  ASSERT_TRUE(windows[app_index]->type == sessions::SessionWindow::TYPE_POPUP);
+  ASSERT_EQ("TestApp", windows[app_index]->app_name);
+
+  tab = windows[app_index]->tabs[0].get();
+  helper_.AssertTabEquals(window2_id, tab2_id, 0, 0, 1, *tab);
+  helper_.AssertNavigationEquals(nav2, tab->navigations[0]);
 }
 
 // Don't track Crostini apps. Only applicable on Chrome OS.
@@ -641,7 +628,8 @@
   for (auto& window : windows)
     ASSERT_NE(window2_id, window->window_id);
 }
-#endif  // defined(OS_CHROMEOS)
+
+#endif  // defined (OS_CHROMEOS)
 
 // Tests pruning from the front.
 TEST_F(SessionServiceTest, PruneFromFront) {