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