77
88#include < utility>
99
10+ #include " brave/components/brave_new_tab/new_tab_prefs.h"
1011#include " brave/components/constants/pref_names.h"
1112#include " brave/components/constants/webui_url_constants.h"
1213#include " brave/grit/brave_generated_resources.h"
@@ -29,44 +30,40 @@ GURL GetNewTabPageURL(Profile* profile) {
2930
3031 auto * prefs = profile->GetPrefs ();
3132
32- NewTabPageShowsOptions option = static_cast <NewTabPageShowsOptions>(
33- prefs->GetInteger (kNewTabPageShowsOptions ));
34- if (option == NewTabPageShowsOptions::kHomepage ) {
35- if (prefs->GetBoolean (prefs::kHomePageIsNewTabPage )) {
33+ switch (brave_new_tab::prefs::GetNewTabShowsOption (prefs)) {
34+ case brave_new_tab::prefs::NewTabShowsOption::kHomepage :
35+ return prefs->GetBoolean (prefs::kHomePageIsNewTabPage )
36+ ? GURL ()
37+ : GURL (prefs->GetString (prefs::kHomePage ));
38+ case brave_new_tab::prefs::NewTabShowsOption::kBlankpage :
39+ case brave_new_tab::prefs::NewTabShowsOption::kDashboard :
3640 return GURL ();
37- }
38- return GURL (prefs->GetString (prefs::kHomePage ));
39- } else if (option == NewTabPageShowsOptions::kBlankpage ) {
40- // NewTab route will handle for blank page.
41- return GURL ();
42- } else {
43- DCHECK_EQ (NewTabPageShowsOptions::kDashboard , option);
44- return GURL ();
4541 }
4642}
4743
4844base::Value::List GetNewTabShowsOptionsList (Profile* profile) {
45+ using brave_new_tab::prefs::NewTabShowsOption;
46+
4947 base::Value::List list;
5048
5149 base::Value::Dict dashboard_option;
5250 dashboard_option.Set (" value" ,
53- static_cast <int >(NewTabPageShowsOptions ::kDashboard ));
51+ static_cast <int >(NewTabShowsOption ::kDashboard ));
5452 dashboard_option.Set (" name" ,
5553 l10n_util::GetStringUTF8 (
5654 IDS_SETTINGS_NEW_TAB_NEW_TAB_PAGE_SHOWS_DASHBOARD));
5755 list.Append (std::move (dashboard_option));
5856
5957 base::Value::Dict homepage_option;
60- homepage_option.Set (" value" ,
61- static_cast <int >(NewTabPageShowsOptions::kHomepage ));
58+ homepage_option.Set (" value" , static_cast <int >(NewTabShowsOption::kHomepage ));
6259 homepage_option.Set (" name" ,
6360 l10n_util::GetStringUTF8 (
6461 IDS_SETTINGS_NEW_TAB_NEW_TAB_PAGE_SHOWS_HOMEPAGE));
6562 list.Append (std::move (homepage_option));
6663
6764 base::Value::Dict blankpage_option;
6865 blankpage_option.Set (" value" ,
69- static_cast <int >(NewTabPageShowsOptions ::kBlankpage ));
66+ static_cast <int >(NewTabShowsOption ::kBlankpage ));
7067 blankpage_option.Set (" name" ,
7168 l10n_util::GetStringUTF8 (
7269 IDS_SETTINGS_NEW_TAB_NEW_TAB_PAGE_SHOWS_BLANKPAGE));
@@ -81,9 +78,8 @@ bool ShouldUseNewTabURLForNewTab(Profile* profile) {
8178}
8279
8380bool ShouldNewTabShowDashboard (Profile* profile) {
84- auto * prefs = profile->GetPrefs ();
85- if (static_cast <NewTabPageShowsOptions>(prefs->GetInteger (
86- kNewTabPageShowsOptions )) == NewTabPageShowsOptions::kBlankpage ) {
81+ auto option = brave_new_tab::prefs::GetNewTabShowsOption (profile->GetPrefs ());
82+ if (option == brave_new_tab::prefs::NewTabShowsOption::kBlankpage ) {
8783 return false ;
8884 }
8985
@@ -95,8 +91,8 @@ bool ShouldNewTabShowBlankpage(Profile* profile) {
9591 return false ;
9692 }
9793
98- return profile->GetPrefs ()-> GetInteger ( kNewTabPageShowsOptions ) ==
99- static_cast < int >(brave::NewTabPageShowsOptions:: kBlankpage ) ;
94+ auto option = brave_new_tab::prefs::GetNewTabShowsOption ( profile->GetPrefs ());
95+ return option == brave_new_tab::prefs::NewTabShowsOption:: kBlankpage ;
10096}
10197
10298} // namespace brave
0 commit comments