Skip to content
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

Fixed redundant creation of Default profile #13929

Closed
wants to merge 3 commits into from
Closed

Conversation

spylogsster
Copy link
Contributor

@spylogsster spylogsster commented Jun 23, 2022

Resolves brave/brave-browser#4599

Fixed redundant creation of default profile. GetPrimaryUserProfile returns Default browser profile, but not the profile which is currently used by user. If user has deleted Default profile it will be re-created in this case. Better to use LastUsedProfile which returns current profile for the user.

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

  • Start a clean profile
  • Click on people icon and click on Manage people
  • Add a new person in Manage people window
  • Click on Person 2 window and click on people icon, lists Person 1 in the list
  • In manage people window, click on 3 dots of Person 1 and delete it
  • Open Person 2 window and click on people icon, still lists Person 1 there. Clicking that will create a new Person 1 window

@@ -120,7 +120,7 @@ BraveStatsUpdater::BraveStatsUpdater(PrefService* pref_service)
BraveStatsUpdater::~BraveStatsUpdater() {}

void BraveStatsUpdater::OnProfileAdded(Profile* profile) {
if (profile == ProfileManager::GetPrimaryUserProfile()) {
Copy link
Member

@simonhong simonhong Jun 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, there is a comment that this method should not be used in desktop.

  // WARNING: do not use this function on Desktop platforms (Windows, Mac,
  // Linux). See https://crbug.com/1264436 for more info.
  // TODO(https://crbug.com/1264436): restrict this function to Android and
  // ChromeOS.

Is there any possibility to introduce regressions from this change? cc @bridiver

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow- nice find, @spylogsster @simonhong. So we were using a bad method this whole time?

I think the re-creation of the deleted folder was the regression 😄

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fundamental problem here is that we're assuming a single profile and there's really no good way to do this. We're comparing it against the P3A data to see if we can drop this entirely, but if we want to collect a few more months of data first I'm hesitant to make any changes that will introduce another variable into the equation

Copy link
Collaborator

@bridiver bridiver Jun 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// WARNING: if the profile does not exist, this function creates it
  // synchronously, causing blocking file I/O. Use GetLastUsedProfileIfLoaded()
  // to avoid creating the profile synchronously.
  static Profile* GetLastUsedProfile();

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false alarm, it does not recreate the default profile

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use GetLastUsedProfileIfLoaded

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will recreate the default profile if all profiles have been deleted so probably GetLastUsedProfileIfLoaded is the way to go because it should not have any side effects

Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM! ++

@DJAndries how do things look for you? This would be a great fix to land if everything is OK

@DJAndries
Copy link
Collaborator

Changes LGTM! ++

@DJAndries how do things look for you? This would be a great fix to land if everything is OK

looks good! will do a smoke test today

Copy link
Collaborator

@DJAndries DJAndries left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stats updater works OK with the suggested change above.

Also, has anyone seen this stack trace when exiting the browser?

Received signal 11 SEGV_MAPERR 000000000008
#0 0x557394fa16c9 base::debug::CollectStackTrace()
#1 0x557394ebaa93 base::debug::StackTrace::StackTrace()
#2 0x557394fa1181 base::debug::(anonymous namespace)::StackDumpSignalHandler()
#3 0x7f69cddf88e0 (/usr/lib/libc.so.6+0x3e8df)
#4 0x55738fba85e9 base::ObserverList<>::RemoveObserver()
#5 0x557394bfa064 (anonymous namespace)::AdBlockSubscriptionDownloadManagerGetterImpl::OnProfileManagerDestroying()
#6 0x557394b74ad7 ProfileManager::~ProfileManager()
#7 0x557392a77a22 BraveProfileManager::~BraveProfileManager()
#8 0x557392a770ae BraveProfileManager::~BraveProfileManager()
#9 0x5573949e3c68 BrowserProcessImpl::StartTearDown()
#10 0x5573949e272a ChromeBrowserMainParts::PostMainMessageLoopRun()
#11 0x557391680ac1 content::BrowserMainLoop::ShutdownThreadsAndCleanUp()
#12 0x55739168299a content::BrowserMainRunnerImpl::Shutdown()
#13 0x55739167e307 content::BrowserMain()
#14 0x55739496d7f5 content::RunBrowserProcessMain()
#15 0x55739496f184 content::ContentMainRunnerImpl::RunBrowser()
#16 0x55739496ec00 content::ContentMainRunnerImpl::Run()
#17 0x55739496c34c content::RunContentProcess()
#18 0x55739496c43e content::ContentMain()
#19 0x55738f9b4233 ChromeMain
#20 0x7f69cdde3290 (/usr/lib/libc.so.6+0x2928f)
#21 0x7f69cdde334a __libc_start_main
#22 0x55738f9b402a _start
  r8: 000030e4005e4120  r9: 0000000000000000 r10: 00007ffd314ed080 r11: 00000000008328cc
 r12: 00007ffd3147e730 r13: 00007ffd3147e750 r14: 0000000000000008 r15: 000030e400b19860
  di: 0000000000000008  si: 000030e400b19860  bp: 00007ffd3147e6a0  bx: 000030e400b19860
  dx: 0000000000000000  ax: 0000000000000000  cx: 0000000000000001  sp: 00007ffd3147e660
  ip: 000055738fba85e9 efl: 0000000000010206 cgf: 002b000000000033 erf: 0000000000000004
 trp: 000000000000000e msk: 0000000000000000 cr2: 0000000000000008
[end of stack trace]

Now, if I open the wallet, and close the browser in less than 30 seconds, the updated last usage time stored in the profile prefs is not persisted.

@@ -120,7 +120,7 @@ BraveStatsUpdater::BraveStatsUpdater(PrefService* pref_service)
BraveStatsUpdater::~BraveStatsUpdater() {}

void BraveStatsUpdater::OnProfileAdded(Profile* profile) {
if (profile == ProfileManager::GetPrimaryUserProfile()) {
if (profile == ProfileManager::GetLastUsedProfileIfLoaded()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this instance to GetLastUsedProfile instead? GetLastUsedProfileIfLoaded seems to always return a null pointer when called from OnProfileAdded.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bridiver wdyt?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's still going to create side effects. Can we compare profile->GetPath() == GetLastUsedProfileDir()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just smoke tested, there's a bug with this approach. Steps to reproduce (assumes you have two profiles, and a log within the if block):

  1. Open browser, open first profile, close
  2. Open again, open first profile, see the log, close
  3. Open again, open second profile, the log is missing, close
  4. Open again, open second profile, the log now exists

This doesn't happen with GetLastUsedProfile.

@@ -214,7 +214,7 @@ BraveReferralsService::BraveReferralsService(PrefService* pref_service,
BraveReferralsService::~BraveReferralsService() {}

void BraveReferralsService::OnProfileAdded(Profile* profile) {
if (profile == ProfileManager::GetPrimaryUserProfile()) {
if (profile == ProfileManager::GetLastUsedProfileIfLoaded()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same may apply here.

@DJAndries
Copy link
Collaborator

DJAndries commented Jun 29, 2022

Also, has anyone seen this stack trace when exiting the browser?

The crash goes away if I remove OnProfileManagerDestroying from AdBlockSubscriptionDownloadManagerGetter. This does not occur on master. Interesting side effect.

@spylogsster spylogsster force-pushed the brave-4599 branch 6 times, most recently from 2d27d6c to 2ef3f5a Compare July 4, 2022 17:44
@@ -102,10 +104,11 @@ class AdBlockSubscriptionDownloadManagerGetterImpl
}

void OnProfileManagerDestroying() override {
g_browser_process->profile_manager()->RemoveObserver(this);
profile_manager_->RemoveObserver(this);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is called from ProfileManager destructor when g_browser_process->profile_manager() is null already.
cc @antonok-edm

@spylogsster
Copy link
Contributor Author

Also, has anyone seen this stack trace when exiting the browser?

The crash goes away if I remove OnProfileManagerDestroying from AdBlockSubscriptionDownloadManagerGetter. This does not occur on master. Interesting side effect.

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Person 1 profile keeps coming back after being deleted - Cannot delete the 'Default' user profile
5 participants