OLD | NEW |
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 "components/infobars/core/infobar_manager.h" | 5 #include "components/infobars/core/infobar_manager.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "components/infobars/core/infobar.h" | 10 #include "components/infobars/core/infobar.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 DCHECK(i != infobars_.end()); | 78 DCHECK(i != infobars_.end()); |
79 | 79 |
80 InfoBar* new_infobar_ptr = new_infobar.release(); | 80 InfoBar* new_infobar_ptr = new_infobar.release(); |
81 i = infobars_.insert(i, new_infobar_ptr); | 81 i = infobars_.insert(i, new_infobar_ptr); |
82 new_infobar_ptr->SetOwner(this); | 82 new_infobar_ptr->SetOwner(this); |
83 | 83 |
84 // Remove the old infobar before notifying, so that if any observers call back | 84 // Remove the old infobar before notifying, so that if any observers call back |
85 // to AddInfoBar() or similar, we don't dupe-check against this infobar. | 85 // to AddInfoBar() or similar, we don't dupe-check against this infobar. |
86 infobars_.erase(++i); | 86 infobars_.erase(++i); |
87 | 87 |
88 FOR_EACH_OBSERVER(Observer, | 88 for (Observer& observer : observer_list_) |
89 observer_list_, | 89 observer.OnInfoBarReplaced(old_infobar, new_infobar_ptr); |
90 OnInfoBarReplaced(old_infobar, new_infobar_ptr)); | |
91 | 90 |
92 old_infobar->CloseSoon(); | 91 old_infobar->CloseSoon(); |
93 return new_infobar_ptr; | 92 return new_infobar_ptr; |
94 } | 93 } |
95 | 94 |
96 void InfoBarManager::AddObserver(Observer* obs) { | 95 void InfoBarManager::AddObserver(Observer* obs) { |
97 observer_list_.AddObserver(obs); | 96 observer_list_.AddObserver(obs); |
98 } | 97 } |
99 | 98 |
100 void InfoBarManager::RemoveObserver(Observer* obs) { | 99 void InfoBarManager::RemoveObserver(Observer* obs) { |
101 observer_list_.RemoveObserver(obs); | 100 observer_list_.RemoveObserver(obs); |
102 } | 101 } |
103 | 102 |
104 InfoBarManager::InfoBarManager() | 103 InfoBarManager::InfoBarManager() |
105 : infobars_enabled_(true) { | 104 : infobars_enabled_(true) { |
106 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 105 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
107 switches::kDisableInfoBars)) | 106 switches::kDisableInfoBars)) |
108 infobars_enabled_ = false; | 107 infobars_enabled_ = false; |
109 } | 108 } |
110 | 109 |
111 InfoBarManager::~InfoBarManager() {} | 110 InfoBarManager::~InfoBarManager() {} |
112 | 111 |
113 void InfoBarManager::ShutDown() { | 112 void InfoBarManager::ShutDown() { |
114 // Destroy all remaining InfoBars. It's important to not animate here so that | 113 // Destroy all remaining InfoBars. It's important to not animate here so that |
115 // we guarantee that we'll delete all delegates before we do anything else. | 114 // we guarantee that we'll delete all delegates before we do anything else. |
116 RemoveAllInfoBars(false); | 115 RemoveAllInfoBars(false); |
117 FOR_EACH_OBSERVER(Observer, observer_list_, OnManagerShuttingDown(this)); | 116 for (Observer& observer : observer_list_) |
| 117 observer.OnManagerShuttingDown(this); |
118 } | 118 } |
119 | 119 |
120 void InfoBarManager::OnNavigation( | 120 void InfoBarManager::OnNavigation( |
121 const InfoBarDelegate::NavigationDetails& details) { | 121 const InfoBarDelegate::NavigationDetails& details) { |
122 // NOTE: It is not safe to change the following code to count upwards or | 122 // NOTE: It is not safe to change the following code to count upwards or |
123 // use iterators, as the RemoveInfoBar() call synchronously modifies our | 123 // use iterators, as the RemoveInfoBar() call synchronously modifies our |
124 // delegate list. | 124 // delegate list. |
125 for (size_t i = infobars_.size(); i > 0; --i) { | 125 for (size_t i = infobars_.size(); i > 0; --i) { |
126 InfoBar* infobar = infobars_[i - 1]; | 126 InfoBar* infobar = infobars_[i - 1]; |
127 if (infobar->delegate()->ShouldExpire(details)) | 127 if (infobar->delegate()->ShouldExpire(details)) |
128 RemoveInfoBar(infobar); | 128 RemoveInfoBar(infobar); |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 void InfoBarManager::NotifyInfoBarAdded(InfoBar* infobar) { | 132 void InfoBarManager::NotifyInfoBarAdded(InfoBar* infobar) { |
133 FOR_EACH_OBSERVER(Observer, observer_list_, OnInfoBarAdded(infobar)); | 133 for (Observer& observer : observer_list_) |
| 134 observer.OnInfoBarAdded(infobar); |
134 } | 135 } |
135 | 136 |
136 void InfoBarManager::NotifyInfoBarRemoved(InfoBar* infobar, bool animate) { | 137 void InfoBarManager::NotifyInfoBarRemoved(InfoBar* infobar, bool animate) { |
137 FOR_EACH_OBSERVER(Observer, observer_list_, | 138 for (Observer& observer : observer_list_) |
138 OnInfoBarRemoved(infobar, animate)); | 139 observer.OnInfoBarRemoved(infobar, animate); |
139 } | 140 } |
140 | 141 |
141 void InfoBarManager::RemoveInfoBarInternal(InfoBar* infobar, bool animate) { | 142 void InfoBarManager::RemoveInfoBarInternal(InfoBar* infobar, bool animate) { |
142 DCHECK(infobar); | 143 DCHECK(infobar); |
143 if (!infobars_enabled_) { | 144 if (!infobars_enabled_) { |
144 DCHECK(infobars_.empty()); | 145 DCHECK(infobars_.empty()); |
145 return; | 146 return; |
146 } | 147 } |
147 | 148 |
148 InfoBars::iterator i(std::find(infobars_.begin(), infobars_.end(), infobar)); | 149 InfoBars::iterator i(std::find(infobars_.begin(), infobars_.end(), infobar)); |
149 DCHECK(i != infobars_.end()); | 150 DCHECK(i != infobars_.end()); |
150 | 151 |
151 // Remove the infobar before notifying, so that if any observers call back to | 152 // Remove the infobar before notifying, so that if any observers call back to |
152 // AddInfoBar() or similar, we don't dupe-check against this infobar. | 153 // AddInfoBar() or similar, we don't dupe-check against this infobar. |
153 infobars_.erase(i); | 154 infobars_.erase(i); |
154 | 155 |
155 // This notification must happen before the call to CloseSoon() below, since | 156 // This notification must happen before the call to CloseSoon() below, since |
156 // observers may want to access |infobar| and that call can delete it. | 157 // observers may want to access |infobar| and that call can delete it. |
157 NotifyInfoBarRemoved(infobar, animate); | 158 NotifyInfoBarRemoved(infobar, animate); |
158 | 159 |
159 infobar->CloseSoon(); | 160 infobar->CloseSoon(); |
160 } | 161 } |
161 | 162 |
162 } // namespace infobars | 163 } // namespace infobars |
OLD | NEW |