7
7
#include " base/basictypes.h"
8
8
#include " base/bind.h"
9
9
#include " base/utf_string_conversions.h"
10
+ #include " components/autofill/browser/autocheckout_request_manager.h"
10
11
#include " components/autofill/browser/autofill_country.h"
11
12
#include " components/autofill/browser/autofill_field.h"
12
13
#include " components/autofill/browser/autofill_manager.h"
13
14
#include " components/autofill/browser/autofill_profile.h"
14
15
#include " components/autofill/browser/credit_card.h"
15
16
#include " components/autofill/browser/field_types.h"
16
17
#include " components/autofill/browser/form_structure.h"
17
- #include " components/autofill/common/autocheckout_status.h"
18
18
#include " components/autofill/common/autofill_messages.h"
19
19
#include " components/autofill/common/form_data.h"
20
20
#include " components/autofill/common/form_field_data.h"
@@ -68,6 +68,8 @@ FormData BuildAutocheckoutFormData() {
68
68
return formdata;
69
69
}
70
70
71
+ const char kTransactionIdNotSet [] = " transaction id not set" ;
72
+
71
73
} // namespace
72
74
73
75
namespace autofill {
@@ -77,8 +79,8 @@ AutocheckoutManager::AutocheckoutManager(AutofillManager* autofill_manager)
77
79
autocheckout_offered_ (false ),
78
80
is_autocheckout_bubble_showing_(false ),
79
81
in_autocheckout_flow_(false ),
80
- ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_( this )) {
81
- }
82
+ google_transaction_id_( kTransactionIdNotSet ),
83
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_( this )) { }
82
84
83
85
AutocheckoutManager::~AutocheckoutManager () {
84
86
}
@@ -117,6 +119,11 @@ void AutocheckoutManager::FillForms() {
117
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
127
void AutocheckoutManager::OnLoadedPageMetaData (
121
128
scoped_ptr<AutocheckoutPageMetaData> page_meta_data) {
122
129
scoped_ptr<AutocheckoutPageMetaData> old_meta_data =
@@ -128,24 +135,30 @@ void AutocheckoutManager::OnLoadedPageMetaData(
128
135
if (!in_autocheckout_flow_)
129
136
return ;
130
137
138
+ AutocheckoutStatus status = SUCCESS;
139
+
131
140
// Missing Autofill server results.
132
141
if (!page_meta_data_) {
133
142
in_autocheckout_flow_ = false ;
143
+ status = MISSING_FIELDMAPPING;
134
144
} else if (page_meta_data_->IsStartOfAutofillableFlow ()) {
135
145
// Not possible unless Autocheckout failed to proceed.
136
146
in_autocheckout_flow_ = false ;
147
+ status = CANNOT_PROCEED;
137
148
} else if (!page_meta_data_->IsInAutofillableFlow ()) {
138
149
// Missing Autocheckout meta data in the Autofill server results.
139
150
in_autocheckout_flow_ = false ;
151
+ status = MISSING_FIELDMAPPING;
140
152
} else if (page_meta_data_->current_page_number <=
141
153
old_meta_data->current_page_number ) {
142
154
// Not possible unless Autocheckout failed to proceed.
143
155
in_autocheckout_flow_ = false ;
156
+ status = CANNOT_PROCEED;
144
157
}
145
158
146
159
// Encountered an error during the Autocheckout flow.
147
160
if (!in_autocheckout_flow_) {
148
- // TODO(ahutter): SendAutocheckoutStatus of the error.
161
+ SendAutocheckoutStatus (status);
149
162
autofill_manager_->delegate ()->OnAutocheckoutError ();
150
163
return ;
151
164
}
@@ -157,7 +170,7 @@ void AutocheckoutManager::OnLoadedPageMetaData(
157
170
FillForms ();
158
171
// If the current page is the last page in the flow, close the dialog.
159
172
if (page_meta_data_->IsEndOfAutofillableFlow ()) {
160
- // TODO(ahutter): SendAutocheckoutStatus of SUCCESS.
173
+ SendAutocheckoutStatus (status);
161
174
autofill_manager_->delegate ()->HideRequestAutocompleteDialog ();
162
175
in_autocheckout_flow_ = false ;
163
176
}
@@ -200,7 +213,7 @@ void AutocheckoutManager::MaybeShowAutocheckoutDialog(
200
213
201
214
FormData form = BuildAutocheckoutFormData ();
202
215
form.ssl_status = ssl_status;
203
- base::Callback<void (const FormStructure*)> callback =
216
+ base::Callback<void (const FormStructure*, const std::string& )> callback =
204
217
base::Bind (&AutocheckoutManager::ReturnAutocheckoutData,
205
218
weak_ptr_factory_.GetWeakPtr ());
206
219
autofill_manager_->ShowRequestAutocompleteDialog (
@@ -215,10 +228,13 @@ bool AutocheckoutManager::IsInAutofillableFlow() const {
215
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
234
if (!result)
220
235
return ;
221
236
237
+ google_transaction_id_ = google_transaction_id;
222
238
in_autocheckout_flow_ = true ;
223
239
224
240
profile_.reset (new AutofillProfile ());
@@ -246,7 +262,7 @@ void AutocheckoutManager::ReturnAutocheckoutData(const FormStructure* result) {
246
262
247
263
// If the current page is the last page in the flow, close the dialog.
248
264
if (page_meta_data_->IsEndOfAutofillableFlow ()) {
249
- // TODO(ahutter): SendAutocheckoutStatus of SUCCESS.
265
+ SendAutocheckoutStatus ( SUCCESS);
250
266
autofill_manager_->delegate ()->HideRequestAutocompleteDialog ();
251
267
in_autocheckout_flow_ = false ;
252
268
}
@@ -290,4 +306,25 @@ void AutocheckoutManager::SetValue(const AutofillField& field,
290
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
330
} // namespace autofill
0 commit comments