Merge pull request #4860 from brave/bsc-fix-default-shields

Explicitly set the default view for shield settings
This commit is contained in:
Brian Clifton
2020-03-10 09:57:25 -07:00
committed by GitHub
3 changed files with 30 additions and 14 deletions
+1 -12
View File
@@ -33,10 +33,6 @@
#include "brave/components/brave_webtorrent/browser/webtorrent_util.h"
#endif
#if !defined(OS_ANDROID)
#include "chrome/browser/first_run/first_run.h"
#endif
#if !BUILDFLAG(USE_GCM_FROM_PLATFORM)
#include "components/gcm_driver/gcm_channel_status_syncer.h"
#endif
@@ -103,12 +99,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterBooleanPref(kHTTPSEVerywhereControlType, true);
registry->RegisterBooleanPref(kNoScriptControlType, false);
registry->RegisterBooleanPref(kAdControlType, true);
// > advanced view is defaulted to true for EXISTING users; false for new
bool is_new_user = false;
#if !defined(OS_ANDROID)
is_new_user = first_run::IsChromeFirstRun();
#endif
registry->RegisterBooleanPref(kShieldsAdvancedViewEnabled, false);
#if !BUILDFLAG(USE_GCM_FROM_PLATFORM)
// PushMessaging
@@ -116,8 +107,6 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
base::Value(false));
#endif
registry->RegisterBooleanPref(kShieldsAdvancedViewEnabled,
is_new_user == false);
registry->RegisterBooleanPref(kShieldsStatsBadgeVisible, true);
registry->RegisterBooleanPref(kGoogleLoginControlType, true);
registry->RegisterBooleanPref(kFBEmbedControlType, true);
+13 -2
View File
@@ -82,17 +82,28 @@ typedef FirstRunMasterPrefsBrowserTestT<kFirstRunEmptyPrefs>
BraveProfilePrefsFirstRunBrowserTest;
IN_PROC_BROWSER_TEST_F(BraveProfilePrefsFirstRunBrowserTest,
AdvancedShieldsNewUserValue) {
EXPECT_FALSE(
browser()->profile()->GetPrefs()->GetBoolean(
// verify value of pref (default to simple view)
EXPECT_FALSE(browser()->profile()->GetPrefs()->GetBoolean(
kShieldsAdvancedViewEnabled));
// verify that pref was set (and is not default)
const PrefService::Preference* pref =
browser()->profile()->GetPrefs()->FindPreference(
kShieldsAdvancedViewEnabled);
EXPECT_TRUE(pref->HasUserSetting());
}
// Existing Brave users should default shields to Advanced view
IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest,
AdvancedShieldsExistingUserValue) {
// verify value of pref (default to advanced view)
EXPECT_TRUE(
browser()->profile()->GetPrefs()->GetBoolean(
kShieldsAdvancedViewEnabled));
// verify that pref was set (and is not default)
const PrefService::Preference* pref =
browser()->profile()->GetPrefs()->FindPreference(
kShieldsAdvancedViewEnabled);
EXPECT_TRUE(pref->HasUserSetting());
}
#endif
+16
View File
@@ -7,11 +7,16 @@
#include "base/task/post_task.h"
#include "brave/browser/profiles/profile_util.h"
#include "brave/common/pref_names.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "content/public/browser/notification_source.h"
#if !defined(OS_ANDROID)
#include "chrome/browser/first_run/first_run.h"
#endif
BraveProfileImpl::BraveProfileImpl(
const base::FilePath& path,
Delegate* delegate,
@@ -20,6 +25,17 @@ BraveProfileImpl::BraveProfileImpl(
scoped_refptr<base::SequencedTaskRunner> io_task_runner)
: ProfileImpl(path, delegate, create_mode, creation_time, io_task_runner),
weak_ptr_factory_(this) {
#if !defined(OS_ANDROID)
const PrefService::Preference* pref =
GetPrefs()->FindPreference(kShieldsAdvancedViewEnabled);
if (!pref->HasUserSetting()) {
// advanced view is defaulted to true for EXISTING users; false for new.
// preference needs to be explicitly set to hold its value
const bool default_value = !first_run::IsChromeFirstRun();
GetPrefs()->SetBoolean(kShieldsAdvancedViewEnabled, default_value);
}
#endif
// In sessions profiles, prefs are created from the original profile like how
// incognito profile works. By the time chromium start to observe prefs
// initialization in ProfileImpl constructor for the async creation case,