Commit 261f7f3a authored by jackhou's avatar jackhou Committed by Commit bot

Don't include hidden windows in IsAppWindowRegisteredInAnyProfile.

All the places that use this function are checking whether there are any app
windows from the point of view of the user.

BUG=442280

Review URL: https://codereview.chromium.org/800473006

Cr-Commit-Position: refs/heads/master@{#310196}
parent 79582464
...@@ -473,7 +473,7 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver { ...@@ -473,7 +473,7 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver {
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)app { - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)app {
// If there are no windows, quit immediately. // If there are no windows, quit immediately.
if (chrome::BrowserIterator().done() && if (chrome::BrowserIterator().done() &&
!AppWindowRegistryUtil::IsAppWindowRegisteredInAnyProfile(0)) { !AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0)) {
return NSTerminateNow; return NSTerminateNow;
} }
......
...@@ -24,7 +24,7 @@ namespace { ...@@ -24,7 +24,7 @@ namespace {
void TerminateIfNoAppWindows() { void TerminateIfNoAppWindows() {
bool app_windows_left = bool app_windows_left =
AppWindowRegistryUtil::IsAppWindowRegisteredInAnyProfile(0); AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0);
if (!app_windows_left && if (!app_windows_left &&
!AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE) !AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)
->IsAppListVisible()) { ->IsAppListVisible()) {
......
...@@ -41,7 +41,7 @@ AppWindow* AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( ...@@ -41,7 +41,7 @@ AppWindow* AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(
} }
// static // static
bool AppWindowRegistryUtil::IsAppWindowRegisteredInAnyProfile( bool AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(
int window_type_mask) { int window_type_mask) {
std::vector<Profile*> profiles = std::vector<Profile*> profiles =
g_browser_process->profile_manager()->GetLoadedProfiles(); g_browser_process->profile_manager()->GetLoadedProfiles();
...@@ -57,12 +57,10 @@ bool AppWindowRegistryUtil::IsAppWindowRegisteredInAnyProfile( ...@@ -57,12 +57,10 @@ bool AppWindowRegistryUtil::IsAppWindowRegisteredInAnyProfile(
if (app_windows.empty()) if (app_windows.empty())
continue; continue;
if (window_type_mask == 0) for (const AppWindow* window : app_windows) {
return true; if (!window->is_hidden() &&
(window_type_mask == 0 ||
for (AppWindowList::const_iterator j = app_windows.begin(); (window->window_type() & window_type_mask)))
j != app_windows.end(); ++j) {
if ((*j)->window_type() & window_type_mask)
return true; return true;
} }
} }
......
...@@ -18,10 +18,10 @@ class AppWindowRegistryUtil { ...@@ -18,10 +18,10 @@ class AppWindowRegistryUtil {
static extensions::AppWindow* GetAppWindowForNativeWindowAnyProfile( static extensions::AppWindow* GetAppWindowForNativeWindowAnyProfile(
gfx::NativeWindow window); gfx::NativeWindow window);
// Returns true if the number of app windows registered across all browser // Returns true if the number of visible app windows registered across all
// contexts is non-zero. |window_type_mask| is a bitwise OR filter of // browser contexts is non-zero. |window_type_mask| is a bitwise OR filter of
// AppWindow::WindowType, or 0 for any window type. // AppWindow::WindowType, or 0 for any window type.
static bool IsAppWindowRegisteredInAnyProfile(int window_type_mask); static bool IsAppWindowVisibleInAnyProfile(int window_type_mask);
// Close all app windows in all profiles. // Close all app windows in all profiles.
static void CloseAllAppWindows(); static void CloseAllAppWindows();
......
...@@ -17,8 +17,8 @@ bool VerifyASHSwitchForApps(gfx::NativeWindow parent_window, ...@@ -17,8 +17,8 @@ bool VerifyASHSwitchForApps(gfx::NativeWindow parent_window,
DCHECK(win_restart_command_id == IDC_WIN_DESKTOP_RESTART || DCHECK(win_restart_command_id == IDC_WIN_DESKTOP_RESTART ||
win_restart_command_id == IDC_WIN8_METRO_RESTART || win_restart_command_id == IDC_WIN8_METRO_RESTART ||
win_restart_command_id == IDC_WIN_CHROMEOS_RESTART); win_restart_command_id == IDC_WIN_CHROMEOS_RESTART);
if (!AppWindowRegistryUtil::IsAppWindowRegisteredInAnyProfile( if (!AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(
extensions::AppWindow::WINDOW_TYPE_DEFAULT)) { extensions::AppWindow::WINDOW_TYPE_DEFAULT)) {
return true; return true;
} }
......
...@@ -151,7 +151,7 @@ bool QuitWithAppsController::ShouldQuit() { ...@@ -151,7 +151,7 @@ bool QuitWithAppsController::ShouldQuit() {
// Quit immediately if there are no packaged app windows or hosted apps open // Quit immediately if there are no packaged app windows or hosted apps open
// or the confirmation has been suppressed. Ignore panels. // or the confirmation has been suppressed. Ignore panels.
if (!AppWindowRegistryUtil::IsAppWindowRegisteredInAnyProfile( if (!AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(
extensions::AppWindow::WINDOW_TYPE_DEFAULT) && extensions::AppWindow::WINDOW_TYPE_DEFAULT) &&
!hosted_apps_open) { !hosted_apps_open) {
return true; return true;
...@@ -159,7 +159,7 @@ bool QuitWithAppsController::ShouldQuit() { ...@@ -159,7 +159,7 @@ bool QuitWithAppsController::ShouldQuit() {
} else { } else {
// Quit immediately if there are no windows or the confirmation has been // Quit immediately if there are no windows or the confirmation has been
// suppressed. // suppressed.
if (!AppWindowRegistryUtil::IsAppWindowRegisteredInAnyProfile( if (!AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(
extensions::AppWindow::WINDOW_TYPE_DEFAULT)) extensions::AppWindow::WINDOW_TYPE_DEFAULT))
return true; return true;
} }
......
...@@ -75,11 +75,11 @@ IN_PROC_BROWSER_TEST_F(QuitWithAppsControllerInteractiveTest, QuitBehavior) { ...@@ -75,11 +75,11 @@ IN_PROC_BROWSER_TEST_F(QuitWithAppsControllerInteractiveTest, QuitBehavior) {
// One browser and one app window at this point. // One browser and one app window at this point.
EXPECT_FALSE(chrome::BrowserIterator().done()); EXPECT_FALSE(chrome::BrowserIterator().done());
EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowRegisteredInAnyProfile(0)); EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0));
// On the first quit, show notification. // On the first quit, show notification.
EXPECT_FALSE(controller->ShouldQuit()); EXPECT_FALSE(controller->ShouldQuit());
EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowRegisteredInAnyProfile(0)); EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0));
notification = g_browser_process->notification_ui_manager()->FindById( notification = g_browser_process->notification_ui_manager()->FindById(
QuitWithAppsController::kQuitWithAppsNotificationID, QuitWithAppsController::kQuitWithAppsNotificationID,
NotificationUIManager::GetProfileID(profiles[0])); NotificationUIManager::GetProfileID(profiles[0]));
...@@ -89,27 +89,27 @@ IN_PROC_BROWSER_TEST_F(QuitWithAppsControllerInteractiveTest, QuitBehavior) { ...@@ -89,27 +89,27 @@ IN_PROC_BROWSER_TEST_F(QuitWithAppsControllerInteractiveTest, QuitBehavior) {
notification->delegate()->Click(); notification->delegate()->Click();
message_center->RemoveAllNotifications(false); message_center->RemoveAllNotifications(false);
EXPECT_FALSE(controller->ShouldQuit()); EXPECT_FALSE(controller->ShouldQuit());
EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowRegisteredInAnyProfile(0)); EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0));
notification = g_browser_process->notification_ui_manager()->FindById( notification = g_browser_process->notification_ui_manager()->FindById(
QuitWithAppsController::kQuitWithAppsNotificationID, QuitWithAppsController::kQuitWithAppsNotificationID,
NotificationUIManager::GetProfileID(profiles[0])); NotificationUIManager::GetProfileID(profiles[0]));
ASSERT_TRUE(notification); ASSERT_TRUE(notification);
EXPECT_FALSE(chrome::BrowserIterator().done()); EXPECT_FALSE(chrome::BrowserIterator().done());
EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowRegisteredInAnyProfile(0)); EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0));
// If notification is closed by user, don't show it next time. // If notification is closed by user, don't show it next time.
notification->delegate()->Close(true); notification->delegate()->Close(true);
message_center->RemoveAllNotifications(false); message_center->RemoveAllNotifications(false);
EXPECT_FALSE(controller->ShouldQuit()); EXPECT_FALSE(controller->ShouldQuit());
EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowRegisteredInAnyProfile(0)); EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0));
notification = g_browser_process->notification_ui_manager()->FindById( notification = g_browser_process->notification_ui_manager()->FindById(
QuitWithAppsController::kQuitWithAppsNotificationID, QuitWithAppsController::kQuitWithAppsNotificationID,
NotificationUIManager::GetProfileID(profiles[0])); NotificationUIManager::GetProfileID(profiles[0]));
EXPECT_EQ(NULL, notification); EXPECT_EQ(NULL, notification);
EXPECT_FALSE(chrome::BrowserIterator().done()); EXPECT_FALSE(chrome::BrowserIterator().done());
EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowRegisteredInAnyProfile(0)); EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0));
// Quitting should not quit but close all browsers // Quitting should not quit but close all browsers
content::WindowedNotificationObserver observer( content::WindowedNotificationObserver observer(
...@@ -119,7 +119,7 @@ IN_PROC_BROWSER_TEST_F(QuitWithAppsControllerInteractiveTest, QuitBehavior) { ...@@ -119,7 +119,7 @@ IN_PROC_BROWSER_TEST_F(QuitWithAppsControllerInteractiveTest, QuitBehavior) {
observer.Wait(); observer.Wait();
EXPECT_TRUE(chrome::BrowserIterator().done()); EXPECT_TRUE(chrome::BrowserIterator().done());
EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowRegisteredInAnyProfile(0)); EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0));
// Trying to quit while there are no browsers always shows notification. // Trying to quit while there are no browsers always shows notification.
EXPECT_FALSE(controller->ShouldQuit()); EXPECT_FALSE(controller->ShouldQuit());
...@@ -135,6 +135,6 @@ IN_PROC_BROWSER_TEST_F(QuitWithAppsControllerInteractiveTest, QuitBehavior) { ...@@ -135,6 +135,6 @@ IN_PROC_BROWSER_TEST_F(QuitWithAppsControllerInteractiveTest, QuitBehavior) {
content::NotificationService::AllSources()); content::NotificationService::AllSources());
notification->delegate()->ButtonClick(0); notification->delegate()->ButtonClick(0);
message_center->RemoveAllNotifications(false); message_center->RemoveAllNotifications(false);
EXPECT_FALSE(AppWindowRegistryUtil::IsAppWindowRegisteredInAnyProfile(0)); EXPECT_FALSE(AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0));
quit_observer.Wait(); quit_observer.Wait();
} }
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