OLD | NEW |
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> |
| 8 |
7 #include "base/macros.h" | 9 #include "base/macros.h" |
8 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/host_desktop.h" | 11 #include "chrome/browser/ui/host_desktop.h" |
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
11 #include "components/infobars/core/infobar.h" | 13 #include "components/infobars/core/infobar.h" |
12 #include "ui/gfx/image/image.h" | 14 #include "ui/gfx/image/image.h" |
13 | 15 |
14 // InfoBarDelegateProxy ------------------------------------------------------- | 16 // InfoBarDelegateProxy ------------------------------------------------------- |
15 | 17 |
16 class GlobalConfirmInfoBar::DelegateProxy : public ConfirmInfoBarDelegate { | 18 class GlobalConfirmInfoBar::DelegateProxy : public ConfirmInfoBarDelegate { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 119 |
118 void GlobalConfirmInfoBar::DelegateProxy::Detach() { | 120 void GlobalConfirmInfoBar::DelegateProxy::Detach() { |
119 global_info_bar_.reset(); | 121 global_info_bar_.reset(); |
120 } | 122 } |
121 | 123 |
122 // GlobalConfirmInfoBar ------------------------------------------------------- | 124 // GlobalConfirmInfoBar ------------------------------------------------------- |
123 | 125 |
124 // static | 126 // static |
125 base::WeakPtr<GlobalConfirmInfoBar> GlobalConfirmInfoBar::Show( | 127 base::WeakPtr<GlobalConfirmInfoBar> GlobalConfirmInfoBar::Show( |
126 scoped_ptr<ConfirmInfoBarDelegate> delegate) { | 128 scoped_ptr<ConfirmInfoBarDelegate> delegate) { |
127 GlobalConfirmInfoBar* info_bar = new GlobalConfirmInfoBar(delegate.Pass()); | 129 GlobalConfirmInfoBar* info_bar = |
| 130 new GlobalConfirmInfoBar(std::move(delegate)); |
128 return info_bar->weak_factory_.GetWeakPtr(); | 131 return info_bar->weak_factory_.GetWeakPtr(); |
129 } | 132 } |
130 | 133 |
131 void GlobalConfirmInfoBar::Close() { | 134 void GlobalConfirmInfoBar::Close() { |
132 delete this; | 135 delete this; |
133 } | 136 } |
134 | 137 |
135 GlobalConfirmInfoBar::GlobalConfirmInfoBar( | 138 GlobalConfirmInfoBar::GlobalConfirmInfoBar( |
136 scoped_ptr<ConfirmInfoBarDelegate> delegate) | 139 scoped_ptr<ConfirmInfoBarDelegate> delegate) |
137 : delegate_(delegate.Pass()), | 140 : delegate_(std::move(delegate)), |
138 browser_tab_strip_tracker_(this, nullptr, nullptr), | 141 browser_tab_strip_tracker_(this, nullptr, nullptr), |
139 weak_factory_(this) { | 142 weak_factory_(this) { |
140 browser_tab_strip_tracker_.Init( | 143 browser_tab_strip_tracker_.Init( |
141 BrowserTabStripTracker::InitWith::BROWSERS_IN_ACTIVE_DESKTOP); | 144 BrowserTabStripTracker::InitWith::BROWSERS_IN_ACTIVE_DESKTOP); |
142 } | 145 } |
143 | 146 |
144 GlobalConfirmInfoBar::~GlobalConfirmInfoBar() { | 147 GlobalConfirmInfoBar::~GlobalConfirmInfoBar() { |
145 while (!proxies_.empty()) { | 148 while (!proxies_.empty()) { |
146 auto it = proxies_.begin(); | 149 auto it = proxies_.begin(); |
147 it->second->Detach(); | 150 it->second->Detach(); |
(...skipping 10 matching lines...) Expand all Loading... |
158 InfoBarService::FromWebContents(web_contents); | 161 InfoBarService::FromWebContents(web_contents); |
159 // WebContents from the tab strip must have the infobar service. | 162 // WebContents from the tab strip must have the infobar service. |
160 DCHECK(infobar_service); | 163 DCHECK(infobar_service); |
161 if (proxies_.find(infobar_service) != proxies_.end()) | 164 if (proxies_.find(infobar_service) != proxies_.end()) |
162 return; | 165 return; |
163 | 166 |
164 scoped_ptr<GlobalConfirmInfoBar::DelegateProxy> proxy( | 167 scoped_ptr<GlobalConfirmInfoBar::DelegateProxy> proxy( |
165 new GlobalConfirmInfoBar::DelegateProxy(weak_factory_.GetWeakPtr())); | 168 new GlobalConfirmInfoBar::DelegateProxy(weak_factory_.GetWeakPtr())); |
166 GlobalConfirmInfoBar::DelegateProxy* proxy_ptr = proxy.get(); | 169 GlobalConfirmInfoBar::DelegateProxy* proxy_ptr = proxy.get(); |
167 infobars::InfoBar* added_bar = infobar_service->AddInfoBar( | 170 infobars::InfoBar* added_bar = infobar_service->AddInfoBar( |
168 infobar_service->CreateConfirmInfoBar(proxy.Pass())); | 171 infobar_service->CreateConfirmInfoBar(std::move(proxy))); |
169 | 172 |
170 proxy_ptr->info_bar_ = added_bar; | 173 proxy_ptr->info_bar_ = added_bar; |
171 DCHECK(added_bar); | 174 DCHECK(added_bar); |
172 proxies_[infobar_service] = proxy_ptr; | 175 proxies_[infobar_service] = proxy_ptr; |
173 infobar_service->AddObserver(this); | 176 infobar_service->AddObserver(this); |
174 } | 177 } |
175 | 178 |
176 void GlobalConfirmInfoBar::TabChangedAt(content::WebContents* web_contents, | 179 void GlobalConfirmInfoBar::TabChangedAt(content::WebContents* web_contents, |
177 int index, | 180 int index, |
178 TabChangeType change_type) { | 181 TabChangeType change_type) { |
(...skipping 13 matching lines...) Expand all Loading... |
192 break; | 195 break; |
193 } | 196 } |
194 } | 197 } |
195 } | 198 } |
196 | 199 |
197 void GlobalConfirmInfoBar::OnManagerShuttingDown( | 200 void GlobalConfirmInfoBar::OnManagerShuttingDown( |
198 infobars::InfoBarManager* manager) { | 201 infobars::InfoBarManager* manager) { |
199 manager->RemoveObserver(this); | 202 manager->RemoveObserver(this); |
200 proxies_.erase(manager); | 203 proxies_.erase(manager); |
201 } | 204 } |
OLD | NEW |