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

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

Issue 11740035: Don't access owner() in the constructor; eventually doing this won't work, because InfoBarDelegates… (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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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" 7 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
8 #include "chrome/browser/api/infobars/infobar_service.h" 8 #include "chrome/browser/api/infobars/infobar_service.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/sessions/session_restore.h" 10 #include "chrome/browser/sessions/session_restore.h"
(...skipping 12 matching lines...) Expand all
23 #include "grit/theme_resources.h" 23 #include "grit/theme_resources.h"
24 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
26 26
27 namespace { 27 namespace {
28 28
29 // A delegate for the InfoBar shown when the previous session has crashed. 29 // A delegate for the InfoBar shown when the previous session has crashed.
30 class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate, 30 class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate,
31 public content::NotificationObserver { 31 public content::NotificationObserver {
32 public: 32 public:
33 explicit SessionCrashedInfoBarDelegate(InfoBarService* infobar_service); 33 SessionCrashedInfoBarDelegate(InfoBarService* infobar_service,
34 Browser* browser);
34 35
35 private: 36 private:
36 virtual ~SessionCrashedInfoBarDelegate(); 37 virtual ~SessionCrashedInfoBarDelegate();
37 38
38 // ConfirmInfoBarDelegate: 39 // ConfirmInfoBarDelegate:
39 virtual gfx::Image* GetIcon() const OVERRIDE; 40 virtual gfx::Image* GetIcon() const OVERRIDE;
40 virtual string16 GetMessageText() const OVERRIDE; 41 virtual string16 GetMessageText() const OVERRIDE;
41 virtual int GetButtons() const OVERRIDE; 42 virtual int GetButtons() const OVERRIDE;
42 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; 43 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
43 virtual bool Accept() OVERRIDE; 44 virtual bool Accept() OVERRIDE;
44 45
45 // content::NotificationObserver: 46 // content::NotificationObserver:
46 virtual void Observe(int type, 47 virtual void Observe(int type,
47 const content::NotificationSource& source, 48 const content::NotificationSource& source,
48 const content::NotificationDetails& details) OVERRIDE; 49 const content::NotificationDetails& details) OVERRIDE;
49 50
50 content::NotificationRegistrar registrar_; 51 content::NotificationRegistrar registrar_;
51 bool accepted_; 52 bool accepted_;
52 bool removed_notification_received_; 53 bool removed_notification_received_;
53 Browser* browser_; 54 Browser* browser_;
54 55
55 DISALLOW_COPY_AND_ASSIGN(SessionCrashedInfoBarDelegate); 56 DISALLOW_COPY_AND_ASSIGN(SessionCrashedInfoBarDelegate);
56 }; 57 };
57 58
58 SessionCrashedInfoBarDelegate::SessionCrashedInfoBarDelegate( 59 SessionCrashedInfoBarDelegate::SessionCrashedInfoBarDelegate(
59 InfoBarService* infobar_service) 60 InfoBarService* infobar_service,
61 Browser* browser)
60 : ConfirmInfoBarDelegate(infobar_service), 62 : ConfirmInfoBarDelegate(infobar_service),
61 accepted_(false), 63 accepted_(false),
62 removed_notification_received_(false), 64 removed_notification_received_(false),
63 browser_(chrome::FindBrowserWithWebContents(owner()->GetWebContents())) { 65 browser_(browser) {
64 // TODO(pkasting,marja): Once InfoBars own they delegates, this is not needed 66 // TODO(pkasting,marja): Once InfoBars own they delegates, this is not needed
65 // any more. Then we can rely on delegates getting destroyed, and we can 67 // any more. Then we can rely on delegates getting destroyed, and we can
66 // initiate the session storage scavenging only in the destructor. (Currently, 68 // initiate the session storage scavenging only in the destructor. (Currently,
67 // info bars are leaked if they get closed while they're in background tabs.) 69 // info bars are leaked if they get closed while they're in background tabs.)
68 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, 70 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
69 content::NotificationService::AllSources()); 71 content::NotificationService::AllSources());
70 } 72 }
71 73
72 SessionCrashedInfoBarDelegate::~SessionCrashedInfoBarDelegate() { 74 SessionCrashedInfoBarDelegate::~SessionCrashedInfoBarDelegate() {
73 // If the info bar wasn't accepted, it was either dismissed or expired. In 75 // If the info bar wasn't accepted, it was either dismissed or expired. In
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 browser->tab_strip_model()->GetActiveWebContents(); 145 browser->tab_strip_model()->GetActiveWebContents();
144 if (!tab) 146 if (!tab)
145 return; 147 return;
146 148
147 // Don't show the info-bar if there are already info-bars showing. 149 // Don't show the info-bar if there are already info-bars showing.
148 InfoBarService* infobar_service = InfoBarService::FromWebContents(tab); 150 InfoBarService* infobar_service = InfoBarService::FromWebContents(tab);
149 if (infobar_service->GetInfoBarCount() > 0) 151 if (infobar_service->GetInfoBarCount() > 0)
150 return; 152 return;
151 153
152 infobar_service->AddInfoBar( 154 infobar_service->AddInfoBar(
153 new SessionCrashedInfoBarDelegate(infobar_service)); 155 new SessionCrashedInfoBarDelegate(infobar_service, browser));
154 } 156 }
155 157
156 } // namespace chrome 158 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698