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

Unified Diff: components/autofill/content/browser/autocheckout_manager.cc

Issue 18179015: Send IPC from renderer to browser on each Autocheckout page completion (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix nits Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/content/browser/autocheckout_manager.cc
diff --git a/components/autofill/content/browser/autocheckout_manager.cc b/components/autofill/content/browser/autocheckout_manager.cc
index b06f41fc0f2b387be3d14c94588d457c172a3a96..4f2455d93276c3f7ddd2b7329a30088dc7bd083a 100644
--- a/components/autofill/content/browser/autocheckout_manager.cc
+++ b/components/autofill/content/browser/autocheckout_manager.cc
@@ -201,26 +201,29 @@ void AutocheckoutManager::FillForms() {
RecordTimeTaken(page_meta_data_->current_page_number);
}
-void AutocheckoutManager::OnClickFailed(AutocheckoutStatus status) {
- // |in_autocheckout_flow_| get reset in |OnLoadedPageMetaData| for the last
- // page, so when click failed on the last page, the value is already 'false'.
- // This check stops crashing, a better solution should be sending an IPC
- // message to browser when the renderer completes a step.
- DCHECK(page_meta_data_->IsEndOfAutofillableFlow() || in_autocheckout_flow_);
+void AutocheckoutManager::OnAutocheckoutPageCompleted(
+ AutocheckoutStatus status) {
+ DVLOG(2) << "OnAutocheckoutPageCompleted, page_no: "
+ << page_meta_data_->current_page_number
+ << " status: "
+ << status;
+ if (!in_autocheckout_flow_)
+ return;
+
DCHECK_NE(MISSING_FIELDMAPPING, status);
- SendAutocheckoutStatus(status);
- SetStepProgressForPage(page_meta_data_->current_page_number,
- AUTOCHECKOUT_STEP_FAILED);
+ SetStepProgressForPage(
+ page_meta_data_->current_page_number,
+ (status == SUCCESS) ? AUTOCHECKOUT_STEP_COMPLETED :
+ AUTOCHECKOUT_STEP_FAILED);
- autofill_manager_->delegate()->OnAutocheckoutError();
- in_autocheckout_flow_ = false;
+ if (page_meta_data_->IsEndOfAutofillableFlow() || status != SUCCESS)
+ EndAutocheckout(status);
}
void AutocheckoutManager::OnLoadedPageMetaData(
scoped_ptr<AutocheckoutPageMetaData> page_meta_data) {
- scoped_ptr<AutocheckoutPageMetaData> old_meta_data =
- page_meta_data_.Pass();
+ scoped_ptr<AutocheckoutPageMetaData> old_meta_data = page_meta_data_.Pass();
page_meta_data_ = page_meta_data.Pass();
// Don't log that the bubble could be displayed if the user entered an
@@ -239,51 +242,33 @@ void AutocheckoutManager::OnLoadedPageMetaData(
AutocheckoutStatus status = SUCCESS;
// Missing Autofill server results.
- if (!page_meta_data_) {
- in_autocheckout_flow_ = false;
+ if (!page_meta_data_.get()) {
status = MISSING_FIELDMAPPING;
- } else if (page_meta_data_->IsStartOfAutofillableFlow()) {
+ } else if (IsStartOfAutofillableFlow()) {
// Not possible unless Autocheckout failed to proceed.
- in_autocheckout_flow_ = false;
status = CANNOT_PROCEED;
} else if (!page_meta_data_->IsInAutofillableFlow()) {
// Missing Autocheckout meta data in the Autofill server results.
- in_autocheckout_flow_ = false;
status = MISSING_FIELDMAPPING;
} else if (page_meta_data_->current_page_number <=
old_meta_data->current_page_number) {
// Not possible unless Autocheckout failed to proceed.
- in_autocheckout_flow_ = false;
status = CANNOT_PROCEED;
}
// Encountered an error during the Autocheckout flow, probably to
// do with a problem on the previous page.
- if (!in_autocheckout_flow_) {
- if (old_meta_data) {
- SetStepProgressForPage(old_meta_data->current_page_number,
- AUTOCHECKOUT_STEP_FAILED);
- }
- SendAutocheckoutStatus(status);
- autofill_manager_->delegate()->OnAutocheckoutError();
+ if (status != SUCCESS) {
+ SetStepProgressForPage(old_meta_data->current_page_number,
+ AUTOCHECKOUT_STEP_FAILED);
+ EndAutocheckout(status);
return;
}
- SetStepProgressForPage(old_meta_data->current_page_number,
- AUTOCHECKOUT_STEP_COMPLETED);
SetStepProgressForPage(page_meta_data_->current_page_number,
AUTOCHECKOUT_STEP_STARTED);
FillForms();
- // If the current page is the last page in the flow, set in-progress
- // steps to 'completed', and send status.
- if (page_meta_data_->IsEndOfAutofillableFlow()) {
- SetStepProgressForPage(page_meta_data_->current_page_number,
- AUTOCHECKOUT_STEP_COMPLETED);
- SendAutocheckoutStatus(status);
- autofill_manager_->delegate()->OnAutocheckoutSuccess();
- in_autocheckout_flow_ = false;
- }
}
void AutocheckoutManager::OnFormsSeen() {
@@ -377,16 +362,6 @@ void AutocheckoutManager::ReturnAutocheckoutData(
AUTOCHECKOUT_STEP_STARTED);
FillForms();
-
- // If the current page is the last page in the flow, set in-progress
- // steps to 'completed', and send status.
- if (page_meta_data_->IsEndOfAutofillableFlow()) {
- SetStepProgressForPage(page_meta_data_->current_page_number,
- AUTOCHECKOUT_STEP_COMPLETED);
- SendAutocheckoutStatus(SUCCESS);
- autofill_manager_->delegate()->OnAutocheckoutSuccess();
- in_autocheckout_flow_ = false;
- }
}
void AutocheckoutManager::set_metric_logger(
@@ -548,4 +523,20 @@ void AutocheckoutManager::RecordTimeTaken(int page_number) {
last_step_completion_timestamp_ = base::TimeTicks().Now();
}
+void AutocheckoutManager::EndAutocheckout(AutocheckoutStatus status) {
+ DCHECK(in_autocheckout_flow_);
+
+ DVLOG(2) << "EndAutocheckout at step: "
+ << page_meta_data_->current_page_number
+ << " with status: "
+ << status;
+
+ SendAutocheckoutStatus(status);
+ if (status == SUCCESS)
+ autofill_manager_->delegate()->OnAutocheckoutSuccess();
+ else
+ autofill_manager_->delegate()->OnAutocheckoutError();
+ in_autocheckout_flow_ = false;
+}
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698