-
Notifications
You must be signed in to change notification settings - Fork 903
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #529 from brave/private_search_engine_provider
Fix alternative search engine provider feature bugs
- Loading branch information
Showing
25 changed files
with
500 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/guest_window_search_engine_provider_controller.h" | ||
|
||
#include "base/auto_reset.h" | ||
#include "brave/browser/search_engine_provider_util.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "components/search_engines/template_url_service.h" | ||
|
||
GuestWindowSearchEngineProviderController:: | ||
GuestWindowSearchEngineProviderController(Profile* profile) | ||
: SearchEngineProviderControllerBase(profile) { | ||
DCHECK_EQ(profile->GetProfileType(), Profile::GUEST_PROFILE); | ||
|
||
// Monitor otr(off the record) profile's search engine changing to tracking | ||
// user's default search engine provider. | ||
// OTR profile's service is used for that. | ||
otr_template_url_service_->AddObserver(this); | ||
ConfigureSearchEngineProvider(); | ||
} | ||
|
||
GuestWindowSearchEngineProviderController:: | ||
~GuestWindowSearchEngineProviderController() { | ||
otr_template_url_service_->RemoveObserver(this); | ||
} | ||
|
||
void GuestWindowSearchEngineProviderController::OnTemplateURLServiceChanged() { | ||
if (ignore_template_url_service_changing_) | ||
return; | ||
|
||
// Prevent search engine changing from settings page for tor profile. | ||
// TODO(simonhong): Revisit when related ux is determined. | ||
if (otr_profile_->IsTorProfile()) { | ||
base::AutoReset<bool> reset(&ignore_template_url_service_changing_, true); | ||
ChangeToAlternativeSearchEngineProvider(); | ||
return; | ||
} | ||
|
||
|
||
// The purpose of below code is turn off alternative prefs | ||
// when user changes to different search engine provider from settings. | ||
// However, this callback is also called during the TemplateURLService | ||
// initialization phase. Because of this, guest view always starts with | ||
// this prefs off state when browser restarted(persisted during the runtime). | ||
// Currently I don't know how to determine who is caller of this callback. | ||
// TODO(simonhong): Revisit here when brave's related ux is determined. | ||
if (UseAlternativeSearchEngineProvider()) | ||
brave::ToggleUseAlternativeSearchEngineProvider(otr_profile_); | ||
} | ||
|
||
void | ||
GuestWindowSearchEngineProviderController::ConfigureSearchEngineProvider() { | ||
base::AutoReset<bool> reset(&ignore_template_url_service_changing_, true); | ||
UseAlternativeSearchEngineProvider() | ||
? ChangeToAlternativeSearchEngineProvider() | ||
: ChangeToNormalWindowSearchEngineProvider(); | ||
} |
Oops, something went wrong.