| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/password_manager/save_password_infobar_delegate.h" | 5 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/sync/profile_sync_service_factory.h" | 12 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 13 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" | 13 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" |
| 14 #include "chrome/grit/chromium_strings.h" | 14 #include "chrome/grit/chromium_strings.h" |
| 15 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
| 16 #include "components/browser_sync/browser/profile_sync_service.h" | 16 #include "components/browser_sync/browser/profile_sync_service.h" |
| 17 #include "components/infobars/core/infobar.h" | 17 #include "components/infobars/core/infobar.h" |
| 18 #include "components/password_manager/core/browser/password_bubble_experiment.h" | 18 #include "components/password_manager/core/browser/password_bubble_experiment.h" |
| 19 #include "components/password_manager/core/browser/password_manager_client.h" | 19 #include "components/password_manager/core/browser/password_manager_client.h" |
| 20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 21 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "url/origin.h" | 23 #include "url/origin.h" |
| 24 | 24 |
| 25 // static | 25 // static |
| 26 void SavePasswordInfoBarDelegate::Create( | 26 void SavePasswordInfoBarDelegate::Create( |
| 27 content::WebContents* web_contents, | 27 content::WebContents* web_contents, |
| 28 scoped_ptr<password_manager::PasswordFormManager> form_to_save, | 28 scoped_ptr<password_manager::PasswordFormManager> form_to_save) { |
| 29 const std::string& uma_histogram_suffix) { | |
| 30 Profile* profile = | 29 Profile* profile = |
| 31 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 30 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 32 sync_driver::SyncService* sync_service = | 31 sync_driver::SyncService* sync_service = |
| 33 ProfileSyncServiceFactory::GetForProfile(profile); | 32 ProfileSyncServiceFactory::GetForProfile(profile); |
| 34 bool is_smartlock_branding_enabled = | 33 bool is_smartlock_branding_enabled = |
| 35 password_bubble_experiment::IsSmartLockBrandingSavePromptEnabled( | 34 password_bubble_experiment::IsSmartLockBrandingSavePromptEnabled( |
| 36 sync_service); | 35 sync_service); |
| 37 bool should_show_first_run_experience = | 36 bool should_show_first_run_experience = |
| 38 password_bubble_experiment::ShouldShowSavePromptFirstRunExperience( | 37 password_bubble_experiment::ShouldShowSavePromptFirstRunExperience( |
| 39 sync_service, profile->GetPrefs()); | 38 sync_service, profile->GetPrefs()); |
| 40 InfoBarService::FromWebContents(web_contents) | 39 InfoBarService::FromWebContents(web_contents) |
| 41 ->AddInfoBar(CreateSavePasswordInfoBar( | 40 ->AddInfoBar(CreateSavePasswordInfoBar(make_scoped_ptr( |
| 42 make_scoped_ptr(new SavePasswordInfoBarDelegate( | 41 new SavePasswordInfoBarDelegate(web_contents, std::move(form_to_save), |
| 43 web_contents, std::move(form_to_save), uma_histogram_suffix, | 42 is_smartlock_branding_enabled, |
| 44 is_smartlock_branding_enabled, | 43 should_show_first_run_experience)))); |
| 45 should_show_first_run_experience)))); | |
| 46 } | 44 } |
| 47 | 45 |
| 48 SavePasswordInfoBarDelegate::~SavePasswordInfoBarDelegate() { | 46 SavePasswordInfoBarDelegate::~SavePasswordInfoBarDelegate() { |
| 49 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse", | 47 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse", |
| 50 infobar_response_, | 48 infobar_response_, |
| 51 password_manager::metrics_util::NUM_RESPONSE_TYPES); | 49 password_manager::metrics_util::NUM_RESPONSE_TYPES); |
| 52 | 50 |
| 53 password_manager::metrics_util::LogUIDismissalReason(infobar_response_); | 51 password_manager::metrics_util::LogUIDismissalReason(infobar_response_); |
| 54 | 52 |
| 55 // The shortest period for which the prompt needs to live, so that we don't | |
| 56 // consider it killed prematurely, as might happen, e.g., if a pre-rendered | |
| 57 // page gets swapped in (and the current WebContents is destroyed). | |
| 58 const base::TimeDelta kMinimumPromptDisplayTime = | |
| 59 base::TimeDelta::FromSeconds(1); | |
| 60 | |
| 61 if (!uma_histogram_suffix_.empty()) { | |
| 62 password_manager::metrics_util::LogUMAHistogramEnumeration( | |
| 63 "PasswordManager.SavePasswordPromptResponse_" + uma_histogram_suffix_, | |
| 64 infobar_response_, | |
| 65 password_manager::metrics_util::NUM_RESPONSE_TYPES); | |
| 66 password_manager::metrics_util::LogUMAHistogramBoolean( | |
| 67 "PasswordManager.SavePasswordPromptDisappearedQuickly_" + | |
| 68 uma_histogram_suffix_, | |
| 69 timer_.Elapsed() < kMinimumPromptDisplayTime); | |
| 70 } | |
| 71 if (should_show_first_run_experience_) { | 53 if (should_show_first_run_experience_) { |
| 72 Profile* profile = | 54 Profile* profile = |
| 73 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 55 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| 74 password_bubble_experiment::RecordSavePromptFirstRunExperienceWasShown( | 56 password_bubble_experiment::RecordSavePromptFirstRunExperienceWasShown( |
| 75 profile->GetPrefs()); | 57 profile->GetPrefs()); |
| 76 } | 58 } |
| 77 } | 59 } |
| 78 | 60 |
| 79 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( | 61 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( |
| 80 content::WebContents* web_contents, | 62 content::WebContents* web_contents, |
| 81 scoped_ptr<password_manager::PasswordFormManager> form_to_save, | 63 scoped_ptr<password_manager::PasswordFormManager> form_to_save, |
| 82 const std::string& uma_histogram_suffix, | |
| 83 bool is_smartlock_branding_enabled, | 64 bool is_smartlock_branding_enabled, |
| 84 bool should_show_first_run_experience) | 65 bool should_show_first_run_experience) |
| 85 : PasswordManagerInfoBarDelegate(), | 66 : PasswordManagerInfoBarDelegate(), |
| 86 form_to_save_(std::move(form_to_save)), | 67 form_to_save_(std::move(form_to_save)), |
| 87 infobar_response_(password_manager::metrics_util::NO_RESPONSE), | 68 infobar_response_(password_manager::metrics_util::NO_RESPONSE), |
| 88 uma_histogram_suffix_(uma_histogram_suffix), | |
| 89 should_show_first_run_experience_(should_show_first_run_experience), | 69 should_show_first_run_experience_(should_show_first_run_experience), |
| 90 web_contents_(web_contents) { | 70 web_contents_(web_contents) { |
| 91 if (!uma_histogram_suffix_.empty()) { | |
| 92 password_manager::metrics_util::LogUMAHistogramBoolean( | |
| 93 "PasswordManager.SavePasswordPromptDisplayed_" + uma_histogram_suffix_, | |
| 94 true); | |
| 95 } | |
| 96 base::string16 message; | 71 base::string16 message; |
| 97 gfx::Range message_link_range = gfx::Range(); | 72 gfx::Range message_link_range = gfx::Range(); |
| 98 PasswordTittleType type = | 73 PasswordTittleType type = |
| 99 form_to_save_->pending_credentials().federation_origin.unique() | 74 form_to_save_->pending_credentials().federation_origin.unique() |
| 100 ? PasswordTittleType::SAVE_PASSWORD | 75 ? PasswordTittleType::SAVE_PASSWORD |
| 101 : PasswordTittleType::UPDATE_PASSWORD; | 76 : PasswordTittleType::UPDATE_PASSWORD; |
| 102 GetSavePasswordDialogTitleTextAndLinkRange( | 77 GetSavePasswordDialogTitleTextAndLinkRange( |
| 103 web_contents->GetVisibleURL(), form_to_save_->observed_form().origin, | 78 web_contents->GetVisibleURL(), form_to_save_->observed_form().origin, |
| 104 is_smartlock_branding_enabled, type, | 79 is_smartlock_branding_enabled, type, |
| 105 &message, &message_link_range); | 80 &message, &message_link_range); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 infobar_response_ = password_manager::metrics_util::REMEMBER_PASSWORD; | 112 infobar_response_ = password_manager::metrics_util::REMEMBER_PASSWORD; |
| 138 return true; | 113 return true; |
| 139 } | 114 } |
| 140 | 115 |
| 141 bool SavePasswordInfoBarDelegate::Cancel() { | 116 bool SavePasswordInfoBarDelegate::Cancel() { |
| 142 DCHECK(form_to_save_.get()); | 117 DCHECK(form_to_save_.get()); |
| 143 form_to_save_->PermanentlyBlacklist(); | 118 form_to_save_->PermanentlyBlacklist(); |
| 144 infobar_response_ = password_manager::metrics_util::NEVER_REMEMBER_PASSWORD; | 119 infobar_response_ = password_manager::metrics_util::NEVER_REMEMBER_PASSWORD; |
| 145 return true; | 120 return true; |
| 146 } | 121 } |
| OLD | NEW |