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

Unified Diff: chrome/browser/ui/startup/session_crashed_prompt.cc

Issue 9963107: Persist sessionStorage on disk. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: code review (pkasting) Created 8 years, 4 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/startup/session_crashed_prompt.cc
diff --git a/chrome/browser/ui/startup/session_crashed_prompt.cc b/chrome/browser/ui/startup/session_crashed_prompt.cc
index 1144577dccbdea86c01ad402fd9eb071a7aacf5a..730f5de1570271013e69a6b008a52754cc07b303 100644
--- a/chrome/browser/ui/startup/session_crashed_prompt.cc
+++ b/chrome/browser/ui/startup/session_crashed_prompt.cc
@@ -12,7 +12,10 @@
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
+#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/url_constants.h"
+#include "content/public/browser/dom_storage_context.h"
+#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
@@ -23,7 +26,8 @@
namespace {
// A delegate for the InfoBar shown when the previous session has crashed.
-class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate {
+class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate,
+ public content::NotificationObserver {
public:
explicit SessionCrashedInfoBarDelegate(InfoBarTabHelper* infobar_helper);
@@ -37,15 +41,42 @@ class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate {
virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
virtual bool Accept() OVERRIDE;
+ // content::NotificationObserver implementation.
Peter Kasting 2012/08/07 01:31:54 Nit: s/ implementation./:/ for consistency
marja 2012/08/07 07:31:22 Done.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ content::NotificationRegistrar registrar_;
+ bool accepted_;
+ bool removed_notification_received_;
+ Browser* browser_;
+
DISALLOW_COPY_AND_ASSIGN(SessionCrashedInfoBarDelegate);
};
SessionCrashedInfoBarDelegate::SessionCrashedInfoBarDelegate(
InfoBarTabHelper* infobar_helper)
- : ConfirmInfoBarDelegate(infobar_helper) {
+ : ConfirmInfoBarDelegate(infobar_helper),
+ accepted_(false),
+ removed_notification_received_(false),
+ browser_(browser::FindBrowserWithWebContents(owner()->web_contents())) {
+ // TODO(pkasting,marja): Once InfoBars own they delegates, this is not needed
+ // any more. Then we can rely on delegates getting destroyed, and we can
+ // initiate the session storage scavenging only in the destructor. (Currently,
+ // info bars are leaked if they get closed while they're in background tabs.)
+ registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
+ content::NotificationService::AllSources());
}
SessionCrashedInfoBarDelegate::~SessionCrashedInfoBarDelegate() {
+ // If the info bar wasn't accepted, it was either dismissed or expired. In
+ // that case, session restore won't happen.
+ if (!accepted_ && !removed_notification_received_) {
+ content::DOMStorageContext* dom_storage_context =
Peter Kasting 2012/08/07 01:31:54 Nit: I would do: content::BrowserContext::Get
marja 2012/08/07 07:31:22 Done.
+ content::BrowserContext::GetDefaultDOMStorageContext(
+ browser_->profile());
+ dom_storage_context->StartScavengingUnusedSessionStorage();
+ }
}
gfx::Image* SessionCrashedInfoBarDelegate::GetIcon() const {
@@ -69,20 +100,38 @@ string16 SessionCrashedInfoBarDelegate::GetButtonLabel(
bool SessionCrashedInfoBarDelegate::Accept() {
uint32 behavior = 0;
- Browser* browser =
- browser::FindBrowserWithWebContents(owner()->web_contents());
- if (browser->tab_count() == 1 &&
- chrome::GetWebContentsAt(browser, 0)->GetURL() ==
+ if (browser_->tab_count() == 1 &&
+ chrome::GetWebContentsAt(browser_, 0)->GetURL() ==
GURL(chrome::kChromeUINewTabURL)) {
// There is only one tab and its the new tab page, make session restore
// clobber it.
behavior = SessionRestore::CLOBBER_CURRENT_TAB;
}
SessionRestore::RestoreSession(
- browser->profile(), browser, behavior, std::vector<GURL>());
+ browser_->profile(), browser_, behavior, std::vector<GURL>());
+ accepted_ = true;
return true;
}
+void SessionCrashedInfoBarDelegate::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ DCHECK(type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED);
+ content::Details<std::pair<InfoBarDelegate*, bool> > det(details);
Peter Kasting 2012/08/07 01:31:54 Nit: |det| is not a good variable name, and you sh
marja 2012/08/07 07:31:22 Done.
+ if (det->first != this)
+ return;
+ // See ~SessionCrashedInfoBarDelegate and the TODO in
Peter Kasting 2012/08/07 01:31:54 Nit: No need for this comment, the TODO in the con
marja 2012/08/07 07:31:22 Done.
+ // SessionCrashedInfoBarDelegate.
+ if (!accepted_) {
+ content::DOMStorageContext* dom_storage_context =
+ content::BrowserContext::GetDefaultDOMStorageContext(
+ browser_->profile());
+ dom_storage_context->StartScavengingUnusedSessionStorage();
+ removed_notification_received_ = true;
+ }
+}
+
} // namespace
namespace chrome {

Powered by Google App Engine
This is Rietveld 408576698