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

Side by Side Diff: components/autofill/browser/autocheckout_manager.cc

Issue 12457033: Implements SendAutocheckoutStatus API calls for stats tracking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing unit tests Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/browser/autocheckout_manager.h" 5 #include "components/autofill/browser/autocheckout_manager.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "components/autofill/browser/autocheckout_request_manager.h"
10 #include "components/autofill/browser/autofill_country.h" 11 #include "components/autofill/browser/autofill_country.h"
11 #include "components/autofill/browser/autofill_field.h" 12 #include "components/autofill/browser/autofill_field.h"
12 #include "components/autofill/browser/autofill_manager.h" 13 #include "components/autofill/browser/autofill_manager.h"
13 #include "components/autofill/browser/autofill_profile.h" 14 #include "components/autofill/browser/autofill_profile.h"
14 #include "components/autofill/browser/credit_card.h" 15 #include "components/autofill/browser/credit_card.h"
15 #include "components/autofill/browser/field_types.h" 16 #include "components/autofill/browser/field_types.h"
16 #include "components/autofill/browser/form_structure.h" 17 #include "components/autofill/browser/form_structure.h"
17 #include "components/autofill/common/autocheckout_status.h"
18 #include "components/autofill/common/autofill_messages.h" 18 #include "components/autofill/common/autofill_messages.h"
19 #include "components/autofill/common/form_data.h" 19 #include "components/autofill/common/form_data.h"
20 #include "components/autofill/common/form_field_data.h" 20 #include "components/autofill/common/form_field_data.h"
21 #include "components/autofill/common/web_element_descriptor.h" 21 #include "components/autofill/common/web_element_descriptor.h"
22 #include "content/public/browser/render_view_host.h" 22 #include "content/public/browser/render_view_host.h"
23 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
24 #include "content/public/common/ssl_status.h" 24 #include "content/public/common/ssl_status.h"
25 #include "googleurl/src/gurl.h" 25 #include "googleurl/src/gurl.h"
26 #include "ui/gfx/rect.h" 26 #include "ui/gfx/rect.h"
27 27
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 formdata.fields.push_back(BuildField("shipping name")); 61 formdata.fields.push_back(BuildField("shipping name"));
62 formdata.fields.push_back(BuildField("shipping street-address")); 62 formdata.fields.push_back(BuildField("shipping street-address"));
63 formdata.fields.push_back(BuildField("shipping locality")); 63 formdata.fields.push_back(BuildField("shipping locality"));
64 formdata.fields.push_back(BuildField("shipping region")); 64 formdata.fields.push_back(BuildField("shipping region"));
65 formdata.fields.push_back(BuildField("shipping country")); 65 formdata.fields.push_back(BuildField("shipping country"));
66 formdata.fields.push_back(BuildField("shipping postal-code")); 66 formdata.fields.push_back(BuildField("shipping postal-code"));
67 formdata.fields.push_back(BuildField("shipping tel")); 67 formdata.fields.push_back(BuildField("shipping tel"));
68 return formdata; 68 return formdata;
69 } 69 }
70 70
71 const char kTransactionIdNotSet[] = "transaction id not set";
72
71 } // namespace 73 } // namespace
72 74
73 namespace autofill { 75 namespace autofill {
74 76
75 AutocheckoutManager::AutocheckoutManager(AutofillManager* autofill_manager) 77 AutocheckoutManager::AutocheckoutManager(AutofillManager* autofill_manager)
76 : autofill_manager_(autofill_manager), 78 : autofill_manager_(autofill_manager),
77 autocheckout_offered_(false), 79 autocheckout_offered_(false),
78 is_autocheckout_bubble_showing_(false), 80 is_autocheckout_bubble_showing_(false),
79 in_autocheckout_flow_(false), 81 in_autocheckout_flow_(false),
80 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 82 google_transaction_id_(kTransactionIdNotSet),
81 } 83 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {}
82 84
83 AutocheckoutManager::~AutocheckoutManager() { 85 AutocheckoutManager::~AutocheckoutManager() {
84 } 86 }
85 87
86 void AutocheckoutManager::FillForms() { 88 void AutocheckoutManager::FillForms() {
87 // |page_meta_data_| should have been set by OnLoadedPageMetaData. 89 // |page_meta_data_| should have been set by OnLoadedPageMetaData.
88 DCHECK(page_meta_data_); 90 DCHECK(page_meta_data_);
89 91
90 // Fill the forms on the page with data given by user. 92 // Fill the forms on the page with data given by user.
91 std::vector<FormData> filled_forms; 93 std::vector<FormData> filled_forms;
(...skipping 18 matching lines...) Expand all
110 autofill_manager_->GetWebContents()->GetRenderViewHost(); 112 autofill_manager_->GetWebContents()->GetRenderViewHost();
111 if (!host) 113 if (!host)
112 return; 114 return;
113 115
114 host->Send(new AutofillMsg_FillFormsAndClick( 116 host->Send(new AutofillMsg_FillFormsAndClick(
115 host->GetRoutingID(), 117 host->GetRoutingID(),
116 filled_forms, 118 filled_forms,
117 *page_meta_data_->proceed_element_descriptor)); 119 *page_meta_data_->proceed_element_descriptor));
118 } 120 }
119 121
122 void AutocheckoutManager::OnClickFailed(AutocheckoutStatus status) {
123 SendAutocheckoutStatus(status);
124 autofill_manager_->delegate()->OnAutocheckoutError();
125 }
126
120 void AutocheckoutManager::OnLoadedPageMetaData( 127 void AutocheckoutManager::OnLoadedPageMetaData(
121 scoped_ptr<AutocheckoutPageMetaData> page_meta_data) { 128 scoped_ptr<AutocheckoutPageMetaData> page_meta_data) {
122 scoped_ptr<AutocheckoutPageMetaData> old_meta_data = 129 scoped_ptr<AutocheckoutPageMetaData> old_meta_data =
123 page_meta_data_.Pass(); 130 page_meta_data_.Pass();
124 page_meta_data_ = page_meta_data.Pass(); 131 page_meta_data_ = page_meta_data.Pass();
125 132
126 // On the first page of an Autocheckout flow, when this function is called the 133 // On the first page of an Autocheckout flow, when this function is called the
127 // user won't have opted into the flow yet. 134 // user won't have opted into the flow yet.
128 if (!in_autocheckout_flow_) 135 if (!in_autocheckout_flow_)
129 return; 136 return;
130 137
138 AutocheckoutStatus status = SUCCESS;
139
131 // Missing Autofill server results. 140 // Missing Autofill server results.
132 if (!page_meta_data_) { 141 if (!page_meta_data_) {
133 in_autocheckout_flow_ = false; 142 in_autocheckout_flow_ = false;
143 status = MISSING_FIELDMAPPING;
134 } else if (page_meta_data_->IsStartOfAutofillableFlow()) { 144 } else if (page_meta_data_->IsStartOfAutofillableFlow()) {
135 // Not possible unless Autocheckout failed to proceed. 145 // Not possible unless Autocheckout failed to proceed.
136 in_autocheckout_flow_ = false; 146 in_autocheckout_flow_ = false;
147 status = CANNOT_PROCEED;
137 } else if (!page_meta_data_->IsInAutofillableFlow()) { 148 } else if (!page_meta_data_->IsInAutofillableFlow()) {
138 // Missing Autocheckout meta data in the Autofill server results. 149 // Missing Autocheckout meta data in the Autofill server results.
139 in_autocheckout_flow_ = false; 150 in_autocheckout_flow_ = false;
151 status = MISSING_FIELDMAPPING;
140 } else if (page_meta_data_->current_page_number <= 152 } else if (page_meta_data_->current_page_number <=
141 old_meta_data->current_page_number) { 153 old_meta_data->current_page_number) {
142 // Not possible unless Autocheckout failed to proceed. 154 // Not possible unless Autocheckout failed to proceed.
143 in_autocheckout_flow_ = false; 155 in_autocheckout_flow_ = false;
156 status = CANNOT_PROCEED;
144 } 157 }
145 158
146 // Encountered an error during the Autocheckout flow. 159 // Encountered an error during the Autocheckout flow.
147 if (!in_autocheckout_flow_) { 160 if (!in_autocheckout_flow_) {
148 // TODO(ahutter): SendAutocheckoutStatus of the error. 161 SendAutocheckoutStatus(status);
149 autofill_manager_->delegate()->OnAutocheckoutError(); 162 autofill_manager_->delegate()->OnAutocheckoutError();
150 return; 163 return;
151 } 164 }
152 165
153 // Add 1.0 since page numbers are 0-indexed. 166 // Add 1.0 since page numbers are 0-indexed.
154 autofill_manager_->delegate()->UpdateProgressBar( 167 autofill_manager_->delegate()->UpdateProgressBar(
155 (1.0 + page_meta_data_->current_page_number) / 168 (1.0 + page_meta_data_->current_page_number) /
156 page_meta_data_->total_pages); 169 page_meta_data_->total_pages);
157 FillForms(); 170 FillForms();
158 // If the current page is the last page in the flow, close the dialog. 171 // If the current page is the last page in the flow, close the dialog.
159 if (page_meta_data_->IsEndOfAutofillableFlow()) { 172 if (page_meta_data_->IsEndOfAutofillableFlow()) {
160 // TODO(ahutter): SendAutocheckoutStatus of SUCCESS. 173 SendAutocheckoutStatus(status);
161 autofill_manager_->delegate()->HideRequestAutocompleteDialog(); 174 autofill_manager_->delegate()->HideRequestAutocompleteDialog();
162 in_autocheckout_flow_ = false; 175 in_autocheckout_flow_ = false;
163 } 176 }
164 } 177 }
165 178
166 void AutocheckoutManager::OnFormsSeen() { 179 void AutocheckoutManager::OnFormsSeen() {
167 autocheckout_offered_ = false; 180 autocheckout_offered_ = false;
168 } 181 }
169 182
170 void AutocheckoutManager::MaybeShowAutocheckoutBubble( 183 void AutocheckoutManager::MaybeShowAutocheckoutBubble(
(...skipping 22 matching lines...) Expand all
193 void AutocheckoutManager::MaybeShowAutocheckoutDialog( 206 void AutocheckoutManager::MaybeShowAutocheckoutDialog(
194 const GURL& frame_url, 207 const GURL& frame_url,
195 const SSLStatus& ssl_status, 208 const SSLStatus& ssl_status,
196 bool show_dialog) { 209 bool show_dialog) {
197 is_autocheckout_bubble_showing_ = false; 210 is_autocheckout_bubble_showing_ = false;
198 if (!show_dialog) 211 if (!show_dialog)
199 return; 212 return;
200 213
201 FormData form = BuildAutocheckoutFormData(); 214 FormData form = BuildAutocheckoutFormData();
202 form.ssl_status = ssl_status; 215 form.ssl_status = ssl_status;
203 base::Callback<void(const FormStructure*)> callback = 216 base::Callback<void(const FormStructure*, const std::string&)> callback =
204 base::Bind(&AutocheckoutManager::ReturnAutocheckoutData, 217 base::Bind(&AutocheckoutManager::ReturnAutocheckoutData,
205 weak_ptr_factory_.GetWeakPtr()); 218 weak_ptr_factory_.GetWeakPtr());
206 autofill_manager_->ShowRequestAutocompleteDialog( 219 autofill_manager_->ShowRequestAutocompleteDialog(
207 form, frame_url, DIALOG_TYPE_AUTOCHECKOUT, callback); 220 form, frame_url, DIALOG_TYPE_AUTOCHECKOUT, callback);
208 } 221 }
209 222
210 bool AutocheckoutManager::IsStartOfAutofillableFlow() const { 223 bool AutocheckoutManager::IsStartOfAutofillableFlow() const {
211 return page_meta_data_ && page_meta_data_->IsStartOfAutofillableFlow(); 224 return page_meta_data_ && page_meta_data_->IsStartOfAutofillableFlow();
212 } 225 }
213 226
214 bool AutocheckoutManager::IsInAutofillableFlow() const { 227 bool AutocheckoutManager::IsInAutofillableFlow() const {
215 return page_meta_data_ && page_meta_data_->IsInAutofillableFlow(); 228 return page_meta_data_ && page_meta_data_->IsInAutofillableFlow();
216 } 229 }
217 230
218 void AutocheckoutManager::ReturnAutocheckoutData(const FormStructure* result) { 231 void AutocheckoutManager::ReturnAutocheckoutData(
232 const FormStructure* result,
233 const std::string& google_transaction_id) {
219 if (!result) 234 if (!result)
220 return; 235 return;
221 236
237 google_transaction_id_ = google_transaction_id;
222 in_autocheckout_flow_ = true; 238 in_autocheckout_flow_ = true;
223 239
224 profile_.reset(new AutofillProfile()); 240 profile_.reset(new AutofillProfile());
225 credit_card_.reset(new CreditCard()); 241 credit_card_.reset(new CreditCard());
226 242
227 for (size_t i = 0; i < result->field_count(); ++i) { 243 for (size_t i = 0; i < result->field_count(); ++i) {
228 AutofillFieldType type = result->field(i)->type(); 244 AutofillFieldType type = result->field(i)->type();
229 if (type == CREDIT_CARD_VERIFICATION_CODE) { 245 if (type == CREDIT_CARD_VERIFICATION_CODE) {
230 cvv_ = result->field(i)->value; 246 cvv_ = result->field(i)->value;
231 continue; 247 continue;
232 } 248 }
233 if (AutofillType(type).group() == AutofillType::CREDIT_CARD) { 249 if (AutofillType(type).group() == AutofillType::CREDIT_CARD) {
234 credit_card_->SetRawInfo(result->field(i)->type(), 250 credit_card_->SetRawInfo(result->field(i)->type(),
235 result->field(i)->value); 251 result->field(i)->value);
236 } else { 252 } else {
237 profile_->SetRawInfo(result->field(i)->type(), result->field(i)->value); 253 profile_->SetRawInfo(result->field(i)->type(), result->field(i)->value);
238 } 254 }
239 } 255 }
240 256
241 // Add 1.0 since page numbers are 0-indexed. 257 // Add 1.0 since page numbers are 0-indexed.
242 autofill_manager_->delegate()->UpdateProgressBar( 258 autofill_manager_->delegate()->UpdateProgressBar(
243 (1.0 + page_meta_data_->current_page_number) / 259 (1.0 + page_meta_data_->current_page_number) /
244 page_meta_data_->total_pages); 260 page_meta_data_->total_pages);
245 FillForms(); 261 FillForms();
246 262
247 // If the current page is the last page in the flow, close the dialog. 263 // If the current page is the last page in the flow, close the dialog.
248 if (page_meta_data_->IsEndOfAutofillableFlow()) { 264 if (page_meta_data_->IsEndOfAutofillableFlow()) {
249 // TODO(ahutter): SendAutocheckoutStatus of SUCCESS. 265 SendAutocheckoutStatus(SUCCESS);
250 autofill_manager_->delegate()->HideRequestAutocompleteDialog(); 266 autofill_manager_->delegate()->HideRequestAutocompleteDialog();
251 in_autocheckout_flow_ = false; 267 in_autocheckout_flow_ = false;
252 } 268 }
253 } 269 }
254 270
255 void AutocheckoutManager::SetValue(const AutofillField& field, 271 void AutocheckoutManager::SetValue(const AutofillField& field,
256 FormFieldData* field_to_fill) { 272 FormFieldData* field_to_fill) {
257 AutofillFieldType type = field.type(); 273 AutofillFieldType type = field.type();
258 274
259 if (type == FIELD_WITH_DEFAULT_VALUE) { 275 if (type == FIELD_WITH_DEFAULT_VALUE) {
(...skipping 23 matching lines...) Expand all
283 } 299 }
284 300
285 // TODO(ramankk): Handle variants in a better fashion, need to distinguish 301 // TODO(ramankk): Handle variants in a better fashion, need to distinguish
286 // between shipping and billing address. 302 // between shipping and billing address.
287 if (AutofillType(type).group() == AutofillType::CREDIT_CARD) 303 if (AutofillType(type).group() == AutofillType::CREDIT_CARD)
288 credit_card_->FillFormField(field, 0, field_to_fill); 304 credit_card_->FillFormField(field, 0, field_to_fill);
289 else 305 else
290 profile_->FillFormField(field, 0, field_to_fill); 306 profile_->FillFormField(field, 0, field_to_fill);
291 } 307 }
292 308
309 void AutocheckoutManager::SendAutocheckoutStatus(AutocheckoutStatus status) {
310 // To ensure stale data isn't being sent.
311 DCHECK_NE(kTransactionIdNotSet, google_transaction_id_);
312
313 AutocheckoutRequestManager::CreateForBrowserContext(
314 autofill_manager_->GetWebContents()->GetBrowserContext());
315 AutocheckoutRequestManager* autocheckout_request_manager =
316 AutocheckoutRequestManager::FromBrowserContext(
317 autofill_manager_->GetWebContents()->GetBrowserContext());
318 // It is assumed that the domain Autocheckout starts on does not change
319 // during the flow. If this proves to be incorrect, the |source_url| from
320 // AutofillDialogControllerImpl will need to be provided in its callback in
321 // addition to the Google transaction id.
322 autocheckout_request_manager->SendAutocheckoutStatus(
323 status,
324 autofill_manager_->GetWebContents()->GetURL(),
325 google_transaction_id_);
326
327 google_transaction_id_ = kTransactionIdNotSet;
328 }
329
293 } // namespace autofill 330 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/browser/autocheckout_manager.h ('k') | components/autofill/browser/autocheckout_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698