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

Side by Side Diff: chrome/browser/ui/startup/session_crashed_prompt.cc

Issue 11644059: Change infobar creation to use a public static Create() method on the infobar delegate classes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/startup/session_crashed_prompt.h" 5 #include "chrome/browser/ui/startup/session_crashed_prompt.h"
6 6
7 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
8 #include "chrome/browser/api/infobars/infobar_service.h" 7 #include "chrome/browser/api/infobars/infobar_service.h"
9 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/sessions/session_restore.h" 9 #include "chrome/browser/sessions/session_restore.h"
11 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_finder.h" 11 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/browser_tabstrip.h" 12 #include "chrome/browser/ui/browser_tabstrip.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" 13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
16 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
17 #include "content/public/browser/dom_storage_context.h" 16 #include "content/public/browser/dom_storage_context.h"
18 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/storage_partition.h" 18 #include "content/public/browser/storage_partition.h"
20 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
21 #include "grit/chromium_strings.h" 20 #include "grit/chromium_strings.h"
22 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
23 #include "grit/theme_resources.h" 22 #include "grit/theme_resources.h"
24 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
26 25
27 namespace { 26 // static
27 void SessionCrashedInfoBarDelegate::Create(Browser* browser) {
28 // Assume that if the user is launching incognito they were previously
29 // running incognito so that we have nothing to restore from.
30 if (browser->profile()->IsOffTheRecord())
31 return;
28 32
29 // A delegate for the InfoBar shown when the previous session has crashed. 33 // In ChromeBot tests, there might be a race. This line appears to get
30 class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate, 34 // called during shutdown and |web_contents| can be NULL.
31 public content::NotificationObserver { 35 content::WebContents* tab =
32 public: 36 browser->tab_strip_model()->GetActiveWebContents();
33 SessionCrashedInfoBarDelegate(InfoBarService* infobar_service, 37 if (!tab)
34 Browser* browser); 38 return;
35 39
36 private: 40 InfoBarService* infobar_service = InfoBarService::FromWebContents(tab);
37 virtual ~SessionCrashedInfoBarDelegate(); 41 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
38 42 new SessionCrashedInfoBarDelegate(infobar_service, browser)));
39 // ConfirmInfoBarDelegate: 43 }
40 virtual gfx::Image* GetIcon() const OVERRIDE;
41 virtual string16 GetMessageText() const OVERRIDE;
42 virtual int GetButtons() const OVERRIDE;
43 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
44 virtual bool Accept() OVERRIDE;
45
46 // content::NotificationObserver:
47 virtual void Observe(int type,
48 const content::NotificationSource& source,
49 const content::NotificationDetails& details) OVERRIDE;
50
51 content::NotificationRegistrar registrar_;
52 bool accepted_;
53 bool removed_notification_received_;
54 Browser* browser_;
55
56 DISALLOW_COPY_AND_ASSIGN(SessionCrashedInfoBarDelegate);
57 };
58 44
59 SessionCrashedInfoBarDelegate::SessionCrashedInfoBarDelegate( 45 SessionCrashedInfoBarDelegate::SessionCrashedInfoBarDelegate(
60 InfoBarService* infobar_service, 46 InfoBarService* infobar_service,
61 Browser* browser) 47 Browser* browser)
62 : ConfirmInfoBarDelegate(infobar_service), 48 : ConfirmInfoBarDelegate(infobar_service),
63 accepted_(false), 49 accepted_(false),
64 removed_notification_received_(false), 50 removed_notification_received_(false),
65 browser_(browser) { 51 browser_(browser) {
66 // TODO(pkasting,marja): Once InfoBars own they delegates, this is not needed 52 // TODO(pkasting,marja): Once InfoBars own they delegates, this is not needed
67 // any more. Then we can rely on delegates getting destroyed, and we can 53 // any more. Then we can rely on delegates getting destroyed, and we can
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 DCHECK(type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED); 107 DCHECK(type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED);
122 if (content::Details<std::pair<InfoBarDelegate*, bool> >(details)->first != 108 if (content::Details<std::pair<InfoBarDelegate*, bool> >(details)->first !=
123 this) 109 this)
124 return; 110 return;
125 if (!accepted_) { 111 if (!accepted_) {
126 content::BrowserContext::GetDefaultStoragePartition(browser_->profile())-> 112 content::BrowserContext::GetDefaultStoragePartition(browser_->profile())->
127 GetDOMStorageContext()->StartScavengingUnusedSessionStorage(); 113 GetDOMStorageContext()->StartScavengingUnusedSessionStorage();
128 removed_notification_received_ = true; 114 removed_notification_received_ = true;
129 } 115 }
130 } 116 }
131
132 } // namespace
133
134 namespace chrome {
135
136 void ShowSessionCrashedPrompt(Browser* browser) {
137 // Assume that if the user is launching incognito they were previously
138 // running incognito so that we have nothing to restore from.
139 if (browser->profile()->IsOffTheRecord())
140 return;
141
142 // In ChromeBot tests, there might be a race. This line appears to get
143 // called during shutdown and |tab| can be NULL.
144 content::WebContents* tab =
145 browser->tab_strip_model()->GetActiveWebContents();
146 if (!tab)
147 return;
148
149 // Don't show the info-bar if there are already info-bars showing.
150 InfoBarService* infobar_service = InfoBarService::FromWebContents(tab);
151 if (infobar_service->GetInfoBarCount() > 0)
152 return;
153
154 infobar_service->AddInfoBar(
155 new SessionCrashedInfoBarDelegate(infobar_service, browser));
156 }
157
158 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/startup/session_crashed_prompt.h ('k') | chrome/browser/ui/startup/startup_browser_creator_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698