summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorjackhou <jackhou@chromium.org>2014-11-13 18:00:27 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-14 02:00:49 +0000
commitccd7df122f3d59d54316a8e6c8248d5b1a66dff7 (patch)
tree5127116891836fdee8fbbe73dd5a7c9efd8fd2ae /apps
parent3ccb614464d1ae6af89cbf02a028ef9f492df300 (diff)
downloadchromium_src-ccd7df122f3d59d54316a8e6c8248d5b1a66dff7.zip
chromium_src-ccd7df122f3d59d54316a8e6c8248d5b1a66dff7.tar.gz
chromium_src-ccd7df122f3d59d54316a8e6c8248d5b1a66dff7.tar.bz2
Don't fire AppLifetimeMonitor::Observer::OnAppActivated on every AppWindow::Show.
The previous logic in AppLifetimeMonitor::OnAppWindowShown causes OnAppActivated to be fired whenever a window is shown. With this change, it will only fire when the first non-visible window becomes visible. This includes http://crrev.com/699363002 but passes |was_hidden| insetad of AppWindow::ShowType. BUG=410435 TEST=Create two windows using the Window State Sample app: https://chrome.google.com/webstore/detail/window-state-sample/hcbhfbnaaancmblfhdknlnojpafjohbi On one of the windows, set a delay of a few seconds, then click "Show". Focus a non-Chrome window so that both app windows are obscured. After the delay, only one app window should be brought to the front. Review URL: https://codereview.chromium.org/705173003 Cr-Commit-Position: refs/heads/master@{#304144}
Diffstat (limited to 'apps')
-rw-r--r--apps/app_lifetime_monitor.cc16
-rw-r--r--apps/app_lifetime_monitor.h11
2 files changed, 17 insertions, 10 deletions
diff --git a/apps/app_lifetime_monitor.cc b/apps/app_lifetime_monitor.cc
index 16323e9..3190e29 100644
--- a/apps/app_lifetime_monitor.cc
+++ b/apps/app_lifetime_monitor.cc
@@ -81,21 +81,24 @@ void AppLifetimeMonitor::Observe(int type,
}
void AppLifetimeMonitor::OnAppWindowRemoved(AppWindow* app_window) {
- if (!HasVisibleAppWindows(app_window))
+ if (!HasOtherVisibleAppWindows(app_window))
NotifyAppDeactivated(app_window->extension_id());
}
void AppLifetimeMonitor::OnAppWindowHidden(AppWindow* app_window) {
- if (!HasVisibleAppWindows(app_window))
+ if (!HasOtherVisibleAppWindows(app_window))
NotifyAppDeactivated(app_window->extension_id());
}
-void AppLifetimeMonitor::OnAppWindowShown(AppWindow* app_window) {
+void AppLifetimeMonitor::OnAppWindowShown(AppWindow* app_window,
+ bool was_hidden) {
if (app_window->window_type() != AppWindow::WINDOW_TYPE_DEFAULT)
return;
- if (HasVisibleAppWindows(app_window))
+ // The app is being activated if this is the first window to become visible.
+ if (was_hidden && !HasOtherVisibleAppWindows(app_window)) {
NotifyAppActivated(app_window->extension_id());
+ }
}
void AppLifetimeMonitor::Shutdown() {
@@ -106,7 +109,8 @@ void AppLifetimeMonitor::Shutdown() {
app_window_registry->RemoveObserver(this);
}
-bool AppLifetimeMonitor::HasVisibleAppWindows(AppWindow* app_window) const {
+bool AppLifetimeMonitor::HasOtherVisibleAppWindows(
+ AppWindow* app_window) const {
AppWindowRegistry::AppWindowList windows =
AppWindowRegistry::Get(app_window->browser_context())
->GetAppWindowsForApp(app_window->extension_id());
@@ -114,7 +118,7 @@ bool AppLifetimeMonitor::HasVisibleAppWindows(AppWindow* app_window) const {
for (AppWindowRegistry::AppWindowList::const_iterator i = windows.begin();
i != windows.end();
++i) {
- if (!(*i)->is_hidden())
+ if (*i != app_window && !(*i)->is_hidden())
return true;
}
return false;
diff --git a/apps/app_lifetime_monitor.h b/apps/app_lifetime_monitor.h
index 8f079fe..90ae2a8 100644
--- a/apps/app_lifetime_monitor.h
+++ b/apps/app_lifetime_monitor.h
@@ -32,9 +32,11 @@ class AppLifetimeMonitor : public KeyedService,
public:
// Called when the app starts running.
virtual void OnAppStart(Profile* profile, const std::string& app_id) {}
- // Called when the app becomes active to the user, i.e. it opens a window.
+ // Called when the app becomes active to the user, i.e. the first window
+ // becomes visible.
virtual void OnAppActivated(Profile* profile, const std::string& app_id) {}
- // Called when the app becomes inactive to the user.
+ // Called when the app becomes inactive to the user, i.e. the last window is
+ // hidden or closed.
virtual void OnAppDeactivated(Profile* profile, const std::string& app_id) {
}
// Called when the app stops running.
@@ -63,12 +65,13 @@ class AppLifetimeMonitor : public KeyedService,
// extensions::AppWindowRegistry::Observer overrides:
void OnAppWindowRemoved(extensions::AppWindow* app_window) override;
void OnAppWindowHidden(extensions::AppWindow* app_window) override;
- void OnAppWindowShown(extensions::AppWindow* app_window) override;
+ void OnAppWindowShown(extensions::AppWindow* app_window,
+ bool was_hidden) override;
// KeyedService overrides:
void Shutdown() override;
- bool HasVisibleAppWindows(extensions::AppWindow* app_window) const;
+ bool HasOtherVisibleAppWindows(extensions::AppWindow* app_window) const;
void NotifyAppStart(const std::string& app_id);
void NotifyAppActivated(const std::string& app_id);