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 crash with search provider extension #8539

Closed
wants to merge 13 commits into from

Conversation

simonhong
Copy link
Member

@simonhong simonhong commented Apr 14, 2021

fix: brave/brave-browser#15224
fix: brave/brave-browser#10601
fix: brave/brave-browser#14218

Crash comes from absense of exension search provider in private profile's TemplateURLService because
we are using different TemplateURLService for private profile. but many places in upstream doesn't know about this.

Changed to use same TemplateURLService for normal & private profile.

Previously we created different TemplateURLService instance for normal and private profile because
we want to use different search provider on both. However, this approach added technical debt over time
because it's different with upstream chromium. chromium uses same instance for both.
And it turns out that search provider extension doesnt work well with current approach.
So, decided to use same architecture - using same TemplateURLService.
Instead of using one instance, active search provider is set for profile of current active windows.
With this, we can delete some patches and overrides for using different TemplateURLService.

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
  • 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:

npm run test brave_browser_tests -- --filter=SearchEngineProviderServiceTest*

See above issue's STR.
and below issue's STR because codes for fixing below issues is cleaned up also.
brave/brave-browser#1758
brave/brave-browser#1037

Check normal window/private/private(tor) 's search engine options works properly.

@simonhong simonhong force-pushed the fix_crash_with_search_provider_extension branch from 2c199a0 to 6d6ae20 Compare April 15, 2021 05:25
@simonhong simonhong changed the title WIP: Fixed crash with search provider extension Fixed crash with search provider extension Apr 15, 2021
@simonhong simonhong marked this pull request as ready for review April 15, 2021 14:21
@simonhong simonhong requested a review from a team as a code owner April 15, 2021 14:21
@simonhong simonhong force-pushed the fix_crash_with_search_provider_extension branch 3 times, most recently from 3de7c8d to 66d4c62 Compare April 16, 2021 04:11
if (ignore_template_url_service_changing_)
return;

base::AutoReset<bool> reset(&ignore_template_url_service_changing_, true);
Copy link
Member

@bsclifton bsclifton Apr 16, 2021

Choose a reason for hiding this comment

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

AutoReset<> is a super nice base library offering 🙂 Had never worked with this before, just looked into it now! Really nice to temporarily change the value and then it resets after going out of scope

@simonhong simonhong force-pushed the fix_crash_with_search_provider_extension branch from 66d4c62 to 6691c44 Compare April 17, 2021 01:20
@simonhong simonhong requested review from darkdh and bsclifton April 17, 2021 01:22
@simonhong simonhong force-pushed the fix_crash_with_search_provider_extension branch 3 times, most recently from c0dfc49 to a1519b6 Compare April 19, 2021 01:30
@simonhong simonhong requested a review from bridiver as a code owner April 19, 2021 01:30
@simonhong simonhong force-pushed the fix_crash_with_search_provider_extension branch 2 times, most recently from 377ae23 to 0db630e Compare April 20, 2021 06:42
@simonhong
Copy link
Member Author

Kindly ping :)

// This doesn't handle guest window's provider because guest window only uses
// its own private profile. Using SearchEngineProviderService for managing guest
// window's DDG toggle button config is sufficient.
class ActiveWindowSearchProviderManager : public views::WidgetObserver {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not quire sure this is a way to go. The service is queried for GetDefaultSearchProvider() across the code and the callers can get different results depending on a visible widget, isn't it strange?

Copy link
Member Author

Choose a reason for hiding this comment

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

With this approach, we can use one service for normal/private like chromium.
Many places & services with single instance service (use one service instance for both profile) refers TemplateURLService. This makes conflict with our needs(we need different TemplateURLService instance).
Search provider extension crash also comes from using different TemplateURLService instance.
Of course, I also think this approach is not the best but this works well and we can archieve our needs w/o patching/overrding anymore.

Copy link
Member Author

@simonhong simonhong Apr 21, 2021

Choose a reason for hiding this comment

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

IMO, we should introduce new complex patches/overriding to fix crash issues(brave/brave-browser#15224, brave/brave-browser#14218) w/o this approach.
and I think this approach is straightforward and can be maintained easily. WDYT? @bridiver

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I agree with @iefremov here. In addition to what @iefremov said, changing the result based on the active window could easily return the wrong result if there are any async calls to it. It seems very risky to me based on that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

in fact I found instances where GetDefaultSearchProvider is called async which means the active window could change from what it was when the action was initiated

Copy link
Member Author

Choose a reason for hiding this comment

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

will close this PR and I'll try to resolve with another approach - #8626

return popup_view_.get();
}

+ BRAVE_OMNIBOX_VIEW_VIEWS_H
Copy link
Collaborator

Choose a reason for hiding this comment

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

#define OnOmniboxPaste NotUsed() {}; friend ... OnOmniboxPaste ?

Copy link
Member Author

Choose a reason for hiding this comment

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

@bridiver Right, we don't need to add new patch file for this :)
Fixed. thanks!

fix: brave/brave-browser#15224
fix: brave/brave-browser#10601
fix: brave/brave-browser#14218

Changed to use same TemplateURLService for normal & private profile.
As we use one TemplateURLService for normal/private profile and set proper provider for
current active window's profile, we always can get proper selection navigation url.
On linux, BraveBrowserFrame is not used. Changed
ActiveWindowSearchProviderManager owner to BrowserView.
and updated test cases.
Omnibox placeholder text includes current search provider info.
As we are using same TemplateURLService for normal/private window,
Inactive browser window's omnibox placeholder could show different search provider.
For example, when private window is active and DDG is on, other inactive window's
omnibox placeholder shows DDG's placeholder if it's current tab is NTP.
Of course, it's set properly when it's activated. but it could make user confusing.

To fix this, inactive windows omnibox place holder will not be updated. and when
activated anytime, omnibox can have proper placeholder text.
As we started to use private profile for tor window instead of guest window,
we don't need to handle kDefaultSearchProviderDataPrefName differently for tor.
When tor window is started, proper search provider is set regardless of
`kDefaultSearchProviderDataPrefName`.
If private window is activated first, cached normal search provider
is empty. In this case, we just use initial default search provider.
@simonhong simonhong force-pushed the fix_crash_with_search_provider_extension branch from 0db630e to ca8f294 Compare April 22, 2021 23:51
@simonhong simonhong requested a review from bridiver April 22, 2021 23:53
@simonhong simonhong closed this May 3, 2021
@simonhong simonhong deleted the fix_crash_with_search_provider_extension branch June 28, 2021 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants