Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Unified Diff: chrome/browser/ui/apps/chrome_app_delegate.cc

Issue 875273003: Hidden windows should not keep Chrome alive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: If window is hidden without being shown, wait for timeout before releasing keep-alive. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/apps/chrome_app_delegate.cc
diff --git a/chrome/browser/ui/apps/chrome_app_delegate.cc b/chrome/browser/ui/apps/chrome_app_delegate.cc
index d5740a1c2bdb9c415f0ecc088afba7bc58e23445..a5e7c9631b34b5bc584bfd0fa76a332d36b6012a 100644
--- a/chrome/browser/ui/apps/chrome_app_delegate.cc
+++ b/chrome/browser/ui/apps/chrome_app_delegate.cc
@@ -25,6 +25,7 @@
#include "chrome/common/extensions/chrome_extension_messages.h"
#include "components/ui/zoom/zoom_controller.h"
#include "content/public/browser/browser_context.h"
+#include "content/public/browser/browser_thread.h"
#include "content/public/browser/host_zoom_map.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_view_host.h"
@@ -47,6 +48,9 @@
namespace {
+// Time to wait for an app window to show before allowing Chrome to quit.
+int kAppWindowFirstShowTimeoutSeconds = 10;
+
bool disable_external_open_for_testing_ = false;
// Opens a URL with Chromium (not external browser) with the right profile.
@@ -111,6 +115,13 @@ class OpenURLFromTabBasedOnBrowserDefault
} // namespace
+// static
+void ChromeAppDelegate::RelinquishKeepAliveAfterTimeout(
+ const base::WeakPtr<ChromeAppDelegate>& chrome_app_delegate) {
+ if (chrome_app_delegate && chrome_app_delegate->is_hidden_)
+ chrome_app_delegate->keep_alive_.reset();
+}
+
class ChromeAppDelegate::NewWindowContentsDelegate
: public content::WebContentsDelegate {
public:
@@ -151,8 +162,11 @@ ChromeAppDelegate::NewWindowContentsDelegate::OpenURLFromTab(
}
ChromeAppDelegate::ChromeAppDelegate(scoped_ptr<ScopedKeepAlive> keep_alive)
- : keep_alive_(keep_alive.Pass()),
- new_window_contents_delegate_(new NewWindowContentsDelegate()) {
+ : has_been_shown_(false),
+ is_hidden_(true),
+ keep_alive_(keep_alive.Pass()),
+ new_window_contents_delegate_(new NewWindowContentsDelegate()),
+ weak_factory_(this) {
registrar_.Add(this,
chrome::NOTIFICATION_APP_TERMINATING,
content::NotificationService::AllSources());
@@ -304,6 +318,28 @@ void ChromeAppDelegate::SetTerminatingCallback(const base::Closure& callback) {
terminating_callback_ = callback;
}
+void ChromeAppDelegate::OnHide() {
+ is_hidden_ = true;
+ if (has_been_shown_) {
+ keep_alive_.reset();
+ return;
+ }
+
+ // Hold on to the keep alive for some time to give the app a chance to show
+ // the window.
+ content::BrowserThread::PostDelayedTask(
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&ChromeAppDelegate::RelinquishKeepAliveAfterTimeout,
+ weak_factory_.GetWeakPtr()),
+ base::TimeDelta::FromSeconds(kAppWindowFirstShowTimeoutSeconds));
+}
+
+void ChromeAppDelegate::OnShow() {
+ has_been_shown_ = true;
+ is_hidden_ = false;
+ keep_alive_.reset(new ScopedKeepAlive);
+}
+
void ChromeAppDelegate::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {

Powered by Google App Engine
This is Rietveld 408576698