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

Side by Side Diff: chrome/browser/ui/autofill/save_card_bubble_controller_impl.cc

Issue 2839683002: Logs different SaveCardPrompt histogram names depending on if user (Closed)
Patch Set: Android compile error. Created 3 years, 8 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/ui/autofill/save_card_bubble_controller_impl.h" 5 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "chrome/browser/ui/autofill/save_card_bubble_view.h" 9 #include "chrome/browser/ui/autofill/save_card_bubble_view.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_finder.h" 11 #include "chrome/browser/ui/browser_finder.h"
12 #include "chrome/browser/ui/browser_window.h" 12 #include "chrome/browser/ui/browser_window.h"
13 #include "chrome/browser/ui/location_bar/location_bar.h" 13 #include "chrome/browser/ui/location_bar/location_bar.h"
14 #include "components/autofill/core/browser/autofill_metrics.h" 14 #include "components/autofill/core/browser/autofill_metrics.h"
15 #include "components/autofill/core/browser/validation.h" 15 #include "components/autofill/core/browser/validation.h"
16 #include "components/autofill/core/common/autofill_constants.h" 16 #include "components/autofill/core/common/autofill_constants.h"
17 #include "components/autofill/core/common/autofill_pref_names.h"
17 #include "components/grit/components_scaled_resources.h" 18 #include "components/grit/components_scaled_resources.h"
19 #include "components/prefs/pref_service.h"
18 #include "components/strings/grit/components_strings.h" 20 #include "components/strings/grit/components_strings.h"
21 #include "components/user_prefs/user_prefs.h"
19 #include "content/public/browser/navigation_handle.h" 22 #include "content/public/browser/navigation_handle.h"
20 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
21 24
22 DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::SaveCardBubbleControllerImpl); 25 DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::SaveCardBubbleControllerImpl);
23 26
24 namespace autofill { 27 namespace autofill {
25 28
26 namespace { 29 namespace {
27 30
28 // Number of seconds the bubble and icon will survive navigations, starting 31 // Number of seconds the bubble and icon will survive navigations, starting
29 // from when the bubble is shown. 32 // from when the bubble is shown.
30 // TODO(bondd): Share with ManagePasswordsUIController. 33 // TODO(bondd): Share with ManagePasswordsUIController.
31 const int kSurviveNavigationSeconds = 5; 34 const int kSurviveNavigationSeconds = 5;
32 35
33 } // namespace 36 } // namespace
34 37
35 SaveCardBubbleControllerImpl::SaveCardBubbleControllerImpl( 38 SaveCardBubbleControllerImpl::SaveCardBubbleControllerImpl(
36 content::WebContents* web_contents) 39 content::WebContents* web_contents)
37 : content::WebContentsObserver(web_contents), 40 : content::WebContentsObserver(web_contents),
38 save_card_bubble_view_(nullptr) { 41 save_card_bubble_view_(nullptr),
39 DCHECK(web_contents); 42 pref_service_(
40 } 43 user_prefs::UserPrefs::Get(web_contents->GetBrowserContext())) {}
41 44
42 SaveCardBubbleControllerImpl::~SaveCardBubbleControllerImpl() { 45 SaveCardBubbleControllerImpl::~SaveCardBubbleControllerImpl() {
43 if (save_card_bubble_view_) 46 if (save_card_bubble_view_)
44 save_card_bubble_view_->Hide(); 47 save_card_bubble_view_->Hide();
45 } 48 }
46 49
47 void SaveCardBubbleControllerImpl::ShowBubbleForLocalSave( 50 void SaveCardBubbleControllerImpl::ShowBubbleForLocalSave(
48 const CreditCard& card, 51 const CreditCard& card,
49 const base::Closure& save_card_callback) { 52 const base::Closure& save_card_callback) {
50 is_uploading_ = false; 53 is_uploading_ = false;
51 is_reshow_ = false; 54 is_reshow_ = false;
52 should_cvc_be_requested_ = false; 55 should_cvc_be_requested_ = false;
53 legal_message_lines_.clear(); 56 legal_message_lines_.clear();
54 57
55 AutofillMetrics::LogSaveCardPromptMetric( 58 AutofillMetrics::LogSaveCardPromptMetric(
56 AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, is_uploading_, 59 AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, is_uploading_,
57 is_reshow_); 60 is_reshow_,
61 pref_service_->GetBoolean(
62 prefs::kAutofillAcceptSaveCreditCardPromptState));
58 63
59 card_ = card; 64 card_ = card;
60 save_card_callback_ = save_card_callback; 65 save_card_callback_ = save_card_callback;
61 ShowBubble(); 66 ShowBubble();
62 } 67 }
63 68
64 void SaveCardBubbleControllerImpl::ShowBubbleForUpload( 69 void SaveCardBubbleControllerImpl::ShowBubbleForUpload(
65 const CreditCard& card, 70 const CreditCard& card,
66 std::unique_ptr<base::DictionaryValue> legal_message, 71 std::unique_ptr<base::DictionaryValue> legal_message,
67 bool should_cvc_be_requested, 72 bool should_cvc_be_requested,
68 const base::Closure& save_card_callback) { 73 const base::Closure& save_card_callback) {
69 is_uploading_ = true; 74 is_uploading_ = true;
70 is_reshow_ = false; 75 is_reshow_ = false;
71 should_cvc_be_requested_ = should_cvc_be_requested; 76 should_cvc_be_requested_ = should_cvc_be_requested;
72 AutofillMetrics::LogSaveCardPromptMetric( 77 AutofillMetrics::LogSaveCardPromptMetric(
73 AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, is_uploading_, 78 AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, is_uploading_,
74 is_reshow_); 79 is_reshow_,
80 pref_service_->GetBoolean(
81 prefs::kAutofillAcceptSaveCreditCardPromptState));
75 82
76 if (!LegalMessageLine::Parse(*legal_message, &legal_message_lines_)) { 83 if (!LegalMessageLine::Parse(*legal_message, &legal_message_lines_)) {
77 AutofillMetrics::LogSaveCardPromptMetric( 84 AutofillMetrics::LogSaveCardPromptMetric(
78 AutofillMetrics::SAVE_CARD_PROMPT_END_INVALID_LEGAL_MESSAGE, 85 AutofillMetrics::SAVE_CARD_PROMPT_END_INVALID_LEGAL_MESSAGE,
79 is_uploading_, is_reshow_); 86 is_uploading_, is_reshow_,
87 pref_service_->GetBoolean(
88 prefs::kAutofillAcceptSaveCreditCardPromptState));
80 return; 89 return;
81 } 90 }
82 91
83 card_ = card; 92 card_ = card;
84 save_card_callback_ = save_card_callback; 93 save_card_callback_ = save_card_callback;
85 ShowBubble(); 94 ShowBubble();
86 } 95 }
87 96
88 void SaveCardBubbleControllerImpl::HideBubble() { 97 void SaveCardBubbleControllerImpl::HideBubble() {
89 if (save_card_bubble_view_) { 98 if (save_card_bubble_view_) {
90 save_card_bubble_view_->Hide(); 99 save_card_bubble_view_->Hide();
91 save_card_bubble_view_ = nullptr; 100 save_card_bubble_view_ = nullptr;
92 } 101 }
93 } 102 }
94 103
95 void SaveCardBubbleControllerImpl::ReshowBubble() { 104 void SaveCardBubbleControllerImpl::ReshowBubble() {
96 is_reshow_ = true; 105 is_reshow_ = true;
97 AutofillMetrics::LogSaveCardPromptMetric( 106 AutofillMetrics::LogSaveCardPromptMetric(
98 AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, is_uploading_, 107 AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, is_uploading_,
99 is_reshow_); 108 is_reshow_,
109 pref_service_->GetBoolean(
110 prefs::kAutofillAcceptSaveCreditCardPromptState));
100 111
101 ShowBubble(); 112 ShowBubble();
102 } 113 }
103 114
104 bool SaveCardBubbleControllerImpl::IsIconVisible() const { 115 bool SaveCardBubbleControllerImpl::IsIconVisible() const {
105 return !save_card_callback_.is_null(); 116 return !save_card_callback_.is_null();
106 } 117 }
107 118
108 SaveCardBubbleView* SaveCardBubbleControllerImpl::save_card_bubble_view() 119 SaveCardBubbleView* SaveCardBubbleControllerImpl::save_card_bubble_view()
109 const { 120 const {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 if (!cvc.empty()) { 155 if (!cvc.empty()) {
145 // Record the CVC entered by the user so it can be sent in the final 156 // Record the CVC entered by the user so it can be sent in the final
146 // request. 157 // request.
147 DCHECK(ShouldRequestCvcFromUser()); 158 DCHECK(ShouldRequestCvcFromUser());
148 DCHECK(InputCvcIsValid(cvc)); 159 DCHECK(InputCvcIsValid(cvc));
149 base::TrimWhitespace(cvc, base::TRIM_ALL, &cvc_entered_by_user_); 160 base::TrimWhitespace(cvc, base::TRIM_ALL, &cvc_entered_by_user_);
150 } 161 }
151 save_card_callback_.Run(); 162 save_card_callback_.Run();
152 save_card_callback_.Reset(); 163 save_card_callback_.Reset();
153 AutofillMetrics::LogSaveCardPromptMetric( 164 AutofillMetrics::LogSaveCardPromptMetric(
154 AutofillMetrics::SAVE_CARD_PROMPT_END_ACCEPTED, is_uploading_, 165 AutofillMetrics::SAVE_CARD_PROMPT_END_ACCEPTED, is_uploading_, is_reshow_,
155 is_reshow_); 166 pref_service_->GetBoolean(
167 prefs::kAutofillAcceptSaveCreditCardPromptState));
168 pref_service_->SetBoolean(prefs::kAutofillAcceptSaveCreditCardPromptState,
169 true);
156 } 170 }
157 171
158 void SaveCardBubbleControllerImpl::OnCancelButton() { 172 void SaveCardBubbleControllerImpl::OnCancelButton() {
159 save_card_callback_.Reset(); 173 save_card_callback_.Reset();
160 AutofillMetrics::LogSaveCardPromptMetric( 174 AutofillMetrics::LogSaveCardPromptMetric(
161 AutofillMetrics::SAVE_CARD_PROMPT_END_DENIED, is_uploading_, is_reshow_); 175 AutofillMetrics::SAVE_CARD_PROMPT_END_DENIED, is_uploading_, is_reshow_,
176 pref_service_->GetBoolean(
177 prefs::kAutofillAcceptSaveCreditCardPromptState));
178 pref_service_->SetBoolean(prefs::kAutofillAcceptSaveCreditCardPromptState,
179 false);
162 } 180 }
163 181
164 void SaveCardBubbleControllerImpl::OnLearnMoreClicked() { 182 void SaveCardBubbleControllerImpl::OnLearnMoreClicked() {
165 OpenUrl(GURL(kHelpURL)); 183 OpenUrl(GURL(kHelpURL));
166 AutofillMetrics::LogSaveCardPromptMetric( 184 AutofillMetrics::LogSaveCardPromptMetric(
167 AutofillMetrics::SAVE_CARD_PROMPT_DISMISS_CLICK_LEARN_MORE, is_uploading_, 185 AutofillMetrics::SAVE_CARD_PROMPT_DISMISS_CLICK_LEARN_MORE, is_uploading_,
168 is_reshow_); 186 is_reshow_,
187 pref_service_->GetBoolean(
188 prefs::kAutofillAcceptSaveCreditCardPromptState));
169 } 189 }
170 190
171 void SaveCardBubbleControllerImpl::OnLegalMessageLinkClicked(const GURL& url) { 191 void SaveCardBubbleControllerImpl::OnLegalMessageLinkClicked(const GURL& url) {
172 OpenUrl(url); 192 OpenUrl(url);
173 AutofillMetrics::LogSaveCardPromptMetric( 193 AutofillMetrics::LogSaveCardPromptMetric(
174 AutofillMetrics::SAVE_CARD_PROMPT_DISMISS_CLICK_LEGAL_MESSAGE, 194 AutofillMetrics::SAVE_CARD_PROMPT_DISMISS_CLICK_LEGAL_MESSAGE,
175 is_uploading_, is_reshow_); 195 is_uploading_, is_reshow_,
196 pref_service_->GetBoolean(
197 prefs::kAutofillAcceptSaveCreditCardPromptState));
176 } 198 }
177 199
178 void SaveCardBubbleControllerImpl::OnBubbleClosed() { 200 void SaveCardBubbleControllerImpl::OnBubbleClosed() {
201 LOG(ERROR) << "OnBubbleClosed";
179 save_card_bubble_view_ = nullptr; 202 save_card_bubble_view_ = nullptr;
180 UpdateIcon(); 203 UpdateIcon();
181 } 204 }
182 205
183 const LegalMessageLines& SaveCardBubbleControllerImpl::GetLegalMessageLines() 206 const LegalMessageLines& SaveCardBubbleControllerImpl::GetLegalMessageLines()
184 const { 207 const {
185 return legal_message_lines_; 208 return legal_message_lines_;
186 } 209 }
187 210
188 bool SaveCardBubbleControllerImpl::InputCvcIsValid( 211 bool SaveCardBubbleControllerImpl::InputCvcIsValid(
(...skipping 26 matching lines...) Expand all
215 return; 238 return;
216 239
217 // Otherwise, get rid of the bubble and icon. 240 // Otherwise, get rid of the bubble and icon.
218 save_card_callback_.Reset(); 241 save_card_callback_.Reset();
219 if (save_card_bubble_view_) { 242 if (save_card_bubble_view_) {
220 save_card_bubble_view_->Hide(); 243 save_card_bubble_view_->Hide();
221 OnBubbleClosed(); 244 OnBubbleClosed();
222 245
223 AutofillMetrics::LogSaveCardPromptMetric( 246 AutofillMetrics::LogSaveCardPromptMetric(
224 AutofillMetrics::SAVE_CARD_PROMPT_END_NAVIGATION_SHOWING, is_uploading_, 247 AutofillMetrics::SAVE_CARD_PROMPT_END_NAVIGATION_SHOWING, is_uploading_,
225 is_reshow_); 248 is_reshow_,
249 pref_service_->GetBoolean(
250 prefs::kAutofillAcceptSaveCreditCardPromptState));
226 } else { 251 } else {
227 UpdateIcon(); 252 UpdateIcon();
228 253
229 AutofillMetrics::LogSaveCardPromptMetric( 254 AutofillMetrics::LogSaveCardPromptMetric(
230 AutofillMetrics::SAVE_CARD_PROMPT_END_NAVIGATION_HIDDEN, is_uploading_, 255 AutofillMetrics::SAVE_CARD_PROMPT_END_NAVIGATION_HIDDEN, is_uploading_,
231 is_reshow_); 256 is_reshow_,
257 pref_service_->GetBoolean(
258 prefs::kAutofillAcceptSaveCreditCardPromptState));
232 } 259 }
233 } 260 }
234 261
235 void SaveCardBubbleControllerImpl::ShowBubble() { 262 void SaveCardBubbleControllerImpl::ShowBubble() {
236 DCHECK(!save_card_callback_.is_null()); 263 DCHECK(!save_card_callback_.is_null());
237 DCHECK(!save_card_bubble_view_); 264 DCHECK(!save_card_bubble_view_);
238 265
239 // Need to create location bar icon before bubble, otherwise bubble will be 266 // Need to create location bar icon before bubble, otherwise bubble will be
240 // unanchored. 267 // unanchored.
241 UpdateIcon(); 268 UpdateIcon();
242 269
243 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); 270 Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
244 save_card_bubble_view_ = browser->window()->ShowSaveCreditCardBubble( 271 save_card_bubble_view_ = browser->window()->ShowSaveCreditCardBubble(
245 web_contents(), this, is_reshow_); 272 web_contents(), this, is_reshow_);
246 DCHECK(save_card_bubble_view_); 273 DCHECK(save_card_bubble_view_);
247 274
248 // Update icon after creating |save_card_bubble_view_| so that icon will show 275 // Update icon after creating |save_card_bubble_view_| so that icon will show
249 // its "toggled on" state. 276 // its "toggled on" state.
250 UpdateIcon(); 277 UpdateIcon();
251 278
252 timer_.reset(new base::ElapsedTimer()); 279 timer_.reset(new base::ElapsedTimer());
253 280
254 AutofillMetrics::LogSaveCardPromptMetric( 281 AutofillMetrics::LogSaveCardPromptMetric(
255 AutofillMetrics::SAVE_CARD_PROMPT_SHOWN, is_uploading_, is_reshow_); 282 AutofillMetrics::SAVE_CARD_PROMPT_SHOWN, is_uploading_, is_reshow_,
283 pref_service_->GetBoolean(
284 prefs::kAutofillAcceptSaveCreditCardPromptState));
256 } 285 }
257 286
258 void SaveCardBubbleControllerImpl::UpdateIcon() { 287 void SaveCardBubbleControllerImpl::UpdateIcon() {
259 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); 288 Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
260 LocationBar* location_bar = browser->window()->GetLocationBar(); 289 LocationBar* location_bar = browser->window()->GetLocationBar();
261 location_bar->UpdateSaveCreditCardIcon(); 290 location_bar->UpdateSaveCreditCardIcon();
262 } 291 }
263 292
264 void SaveCardBubbleControllerImpl::OpenUrl(const GURL& url) { 293 void SaveCardBubbleControllerImpl::OpenUrl(const GURL& url) {
265 web_contents()->OpenURL(content::OpenURLParams( 294 web_contents()->OpenURL(content::OpenURLParams(
266 url, content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, 295 url, content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB,
267 ui::PAGE_TRANSITION_LINK, false)); 296 ui::PAGE_TRANSITION_LINK, false));
268 } 297 }
269 298
270 } // namespace autofill 299 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698