Commit c7340785 authored by Timothy Loh's avatar Timothy Loh Committed by Commit Bot

Fix crashes when switching profiles with incomplete terminal launch

This CL fixes a crash that occurs when switching to a profile with an
incomplete Crostini terminal launch. While the BrowserStatusMonitor was
already excluding the Crostini terminal from getting a shelf item, it
was still tracking the Browsers, and ended up trying to add these
to the shelf on profile switching.

Bug: 882782
Change-Id: I7e406b1481a9ad5adb372335ebab421f1742acc1
Reviewed-on: https://chromium-review.googlesource.com/1235775Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Timothy Loh <timloh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593759}
parent 606d82b5
......@@ -22,6 +22,19 @@
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
namespace {
bool IsV1WindowedApp(Browser* browser) {
if (!browser->is_type_popup() || !browser->is_app())
return false;
// Crostini terminal windows do not have an app id and are handled by
// CrostiniAppWindowShelfController. All other app windows should have a non
// empty app id.
return !web_app::GetAppIdFromApplicationName(browser->app_name()).empty();
}
} // namespace
// This class monitors the WebContent of the all tab and notifies a navigation
// to the BrowserStatusMonitor.
class BrowserStatusMonitor::LocalWebContentsObserver
......@@ -107,7 +120,7 @@ bool BrowserStatusMonitor::ShouldTrackBrowser(Browser* browser) {
void BrowserStatusMonitor::OnBrowserAdded(Browser* browser) {
DCHECK(initialized_);
if (browser->is_type_popup() && browser->is_app()) {
if (IsV1WindowedApp(browser)) {
// Note: A V1 application will set the tab strip observer when the app gets
// added to the shelf. This makes sure that in the multi user case we will
// only set the observer while the app item exists in the shelf.
......@@ -117,7 +130,7 @@ void BrowserStatusMonitor::OnBrowserAdded(Browser* browser) {
void BrowserStatusMonitor::OnBrowserRemoved(Browser* browser) {
DCHECK(initialized_);
if (browser->is_type_popup() && browser->is_app())
if (IsV1WindowedApp(browser))
RemoveV1AppFromShelf(browser);
UpdateBrowserItemState();
......@@ -187,20 +200,19 @@ void BrowserStatusMonitor::WebContentsDestroyed(
}
void BrowserStatusMonitor::AddV1AppToShelf(Browser* browser) {
DCHECK(browser->is_type_popup() && browser->is_app());
DCHECK(IsV1WindowedApp(browser));
DCHECK(initialized_);
std::string app_id =
web_app::GetAppIdFromApplicationName(browser->app_name());
if (!app_id.empty()) {
if (!IsV1AppInShelfWithAppId(app_id))
launcher_controller_->SetV1AppStatus(app_id, ash::STATUS_RUNNING);
browser_to_app_id_map_[browser] = app_id;
}
DCHECK(!app_id.empty());
if (!IsV1AppInShelfWithAppId(app_id))
launcher_controller_->SetV1AppStatus(app_id, ash::STATUS_RUNNING);
browser_to_app_id_map_[browser] = app_id;
}
void BrowserStatusMonitor::RemoveV1AppFromShelf(Browser* browser) {
DCHECK(browser->is_type_popup() && browser->is_app());
DCHECK(IsV1WindowedApp(browser));
DCHECK(initialized_);
auto iter = browser_to_app_id_map_.find(browser);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment