Skip to content

Commit 6f99d22

Browse files
author
ahutter@chromium.org
committed
Implements SendAutocheckoutStatus API calls for stats tracking.
BUG=224159 Review URL: https://chromiumcodereview.appspot.com/12457033 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191445 0039d316-1c4b-4281-b951-d872f2087c98
1 parent 62d4d61 commit 6f99d22

21 files changed

+352
-68
lines changed

chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace autofill {
2121

2222
namespace {
2323

24-
void MockCallback(const FormStructure*) {}
24+
void MockCallback(const FormStructure*, const std::string&) {}
2525

2626
class MockAutofillMetrics : public AutofillMetrics {
2727
public:

chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc

+11-10
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ AutofillDialogControllerImpl::AutofillDialogControllerImpl(
227227
const GURL& source_url,
228228
const AutofillMetrics& metric_logger,
229229
DialogType dialog_type,
230-
const base::Callback<void(const FormStructure*)>& callback)
230+
const base::Callback<void(const FormStructure*,
231+
const std::string&)>& callback)
231232
: profile_(Profile::FromBrowserContext(contents->GetBrowserContext())),
232233
contents_(contents),
233234
form_structure_(form, std::string()),
@@ -301,7 +302,7 @@ void AutofillDialogControllerImpl::Show() {
301302
&has_sections);
302303
// Fail if the author didn't specify autocomplete types.
303304
if (!has_types) {
304-
callback_.Run(NULL);
305+
callback_.Run(NULL, std::string());
305306
delete this;
306307
return;
307308
}
@@ -1147,8 +1148,9 @@ void AutofillDialogControllerImpl::OnCancel() {
11471148
// submitted to start the flow and then cancelled to close the dialog after
11481149
// the error.
11491150
if (!callback_.is_null()) {
1150-
callback_.Run(NULL);
1151-
callback_ = base::Callback<void(const FormStructure*)>();
1151+
callback_.Run(NULL, std::string());
1152+
callback_ = base::Callback<void(const FormStructure*,
1153+
const std::string&)>();
11521154
}
11531155
}
11541156

@@ -1373,10 +1375,6 @@ void AutofillDialogControllerImpl::OnDidSaveInstrumentAndAddress(
13731375
GetFullWallet();
13741376
}
13751377

1376-
void AutofillDialogControllerImpl::OnDidSendAutocheckoutStatus() {
1377-
NOTIMPLEMENTED();
1378-
}
1379-
13801378
void AutofillDialogControllerImpl::OnDidUpdateAddress(
13811379
const std::string& address_id,
13821380
const std::vector<wallet::RequiredAction>& required_actions) {
@@ -1893,8 +1891,11 @@ void AutofillDialogControllerImpl::FinishSubmit() {
18931891
} else {
18941892
FillOutputForSection(SECTION_SHIPPING);
18951893
}
1896-
callback_.Run(&form_structure_);
1897-
callback_ = base::Callback<void(const FormStructure*)>();
1894+
if (wallet_items_)
1895+
callback_.Run(&form_structure_, wallet_items_->google_transaction_id());
1896+
else
1897+
callback_.Run(&form_structure_, std::string());
1898+
callback_ = base::Callback<void(const FormStructure*, const std::string&)>();
18981899

18991900
if (dialog_type_ == DIALOG_TYPE_REQUEST_AUTOCOMPLETE) {
19001901
// This may delete us.

chrome/browser/ui/autofill/autofill_dialog_controller_impl.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ class AutofillDialogControllerImpl : public AutofillDialogController,
7575
const GURL& source_url,
7676
const AutofillMetrics& metric_logger,
7777
const DialogType dialog_type,
78-
const base::Callback<void(const FormStructure*)>& callback);
78+
const base::Callback<void(const FormStructure*,
79+
const std::string&)>& callback);
7980
virtual ~AutofillDialogControllerImpl();
8081

8182
static void RegisterUserPrefs(PrefRegistrySyncable* registry);
@@ -186,7 +187,6 @@ class AutofillDialogControllerImpl : public AutofillDialogController,
186187
const std::string& instrument_id,
187188
const std::string& address_id,
188189
const std::vector<wallet::RequiredAction>& required_actions) OVERRIDE;
189-
virtual void OnDidSendAutocheckoutStatus() OVERRIDE;
190190
virtual void OnDidUpdateAddress(
191191
const std::string& address_id,
192192
const std::vector<wallet::RequiredAction>& required_actions) OVERRIDE;
@@ -369,8 +369,9 @@ class AutofillDialogControllerImpl : public AutofillDialogController,
369369
// The SSL info from the invoking site.
370370
content::SSLStatus ssl_status_;
371371

372-
// The callback via which we return the collected data.
373-
base::Callback<void(const FormStructure*)> callback_;
372+
// The callback via which we return the collected data and, if Online Wallet
373+
// was used, the Google transaction id.
374+
base::Callback<void(const FormStructure*, const std::string&)> callback_;
374375

375376
// The AccountChooserModel acts as the MenuModel for the account chooser,
376377
// and also tracks which data source the dialog is using.

chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ class TestAutofillDialogController : public AutofillDialogControllerImpl {
122122
const GURL& source_url,
123123
const AutofillMetrics& metric_logger,
124124
const DialogType dialog_type,
125-
const base::Callback<void(const FormStructure*)>& callback)
125+
const base::Callback<void(const FormStructure*,
126+
const std::string&)>& callback)
126127
: AutofillDialogControllerImpl(contents,
127128
form_structure,
128129
source_url,
@@ -207,7 +208,7 @@ class AutofillDialogControllerTest : public testing::Test {
207208
test_web_contents_.reset(
208209
content::WebContentsTester::CreateTestWebContents(profile(), NULL));
209210

210-
base::Callback<void(const FormStructure*)> callback;
211+
base::Callback<void(const FormStructure*, const std::string&)> callback;
211212
controller_ = new TestAutofillDialogController(
212213
test_web_contents_.get(),
213214
form_data,

chrome/browser/ui/autofill/tab_autofill_manager_delegate.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ void TabAutofillManagerDelegate::ShowRequestAutocompleteDialog(
157157
const GURL& source_url,
158158
const AutofillMetrics& metric_logger,
159159
DialogType dialog_type,
160-
const base::Callback<void(const FormStructure*)>& callback) {
160+
const base::Callback<void(const FormStructure*,
161+
const std::string&)>& callback) {
161162
HideRequestAutocompleteDialog();
162163

163164
dialog_controller_ =

chrome/browser/ui/autofill/tab_autofill_manager_delegate.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class TabAutofillManagerDelegate
6666
const GURL& source_url,
6767
const AutofillMetrics& metric_logger,
6868
DialogType dialog_type,
69-
const base::Callback<void(const FormStructure*)>& callback) OVERRIDE;
69+
const base::Callback<void(const FormStructure*,
70+
const std::string&)>& callback) OVERRIDE;
7071
virtual void RequestAutocompleteDialogClosed() OVERRIDE;
7172
virtual void ShowAutofillPopup(const gfx::RectF& element_bounds,
7273
const std::vector<string16>& values,

chrome/chrome_browser.gypi

+2
Original file line numberDiff line numberDiff line change
@@ -2154,6 +2154,8 @@
21542154
'../components/autofill/browser/autocheckout_manager.h',
21552155
'../components/autofill/browser/autocheckout_page_meta_data.cc',
21562156
'../components/autofill/browser/autocheckout_page_meta_data.h',
2157+
'../components/autofill/browser/autocheckout_request_manager.cc',
2158+
'../components/autofill/browser/autocheckout_request_manager.h',
21572159
'../components/autofill/browser/autocomplete_history_manager.cc',
21582160
'../components/autofill/browser/autocomplete_history_manager.h',
21592161
'../components/autofill/browser/autofill-inl.h',

components/autofill/browser/autocheckout_manager.cc

+45-8
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
#include "base/basictypes.h"
88
#include "base/bind.h"
99
#include "base/utf_string_conversions.h"
10+
#include "components/autofill/browser/autocheckout_request_manager.h"
1011
#include "components/autofill/browser/autofill_country.h"
1112
#include "components/autofill/browser/autofill_field.h"
1213
#include "components/autofill/browser/autofill_manager.h"
1314
#include "components/autofill/browser/autofill_profile.h"
1415
#include "components/autofill/browser/credit_card.h"
1516
#include "components/autofill/browser/field_types.h"
1617
#include "components/autofill/browser/form_structure.h"
17-
#include "components/autofill/common/autocheckout_status.h"
1818
#include "components/autofill/common/autofill_messages.h"
1919
#include "components/autofill/common/form_data.h"
2020
#include "components/autofill/common/form_field_data.h"
@@ -68,6 +68,8 @@ FormData BuildAutocheckoutFormData() {
6868
return formdata;
6969
}
7070

71+
const char kTransactionIdNotSet[] = "transaction id not set";
72+
7173
} // namespace
7274

7375
namespace autofill {
@@ -77,8 +79,8 @@ AutocheckoutManager::AutocheckoutManager(AutofillManager* autofill_manager)
7779
autocheckout_offered_(false),
7880
is_autocheckout_bubble_showing_(false),
7981
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)) {}
8284

8385
AutocheckoutManager::~AutocheckoutManager() {
8486
}
@@ -117,6 +119,11 @@ void AutocheckoutManager::FillForms() {
117119
*page_meta_data_->proceed_element_descriptor));
118120
}
119121

122+
void AutocheckoutManager::OnClickFailed(AutocheckoutStatus status) {
123+
SendAutocheckoutStatus(status);
124+
autofill_manager_->delegate()->OnAutocheckoutError();
125+
}
126+
120127
void AutocheckoutManager::OnLoadedPageMetaData(
121128
scoped_ptr<AutocheckoutPageMetaData> page_meta_data) {
122129
scoped_ptr<AutocheckoutPageMetaData> old_meta_data =
@@ -128,24 +135,30 @@ void AutocheckoutManager::OnLoadedPageMetaData(
128135
if (!in_autocheckout_flow_)
129136
return;
130137

138+
AutocheckoutStatus status = SUCCESS;
139+
131140
// Missing Autofill server results.
132141
if (!page_meta_data_) {
133142
in_autocheckout_flow_ = false;
143+
status = MISSING_FIELDMAPPING;
134144
} else if (page_meta_data_->IsStartOfAutofillableFlow()) {
135145
// Not possible unless Autocheckout failed to proceed.
136146
in_autocheckout_flow_ = false;
147+
status = CANNOT_PROCEED;
137148
} else if (!page_meta_data_->IsInAutofillableFlow()) {
138149
// Missing Autocheckout meta data in the Autofill server results.
139150
in_autocheckout_flow_ = false;
151+
status = MISSING_FIELDMAPPING;
140152
} else if (page_meta_data_->current_page_number <=
141153
old_meta_data->current_page_number) {
142154
// Not possible unless Autocheckout failed to proceed.
143155
in_autocheckout_flow_ = false;
156+
status = CANNOT_PROCEED;
144157
}
145158

146159
// Encountered an error during the Autocheckout flow.
147160
if (!in_autocheckout_flow_) {
148-
// TODO(ahutter): SendAutocheckoutStatus of the error.
161+
SendAutocheckoutStatus(status);
149162
autofill_manager_->delegate()->OnAutocheckoutError();
150163
return;
151164
}
@@ -157,7 +170,7 @@ void AutocheckoutManager::OnLoadedPageMetaData(
157170
FillForms();
158171
// If the current page is the last page in the flow, close the dialog.
159172
if (page_meta_data_->IsEndOfAutofillableFlow()) {
160-
// TODO(ahutter): SendAutocheckoutStatus of SUCCESS.
173+
SendAutocheckoutStatus(status);
161174
autofill_manager_->delegate()->HideRequestAutocompleteDialog();
162175
in_autocheckout_flow_ = false;
163176
}
@@ -200,7 +213,7 @@ void AutocheckoutManager::MaybeShowAutocheckoutDialog(
200213

201214
FormData form = BuildAutocheckoutFormData();
202215
form.ssl_status = ssl_status;
203-
base::Callback<void(const FormStructure*)> callback =
216+
base::Callback<void(const FormStructure*, const std::string&)> callback =
204217
base::Bind(&AutocheckoutManager::ReturnAutocheckoutData,
205218
weak_ptr_factory_.GetWeakPtr());
206219
autofill_manager_->ShowRequestAutocompleteDialog(
@@ -215,10 +228,13 @@ bool AutocheckoutManager::IsInAutofillableFlow() const {
215228
return page_meta_data_ && page_meta_data_->IsInAutofillableFlow();
216229
}
217230

218-
void AutocheckoutManager::ReturnAutocheckoutData(const FormStructure* result) {
231+
void AutocheckoutManager::ReturnAutocheckoutData(
232+
const FormStructure* result,
233+
const std::string& google_transaction_id) {
219234
if (!result)
220235
return;
221236

237+
google_transaction_id_ = google_transaction_id;
222238
in_autocheckout_flow_ = true;
223239

224240
profile_.reset(new AutofillProfile());
@@ -246,7 +262,7 @@ void AutocheckoutManager::ReturnAutocheckoutData(const FormStructure* result) {
246262

247263
// If the current page is the last page in the flow, close the dialog.
248264
if (page_meta_data_->IsEndOfAutofillableFlow()) {
249-
// TODO(ahutter): SendAutocheckoutStatus of SUCCESS.
265+
SendAutocheckoutStatus(SUCCESS);
250266
autofill_manager_->delegate()->HideRequestAutocompleteDialog();
251267
in_autocheckout_flow_ = false;
252268
}
@@ -290,4 +306,25 @@ void AutocheckoutManager::SetValue(const AutofillField& field,
290306
profile_->FillFormField(field, 0, field_to_fill);
291307
}
292308

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+
293330
} // namespace autofill

components/autofill/browser/autocheckout_manager.h

+12-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "base/memory/weak_ptr.h"
1212
#include "base/string16.h"
1313
#include "components/autofill/browser/autocheckout_page_meta_data.h"
14+
#include "components/autofill/common/autocheckout_status.h"
1415
#include "ui/gfx/native_widget_types.h"
1516

1617
class AutofillField;
@@ -42,6 +43,10 @@ class AutocheckoutManager {
4243
// gathered from the requestAutocomplete dialog.
4344
void FillForms();
4445

46+
// Called when clicking a proceed element in an Autocheckout flow fails.
47+
// |status| is the reason for the failure.
48+
void OnClickFailed(AutocheckoutStatus status);
49+
4550
// Sets |page_meta_data_| with the meta data for the current page.
4651
void OnLoadedPageMetaData(
4752
scoped_ptr<AutocheckoutPageMetaData> page_meta_data);
@@ -84,7 +89,11 @@ class AutocheckoutManager {
8489
bool IsInAutofillableFlow() const;
8590

8691
// Callback called from AutofillDialogController on filling up the UI form.
87-
void ReturnAutocheckoutData(const FormStructure* result);
92+
void ReturnAutocheckoutData(const FormStructure* result,
93+
const std::string& google_transaction_id);
94+
95+
// Sends |status| to Online Wallet using AutocheckoutRequestManager.
96+
void SendAutocheckoutStatus(AutocheckoutStatus status);
8897

8998
// Sets value of form field data |field_to_fill| based on the Autofill
9099
// field type specified by |field|.
@@ -115,6 +124,8 @@ class AutocheckoutManager {
115124
// Whether or not the user is in an Autocheckout flow.
116125
bool in_autocheckout_flow_;
117126

127+
std::string google_transaction_id_;
128+
118129
base::WeakPtrFactory<AutocheckoutManager> weak_ptr_factory_;
119130

120131
DISALLOW_COPY_AND_ASSIGN(AutocheckoutManager);

components/autofill/browser/autocheckout_manager_unittest.cc

+11-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "base/tuple.h"
66
#include "base/utf_string_conversions.h"
77
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
8+
#include "chrome/test/base/testing_profile.h"
89
#include "components/autofill/browser/autocheckout_manager.h"
910
#include "components/autofill/browser/autofill_common_test.h"
1011
#include "components/autofill/browser/autofill_manager.h"
@@ -237,9 +238,10 @@ class MockAutofillManagerDelegate : public TestAutofillManagerDelegate {
237238
const GURL& source_url,
238239
const AutofillMetrics& metric_logger,
239240
DialogType dialog_type,
240-
const base::Callback<void(const FormStructure*)>& callback) OVERRIDE {
241+
const base::Callback<void(const FormStructure*,
242+
const std::string&)>& callback) OVERRIDE {
241243
request_autocomplete_dialog_open_ = true;
242-
callback.Run(user_supplied_data_.get());
244+
callback.Run(user_supplied_data_.get(), "google_transaction_id");
243245
}
244246

245247
MOCK_METHOD1(UpdateProgressBar, void(double value));
@@ -297,7 +299,8 @@ class AutocheckoutManagerTest : public ChromeRenderViewHostTestHarness {
297299
public:
298300
AutocheckoutManagerTest()
299301
: ChromeRenderViewHostTestHarness(),
300-
ui_thread_(BrowserThread::UI, &message_loop_) {
302+
ui_thread_(BrowserThread::UI, &message_loop_),
303+
io_thread_(BrowserThread::IO) {
301304
}
302305

303306
std::vector<FormData> ReadFilledForms() {
@@ -355,13 +358,16 @@ class AutocheckoutManagerTest : public ChromeRenderViewHostTestHarness {
355358

356359
protected:
357360
content::TestBrowserThread ui_thread_;
361+
content::TestBrowserThread io_thread_;
358362
scoped_ptr<TestAutofillManager> autofill_manager_;
359363
scoped_ptr<TestAutocheckoutManager> autocheckout_manager_;
360364
scoped_ptr<MockAutofillManagerDelegate> autofill_manager_delegate_;
361365

362366
private:
363367
virtual void SetUp() OVERRIDE {
364368
ChromeRenderViewHostTestHarness::SetUp();
369+
io_thread_.StartIOThread();
370+
profile()->CreateRequestContext();
365371
autofill_manager_delegate_.reset(new MockAutofillManagerDelegate());
366372
autofill_manager_.reset(new TestAutofillManager(
367373
web_contents(),
@@ -374,7 +380,9 @@ class AutocheckoutManagerTest : public ChromeRenderViewHostTestHarness {
374380
autocheckout_manager_.reset();
375381
autofill_manager_delegate_.reset();
376382
autofill_manager_.reset();
383+
profile()->ResetRequestContext();
377384
ChromeRenderViewHostTestHarness::TearDown();
385+
io_thread_.Stop();
378386
}
379387

380388
DISALLOW_COPY_AND_ASSIGN(AutocheckoutManagerTest);

0 commit comments

Comments
 (0)