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

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: Rebased. Created 8 years, 5 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 5998e35a9aefe6ca0f5603eaeffcfe57bfd26e17..2d4a5c6ab1f19a710068029701474f9a3c070994 100644
--- a/chrome/browser/ui/startup/session_crashed_prompt.cc
+++ b/chrome/browser/ui/startup/session_crashed_prompt.cc
@@ -12,7 +12,11 @@
#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/browser_context.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/dom_storage_context.h"
#include "content/public/browser/web_contents.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
@@ -24,7 +28,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);
@@ -38,12 +43,25 @@ class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate {
virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
virtual bool Accept() OVERRIDE;
+ // content::NotificationObserver implementation.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ content::NotificationRegistrar registrar_;
+ bool accepted_;
+ Browser* browser_;
+
DISALLOW_COPY_AND_ASSIGN(SessionCrashedInfoBarDelegate);
};
SessionCrashedInfoBarDelegate::SessionCrashedInfoBarDelegate(
InfoBarTabHelper* infobar_helper)
- : ConfirmInfoBarDelegate(infobar_helper) {
+ : ConfirmInfoBarDelegate(infobar_helper),
+ accepted_(false),
+ browser_(browser::FindBrowserWithWebContents(owner()->web_contents())) {
+ registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
+ content::NotificationService::AllSources());
}
SessionCrashedInfoBarDelegate::~SessionCrashedInfoBarDelegate() {
@@ -70,20 +88,39 @@ 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) {
+ switch (type) {
+ case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED:
+ // If the info bar wasn't accepted, it was either dismissed or expired. In
+ // that case, session restore won't happen.
+ if (!accepted_) {
+ content::DOMStorageContext* dom_storage_context =
+ content::BrowserContext::GetDOMStorageContext(browser_->profile());
+ dom_storage_context->StartScavengingUnusedSessionStorage();
+ }
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+}
+
} // namespace
namespace chrome {

Powered by Google App Engine
This is Rietveld 408576698