ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / password_manager / save_password_infobar_delegate.cc
blobef4836ad478e2e79843880d45978de3cad24925c
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
3 // found in the LICENSE file.
5 #include "chrome/browser/password_manager/save_password_infobar_delegate.h"
7 #include "base/metrics/histogram.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/infobars/infobar_service.h"
10 #include "chrome/grit/chromium_strings.h"
11 #include "chrome/grit/generated_resources.h"
12 #include "components/infobars/core/infobar.h"
13 #include "components/password_manager/core/browser/password_form_manager.h"
14 #include "content/public/browser/navigation_entry.h"
15 #include "content/public/browser/web_contents.h"
16 #include "grit/theme_resources.h"
17 #include "ui/base/l10n/l10n_util.h"
19 // static
20 void SavePasswordInfoBarDelegate::Create(
21 content::WebContents* web_contents,
22 scoped_ptr<password_manager::PasswordFormManager> form_to_save,
23 const std::string& uma_histogram_suffix) {
24 InfoBarService* infobar_service =
25 InfoBarService::FromWebContents(web_contents);
26 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar(
27 scoped_ptr<ConfirmInfoBarDelegate>(new SavePasswordInfoBarDelegate(
28 form_to_save.Pass(), uma_histogram_suffix))));
31 SavePasswordInfoBarDelegate::~SavePasswordInfoBarDelegate() {
32 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse",
33 infobar_response_,
34 password_manager::metrics_util::NUM_RESPONSE_TYPES);
36 password_manager::metrics_util::LogUIDismissalReason(infobar_response_);
38 // The shortest period for which the prompt needs to live, so that we don't
39 // consider it killed prematurely, as might happen, e.g., if a pre-rendered
40 // page gets swapped in (and the current WebContents is destroyed).
41 const base::TimeDelta kMinimumPromptDisplayTime =
42 base::TimeDelta::FromSeconds(1);
44 if (!uma_histogram_suffix_.empty()) {
45 password_manager::metrics_util::LogUMAHistogramEnumeration(
46 "PasswordManager.SavePasswordPromptResponse_" + uma_histogram_suffix_,
47 infobar_response_,
48 password_manager::metrics_util::NUM_RESPONSE_TYPES);
49 password_manager::metrics_util::LogUMAHistogramBoolean(
50 "PasswordManager.SavePasswordPromptDisappearedQuickly_" +
51 uma_histogram_suffix_,
52 timer_.Elapsed() < kMinimumPromptDisplayTime);
56 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate(
57 scoped_ptr<password_manager::PasswordFormManager> form_to_save,
58 const std::string& uma_histogram_suffix)
59 : ConfirmInfoBarDelegate(),
60 form_to_save_(form_to_save.Pass()),
61 infobar_response_(password_manager::metrics_util::NO_RESPONSE),
62 uma_histogram_suffix_(uma_histogram_suffix) {
63 if (!uma_histogram_suffix_.empty()) {
64 password_manager::metrics_util::LogUMAHistogramBoolean(
65 "PasswordManager.SavePasswordPromptDisplayed_" + uma_histogram_suffix_,
66 true);
70 infobars::InfoBarDelegate::Type
71 SavePasswordInfoBarDelegate::GetInfoBarType() const {
72 return PAGE_ACTION_TYPE;
75 infobars::InfoBarDelegate::InfoBarAutomationType
76 SavePasswordInfoBarDelegate::GetInfoBarAutomationType() const {
77 return PASSWORD_INFOBAR;
80 int SavePasswordInfoBarDelegate::GetIconID() const {
81 return IDR_INFOBAR_SAVE_PASSWORD;
84 bool SavePasswordInfoBarDelegate::ShouldExpire(
85 const NavigationDetails& details) const {
86 return !details.is_redirect &&
87 infobars::InfoBarDelegate::ShouldExpire(details);
90 void SavePasswordInfoBarDelegate::InfoBarDismissed() {
91 DCHECK(form_to_save_.get());
92 infobar_response_ = password_manager::metrics_util::INFOBAR_DISMISSED;
95 base::string16 SavePasswordInfoBarDelegate::GetMessageText() const {
96 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT);
99 base::string16 SavePasswordInfoBarDelegate::GetButtonLabel(
100 InfoBarButton button) const {
101 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
102 IDS_PASSWORD_MANAGER_SAVE_BUTTON : IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON);
105 bool SavePasswordInfoBarDelegate::Accept() {
106 DCHECK(form_to_save_.get());
107 form_to_save_->Save();
108 infobar_response_ = password_manager::metrics_util::REMEMBER_PASSWORD;
109 return true;
112 bool SavePasswordInfoBarDelegate::Cancel() {
113 DCHECK(form_to_save_.get());
114 form_to_save_->PermanentlyBlacklist();
115 infobar_response_ = password_manager::metrics_util::NEVER_REMEMBER_PASSWORD;
116 return true;