diff --git a/components/games/core/games_prefs.cc b/components/games/core/games_prefs.cc index 42ab153de86c8e..4bb5ec19b494e7 100644 --- a/components/games/core/games_prefs.cc +++ b/components/games/core/games_prefs.cc @@ -9,46 +9,21 @@ namespace prefs { namespace { -const char kGamesCatalogPathPref[] = "games.data_files_paths.games-catalog"; -const char kHighlightedGamesPathPref[] = - "games.data_files_paths.highlighted-games"; - -void SetFilePathPref(PrefService* prefs, - const std::string& pref_path, - const base::FilePath& file_path) { - prefs->SetFilePath(pref_path, file_path); -} - -bool TryGetFilePathPref(PrefService* prefs, - const std::string& pref_path, - base::FilePath* out_file_path) { - *out_file_path = prefs->GetFilePath(pref_path); - return !out_file_path->empty(); -} +const char kGamesInstallDirPref[] = "games.data_files_paths"; } // namespace void RegisterProfilePrefs(PrefRegistrySimple* registry) { - registry->RegisterFilePathPref(kGamesCatalogPathPref, base::FilePath()); - registry->RegisterFilePathPref(kHighlightedGamesPathPref, base::FilePath()); + registry->RegisterFilePathPref(kGamesInstallDirPref, base::FilePath()); } -void SetGamesCatalogPath(PrefService* prefs, const base::FilePath& file_path) { - SetFilePathPref(prefs, kGamesCatalogPathPref, file_path); +void SetInstallDirPath(PrefService* prefs, const base::FilePath& file_path) { + prefs->SetFilePath(kGamesInstallDirPref, file_path); } -void SetHighlightedGamesPath(PrefService* prefs, - const base::FilePath& file_path) { - SetFilePathPref(prefs, kHighlightedGamesPathPref, file_path); -} - -bool TryGetGamesCatalogPath(PrefService* prefs, base::FilePath* out_file_path) { - return TryGetFilePathPref(prefs, kGamesCatalogPathPref, out_file_path); -} - -bool TryGetHighlightedGamesPath(PrefService* prefs, - base::FilePath* out_file_path) { - return TryGetFilePathPref(prefs, kHighlightedGamesPathPref, out_file_path); +bool TryGetInstallDirPath(PrefService* prefs, base::FilePath* out_file_path) { + *out_file_path = prefs->GetFilePath(kGamesInstallDirPref); + return !out_file_path->empty(); } } // namespace prefs diff --git a/components/games/core/games_prefs.h b/components/games/core/games_prefs.h index b164a93875b2f9..f3060379d9f115 100644 --- a/components/games/core/games_prefs.h +++ b/components/games/core/games_prefs.h @@ -12,18 +12,12 @@ namespace games { namespace prefs { -// Registers Games prefs. +// Registers Games pref. void RegisterProfilePrefs(PrefRegistrySimple* registry); -void SetGamesCatalogPath(PrefService* prefs, const base::FilePath& file_path); +void SetInstallDirPath(PrefService* prefs, const base::FilePath& file_path); -void SetHighlightedGamesPath(PrefService* prefs, - const base::FilePath& file_path); - -bool TryGetGamesCatalogPath(PrefService* prefs, base::FilePath* out_file_path); - -bool TryGetHighlightedGamesPath(PrefService* prefs, - base::FilePath* out_file_path); +bool TryGetInstallDirPath(PrefService* prefs, base::FilePath* out_file_path); } // namespace prefs } // namespace games diff --git a/components/games/core/games_prefs_unittest.cc b/components/games/core/games_prefs_unittest.cc index 79bdcea084c22e..dccc9a1d4000c6 100644 --- a/components/games/core/games_prefs_unittest.cc +++ b/components/games/core/games_prefs_unittest.cc @@ -23,33 +23,18 @@ class GamesPrefsTest : public testing::Test { std::unique_ptr test_pref_service_; }; -TEST_F(GamesPrefsTest, GetGamesCatalogPath_Empty) { +TEST_F(GamesPrefsTest, GetInstallDirPath_Empty) { base::FilePath path; - ASSERT_FALSE(TryGetGamesCatalogPath(test_pref_service_.get(), &path)); + ASSERT_FALSE(TryGetInstallDirPath(test_pref_service_.get(), &path)); ASSERT_TRUE(path.empty()); } -TEST_F(GamesPrefsTest, SetGetGamesCatalogPath_Valid) { +TEST_F(GamesPrefsTest, SetGetInstallDirPath_Valid) { base::FilePath expected_path(FILE_PATH_LITERAL("some/long/path")); - SetGamesCatalogPath(test_pref_service_.get(), expected_path); + SetInstallDirPath(test_pref_service_.get(), expected_path); base::FilePath path; - ASSERT_TRUE(TryGetGamesCatalogPath(test_pref_service_.get(), &path)); - ASSERT_EQ(expected_path, path); -} - -TEST_F(GamesPrefsTest, GetHighlightedGamesPath_Empty) { - base::FilePath path; - ASSERT_FALSE(TryGetHighlightedGamesPath(test_pref_service_.get(), &path)); - ASSERT_TRUE(path.empty()); -} - -TEST_F(GamesPrefsTest, SetGetHighlightedGamesPath_Valid) { - base::FilePath expected_path(FILE_PATH_LITERAL("some/long/path")); - SetHighlightedGamesPath(test_pref_service_.get(), expected_path); - - base::FilePath path; - ASSERT_TRUE(TryGetHighlightedGamesPath(test_pref_service_.get(), &path)); + ASSERT_TRUE(TryGetInstallDirPath(test_pref_service_.get(), &path)); ASSERT_EQ(expected_path, path); } diff --git a/components/games/core/games_service_impl.cc b/components/games/core/games_service_impl.cc index 60be9eeb636e56..2b410f9eea7796 100644 --- a/components/games/core/games_service_impl.cc +++ b/components/games/core/games_service_impl.cc @@ -18,10 +18,10 @@ GamesServiceImpl::GamesServiceImpl(PrefService* prefs) : prefs_(prefs) {} GamesServiceImpl::~GamesServiceImpl() = default; void GamesServiceImpl::GetHighlightedGame(HighlightedGameCallback callback) { - // If we don't have the highlighted games data file downloaded, we cannot - // provide the surface with a highlighted game. + // If we don't have the install dir pref, then the Games component wasn't + // downloaded and we cannot provide the surface with a highlighted game. base::FilePath data_file_path; - if (!prefs::TryGetHighlightedGamesPath(prefs_, &data_file_path)) { + if (!prefs::TryGetInstallDirPath(prefs_, &data_file_path)) { // TODO crbug.com/1018201: Add callback error handling. return; } diff --git a/components/games/core/games_service_impl_unittest.cc b/components/games/core/games_service_impl_unittest.cc index 266fb9e748019c..603a4619037e10 100644 --- a/components/games/core/games_service_impl_unittest.cc +++ b/components/games/core/games_service_impl_unittest.cc @@ -34,8 +34,8 @@ class GamesServiceImplTest : public testing::Test { }; TEST_F(GamesServiceImplTest, GetHighlightedGame_SameTitle) { - prefs::SetHighlightedGamesPath( - test_pref_service_.get(), base::FilePath(FILE_PATH_LITERAL("some/path"))); + prefs::SetInstallDirPath(test_pref_service_.get(), + base::FilePath(FILE_PATH_LITERAL("some/path"))); std::string expected_title = "Some Game!"; std::string result_title = "not the same";