-
Notifications
You must be signed in to change notification settings - Fork 868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sync reset if browser was closed before the chain was fully created #3730
Conversation
CI marked this PR as UNSTABLE because |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Close browser is not the only way to interrupt sync chain setup process, closing sync page can do that. So we might also want to do the check when SyncUI is closed.
That needs ~SyncUIDOMHandler
to inform BraveProfileSyncServiceImpl
by OnSyncPageClosed
and then we can do the check there. We can even only check incomplete sync chain setup there because when browser shutdown, the destructor will also be triggered.
It is also better to do this in shutdown rather than startup to prevent unnecessary loading sync extension.
// We want to reset the chain because it was not fully created | ||
// We cannot make it here directly, because some sync classes may not be | ||
// constructed yet | ||
reseting_ = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this to trigger ResetSyncInternal()
by ForceCompleteReset()
?
If so, then we don't need to clear pref here https://github.com/brave/brave-core/pull/3730/files#diff-ab344835b09fb6ac1c601af787b116bbR184
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this to trigger ResetSyncInternal() by ForceCompleteReset()?
yes
but if we don't reset devices list, UI page will never trigger BraveProfileSyncServiceImpl::OnSetupSyncHaveCode because device name is not empty https://github.com/brave/brave-core/blob/master/components/brave_sync/ui/components/modals/enterSyncCode.tsx#L92
so instead of clearing all prefs it would be enough co clean only the current device name, but I decided to clean all non-actual data
Yes, also we can have this situation when browser process is killed or after power failure. So I don't want remove this check at startup. Thanks for pointing to more elegant way in |
79757a8
to
9450b81
Compare
I had made reset of sync prefs at WebUI pages, if they passed sync words, and then are closed, they don't prevent the chain from creation. Another thing - we can have more than one opened STR(1) to see the tab of brave://sync can be closed while chain creation.
STR(2) to show an interesting case
So with STR(2) the chain will be created. But we cannot distinguish such case and in the worst case the state of sync will be broken. So I made reset of sync prefs at |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9450b81
to
836ecff
Compare
Ah, you meant that.
|
836ecff
to
07d9e40
Compare
…when browser starts
…led but the chain is not fully created
…when the chain is not fully created
9324f5b
to
4bed52e
Compare
Updated the PR to keep brave sync prefs in memory until the sync chain would have two or more devices. |
4bed52e
to
99a262b
Compare
// We are using latest device record until chain is not fully created | ||
base::Time latest_device_record_time_; | ||
|
||
NamedChangeCallback obs_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only allows one observer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, as it is used only by one method in BraveProfileSyncServiceImpl, I decided to keep just one.
base::Time latest_device_record_time_; | ||
|
||
NamedChangeCallback obs_; | ||
void FireCallback(const std::string& name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be NotifyObserver
or NotifyObservers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, thanks
|
||
namespace prefs { | ||
|
||
class PrefsMemStore : public PrefsBase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need PrefsBase
? PrefsMemStore
can be a subclass of Prefs
and you can still do the switch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it was not required, but since PrefsMemStore
would override all methods of Prefs
, I did as it is there now.
std::make_unique<prefs::Prefs>(sync_client_->GetPrefService()); | ||
brave_sync_prefs_ = brave_sync_prefs_disk_store_.get(); | ||
|
||
if (IsSyncSetupIncomplete()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
having IsBraveSyncInitialized
, IsBraveSyncConfigured
and IsSyncSetupIncomplete
is just way too confusing. We need to simplify the possible states and add comments to explain what they are. Also we shouldn't mix the "positive" and "negative" forms of checks because that's also confusing to read. IsSyncSetupComplete
is the "positive" form vs IsSyncSetupIncomplete
@@ -232,6 +253,17 @@ BraveProfileSyncServiceImpl::~BraveProfileSyncServiceImpl() { | |||
network_connection_tracker_->RemoveNetworkConnectionObserver(this); | |||
} | |||
|
|||
bool BraveProfileSyncServiceImpl::IsSyncSetupIncomplete() const { | |||
auto devices = brave_sync_prefs_->GetSyncDevices(); | |||
if (devices->size() < 2 && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sync setup is not complete is more than one device?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, sync setup is not complete when have less than 2 devices
@@ -320,6 +352,7 @@ void BraveProfileSyncServiceImpl::OnResetSync() { | |||
// We have to send delete record and wait for library deleted response then | |||
// we can reset it by ResetSyncInternal() | |||
const std::string device_id = brave_sync_prefs_->GetThisDeviceId(); | |||
DCHECK(!device_id.empty()); | |||
OnDeleteDevice(device_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we care about deleting devices if we're resetting sync?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To summarize the discussion on Slack,
- We should only have states like
enabled/initializing/initialized/ready
- Getting rids of
brave_sync::Prefs
class because it's mostly just calling get/set on the pref service anyway - Only state that has transient data is
initializing
(seed and device id) - Getting rids of all two devices check, ex. waiting for 2nd device when setup, reset sync chain when it comes down to 1 device, ... etc. Let UI flow handle the "at two devices on sync chain" requirement
PR requires a lot of changes, so the reviewed points will be removed or redone. |
Closing this, as prefs are redone in #3988 according to #3730 (review) |
brave/brave-browser#6504
Submitter Checklist:
npm run lint
)git rebase master
(if needed).git rebase -i
to squash commits (if needed).Test Plan:
From brave/brave-browser#6504
Reviewer Checklist:
After-merge Checklist:
changes has landed on.