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

Side by Side Diff: chrome/browser/infobars/infobar_manager.cc

Issue 228293004: InfoBarService inherits from InfoBarManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 6 years, 8 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 | « chrome/browser/infobars/infobar_manager.h ('k') | chrome/browser/infobars/infobar_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/infobars/infobar_manager.h" 5 #include "chrome/browser/infobars/infobar_manager.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/infobars/infobar.h" 8 #include "chrome/browser/infobars/infobar.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 10
11 InfoBar* InfoBarManager::AddInfoBar(scoped_ptr<InfoBar> infobar) { 11 InfoBar* InfoBarManager::AddInfoBar(scoped_ptr<InfoBar> infobar) {
12 DCHECK(infobar); 12 DCHECK(infobar);
13 if (!infobars_enabled_) 13 if (!infobars_enabled_)
14 return NULL; 14 return NULL;
15 15
16 for (InfoBars::const_iterator i(infobars_.begin()); i != infobars_.end(); 16 for (InfoBars::const_iterator i(infobars_.begin()); i != infobars_.end();
17 ++i) { 17 ++i) {
18 if ((*i)->delegate()->EqualsDelegate(infobar->delegate())) { 18 if ((*i)->delegate()->EqualsDelegate(infobar->delegate())) {
19 DCHECK_NE((*i)->delegate(), infobar->delegate()); 19 DCHECK_NE((*i)->delegate(), infobar->delegate());
20 return NULL; 20 return NULL;
21 } 21 }
22 } 22 }
23 23
24 InfoBar* infobar_ptr = infobar.release(); 24 InfoBar* infobar_ptr = infobar.release();
25 infobars_.push_back(infobar_ptr); 25 infobars_.push_back(infobar_ptr);
26 infobar_ptr->SetOwner(this); 26 infobar_ptr->SetOwner(this);
27 27
28 FOR_EACH_OBSERVER(Observer, observer_list_, OnInfoBarAdded(infobar_ptr)); 28 NotifyInfoBarAdded(infobar_ptr);
29 29
30 return infobar_ptr; 30 return infobar_ptr;
31 } 31 }
32 32
33 void InfoBarManager::RemoveInfoBar(InfoBar* infobar) { 33 void InfoBarManager::RemoveInfoBar(InfoBar* infobar) {
34 RemoveInfoBarInternal(infobar, true); 34 RemoveInfoBarInternal(infobar, true);
35 } 35 }
36 36
37 void InfoBarManager::RemoveAllInfoBars(bool animate) { 37 void InfoBarManager::RemoveAllInfoBars(bool animate) {
38 while (!infobars_.empty()) 38 while (!infobars_.empty())
(...skipping 12 matching lines...) Expand all
51 DCHECK(i != infobars_.end()); 51 DCHECK(i != infobars_.end());
52 52
53 InfoBar* new_infobar_ptr = new_infobar.release(); 53 InfoBar* new_infobar_ptr = new_infobar.release();
54 i = infobars_.insert(i, new_infobar_ptr); 54 i = infobars_.insert(i, new_infobar_ptr);
55 new_infobar_ptr->SetOwner(this); 55 new_infobar_ptr->SetOwner(this);
56 56
57 // Remove the old infobar before notifying, so that if any observers call back 57 // Remove the old infobar before notifying, so that if any observers call back
58 // to AddInfoBar() or similar, we don't dupe-check against this infobar. 58 // to AddInfoBar() or similar, we don't dupe-check against this infobar.
59 infobars_.erase(++i); 59 infobars_.erase(++i);
60 60
61 FOR_EACH_OBSERVER(Observer, 61 NotifyInfoBarReplaced(old_infobar, new_infobar_ptr);
62 observer_list_,
63 OnInfoBarReplaced(old_infobar, new_infobar_ptr));
64 62
65 old_infobar->CloseSoon(); 63 old_infobar->CloseSoon();
66 return new_infobar_ptr; 64 return new_infobar_ptr;
67 } 65 }
68 66
69 void InfoBarManager::AddObserver(Observer* obs) { 67 void InfoBarManager::AddObserver(Observer* obs) {
70 observer_list_.AddObserver(obs); 68 observer_list_.AddObserver(obs);
71 } 69 }
72 70
73 void InfoBarManager::RemoveObserver(Observer* obs) { 71 void InfoBarManager::RemoveObserver(Observer* obs) {
74 observer_list_.RemoveObserver(obs); 72 observer_list_.RemoveObserver(obs);
75 } 73 }
76 74
77 InfoBarManager::InfoBarManager(content::WebContents* web_contents) 75 InfoBarManager::InfoBarManager()
78 : infobars_enabled_(true), 76 : infobars_enabled_(true) {
79 web_contents_(web_contents) {
80 DCHECK(web_contents);
81 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableInfoBars)) 77 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableInfoBars))
82 infobars_enabled_ = false; 78 infobars_enabled_ = false;
83 } 79 }
84 80
85 InfoBarManager::~InfoBarManager() { 81 InfoBarManager::~InfoBarManager() {}
82
83 void InfoBarManager::ShutDown() {
86 // Destroy all remaining InfoBars. It's important to not animate here so that 84 // Destroy all remaining InfoBars. It's important to not animate here so that
87 // we guarantee that we'll delete all delegates before we do anything else. 85 // we guarantee that we'll delete all delegates before we do anything else.
88 RemoveAllInfoBars(false); 86 RemoveAllInfoBars(false);
89 FOR_EACH_OBSERVER(Observer, observer_list_, OnManagerShuttingDown(this)); 87 FOR_EACH_OBSERVER(Observer, observer_list_, OnManagerShuttingDown(this));
90 } 88 }
91 89
92 void InfoBarManager::OnNavigation( 90 void InfoBarManager::OnNavigation(
93 const InfoBarDelegate::NavigationDetails& details) { 91 const InfoBarDelegate::NavigationDetails& details) {
94 // NOTE: It is not safe to change the following code to count upwards or 92 // NOTE: It is not safe to change the following code to count upwards or
95 // use iterators, as the RemoveInfoBar() call synchronously modifies our 93 // use iterators, as the RemoveInfoBar() call synchronously modifies our
96 // delegate list. 94 // delegate list.
97 for (size_t i = infobars_.size(); i > 0; --i) { 95 for (size_t i = infobars_.size(); i > 0; --i) {
98 InfoBar* infobar = infobars_[i - 1]; 96 InfoBar* infobar = infobars_[i - 1];
99 if (infobar->delegate()->ShouldExpire(details)) 97 if (infobar->delegate()->ShouldExpire(details))
100 RemoveInfoBar(infobar); 98 RemoveInfoBar(infobar);
101 } 99 }
102 } 100 }
103 101
104 void InfoBarManager::OnWebContentsDestroyed() { web_contents_ = NULL; } 102 void InfoBarManager::NotifyInfoBarAdded(InfoBar* infobar) {
103 FOR_EACH_OBSERVER(Observer, observer_list_, OnInfoBarAdded(infobar));
104 }
105
106 void InfoBarManager::NotifyInfoBarRemoved(InfoBar* infobar, bool animate) {
107 FOR_EACH_OBSERVER(Observer, observer_list_,
108 OnInfoBarRemoved(infobar, animate));
109 }
110
111 void InfoBarManager::NotifyInfoBarReplaced(InfoBar* old_infobar,
112 InfoBar* new_infobar) {
113 FOR_EACH_OBSERVER(Observer,
114 observer_list_,
115 OnInfoBarReplaced(old_infobar, new_infobar));
116 }
105 117
106 void InfoBarManager::RemoveInfoBarInternal(InfoBar* infobar, bool animate) { 118 void InfoBarManager::RemoveInfoBarInternal(InfoBar* infobar, bool animate) {
107 DCHECK(infobar); 119 DCHECK(infobar);
108 if (!infobars_enabled_) { 120 if (!infobars_enabled_) {
109 DCHECK(infobars_.empty()); 121 DCHECK(infobars_.empty());
110 return; 122 return;
111 } 123 }
112 124
113 InfoBars::iterator i(std::find(infobars_.begin(), infobars_.end(), infobar)); 125 InfoBars::iterator i(std::find(infobars_.begin(), infobars_.end(), infobar));
114 DCHECK(i != infobars_.end()); 126 DCHECK(i != infobars_.end());
115 127
116 // Remove the infobar before notifying, so that if any observers call back to 128 // Remove the infobar before notifying, so that if any observers call back to
117 // AddInfoBar() or similar, we don't dupe-check against this infobar. 129 // AddInfoBar() or similar, we don't dupe-check against this infobar.
118 infobars_.erase(i); 130 infobars_.erase(i);
119 131
120 // This notification must happen before the call to CloseSoon() below, since 132 // This notification must happen before the call to CloseSoon() below, since
121 // observers may want to access |infobar| and that call can delete it. 133 // observers may want to access |infobar| and that call can delete it.
122 FOR_EACH_OBSERVER(Observer, observer_list_, 134 NotifyInfoBarRemoved(infobar, animate);
123 OnInfoBarRemoved(infobar, animate));
124 135
125 infobar->CloseSoon(); 136 infobar->CloseSoon();
126 } 137 }
OLDNEW
« no previous file with comments | « chrome/browser/infobars/infobar_manager.h ('k') | chrome/browser/infobars/infobar_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698