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

Side by Side Diff: components/autofill/core/browser/autofill_external_delegate.cc

Issue 578383002: mac: Only show the access Address Book prompt a fixed number of times. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@autofill-contacts
Patch Set: Comments from estade. Created 6 years, 3 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/autofill/core/browser/autofill_external_delegate.h" 5 #include "components/autofill/core/browser/autofill_external_delegate.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/core/browser/autocomplete_history_manager.h" 10 #include "components/autofill/core/browser/autocomplete_history_manager.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 namespace autofill { 42 namespace autofill {
43 43
44 AutofillExternalDelegate::AutofillExternalDelegate(AutofillManager* manager, 44 AutofillExternalDelegate::AutofillExternalDelegate(AutofillManager* manager,
45 AutofillDriver* driver) 45 AutofillDriver* driver)
46 : manager_(manager), 46 : manager_(manager),
47 driver_(driver), 47 driver_(driver),
48 query_id_(0), 48 query_id_(0),
49 display_warning_if_disabled_(false), 49 display_warning_if_disabled_(false),
50 has_suggestion_(false), 50 has_suggestion_(false),
51 has_shown_popup_for_current_edit_(false), 51 has_shown_popup_for_current_edit_(false),
52 weak_ptr_factory_(this) { 52 weak_ptr_factory_(this),
53 has_shown_address_book_prompt(false) {
53 DCHECK(manager); 54 DCHECK(manager);
54 } 55 }
55 56
56 AutofillExternalDelegate::~AutofillExternalDelegate() {} 57 AutofillExternalDelegate::~AutofillExternalDelegate() {}
57 58
58 void AutofillExternalDelegate::OnQuery(int query_id, 59 void AutofillExternalDelegate::OnQuery(int query_id,
59 const FormData& form, 60 const FormData& form,
60 const FormFieldData& field, 61 const FormFieldData& field,
61 const gfx::RectF& element_bounds, 62 const gfx::RectF& element_bounds,
62 bool display_warning_if_disabled) { 63 bool display_warning_if_disabled) {
64 if (query_form_ != form)
65 has_shown_address_book_prompt = false;
66
63 query_form_ = form; 67 query_form_ = form;
64 query_field_ = field; 68 query_field_ = field;
65 display_warning_if_disabled_ = display_warning_if_disabled; 69 display_warning_if_disabled_ = display_warning_if_disabled;
66 query_id_ = query_id; 70 query_id_ = query_id;
67 element_bounds_ = element_bounds; 71 element_bounds_ = element_bounds;
68 } 72 }
69 73
70 void AutofillExternalDelegate::OnSuggestionsReturned( 74 void AutofillExternalDelegate::OnSuggestionsReturned(
71 int query_id, 75 int query_id,
72 const std::vector<base::string16>& suggested_values, 76 const std::vector<base::string16>& suggested_values,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 labels.pop_back(); 114 labels.pop_back();
111 icons.pop_back(); 115 icons.pop_back();
112 ids.pop_back(); 116 ids.pop_back();
113 } 117 }
114 118
115 // If anything else is added to modify the values after inserting the data 119 // If anything else is added to modify the values after inserting the data
116 // list, AutofillPopupControllerImpl::UpdateDataListValues will need to be 120 // list, AutofillPopupControllerImpl::UpdateDataListValues will need to be
117 // updated to match. 121 // updated to match.
118 InsertDataListValues(&values, &labels, &icons, &ids); 122 InsertDataListValues(&values, &labels, &icons, &ids);
119 123
120 // Temporarily disabled. See http://crbug.com/408695
121 #if 0
122 #if defined(OS_MACOSX) && !defined(OS_IOS) 124 #if defined(OS_MACOSX) && !defined(OS_IOS)
123 if (values.empty() && 125 if (values.empty() &&
124 manager_->ShouldShowAccessAddressBookSuggestion(query_form_, 126 manager_->ShouldShowAccessAddressBookSuggestion(query_form_,
125 query_field_)) { 127 query_field_)) {
126 values.push_back( 128 values.push_back(
127 l10n_util::GetStringUTF16(IDS_AUTOFILL_ACCESS_MAC_CONTACTS)); 129 l10n_util::GetStringUTF16(IDS_AUTOFILL_ACCESS_MAC_CONTACTS));
128 labels.push_back(base::string16()); 130 labels.push_back(base::string16());
129 icons.push_back(base::ASCIIToUTF16("macContactsIcon")); 131 icons.push_back(base::ASCIIToUTF16("macContactsIcon"));
130 ids.push_back(POPUP_ITEM_ID_MAC_ACCESS_CONTACTS); 132 ids.push_back(POPUP_ITEM_ID_MAC_ACCESS_CONTACTS);
131 133
132 EmitHistogram(SHOWED_ACCESS_ADDRESS_BOOK_ENTRY); 134 if (!has_shown_address_book_prompt) {
135 has_shown_address_book_prompt = true;
136 EmitHistogram(SHOWED_ACCESS_ADDRESS_BOOK_ENTRY);
137 manager_->ShowedAccessAddressBookPrompt();
138 }
133 } 139 }
134 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 140 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
135 #endif
136 141
137 if (values.empty()) { 142 if (values.empty()) {
138 // No suggestions, any popup currently showing is obsolete. 143 // No suggestions, any popup currently showing is obsolete.
139 manager_->client()->HideAutofillPopup(); 144 manager_->client()->HideAutofillPopup();
140 return; 145 return;
141 } 146 }
142 147
143 // Send to display. 148 // Send to display.
144 if (query_field_.is_focusable) { 149 if (query_field_.is_focusable) {
145 manager_->client()->ShowAutofillPopup(element_bounds_, 150 manager_->client()->ShowAutofillPopup(element_bounds_,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } else if (identifier == POPUP_ITEM_ID_PASSWORD_ENTRY) { 199 } else if (identifier == POPUP_ITEM_ID_PASSWORD_ENTRY) {
195 NOTREACHED(); // Should be handled elsewhere. 200 NOTREACHED(); // Should be handled elsewhere.
196 } else if (identifier == POPUP_ITEM_ID_DATALIST_ENTRY) { 201 } else if (identifier == POPUP_ITEM_ID_DATALIST_ENTRY) {
197 driver_->RendererShouldAcceptDataListSuggestion(value); 202 driver_->RendererShouldAcceptDataListSuggestion(value);
198 } else if (identifier == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY) { 203 } else if (identifier == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY) {
199 // User selected an Autocomplete, so we fill directly. 204 // User selected an Autocomplete, so we fill directly.
200 driver_->RendererShouldFillFieldWithValue(value); 205 driver_->RendererShouldFillFieldWithValue(value);
201 } else if (identifier == POPUP_ITEM_ID_MAC_ACCESS_CONTACTS) { 206 } else if (identifier == POPUP_ITEM_ID_MAC_ACCESS_CONTACTS) {
202 #if defined(OS_MACOSX) && !defined(OS_IOS) 207 #if defined(OS_MACOSX) && !defined(OS_IOS)
203 EmitHistogram(SELECTED_ACCESS_ADDRESS_BOOK_ENTRY); 208 EmitHistogram(SELECTED_ACCESS_ADDRESS_BOOK_ENTRY);
209 LOCAL_HISTOGRAM_ENUMERATION("Autofill.MacAddressBook.ShowedCount",
Evan Stade 2014/09/18 22:06:09 instead of ShowedCount, how about NumShowsBeforeSe
erikchen 2014/09/18 22:49:50 Done.
210 manager_->AccessAddressBookPromptCount(),
211 30);
erikchen 2014/09/18 21:55:58 This number is intentionally larger than 5, and al
204 212
205 // User wants to give Chrome access to user's address book. 213 // User wants to give Chrome access to user's address book.
206 manager_->AccessAddressBook(); 214 manager_->AccessAddressBook();
207 215
208 // There is no deterministic method for deciding whether a blocking dialog 216 // There is no deterministic method for deciding whether a blocking dialog
209 // was presented. The following comments and code assume that a blocking 217 // was presented. The following comments and code assume that a blocking
210 // dialog was presented, but still behave correctly if no dialog was 218 // dialog was presented, but still behave correctly if no dialog was
211 // presented. 219 // presented.
212 220
213 // A blocking dialog was presented, and the user has already responded to 221 // A blocking dialog was presented, and the user has already responded to
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 POPUP_ITEM_ID_DATALIST_ENTRY); 400 POPUP_ITEM_ID_DATALIST_ENTRY);
393 } 401 }
394 402
395 #if defined(OS_MACOSX) && !defined(OS_IOS) 403 #if defined(OS_MACOSX) && !defined(OS_IOS)
396 void AutofillExternalDelegate::PingRenderer() { 404 void AutofillExternalDelegate::PingRenderer() {
397 driver_->PingRenderer(); 405 driver_->PingRenderer();
398 } 406 }
399 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 407 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
400 408
401 } // namespace autofill 409 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698