Skip to content

Commit

Permalink
Update SSLAddCertData to use the Observer style from InfoBarManager.
Browse files Browse the repository at this point in the history
This way we can move away from content notifications, which is deprecated and
should be removed. The observer is the new way to listen for infobar
notifications.

BUG=354380
TEST=None
R=pkasting@chromium.org,wtc@chromium.org

Review URL: https://codereview.chromium.org/285493002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270477 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
tfarina@chromium.org committed May 14, 2014
1 parent 27e16d0 commit 63914da
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 62 deletions.
6 changes: 0 additions & 6 deletions chrome/browser/chrome_notification_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,6 @@ enum NotificationType {
// Details<InfoBar::RemovedDetails>.
NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,

// This message is sent when an InfoBar is replacing another infobar in an
// InfoBarService. The source is a Source<InfoBarService> with a pointer to
// the InfoBarService the InfoBar was removed from. The details is a
// Details<InfoBar::ReplacedDetails>.
NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED,

// Used to fire notifications about how long various events took to
// complete. E.g., this is used to get more fine grained timings from the
// new tab page. The source is a WebContents and the details is a
Expand Down
16 changes: 2 additions & 14 deletions chrome/browser/infobars/infobar_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int InfoBarService::GetActiveEntryID() {
void InfoBarService::NotifyInfoBarAdded(InfoBar* infobar) {
InfoBarManager::NotifyInfoBarAdded(infobar);
// TODO(droger): Remove the notifications and have listeners change to be
// NavigationManager::Observers instead. See http://crbug.com/354380
// InfoBarManager::Observers instead. See http://crbug.com/354380
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
content::Source<InfoBarService>(this),
Expand All @@ -78,26 +78,14 @@ void InfoBarService::NotifyInfoBarAdded(InfoBar* infobar) {
void InfoBarService::NotifyInfoBarRemoved(InfoBar* infobar, bool animate) {
InfoBarManager::NotifyInfoBarRemoved(infobar, animate);
// TODO(droger): Remove the notifications and have listeners change to be
// NavigationManager::Observers instead. See http://crbug.com/354380
// InfoBarManager::Observers instead. See http://crbug.com/354380
InfoBar::RemovedDetails removed_details(infobar, animate);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
content::Source<InfoBarService>(this),
content::Details<InfoBar::RemovedDetails>(&removed_details));
}

void InfoBarService::NotifyInfoBarReplaced(InfoBar* old_infobar,
InfoBar* new_infobar) {
InfoBarManager::NotifyInfoBarReplaced(old_infobar, new_infobar);
// TODO(droger): Remove the notifications and have listeners change to be
// NavigationManager::Observers instead. See http://crbug.com/354380
InfoBar::ReplacedDetails replaced_details(old_infobar, new_infobar);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED,
content::Source<InfoBarService>(this),
content::Details<InfoBar::ReplacedDetails>(&replaced_details));
}

void InfoBarService::RenderProcessGone(base::TerminationStatus status) {
RemoveAllInfoBars(true);
}
Expand Down
2 changes: 0 additions & 2 deletions chrome/browser/infobars/infobar_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ class InfoBarService : public infobars::InfoBarManager,
virtual void NotifyInfoBarAdded(infobars::InfoBar* infobar) OVERRIDE;
virtual void NotifyInfoBarRemoved(infobars::InfoBar* infobar,
bool animate) OVERRIDE;
virtual void NotifyInfoBarReplaced(infobars::InfoBar* old_infobar,
infobars::InfoBar* new_infobar) OVERRIDE;

// content::WebContentsObserver:
virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
Expand Down
48 changes: 19 additions & 29 deletions chrome/browser/ssl/ssl_tab_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/common/chrome_switches.h"
#include "components/infobars/core/infobar.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_source.h"
#include "components/infobars/core/infobar_manager.h"
#include "content/public/browser/web_contents.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
Expand Down Expand Up @@ -132,8 +129,7 @@ bool SSLCertResultInfoBarDelegate::Accept() {

// SSLTabHelper::SSLAddCertData ------------------------------------------------

class SSLTabHelper::SSLAddCertData
: public content::NotificationObserver {
class SSLTabHelper::SSLAddCertData : public infobars::InfoBarManager::Observer {
public:
explicit SSLAddCertData(InfoBarService* infobar_service);
virtual ~SSLAddCertData();
Expand All @@ -142,29 +138,26 @@ class SSLTabHelper::SSLAddCertData
void ShowInfoBar(const base::string16& message, net::X509Certificate* cert);

private:
// content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// infobars::InfoBarManager::Observer:
virtual void OnInfoBarRemoved(infobars::InfoBar* infobar,
bool animate) OVERRIDE;
virtual void OnInfoBarReplaced(infobars::InfoBar* old_infobar,
infobars::InfoBar* new_infobar) OVERRIDE;

InfoBarService* infobar_service_;
infobars::InfoBar* infobar_;
content::NotificationRegistrar registrar_;

DISALLOW_COPY_AND_ASSIGN(SSLAddCertData);
};

SSLTabHelper::SSLAddCertData::SSLAddCertData(InfoBarService* infobar_service)
: infobar_service_(infobar_service),
infobar_(NULL) {
content::Source<InfoBarService> source(infobar_service_);
registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
source);
registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED,
source);
infobar_service_->AddObserver(this);
}

SSLTabHelper::SSLAddCertData::~SSLAddCertData() {
infobar_service_->RemoveObserver(this);
}

void SSLTabHelper::SSLAddCertData::ShowInfoBar(const base::string16& message,
Expand All @@ -173,20 +166,17 @@ void SSLTabHelper::SSLAddCertData::ShowInfoBar(const base::string16& message,
message, cert);
}

void SSLTabHelper::SSLAddCertData::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK(type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED ||
type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED);
if (infobar_ ==
((type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED) ?
content::Details<infobars::InfoBar::RemovedDetails>(
details)->first :
content::Details<infobars::InfoBar::ReplacedDetails>(
details)->first)) {
void SSLTabHelper::SSLAddCertData::OnInfoBarRemoved(infobars::InfoBar* infobar,
bool animate) {
if (infobar_ == infobar)
infobar_ = NULL;
}

void SSLTabHelper::SSLAddCertData::OnInfoBarReplaced(
infobars::InfoBar* old_infobar,
infobars::InfoBar* new_infobar) {
if (infobar_ == old_infobar)
infobar_ = NULL;
}
}


Expand Down
1 change: 0 additions & 1 deletion components/infobars/core/infobar.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class InfoBar : public gfx::AnimationDelegate {
// These are the types passed as Details for infobar-related notifications.
typedef InfoBar AddedDetails;
typedef std::pair<InfoBar*, bool> RemovedDetails;
typedef std::pair<InfoBar*, InfoBar*> ReplacedDetails;

// Platforms must define these.
static const int kDefaultBarTargetHeight;
Expand Down
11 changes: 3 additions & 8 deletions components/infobars/core/infobar_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ InfoBar* InfoBarManager::ReplaceInfoBar(InfoBar* old_infobar,
// to AddInfoBar() or similar, we don't dupe-check against this infobar.
infobars_.erase(++i);

NotifyInfoBarReplaced(old_infobar, new_infobar_ptr);
FOR_EACH_OBSERVER(Observer,
observer_list_,
OnInfoBarReplaced(old_infobar, new_infobar_ptr));

old_infobar->CloseSoon();
return new_infobar_ptr;
Expand Down Expand Up @@ -130,13 +132,6 @@ void InfoBarManager::NotifyInfoBarRemoved(InfoBar* infobar, bool animate) {
OnInfoBarRemoved(infobar, animate));
}

void InfoBarManager::NotifyInfoBarReplaced(InfoBar* old_infobar,
InfoBar* new_infobar) {
FOR_EACH_OBSERVER(Observer,
observer_list_,
OnInfoBarReplaced(old_infobar, new_infobar));
}

void InfoBarManager::RemoveInfoBarInternal(InfoBar* infobar, bool animate) {
DCHECK(infobar);
if (!infobars_enabled_) {
Expand Down
2 changes: 0 additions & 2 deletions components/infobars/core/infobar_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ class InfoBarManager {
// overrides are removed (see http://crbug.com/354380).
virtual void NotifyInfoBarAdded(InfoBar* infobar);
virtual void NotifyInfoBarRemoved(InfoBar* infobar, bool animate);
virtual void NotifyInfoBarReplaced(InfoBar* old_infobar,
InfoBar* new_infobar);

private:
// InfoBars associated with this InfoBarManager. We own these pointers.
Expand Down

0 comments on commit 63914da

Please sign in to comment.