Commit c935328d authored by Jan Krcal's avatar Jan Krcal Committed by Commit Bot

[AF Wallet] Make AutofillWalletMetadataSizeChecker not timeout, take 2

The pervious CL 1563930 disregarded the fact the the initial Wait()
calls IsExitConditionSatisfied() directly without exercising
CheckExitCondition().

This Cl fixes that and implements the logic in
IsExitConditionSatisfied().

Bug: 921386
Change-Id: I8974c13cdba54a0579e41c865a44ed67efcb9ca7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1563995
Commit-Queue: Jan Krcal <jkrcal@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Auto-Submit: Jan Krcal <jkrcal@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649843}
parent ded95422
...@@ -543,6 +543,40 @@ AutofillWalletMetadataSizeChecker::~AutofillWalletMetadataSizeChecker() { ...@@ -543,6 +543,40 @@ AutofillWalletMetadataSizeChecker::~AutofillWalletMetadataSizeChecker() {
} }
bool AutofillWalletMetadataSizeChecker::IsExitConditionSatisfied() { bool AutofillWalletMetadataSizeChecker::IsExitConditionSatisfied() {
// Make sure we do not nest IsExitConditionSatisfiedImpl() (as it can happen
// that OnPersonalDataChanged() gets notified while we're inside
// IsExitConditionSatisfiedImpl(), waiting for the DB task that loads metadata
// to finish).
switch (state_) {
case IDLE:
do {
state_ = CHECKING;
if (IsExitConditionSatisfiedImpl()) {
return true;
}
} while (state_ == SHOULD_RECHECK);
state_ = IDLE;
return false;
case CHECKING:
// Make sure that each IsExitConditionSatisfied() call is followed by a
// IsExitConditionSatisfiedImpl() call so that we do not miss any updates
// to the DB.
state_ = SHOULD_RECHECK;
return false;
case SHOULD_RECHECK:
return false;
}
}
std::string AutofillWalletMetadataSizeChecker::GetDebugMessage() const {
return "Waiting for matching autofill wallet metadata sizes";
}
void AutofillWalletMetadataSizeChecker::OnPersonalDataChanged() {
CheckExitCondition();
}
bool AutofillWalletMetadataSizeChecker::IsExitConditionSatisfiedImpl() {
// There could be trailing metadata left on one of the clients. Check that // There could be trailing metadata left on one of the clients. Check that
// metadata.size() is the same on both clients. // metadata.size() is the same on both clients.
std::map<std::string, AutofillMetadata> addresses_metadata_a = std::map<std::string, AutofillMetadata> addresses_metadata_a =
...@@ -568,39 +602,6 @@ bool AutofillWalletMetadataSizeChecker::IsExitConditionSatisfied() { ...@@ -568,39 +602,6 @@ bool AutofillWalletMetadataSizeChecker::IsExitConditionSatisfied() {
return true; return true;
} }
std::string AutofillWalletMetadataSizeChecker::GetDebugMessage() const {
return "Waiting for matching autofill wallet metadata sizes";
}
void AutofillWalletMetadataSizeChecker::CheckExitCondition() {
// Make sure we do not nest IsExitConditionSatisfied() (as it can happen that
// OnPersonalDataChanged() gets notified while we're inside
// IsExitConditionSatisfied(), waiting for the DB task that loads metadata to
// finish).
switch (state_) {
case IDLE:
do {
state_ = CHECKING;
StatusChangeChecker::CheckExitCondition();
} while (state_ == SHOULD_RECHECK);
state_ = IDLE;
return;
case CHECKING:
// Make sure that each
// AutofillWalletMetadataSizeChecker::CheckExitCondition() call is
// followed by a StatusChangeChecker::CheckExitCondition() call so that we
// do not miss any updates to the DB.
state_ = SHOULD_RECHECK;
return;
case SHOULD_RECHECK:
return;
}
}
void AutofillWalletMetadataSizeChecker::OnPersonalDataChanged() {
CheckExitCondition();
}
UssWalletSwitchToggler::UssWalletSwitchToggler() {} UssWalletSwitchToggler::UssWalletSwitchToggler() {}
void UssWalletSwitchToggler::InitWithDefaultFeatures() { void UssWalletSwitchToggler::InitWithDefaultFeatures() {
......
...@@ -145,7 +145,6 @@ class AutofillWalletMetadataSizeChecker ...@@ -145,7 +145,6 @@ class AutofillWalletMetadataSizeChecker
// StatusChangeChecker implementation. // StatusChangeChecker implementation.
bool IsExitConditionSatisfied() override; bool IsExitConditionSatisfied() override;
void CheckExitCondition() override;
std::string GetDebugMessage() const override; std::string GetDebugMessage() const override;
// autofill::PersonalDataManager implementation. // autofill::PersonalDataManager implementation.
...@@ -154,6 +153,9 @@ class AutofillWalletMetadataSizeChecker ...@@ -154,6 +153,9 @@ class AutofillWalletMetadataSizeChecker
private: private:
// A state machine that makes sure we do not nest checking exit conditions. // A state machine that makes sure we do not nest checking exit conditions.
enum State { IDLE, CHECKING, SHOULD_RECHECK }; enum State { IDLE, CHECKING, SHOULD_RECHECK };
bool IsExitConditionSatisfiedImpl();
State state_ = IDLE; State state_ = IDLE;
const int profile_a_; const int profile_a_;
const int profile_b_; const int profile_b_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment