Commit aaa4fd8f authored by nancy's avatar nancy Committed by Commit Bot

Delete Chrome window instance when the browser is closed.

When the browser is closed/removed, update the related Chrome window in
AppService InstanceRegistry as destroyed to delete the Chrome window
instance.

BUG=1011235

Change-Id: I67327279423ae0b9ade0e089f1a615e91bb87ab2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1959919
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarAga Wronska <agawronska@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#723638}
parent 1d117fc8
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/ui/ash/launcher/app_service_instance_registry_helper.h" #include "chrome/browser/ui/ash/launcher/app_service_instance_registry_helper.h"
#include <set>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -13,6 +14,7 @@ ...@@ -13,6 +14,7 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/web_applications/components/web_app_helpers.h" #include "chrome/browser/web_applications/components/web_app_helpers.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
...@@ -108,6 +110,19 @@ void AppServiceInstanceRegistryHelper::OnTabClosing( ...@@ -108,6 +110,19 @@ void AppServiceInstanceRegistryHelper::OnTabClosing(
apps::InstanceState::kDestroyed); apps::InstanceState::kDestroyed);
} }
void AppServiceInstanceRegistryHelper::OnBrowserRemoved() {
std::set<aura::Window*> windows =
proxy_->InstanceRegistry().GetWindows(extension_misc::kChromeAppId);
for (auto* window : windows) {
if (!chrome::FindBrowserWithWindow(window)) {
// The browser is removed if the window can't be found, so update the
// Chrome window instance as destroyed.
OnInstances(extension_misc::kChromeAppId, window, std::string(),
apps::InstanceState::kDestroyed);
}
}
}
void AppServiceInstanceRegistryHelper::OnInstances(const std::string& app_id, void AppServiceInstanceRegistryHelper::OnInstances(const std::string& app_id,
aura::Window* window, aura::Window* window,
const std::string& launch_id, const std::string& launch_id,
......
...@@ -50,6 +50,10 @@ class AppServiceInstanceRegistryHelper { ...@@ -50,6 +50,10 @@ class AppServiceInstanceRegistryHelper {
// instance will be removed from App Service InstanceRegistry. // instance will be removed from App Service InstanceRegistry.
void OnTabClosing(content::WebContents* contents); void OnTabClosing(content::WebContents* contents);
// Notifies the AppService InstanceRegistry that the browser is closed. The
// instance will be removed from App Service InstanceRegistry.
void OnBrowserRemoved();
// Helper function to update App Service InstanceRegistry. // Helper function to update App Service InstanceRegistry.
void OnInstances(const std::string& app_id, void OnInstances(const std::string& app_id,
aura::Window* window, aura::Window* window,
......
...@@ -138,6 +138,7 @@ void BrowserStatusMonitor::OnBrowserRemoved(Browser* browser) { ...@@ -138,6 +138,7 @@ void BrowserStatusMonitor::OnBrowserRemoved(Browser* browser) {
RemoveV1AppFromShelf(browser); RemoveV1AppFromShelf(browser);
UpdateBrowserItemState(); UpdateBrowserItemState();
app_service_instance_helper_->OnBrowserRemoved();
} }
void BrowserStatusMonitor::OnTabStripModelChanged( void BrowserStatusMonitor::OnTabStripModelChanged(
......
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