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

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

Issue 2335203003: Add metrics to keep track of the tab activate/deactivate cycle (Closed)
Patch Set: Addressed comments 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 // Do not use |tab_strip_model| as it may be null from the call in
164 // TabChangedAt().
165 void GlobalConfirmInfoBar::TabInsertedAt(TabStripModel* tab_strip_model,
166 content::WebContents* web_contents,
164 int index, 167 int index,
165 bool foreground) { 168 bool foreground) {
166 InfoBarService* infobar_service = 169 InfoBarService* infobar_service =
167 InfoBarService::FromWebContents(web_contents); 170 InfoBarService::FromWebContents(web_contents);
168 // WebContents from the tab strip must have the infobar service. 171 // WebContents from the tab strip must have the infobar service.
169 DCHECK(infobar_service); 172 DCHECK(infobar_service);
170 if (proxies_.find(infobar_service) != proxies_.end()) 173 if (proxies_.find(infobar_service) != proxies_.end())
171 return; 174 return;
172 175
173 std::unique_ptr<GlobalConfirmInfoBar::DelegateProxy> proxy( 176 std::unique_ptr<GlobalConfirmInfoBar::DelegateProxy> proxy(
174 new GlobalConfirmInfoBar::DelegateProxy(weak_factory_.GetWeakPtr())); 177 new GlobalConfirmInfoBar::DelegateProxy(weak_factory_.GetWeakPtr()));
175 GlobalConfirmInfoBar::DelegateProxy* proxy_ptr = proxy.get(); 178 GlobalConfirmInfoBar::DelegateProxy* proxy_ptr = proxy.get();
176 infobars::InfoBar* added_bar = infobar_service->AddInfoBar( 179 infobars::InfoBar* added_bar = infobar_service->AddInfoBar(
177 infobar_service->CreateConfirmInfoBar(std::move(proxy))); 180 infobar_service->CreateConfirmInfoBar(std::move(proxy)));
178 181
179 proxy_ptr->info_bar_ = added_bar; 182 proxy_ptr->info_bar_ = added_bar;
180 DCHECK(added_bar); 183 DCHECK(added_bar);
181 proxies_[infobar_service] = proxy_ptr; 184 proxies_[infobar_service] = proxy_ptr;
182 infobar_service->AddObserver(this); 185 infobar_service->AddObserver(this);
183 } 186 }
184 187
185 void GlobalConfirmInfoBar::TabChangedAt(content::WebContents* web_contents, 188 void GlobalConfirmInfoBar::TabChangedAt(content::WebContents* web_contents,
186 int index, 189 int index,
187 TabChangeType change_type) { 190 TabChangeType change_type) {
188 InfoBarService* infobar_service = 191 InfoBarService* infobar_service =
189 InfoBarService::FromWebContents(web_contents); 192 InfoBarService::FromWebContents(web_contents);
190 auto it = proxies_.find(infobar_service); 193 auto it = proxies_.find(infobar_service);
191 if (it == proxies_.end()) 194 if (it == proxies_.end())
192 TabInsertedAt(web_contents, index, false); 195 TabInsertedAt(nullptr, web_contents, index, false);
193 } 196 }
194 197
195 void GlobalConfirmInfoBar::OnInfoBarRemoved(infobars::InfoBar* info_bar, 198 void GlobalConfirmInfoBar::OnInfoBarRemoved(infobars::InfoBar* info_bar,
196 bool animate) { 199 bool animate) {
197 // Do not process alien infobars. 200 // Do not process alien infobars.
198 for (auto it : proxies_) { 201 for (auto it : proxies_) {
199 if (it.second->info_bar_ == info_bar) { 202 if (it.second->info_bar_ == info_bar) {
200 OnManagerShuttingDown(info_bar->owner()); 203 OnManagerShuttingDown(info_bar->owner());
201 break; 204 break;
202 } 205 }
203 } 206 }
204 } 207 }
205 208
206 void GlobalConfirmInfoBar::OnManagerShuttingDown( 209 void GlobalConfirmInfoBar::OnManagerShuttingDown(
207 infobars::InfoBarManager* manager) { 210 infobars::InfoBarManager* manager) {
208 manager->RemoveObserver(this); 211 manager->RemoveObserver(this);
209 proxies_.erase(manager); 212 proxies_.erase(manager);
210 } 213 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698