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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/content/browser/autocheckout_manager.h" 5 #include "components/autofill/content/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/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/content/browser/autocheckout_request_manager.h" 10 #include "components/autofill/content/browser/autocheckout_request_manager.h"
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 host->Send(new AutofillMsg_FillFormsAndClick( 194 host->Send(new AutofillMsg_FillFormsAndClick(
195 host->GetRoutingID(), 195 host->GetRoutingID(),
196 filled_forms, 196 filled_forms,
197 page_meta_data_->click_elements_before_form_fill, 197 page_meta_data_->click_elements_before_form_fill,
198 page_meta_data_->click_elements_after_form_fill, 198 page_meta_data_->click_elements_after_form_fill,
199 page_meta_data_->proceed_element_descriptor)); 199 page_meta_data_->proceed_element_descriptor));
200 // Record time taken for navigating current page. 200 // Record time taken for navigating current page.
201 RecordTimeTaken(page_meta_data_->current_page_number); 201 RecordTimeTaken(page_meta_data_->current_page_number);
202 } 202 }
203 203
204 void AutocheckoutManager::OnClickFailed(AutocheckoutStatus status) { 204 void AutocheckoutManager::OnAutocheckoutPageCompleted(
205 // |in_autocheckout_flow_| get reset in |OnLoadedPageMetaData| for the last 205 AutocheckoutStatus status) {
206 // page, so when click failed on the last page, the value is already 'false'. 206 DVLOG(2) << "OnAutocheckoutPageCompleted, page_no: "
207 // This check stops crashing, a better solution should be sending an IPC 207 << page_meta_data_->current_page_number
208 // message to browser when the renderer completes a step. 208 << " status: "
209 DCHECK(page_meta_data_->IsEndOfAutofillableFlow() || in_autocheckout_flow_); 209 << status;
210 if (!in_autocheckout_flow_)
211 return;
212
210 DCHECK_NE(MISSING_FIELDMAPPING, status); 213 DCHECK_NE(MISSING_FIELDMAPPING, status);
211 214
212 SendAutocheckoutStatus(status); 215 SetStepProgressForPage(
213 SetStepProgressForPage(page_meta_data_->current_page_number, 216 page_meta_data_->current_page_number,
214 AUTOCHECKOUT_STEP_FAILED); 217 (status == SUCCESS) ? AUTOCHECKOUT_STEP_COMPLETED :
218 AUTOCHECKOUT_STEP_FAILED);
215 219
216 autofill_manager_->delegate()->OnAutocheckoutError(); 220 if (page_meta_data_->IsEndOfAutofillableFlow() || status != SUCCESS)
217 in_autocheckout_flow_ = false; 221 EndAutocheckout(status);
218 } 222 }
219 223
220 void AutocheckoutManager::OnLoadedPageMetaData( 224 void AutocheckoutManager::OnLoadedPageMetaData(
221 scoped_ptr<AutocheckoutPageMetaData> page_meta_data) { 225 scoped_ptr<AutocheckoutPageMetaData> page_meta_data) {
222 scoped_ptr<AutocheckoutPageMetaData> old_meta_data = 226 scoped_ptr<AutocheckoutPageMetaData> old_meta_data = page_meta_data_.Pass();
223 page_meta_data_.Pass();
224 page_meta_data_ = page_meta_data.Pass(); 227 page_meta_data_ = page_meta_data.Pass();
225 228
226 // Don't log that the bubble could be displayed if the user entered an 229 // Don't log that the bubble could be displayed if the user entered an
227 // Autocheckout flow and sees the first page of the flow again due to an 230 // Autocheckout flow and sees the first page of the flow again due to an
228 // error. 231 // error.
229 if (IsStartOfAutofillableFlow() && !in_autocheckout_flow_) { 232 if (IsStartOfAutofillableFlow() && !in_autocheckout_flow_) {
230 metric_logger_->LogAutocheckoutBubbleMetric( 233 metric_logger_->LogAutocheckoutBubbleMetric(
231 AutofillMetrics::BUBBLE_COULD_BE_DISPLAYED); 234 AutofillMetrics::BUBBLE_COULD_BE_DISPLAYED);
232 } 235 }
233 236
234 // On the first page of an Autocheckout flow, when this function is called the 237 // On the first page of an Autocheckout flow, when this function is called the
235 // user won't have opted into the flow yet. 238 // user won't have opted into the flow yet.
236 if (!in_autocheckout_flow_) 239 if (!in_autocheckout_flow_)
237 return; 240 return;
238 241
239 AutocheckoutStatus status = SUCCESS; 242 AutocheckoutStatus status = SUCCESS;
240 243
241 // Missing Autofill server results. 244 // Missing Autofill server results.
242 if (!page_meta_data_) { 245 if (!page_meta_data_.get()) {
243 in_autocheckout_flow_ = false;
244 status = MISSING_FIELDMAPPING; 246 status = MISSING_FIELDMAPPING;
245 } else if (page_meta_data_->IsStartOfAutofillableFlow()) { 247 } else if (IsStartOfAutofillableFlow()) {
246 // Not possible unless Autocheckout failed to proceed. 248 // Not possible unless Autocheckout failed to proceed.
247 in_autocheckout_flow_ = false;
248 status = CANNOT_PROCEED; 249 status = CANNOT_PROCEED;
249 } else if (!page_meta_data_->IsInAutofillableFlow()) { 250 } else if (!page_meta_data_->IsInAutofillableFlow()) {
250 // Missing Autocheckout meta data in the Autofill server results. 251 // Missing Autocheckout meta data in the Autofill server results.
251 in_autocheckout_flow_ = false;
252 status = MISSING_FIELDMAPPING; 252 status = MISSING_FIELDMAPPING;
253 } else if (page_meta_data_->current_page_number <= 253 } else if (page_meta_data_->current_page_number <=
254 old_meta_data->current_page_number) { 254 old_meta_data->current_page_number) {
255 // Not possible unless Autocheckout failed to proceed. 255 // Not possible unless Autocheckout failed to proceed.
256 in_autocheckout_flow_ = false;
257 status = CANNOT_PROCEED; 256 status = CANNOT_PROCEED;
258 } 257 }
259 258
260 // Encountered an error during the Autocheckout flow, probably to 259 // Encountered an error during the Autocheckout flow, probably to
261 // do with a problem on the previous page. 260 // do with a problem on the previous page.
262 if (!in_autocheckout_flow_) { 261 if (status != SUCCESS) {
263 if (old_meta_data) { 262 SetStepProgressForPage(old_meta_data->current_page_number,
264 SetStepProgressForPage(old_meta_data->current_page_number, 263 AUTOCHECKOUT_STEP_FAILED);
265 AUTOCHECKOUT_STEP_FAILED); 264 EndAutocheckout(status);
266 }
267 SendAutocheckoutStatus(status);
268 autofill_manager_->delegate()->OnAutocheckoutError();
269 return; 265 return;
270 } 266 }
271 267
272 SetStepProgressForPage(old_meta_data->current_page_number,
273 AUTOCHECKOUT_STEP_COMPLETED);
274 SetStepProgressForPage(page_meta_data_->current_page_number, 268 SetStepProgressForPage(page_meta_data_->current_page_number,
275 AUTOCHECKOUT_STEP_STARTED); 269 AUTOCHECKOUT_STEP_STARTED);
276 270
277 FillForms(); 271 FillForms();
278 // If the current page is the last page in the flow, set in-progress
279 // steps to 'completed', and send status.
280 if (page_meta_data_->IsEndOfAutofillableFlow()) {
281 SetStepProgressForPage(page_meta_data_->current_page_number,
282 AUTOCHECKOUT_STEP_COMPLETED);
283 SendAutocheckoutStatus(status);
284 autofill_manager_->delegate()->OnAutocheckoutSuccess();
285 in_autocheckout_flow_ = false;
286 }
287 } 272 }
288 273
289 void AutocheckoutManager::OnFormsSeen() { 274 void AutocheckoutManager::OnFormsSeen() {
290 should_show_bubble_ = true; 275 should_show_bubble_ = true;
291 } 276 }
292 277
293 bool AutocheckoutManager::ShouldIgnoreAjax() { 278 bool AutocheckoutManager::ShouldIgnoreAjax() {
294 return in_autocheckout_flow_ && page_meta_data_->ignore_ajax; 279 return in_autocheckout_flow_ && page_meta_data_->ignore_ajax;
295 } 280 }
296 281
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 } 355 }
371 } 356 }
372 357
373 // Page types only available in first-page meta data, so save 358 // Page types only available in first-page meta data, so save
374 // them for use later as we navigate. 359 // them for use later as we navigate.
375 page_types_ = page_meta_data_->page_types; 360 page_types_ = page_meta_data_->page_types;
376 SetStepProgressForPage(page_meta_data_->current_page_number, 361 SetStepProgressForPage(page_meta_data_->current_page_number,
377 AUTOCHECKOUT_STEP_STARTED); 362 AUTOCHECKOUT_STEP_STARTED);
378 363
379 FillForms(); 364 FillForms();
380
381 // If the current page is the last page in the flow, set in-progress
382 // steps to 'completed', and send status.
383 if (page_meta_data_->IsEndOfAutofillableFlow()) {
384 SetStepProgressForPage(page_meta_data_->current_page_number,
385 AUTOCHECKOUT_STEP_COMPLETED);
386 SendAutocheckoutStatus(SUCCESS);
387 autofill_manager_->delegate()->OnAutocheckoutSuccess();
388 in_autocheckout_flow_ = false;
389 }
390 } 365 }
391 366
392 void AutocheckoutManager::set_metric_logger( 367 void AutocheckoutManager::set_metric_logger(
393 scoped_ptr<AutofillMetrics> metric_logger) { 368 scoped_ptr<AutofillMetrics> metric_logger) {
394 metric_logger_ = metric_logger.Pass(); 369 metric_logger_ = metric_logger.Pass();
395 } 370 }
396 371
397 void AutocheckoutManager::MaybeShowAutocheckoutDialog( 372 void AutocheckoutManager::MaybeShowAutocheckoutDialog(
398 const GURL& frame_url, 373 const GURL& frame_url,
399 AutocheckoutBubbleState state) { 374 AutocheckoutBubbleState state) {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 } 516 }
542 517
543 statistic.time_taken = 518 statistic.time_taken =
544 base::TimeTicks().Now() - last_step_completion_timestamp_; 519 base::TimeTicks().Now() - last_step_completion_timestamp_;
545 latency_statistics_.push_back(statistic); 520 latency_statistics_.push_back(statistic);
546 521
547 // Reset timestamp. 522 // Reset timestamp.
548 last_step_completion_timestamp_ = base::TimeTicks().Now(); 523 last_step_completion_timestamp_ = base::TimeTicks().Now();
549 } 524 }
550 525
526 void AutocheckoutManager::EndAutocheckout(AutocheckoutStatus status) {
527 DCHECK(in_autocheckout_flow_);
528
529 DVLOG(2) << "EndAutocheckout at step: "
530 << page_meta_data_->current_page_number
531 << " with status: "
532 << status;
533
534 SendAutocheckoutStatus(status);
535 if (status == SUCCESS)
536 autofill_manager_->delegate()->OnAutocheckoutSuccess();
537 else
538 autofill_manager_->delegate()->OnAutocheckoutError();
539 in_autocheckout_flow_ = false;
540 }
541
551 } // namespace autofill 542 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698