Skip to content

Commit

Permalink
Updated Games Pref to only use Component's Install Dir
Browse files Browse the repository at this point in the history
Bug: 1018201
Change-Id: I43fa12d5a8b25bf7a7fa3c48b4e0c1b16f438009
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1921697
Auto-Submit: Sebastien Lalancette <seblalancette@chromium.org>
Commit-Queue: Chris Sharp <csharp@chromium.org>
Reviewed-by: Chris Sharp <csharp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#716244}
  • Loading branch information
Sebastien authored and Commit Bot committed Nov 18, 2019
1 parent ad7cdae commit 5af6c5c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 66 deletions.
39 changes: 7 additions & 32 deletions components/games/core/games_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 3 additions & 9 deletions components/games/core/games_prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 5 additions & 20 deletions components/games/core/games_prefs_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,18 @@ class GamesPrefsTest : public testing::Test {
std::unique_ptr<TestingPrefServiceSimple> 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);
}

Expand Down
6 changes: 3 additions & 3 deletions components/games/core/games_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions components/games/core/games_service_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 5af6c5c

Please sign in to comment.