diff options
author | skuhne@chromium.org <skuhne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-05 00:01:34 +0000 |
---|---|---|
committer | skuhne@chromium.org <skuhne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-05 00:01:34 +0000 |
commit | 0c3aa34d1d743df6aae953b3eb9deb0a3252f997 (patch) | |
tree | 18741e2bb15bb49c802197190d9da08206d5c6fb /chrome/browser/ui/ash | |
parent | 454b78d45ebe02524f7d3bdbe06debd7b27831c0 (diff) | |
download | chromium_src-0c3aa34d1d743df6aae953b3eb9deb0a3252f997.zip chromium_src-0c3aa34d1d743df6aae953b3eb9deb0a3252f997.tar.gz chromium_src-0c3aa34d1d743df6aae953b3eb9deb0a3252f997.tar.bz2 |
Fixing crasher with deleted content still being present in our ChromeLauncherController's |web_contents_to_app_id_| list
BUG=359037
TEST=none since the exact condition how to get there is still unknown
Review URL: https://codereview.chromium.org/223403010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261919 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/ash')
4 files changed, 35 insertions, 8 deletions
diff --git a/chrome/browser/ui/ash/launcher/browser_status_monitor.cc b/chrome/browser/ui/ash/launcher/browser_status_monitor.cc index 285d0fc..7d8123d 100644 --- a/chrome/browser/ui/ash/launcher/browser_status_monitor.cc +++ b/chrome/browser/ui/ash/launcher/browser_status_monitor.cc @@ -55,6 +55,16 @@ void BrowserStatusMonitor::LocalWebContentsObserver::DidNavigateMainFrame( } } +void BrowserStatusMonitor::LocalWebContentsObserver::WebContentsDestroyed( + content::WebContents* web_content) { + if (web_content == web_contents()) { + // We can only come here when there was a non standard termination like + // an app got un-installed while running, etc. + monitor_->WebContentsDestroyed(web_content); + // |this| is gone now. + } +} + BrowserStatusMonitor::BrowserStatusMonitor( ChromeLauncherController* launcher_controller) : launcher_controller_(launcher_controller), @@ -106,9 +116,11 @@ void BrowserStatusMonitor::UpdateAppItemState( ChromeLauncherController::AppState app_state) { DCHECK(contents); // It is possible to come here from Browser::SwapTabContent where the contents - // cannot be associated with a browser. + // cannot be associated with a browser. A removal however should be properly + // processed. Browser* browser = chrome::FindBrowserWithWebContents(contents); - if (browser && launcher_controller_->IsBrowserFromActiveUser(browser)) + if (app_state == ChromeLauncherController::APP_STATE_REMOVED || + (browser && launcher_controller_->IsBrowserFromActiveUser(browser))) launcher_controller_->UpdateAppState(contents, app_state); } @@ -288,6 +300,12 @@ void BrowserStatusMonitor::TabClosingAt(TabStripModel* tab_strip_mode, RemoveWebContentsObserver(contents); } +void BrowserStatusMonitor::WebContentsDestroyed( + content::WebContents* contents) { + UpdateAppItemState(contents, ChromeLauncherController::APP_STATE_REMOVED); + RemoveWebContentsObserver(contents); +} + void BrowserStatusMonitor::AddV1AppToShelf(Browser* browser) { DCHECK(browser->is_type_popup() && browser->is_app()); diff --git a/chrome/browser/ui/ash/launcher/browser_status_monitor.h b/chrome/browser/ui/ash/launcher/browser_status_monitor.h index 6e54ac2..fd1d205 100644 --- a/chrome/browser/ui/ash/launcher/browser_status_monitor.h +++ b/chrome/browser/ui/ash/launcher/browser_status_monitor.h @@ -88,6 +88,11 @@ class BrowserStatusMonitor : public aura::client::ActivationChangeObserver, content::WebContents* contents, int index) OVERRIDE; + // Called from our own |LocalWebContentsObserver| when web contents did go + // away without any other notification. This might happen in case of + // application uninstalls, page crashes, ...). + void WebContentsDestroyed(content::WebContents* web_contents); + protected: // Add a V1 application to the shelf. This can get overwritten for multi // profile implementations. @@ -113,6 +118,8 @@ class BrowserStatusMonitor : public aura::client::ActivationChangeObserver, virtual void DidNavigateMainFrame( const content::LoadCommittedDetails& details, const content::FrameNavigateParams& params) OVERRIDE; + virtual void WebContentsDestroyed( + content::WebContents* web_contents) OVERRIDE; private: BrowserStatusMonitor* monitor_; diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc index 25f83d9..0675094 100644 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc @@ -1687,10 +1687,11 @@ ash::ShelfItemStatus ChromeLauncherController::GetAppState( ++it) { if (it->second == app_id) { Browser* browser = chrome::FindBrowserWithWebContents(it->first); - // There should never be an item in our |web_contents_to_app_id_| list - // which got deleted already. If it is, it is likely that - // BrowserStatusMonitor forgot to inform us of that change. - DCHECK(browser); + // Usually there should never be an item in our |web_contents_to_app_id_| + // list which got deleted already. However - in some situations e.g. + // Browser::SwapTabContent there is temporarily no associated browser. + if (!browser) + continue; if (browser->window()->IsActive()) { return browser->tab_strip_model()->GetActiveWebContents() == it->first ? ash::STATUS_ACTIVE : ash::STATUS_RUNNING; diff --git a/chrome/browser/ui/ash/launcher/launcher_app_tab_helper.cc b/chrome/browser/ui/ash/launcher/launcher_app_tab_helper.cc index 862bccc..fe6e5ff 100644 --- a/chrome/browser/ui/ash/launcher/launcher_app_tab_helper.cc +++ b/chrome/browser/ui/ash/launcher/launcher_app_tab_helper.cc @@ -28,12 +28,13 @@ const extensions::Extension* GetExtensionForTab(Profile* profile, if (!extension_service || !extension_service->extensions_enabled()) return NULL; + // Note: It is possible to come here after a tab got removed form the browser + // before it gets destroyed, in which case there is no browser. Browser* browser = chrome::FindBrowserWithWebContents(tab); - DCHECK(browser); // Use the Browser's app name to determine the extension for app windows and // use the tab's url for app tabs. - if (browser->is_app()) { + if (browser && browser->is_app()) { return extension_service->GetInstalledExtension( web_app::GetExtensionIdFromApplicationName(browser->app_name())); } |