OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/auto_login_info_bar_delegate.h" | 5 #include "chrome/browser/ui/auto_login_info_bar_delegate.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } // namepsace | 158 } // namepsace |
159 | 159 |
160 | 160 |
161 // AutoLoginInfoBarDelegate --------------------------------------------------- | 161 // AutoLoginInfoBarDelegate --------------------------------------------------- |
162 | 162 |
163 // AutoLoginInfoBarDelegate::Params ------------------------------------------- | 163 // AutoLoginInfoBarDelegate::Params ------------------------------------------- |
164 | 164 |
165 AutoLoginInfoBarDelegate::Params::Params() {} | 165 AutoLoginInfoBarDelegate::Params::Params() {} |
166 AutoLoginInfoBarDelegate::Params::~Params() {} | 166 AutoLoginInfoBarDelegate::Params::~Params() {} |
167 | 167 |
168 AutoLoginInfoBarDelegate::AutoLoginInfoBarDelegate( | 168 // static |
169 InfoBarService* owner, | 169 void AutoLoginInfoBarDelegate::Create(InfoBarService* infobar_service, |
170 const Params& params) | 170 const Params& params) { |
171 : ConfirmInfoBarDelegate(owner), | 171 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
172 params_(params), | 172 new AutoLoginInfoBarDelegate(infobar_service, params))); |
173 button_pressed_(false) { | |
174 RecordHistogramAction(HISTOGRAM_SHOWN); | |
175 registrar_.Add(this, | |
176 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, | |
177 content::Source<Profile>(Profile::FromBrowserContext( | |
178 owner->GetWebContents()->GetBrowserContext()))); | |
179 } | |
180 | |
181 AutoLoginInfoBarDelegate::~AutoLoginInfoBarDelegate() { | |
182 if (!button_pressed_) | |
183 RecordHistogramAction(HISTOGRAM_IGNORED); | |
184 } | 173 } |
185 | 174 |
186 AutoLoginInfoBarDelegate* | 175 AutoLoginInfoBarDelegate* |
187 AutoLoginInfoBarDelegate::AsAutoLoginInfoBarDelegate() { | 176 AutoLoginInfoBarDelegate::AsAutoLoginInfoBarDelegate() { |
188 return this; | 177 return this; |
189 } | 178 } |
190 | 179 |
191 void AutoLoginInfoBarDelegate::InfoBarDismissed() { | 180 void AutoLoginInfoBarDelegate::InfoBarDismissed() { |
192 RecordHistogramAction(HISTOGRAM_DISMISSED); | 181 RecordHistogramAction(HISTOGRAM_DISMISSED); |
193 button_pressed_ = true; | 182 button_pressed_ = true; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 button_pressed_ = true; | 219 button_pressed_ = true; |
231 return true; | 220 return true; |
232 } | 221 } |
233 | 222 |
234 string16 AutoLoginInfoBarDelegate::GetMessageText( | 223 string16 AutoLoginInfoBarDelegate::GetMessageText( |
235 const std::string& username) const { | 224 const std::string& username) const { |
236 return l10n_util::GetStringFUTF16(IDS_AUTOLOGIN_INFOBAR_MESSAGE, | 225 return l10n_util::GetStringFUTF16(IDS_AUTOLOGIN_INFOBAR_MESSAGE, |
237 UTF8ToUTF16(username)); | 226 UTF8ToUTF16(username)); |
238 } | 227 } |
239 | 228 |
| 229 AutoLoginInfoBarDelegate::AutoLoginInfoBarDelegate( |
| 230 InfoBarService* owner, |
| 231 const Params& params) |
| 232 : ConfirmInfoBarDelegate(owner), |
| 233 params_(params), |
| 234 button_pressed_(false) { |
| 235 RecordHistogramAction(HISTOGRAM_SHOWN); |
| 236 registrar_.Add(this, |
| 237 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, |
| 238 content::Source<Profile>(Profile::FromBrowserContext( |
| 239 owner->GetWebContents()->GetBrowserContext()))); |
| 240 } |
| 241 |
| 242 AutoLoginInfoBarDelegate::~AutoLoginInfoBarDelegate() { |
| 243 if (!button_pressed_) |
| 244 RecordHistogramAction(HISTOGRAM_IGNORED); |
| 245 } |
| 246 |
240 void AutoLoginInfoBarDelegate::RecordHistogramAction(int action) { | 247 void AutoLoginInfoBarDelegate::RecordHistogramAction(int action) { |
241 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Regular", action, HISTOGRAM_MAX); | 248 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Regular", action, HISTOGRAM_MAX); |
242 } | 249 } |
243 | 250 |
244 void AutoLoginInfoBarDelegate::Observe(int type, | 251 void AutoLoginInfoBarDelegate::Observe(int type, |
245 const NotificationSource& source, | 252 const NotificationSource& source, |
246 const NotificationDetails& details) { | 253 const NotificationDetails& details) { |
247 DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, type); | 254 DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, type); |
248 // owner() can be NULL when InfoBarService removes us. See | 255 // owner() can be NULL when InfoBarService removes us. See |
249 // |InfoBarDelegate::clear_owner|. | 256 // |InfoBarDelegate::clear_owner|. |
250 if (owner()) | 257 if (owner()) |
251 owner()->RemoveInfoBar(this); | 258 owner()->RemoveInfoBar(this); |
252 } | 259 } |
OLD | NEW |