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

Side by Side Diff: chrome/browser/devtools/global_confirm_info_bar.cc

Issue 2354673004: Add TabStripModel as a parameter of some functions in TabStripModelObserver (Closed)
Patch Set: Addressed comment + fix compilation Created 4 years, 3 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/devtools/global_confirm_info_bar.h" 5 #include "chrome/browser/devtools/global_confirm_info_bar.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 GlobalConfirmInfoBar::~GlobalConfirmInfoBar() { 153 GlobalConfirmInfoBar::~GlobalConfirmInfoBar() {
154 while (!proxies_.empty()) { 154 while (!proxies_.empty()) {
155 auto it = proxies_.begin(); 155 auto it = proxies_.begin();
156 it->second->Detach(); 156 it->second->Detach();
157 it->first->RemoveObserver(this); 157 it->first->RemoveObserver(this);
158 it->first->RemoveInfoBar(it->second->info_bar_); 158 it->first->RemoveInfoBar(it->second->info_bar_);
159 proxies_.erase(it); 159 proxies_.erase(it);
160 } 160 }
161 } 161 }
162 162
163 void GlobalConfirmInfoBar::TabInsertedAt(content::WebContents* web_contents, 163 void GlobalConfirmInfoBar::TabInsertedAt(TabStripModel* tab_strip_model,
164 content::WebContents* web_contents,
164 int index, 165 int index,
165 bool foreground) { 166 bool foreground) {
166 InfoBarService* infobar_service = 167 MaybeAddInfoBar(web_contents);
167 InfoBarService::FromWebContents(web_contents);
168 // WebContents from the tab strip must have the infobar service.
169 DCHECK(infobar_service);
170 if (proxies_.find(infobar_service) != proxies_.end())
171 return;
172
173 std::unique_ptr<GlobalConfirmInfoBar::DelegateProxy> proxy(
174 new GlobalConfirmInfoBar::DelegateProxy(weak_factory_.GetWeakPtr()));
175 GlobalConfirmInfoBar::DelegateProxy* proxy_ptr = proxy.get();
176 infobars::InfoBar* added_bar = infobar_service->AddInfoBar(
177 infobar_service->CreateConfirmInfoBar(std::move(proxy)));
178
179 proxy_ptr->info_bar_ = added_bar;
180 DCHECK(added_bar);
181 proxies_[infobar_service] = proxy_ptr;
182 infobar_service->AddObserver(this);
183 } 168 }
184 169
185 void GlobalConfirmInfoBar::TabChangedAt(content::WebContents* web_contents, 170 void GlobalConfirmInfoBar::TabChangedAt(content::WebContents* web_contents,
186 int index, 171 int index,
187 TabChangeType change_type) { 172 TabChangeType change_type) {
188 InfoBarService* infobar_service = 173 MaybeAddInfoBar(web_contents);
189 InfoBarService::FromWebContents(web_contents);
190 auto it = proxies_.find(infobar_service);
191 if (it == proxies_.end())
192 TabInsertedAt(web_contents, index, false);
193 } 174 }
194 175
195 void GlobalConfirmInfoBar::OnInfoBarRemoved(infobars::InfoBar* info_bar, 176 void GlobalConfirmInfoBar::OnInfoBarRemoved(infobars::InfoBar* info_bar,
196 bool animate) { 177 bool animate) {
197 // Do not process alien infobars. 178 // Do not process alien infobars.
198 for (auto it : proxies_) { 179 for (auto it : proxies_) {
199 if (it.second->info_bar_ == info_bar) { 180 if (it.second->info_bar_ == info_bar) {
200 OnManagerShuttingDown(info_bar->owner()); 181 OnManagerShuttingDown(info_bar->owner());
201 break; 182 break;
202 } 183 }
203 } 184 }
204 } 185 }
205 186
206 void GlobalConfirmInfoBar::OnManagerShuttingDown( 187 void GlobalConfirmInfoBar::OnManagerShuttingDown(
207 infobars::InfoBarManager* manager) { 188 infobars::InfoBarManager* manager) {
208 manager->RemoveObserver(this); 189 manager->RemoveObserver(this);
209 proxies_.erase(manager); 190 proxies_.erase(manager);
210 } 191 }
192
193 void GlobalConfirmInfoBar::MaybeAddInfoBar(content::WebContents* web_contents) {
194 InfoBarService* infobar_service =
195 InfoBarService::FromWebContents(web_contents);
196 // WebContents from the tab strip must have the infobar service.
197 DCHECK(infobar_service);
198 if (proxies_.find(infobar_service) != proxies_.end())
sky 2016/09/20 20:00:46 optional: ContainsKey(proxies_, infobar_service);
Patrick Monette 2016/09/20 20:11:54 Done.
199 return;
200
201 std::unique_ptr<GlobalConfirmInfoBar::DelegateProxy> proxy(
202 new GlobalConfirmInfoBar::DelegateProxy(weak_factory_.GetWeakPtr()));
203 GlobalConfirmInfoBar::DelegateProxy* proxy_ptr = proxy.get();
204 infobars::InfoBar* added_bar = infobar_service->AddInfoBar(
205 infobar_service->CreateConfirmInfoBar(std::move(proxy)));
206
207 proxy_ptr->info_bar_ = added_bar;
208 DCHECK(added_bar);
209 proxies_[infobar_service] = proxy_ptr;
210 infobar_service->AddObserver(this);
211 }
OLDNEW
« no previous file with comments | « chrome/browser/devtools/global_confirm_info_bar.h ('k') | chrome/browser/extensions/api/tabs/tabs_event_router.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698