| OLD | NEW |
| 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 "chrome/browser/profile_resetter/automatic_profile_resetter.h" | 5 #include "chrome/browser/profile_resetter/automatic_profile_resetter.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 const uint32 kCombinedStatusMaskMaximumValue = | 84 const uint32 kCombinedStatusMaskMaximumValue = |
| 85 (1u << kCombinedStatusMaskNumberOfBits); | 85 (1u << kCombinedStatusMaskNumberOfBits); |
| 86 | 86 |
| 87 COMPILE_ASSERT( | 87 COMPILE_ASSERT( |
| 88 arraysize(kSatisfiedCriteriaMaskKeys) == kSatisfiedCriteriaMaskNumberOfBits, | 88 arraysize(kSatisfiedCriteriaMaskKeys) == kSatisfiedCriteriaMaskNumberOfBits, |
| 89 satisfied_criteria_mask_bits_mismatch); | 89 satisfied_criteria_mask_bits_mismatch); |
| 90 COMPILE_ASSERT( | 90 COMPILE_ASSERT( |
| 91 arraysize(kCombinedStatusMaskKeys) == kCombinedStatusMaskNumberOfBits, | 91 arraysize(kCombinedStatusMaskKeys) == kCombinedStatusMaskNumberOfBits, |
| 92 combined_status_mask_bits_mismatch); | 92 combined_status_mask_bits_mismatch); |
| 93 | 93 |
| 94 // Enumeration of the possible outcomes of showing the profile reset prompt. | |
| 95 enum PromptResult { | |
| 96 // Prompt was not shown because only a dry-run was performed. | |
| 97 PROMPT_NOT_SHOWN, | |
| 98 PROMPT_ACTION_RESET, | |
| 99 PROMPT_ACTION_NO_RESET, | |
| 100 PROMPT_DISMISSED, | |
| 101 // Prompt was still shown (not dismissed by the user) when Chrome was closed. | |
| 102 PROMPT_IGNORED, | |
| 103 PROMPT_RESULT_MAX | |
| 104 }; | |
| 105 | |
| 106 // Returns whether or not a dry-run shall be performed. | 94 // Returns whether or not a dry-run shall be performed. |
| 107 bool ShouldPerformDryRun() { | 95 bool ShouldPerformDryRun() { |
| 108 return StartsWithASCII( | 96 return StartsWithASCII( |
| 109 base::FieldTrialList::FindFullName(kAutomaticProfileResetStudyName), | 97 base::FieldTrialList::FindFullName(kAutomaticProfileResetStudyName), |
| 110 kAutomaticProfileResetStudyDryRunGroupName, true); | 98 kAutomaticProfileResetStudyDryRunGroupName, true); |
| 111 } | 99 } |
| 112 | 100 |
| 113 // Returns whether or not a live-run shall be performed. | 101 // Returns whether or not a live-run shall be performed. |
| 114 bool ShouldPerformLiveRun() { | 102 bool ShouldPerformLiveRun() { |
| 115 return StartsWithASCII( | 103 return StartsWithASCII( |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 }; | 373 }; |
| 386 | 374 |
| 387 | 375 |
| 388 // AutomaticProfileResetter -------------------------------------------------- | 376 // AutomaticProfileResetter -------------------------------------------------- |
| 389 | 377 |
| 390 AutomaticProfileResetter::AutomaticProfileResetter(Profile* profile) | 378 AutomaticProfileResetter::AutomaticProfileResetter(Profile* profile) |
| 391 : profile_(profile), | 379 : profile_(profile), |
| 392 state_(STATE_UNINITIALIZED), | 380 state_(STATE_UNINITIALIZED), |
| 393 enumeration_of_loaded_modules_ready_(false), | 381 enumeration_of_loaded_modules_ready_(false), |
| 394 template_url_service_ready_(false), | 382 template_url_service_ready_(false), |
| 383 has_already_dismissed_prompt_(false), |
| 395 weak_ptr_factory_(this) { | 384 weak_ptr_factory_(this) { |
| 396 DCHECK(profile_); | 385 DCHECK(profile_); |
| 397 } | 386 } |
| 398 | 387 |
| 399 AutomaticProfileResetter::~AutomaticProfileResetter() {} | 388 AutomaticProfileResetter::~AutomaticProfileResetter() {} |
| 400 | 389 |
| 401 void AutomaticProfileResetter::Initialize() { | 390 void AutomaticProfileResetter::Initialize() { |
| 402 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 391 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 403 DCHECK_EQ(state_, STATE_UNINITIALIZED); | 392 DCHECK_EQ(state_, STATE_UNINITIALIZED); |
| 404 | 393 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 416 IDR_AUTOMATIC_PROFILE_RESET_HASH_SEED).as_string(); | 405 IDR_AUTOMATIC_PROFILE_RESET_HASH_SEED).as_string(); |
| 417 } else { // ShouldPerformDryRun() | 406 } else { // ShouldPerformDryRun() |
| 418 program_ = resources.GetRawDataResource( | 407 program_ = resources.GetRawDataResource( |
| 419 IDR_AUTOMATIC_PROFILE_RESET_RULES_DRY).as_string(); | 408 IDR_AUTOMATIC_PROFILE_RESET_RULES_DRY).as_string(); |
| 420 hash_seed_ = resources.GetRawDataResource( | 409 hash_seed_ = resources.GetRawDataResource( |
| 421 IDR_AUTOMATIC_PROFILE_RESET_HASH_SEED_DRY).as_string(); | 410 IDR_AUTOMATIC_PROFILE_RESET_HASH_SEED_DRY).as_string(); |
| 422 } | 411 } |
| 423 } | 412 } |
| 424 | 413 |
| 425 delegate_.reset(new AutomaticProfileResetterDelegateImpl( | 414 delegate_.reset(new AutomaticProfileResetterDelegateImpl( |
| 426 TemplateURLServiceFactory::GetForProfile(profile_))); | 415 profile_, ProfileResetter::ALL)); |
| 427 task_runner_for_waiting_ = | 416 task_runner_for_waiting_ = |
| 428 content::BrowserThread::GetMessageLoopProxyForThread( | 417 content::BrowserThread::GetMessageLoopProxyForThread( |
| 429 content::BrowserThread::UI); | 418 content::BrowserThread::UI); |
| 430 | 419 |
| 431 state_ = STATE_INITIALIZED; | 420 state_ = STATE_INITIALIZED; |
| 432 } | 421 } |
| 433 | 422 |
| 434 void AutomaticProfileResetter::Activate() { | 423 void AutomaticProfileResetter::Activate() { |
| 435 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 424 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 436 DCHECK(state_ == STATE_INITIALIZED || state_ == STATE_DISABLED); | 425 DCHECK(state_ == STATE_INITIALIZED || state_ == STATE_DISABLED); |
| 437 | 426 |
| 438 if (state_ == STATE_INITIALIZED) { | 427 if (state_ == STATE_INITIALIZED) { |
| 439 if (!program_.empty()) { | 428 if (!program_.empty()) { |
| 440 // Some steps in the flow (e.g. loaded modules, file-based memento) are | 429 // Some steps in the flow (e.g. loaded modules, file-based memento) are |
| 441 // IO-intensive, so defer execution until some time later. | 430 // IO-intensive, so defer execution until some time later. |
| 442 task_runner_for_waiting_->PostDelayedTask( | 431 task_runner_for_waiting_->PostDelayedTask( |
| 443 FROM_HERE, | 432 FROM_HERE, |
| 444 base::Bind(&AutomaticProfileResetter::PrepareEvaluationFlow, | 433 base::Bind(&AutomaticProfileResetter::PrepareEvaluationFlow, |
| 445 weak_ptr_factory_.GetWeakPtr()), | 434 weak_ptr_factory_.GetWeakPtr()), |
| 446 base::TimeDelta::FromSeconds(kEvaluationFlowDelayInSeconds)); | 435 base::TimeDelta::FromSeconds(kEvaluationFlowDelayInSeconds)); |
| 447 } else { | 436 } else { |
| 448 // Terminate early if there is no program included (nor set by tests). | 437 // Terminate early if there is no program included (nor set by tests). |
| 449 state_ = STATE_DISABLED; | 438 state_ = STATE_DISABLED; |
| 450 } | 439 } |
| 451 } | 440 } |
| 452 } | 441 } |
| 453 | 442 |
| 443 void AutomaticProfileResetter::TriggerProfileReset(bool send_feedback) { |
| 444 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 445 DCHECK_EQ(state_, STATE_HAS_SHOWN_BUBBLE); |
| 446 |
| 447 state_ = STATE_PERFORMING_RESET; |
| 448 |
| 449 ReportPromptResult(PROMPT_ACTION_RESET); |
| 450 delegate_->TriggerProfileSettingsReset( |
| 451 send_feedback, |
| 452 base::Bind(&AutomaticProfileResetter::OnProfileSettingsResetCompleted, |
| 453 weak_ptr_factory_.GetWeakPtr())); |
| 454 } |
| 455 |
| 456 void AutomaticProfileResetter::SkipProfileReset() { |
| 457 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 458 DCHECK_EQ(state_, STATE_HAS_SHOWN_BUBBLE); |
| 459 |
| 460 ReportPromptResult(PROMPT_ACTION_NO_RESET); |
| 461 delegate_->DismissPrompt(); |
| 462 FinishResetPromptFlow(); |
| 463 } |
| 464 |
| 465 bool AutomaticProfileResetter::IsResetPromptFlowActive() const { |
| 466 return state_ == STATE_HAS_TRIGGERED_PROMPT || |
| 467 state_ == STATE_HAS_SHOWN_BUBBLE; |
| 468 } |
| 469 |
| 470 void AutomaticProfileResetter::NotifyDidShowResetBubble() { |
| 471 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 472 DCHECK_EQ(state_, STATE_HAS_TRIGGERED_PROMPT); |
| 473 |
| 474 state_ = STATE_HAS_SHOWN_BUBBLE; |
| 475 |
| 476 PersistMementos(); |
| 477 ReportPromptResult(PROMPT_SHOWN_BUBBLE); |
| 478 } |
| 479 |
| 480 void AutomaticProfileResetter::NotifyDidOpenWebUIResetDialog() { |
| 481 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 482 |
| 483 // This notification is invoked unconditionally by the WebUI, only care about |
| 484 // it when the prompt flow is currently active (and not yet resetting). |
| 485 if (state_ == STATE_HAS_TRIGGERED_PROMPT || |
| 486 state_ == STATE_HAS_SHOWN_BUBBLE) { |
| 487 has_already_dismissed_prompt_ = true; |
| 488 delegate_->DismissPrompt(); |
| 489 } |
| 490 } |
| 491 |
| 492 void AutomaticProfileResetter::NotifyDidCloseWebUIResetDialog( |
| 493 bool performed_reset) { |
| 494 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 495 |
| 496 // This notification is invoked unconditionally by the WebUI, only care about |
| 497 // it when the prompt flow is currently active (and not yet resetting). |
| 498 if (state_ == STATE_HAS_TRIGGERED_PROMPT || |
| 499 state_ == STATE_HAS_SHOWN_BUBBLE) { |
| 500 if (!has_already_dismissed_prompt_) |
| 501 delegate_->DismissPrompt(); |
| 502 if (state_ == STATE_HAS_TRIGGERED_PROMPT) { |
| 503 PersistMementos(); |
| 504 ReportPromptResult(performed_reset ? |
| 505 PROMPT_NOT_SHOWN_BUBBLE_BUT_HAD_WEBUI_RESET : |
| 506 PROMPT_NOT_SHOWN_BUBBLE_BUT_HAD_WEBUI_NO_RESET); |
| 507 } else { // if (state_ == STATE_HAS_SHOWN_PROMPT) |
| 508 ReportPromptResult(performed_reset ? |
| 509 PROMPT_FOLLOWED_BY_WEBUI_RESET : |
| 510 PROMPT_FOLLOWED_BY_WEBUI_NO_RESET); |
| 511 } |
| 512 FinishResetPromptFlow(); |
| 513 } |
| 514 } |
| 515 |
| 454 void AutomaticProfileResetter::SetProgramForTesting( | 516 void AutomaticProfileResetter::SetProgramForTesting( |
| 455 const std::string& program) { | 517 const std::string& program) { |
| 456 program_ = program; | 518 program_ = program; |
| 457 } | 519 } |
| 458 | 520 |
| 459 void AutomaticProfileResetter::SetHashSeedForTesting( | 521 void AutomaticProfileResetter::SetHashSeedForTesting( |
| 460 const std::string& hash_key) { | 522 const std::string& hash_key) { |
| 461 hash_seed_ = hash_key; | 523 hash_seed_ = hash_key; |
| 462 } | 524 } |
| 463 | 525 |
| 464 void AutomaticProfileResetter::SetDelegateForTesting( | 526 void AutomaticProfileResetter::SetDelegateForTesting( |
| 465 scoped_ptr<AutomaticProfileResetterDelegate> delegate) { | 527 scoped_ptr<AutomaticProfileResetterDelegate> delegate) { |
| 466 delegate_ = delegate.Pass(); | 528 delegate_ = delegate.Pass(); |
| 467 } | 529 } |
| 468 | 530 |
| 469 void AutomaticProfileResetter::SetTaskRunnerForWaitingForTesting( | 531 void AutomaticProfileResetter::SetTaskRunnerForWaitingForTesting( |
| 470 const scoped_refptr<base::TaskRunner>& task_runner) { | 532 const scoped_refptr<base::TaskRunner>& task_runner) { |
| 471 task_runner_for_waiting_ = task_runner; | 533 task_runner_for_waiting_ = task_runner; |
| 472 } | 534 } |
| 473 | 535 |
| 536 void AutomaticProfileResetter::Shutdown() { |
| 537 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 538 |
| 539 // We better not do anything substantial at this point. The metrics service |
| 540 // has already been shut down; and local state has already been commited to |
| 541 // file (in the regular fashion) for the last time. |
| 542 |
| 543 state_ = STATE_DISABLED; |
| 544 |
| 545 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 546 delegate_.reset(); |
| 547 } |
| 548 |
| 474 void AutomaticProfileResetter::PrepareEvaluationFlow() { | 549 void AutomaticProfileResetter::PrepareEvaluationFlow() { |
| 475 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 550 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 476 DCHECK_EQ(state_, STATE_INITIALIZED); | 551 DCHECK_EQ(state_, STATE_INITIALIZED); |
| 477 | 552 |
| 478 state_ = STATE_WAITING_ON_DEPENDENCIES; | 553 state_ = STATE_WAITING_ON_DEPENDENCIES; |
| 479 | 554 |
| 480 delegate_->RequestCallbackWhenTemplateURLServiceIsLoaded( | 555 delegate_->RequestCallbackWhenTemplateURLServiceIsLoaded( |
| 481 base::Bind(&AutomaticProfileResetter::OnTemplateURLServiceIsLoaded, | 556 base::Bind(&AutomaticProfileResetter::OnTemplateURLServiceIsLoaded, |
| 482 weak_ptr_factory_.GetWeakPtr())); | 557 weak_ptr_factory_.GetWeakPtr())); |
| 483 delegate_->RequestCallbackWhenLoadedModulesAreEnumerated( | 558 delegate_->RequestCallbackWhenLoadedModulesAreEnumerated( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 510 weak_ptr_factory_.GetWeakPtr())); | 585 weak_ptr_factory_.GetWeakPtr())); |
| 511 } | 586 } |
| 512 } | 587 } |
| 513 | 588 |
| 514 void AutomaticProfileResetter::BeginEvaluationFlow() { | 589 void AutomaticProfileResetter::BeginEvaluationFlow() { |
| 515 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 590 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 516 DCHECK_EQ(state_, STATE_READY); | 591 DCHECK_EQ(state_, STATE_READY); |
| 517 DCHECK(!program_.empty()); | 592 DCHECK(!program_.empty()); |
| 518 DCHECK(!input_builder_); | 593 DCHECK(!input_builder_); |
| 519 | 594 |
| 520 state_ = STATE_WORKING; | 595 state_ = STATE_EVALUATING_CONDITIONS; |
| 521 | 596 |
| 522 input_builder_.reset(new InputBuilder(profile_, delegate_.get())); | 597 input_builder_.reset(new InputBuilder(profile_, delegate_.get())); |
| 523 input_builder_->BuildEvaluatorProgramInput( | 598 input_builder_->BuildEvaluatorProgramInput( |
| 524 base::Bind(&AutomaticProfileResetter::ContinueWithEvaluationFlow, | 599 base::Bind(&AutomaticProfileResetter::ContinueWithEvaluationFlow, |
| 525 weak_ptr_factory_.GetWeakPtr())); | 600 weak_ptr_factory_.GetWeakPtr())); |
| 526 } | 601 } |
| 527 | 602 |
| 528 void AutomaticProfileResetter::ContinueWithEvaluationFlow( | 603 void AutomaticProfileResetter::ContinueWithEvaluationFlow( |
| 529 scoped_ptr<base::DictionaryValue> program_input) { | 604 scoped_ptr<base::DictionaryValue> program_input) { |
| 530 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 605 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 531 DCHECK_EQ(state_, STATE_WORKING); | 606 DCHECK_EQ(state_, STATE_EVALUATING_CONDITIONS); |
| 532 | 607 |
| 533 input_builder_.reset(); | 608 input_builder_.reset(); |
| 534 | 609 |
| 535 base::SequencedWorkerPool* blocking_pool = | 610 base::SequencedWorkerPool* blocking_pool = |
| 536 content::BrowserThread::GetBlockingPool(); | 611 content::BrowserThread::GetBlockingPool(); |
| 537 scoped_refptr<base::TaskRunner> task_runner = | 612 scoped_refptr<base::TaskRunner> task_runner = |
| 538 blocking_pool->GetTaskRunnerWithShutdownBehavior( | 613 blocking_pool->GetTaskRunnerWithShutdownBehavior( |
| 539 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 614 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 540 | 615 |
| 541 base::PostTaskAndReplyWithResult( | 616 base::PostTaskAndReplyWithResult( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 } | 654 } |
| 580 for (size_t i = 0; i < arraysize(kSatisfiedCriteriaMaskKeys); ++i) { | 655 for (size_t i = 0; i < arraysize(kSatisfiedCriteriaMaskKeys); ++i) { |
| 581 bool flag = false; | 656 bool flag = false; |
| 582 if (interpreter.GetOutputBoolean(kSatisfiedCriteriaMaskKeys[i], &flag) && | 657 if (interpreter.GetOutputBoolean(kSatisfiedCriteriaMaskKeys[i], &flag) && |
| 583 flag) | 658 flag) |
| 584 results->satisfied_criteria_mask |= (1 << i); | 659 results->satisfied_criteria_mask |= (1 << i); |
| 585 } | 660 } |
| 586 return results.Pass(); | 661 return results.Pass(); |
| 587 } | 662 } |
| 588 | 663 |
| 589 void AutomaticProfileResetter::FinishEvaluationFlow( | |
| 590 scoped_ptr<EvaluationResults> results) { | |
| 591 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 592 DCHECK_EQ(state_, STATE_WORKING); | |
| 593 | |
| 594 ReportStatistics(results->satisfied_criteria_mask, | |
| 595 results->combined_status_mask); | |
| 596 | |
| 597 if (results->satisfied_criteria_mask != 0 && !results->had_prompted_already) { | |
| 598 PreferenceHostedPromptMemento memento_in_prefs(profile_); | |
| 599 LocalStateHostedPromptMemento memento_in_local_state(profile_); | |
| 600 FileHostedPromptMemento memento_in_file(profile_); | |
| 601 | |
| 602 memento_in_prefs.StoreValue(results->memento_value_in_prefs); | |
| 603 memento_in_local_state.StoreValue(results->memento_value_in_local_state); | |
| 604 memento_in_file.StoreValue(results->memento_value_in_file); | |
| 605 | |
| 606 if (ShouldPerformLiveRun()) { | |
| 607 delegate_->ShowPrompt(); | |
| 608 } else { | |
| 609 UMA_HISTOGRAM_ENUMERATION("AutomaticProfileReset.PromptResult", | |
| 610 PROMPT_NOT_SHOWN, | |
| 611 PROMPT_RESULT_MAX); | |
| 612 } | |
| 613 } | |
| 614 | |
| 615 state_ = STATE_DONE; | |
| 616 } | |
| 617 | |
| 618 void AutomaticProfileResetter::ReportStatistics(uint32 satisfied_criteria_mask, | 664 void AutomaticProfileResetter::ReportStatistics(uint32 satisfied_criteria_mask, |
| 619 uint32 combined_status_mask) { | 665 uint32 combined_status_mask) { |
| 620 UMA_HISTOGRAM_ENUMERATION("AutomaticProfileReset.SatisfiedCriteriaMask", | 666 UMA_HISTOGRAM_ENUMERATION("AutomaticProfileReset.SatisfiedCriteriaMask", |
| 621 satisfied_criteria_mask, | 667 satisfied_criteria_mask, |
| 622 kSatisfiedCriteriaMaskMaximumValue); | 668 kSatisfiedCriteriaMaskMaximumValue); |
| 623 UMA_HISTOGRAM_ENUMERATION("AutomaticProfileReset.CombinedStatusMask", | 669 UMA_HISTOGRAM_ENUMERATION("AutomaticProfileReset.CombinedStatusMask", |
| 624 combined_status_mask, | 670 combined_status_mask, |
| 625 kCombinedStatusMaskMaximumValue); | 671 kCombinedStatusMaskMaximumValue); |
| 626 } | 672 } |
| 627 | 673 |
| 628 void AutomaticProfileResetter::Shutdown() { | 674 void AutomaticProfileResetter::FinishEvaluationFlow( |
| 675 scoped_ptr<EvaluationResults> results) { |
| 629 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 676 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 677 DCHECK_EQ(state_, STATE_EVALUATING_CONDITIONS); |
| 630 | 678 |
| 631 state_ = STATE_DISABLED; | 679 ReportStatistics(results->satisfied_criteria_mask, |
| 632 delegate_.reset(); | 680 results->combined_status_mask); |
| 633 weak_ptr_factory_.InvalidateWeakPtrs(); | 681 |
| 682 if (results->satisfied_criteria_mask != 0 && !results->had_prompted_already) { |
| 683 evaluation_results_ = results.Pass(); |
| 684 BeginResetPromptFlow(); |
| 685 } else { |
| 686 state_ = STATE_DONE; |
| 687 } |
| 634 } | 688 } |
| 689 |
| 690 void AutomaticProfileResetter::BeginResetPromptFlow() { |
| 691 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 692 DCHECK_EQ(state_, STATE_EVALUATING_CONDITIONS); |
| 693 |
| 694 state_ = STATE_HAS_TRIGGERED_PROMPT; |
| 695 |
| 696 if (ShouldPerformLiveRun() && delegate_->TriggerPrompt()) { |
| 697 // Start fetching the brandcoded default settings speculatively in the |
| 698 // background, so as to reduce waiting time if the user chooses to go |
| 699 // through with the reset. |
| 700 delegate_->FetchBrandcodedDefaultSettingsIfNeeded(); |
| 701 } else { |
| 702 PersistMementos(); |
| 703 ReportPromptResult(PROMPT_NOT_TRIGGERED); |
| 704 FinishResetPromptFlow(); |
| 705 } |
| 706 } |
| 707 |
| 708 void AutomaticProfileResetter::OnProfileSettingsResetCompleted() { |
| 709 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 710 DCHECK_EQ(state_, STATE_PERFORMING_RESET); |
| 711 |
| 712 delegate_->DismissPrompt(); |
| 713 FinishResetPromptFlow(); |
| 714 } |
| 715 |
| 716 void AutomaticProfileResetter::ReportPromptResult(PromptResult result) { |
| 717 UMA_HISTOGRAM_ENUMERATION( |
| 718 "AutomaticProfileReset.PromptResult", result, PROMPT_RESULT_MAX); |
| 719 } |
| 720 |
| 721 void AutomaticProfileResetter::PersistMementos() { |
| 722 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 723 DCHECK(state_ == STATE_HAS_TRIGGERED_PROMPT || |
| 724 state_ == STATE_HAS_SHOWN_BUBBLE); |
| 725 DCHECK(evaluation_results_); |
| 726 |
| 727 PreferenceHostedPromptMemento memento_in_prefs(profile_); |
| 728 LocalStateHostedPromptMemento memento_in_local_state(profile_); |
| 729 FileHostedPromptMemento memento_in_file(profile_); |
| 730 |
| 731 memento_in_prefs.StoreValue(evaluation_results_->memento_value_in_prefs); |
| 732 memento_in_local_state.StoreValue( |
| 733 evaluation_results_->memento_value_in_local_state); |
| 734 memento_in_file.StoreValue(evaluation_results_->memento_value_in_file); |
| 735 |
| 736 evaluation_results_.reset(); |
| 737 } |
| 738 |
| 739 void AutomaticProfileResetter::FinishResetPromptFlow() { |
| 740 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 741 DCHECK(state_ == STATE_HAS_TRIGGERED_PROMPT || |
| 742 state_ == STATE_HAS_SHOWN_BUBBLE || |
| 743 state_ == STATE_PERFORMING_RESET); |
| 744 DCHECK(!evaluation_results_); |
| 745 |
| 746 state_ = STATE_DONE; |
| 747 } |
| OLD | NEW |