Chromium Code Reviews| 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..75a58665953f2a6c0423d4a79354fa1b25902f8e 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(); |
|
Ilya Sherman
2013/07/16 22:56:26
nit: One space too many after the equals sign.
benquan
2013/07/17 00:28:57
Done.
|
| 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) { |
| + old_meta_data->current_page_number) { |
|
Ilya Sherman
2013/07/16 22:56:26
nit: The previous indentation for this line was co
benquan
2013/07/17 00:28:57
Done.
|
| // 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 |