Skip to content

Commit

Permalink
[game search] Add SourceExtras subclass for games
Browse files Browse the repository at this point in the history
Bug: 1305880
Change-Id: Ie5b5b8a06e5ad72d4757c6f49b38247477e82bdd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3546138
Reviewed-by: Melissa Zhang <melzhang@chromium.org>
Commit-Queue: Tony Yeoman <tby@chromium.org>
Cr-Commit-Position: refs/heads/main@{#985192}
  • Loading branch information
tby authored and Chromium LUCI CQ committed Mar 25, 2022
1 parent a5cc3f3 commit 79c1639
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 10 deletions.
2 changes: 2 additions & 0 deletions chrome/browser/BUILD.gn
Expand Up @@ -4553,6 +4553,8 @@ static_library("browser") {
"apps/app_discovery_service/app_discovery_util.h",
"apps/app_discovery_service/app_fetcher_manager.cc",
"apps/app_discovery_service/app_fetcher_manager.h",
"apps/app_discovery_service/game_extras.cc",
"apps/app_discovery_service/game_extras.h",
"apps/app_discovery_service/play_extras.cc",
"apps/app_discovery_service/play_extras.h",
"apps/app_discovery_service/recommended_arc_app_fetcher.cc",
Expand Down
53 changes: 53 additions & 0 deletions chrome/browser/apps/app_discovery_service/game_extras.cc
@@ -0,0 +1,53 @@
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/apps/app_discovery_service/game_extras.h"

namespace apps {
namespace {

using Source = GameExtras::Source;

} // namespace

GameExtras::GameExtras(
const std::string& id,
const std::u16string& title,
Source source,
const absl::optional<std::vector<std::u16string>>& platforms,
const GURL& icon_url)
: id_(id),
title_(title),
source_(source),
platforms_(platforms),
icon_url_(icon_url) {}

GameExtras::~GameExtras() = default;

const std::string& GameExtras::GetId() const {
return id_;
}

const std::u16string& GameExtras::GetTitle() const {
return title_;
}

Source GameExtras::GetSource() const {
return source_;
}

const absl::optional<std::vector<std::u16string>>& GameExtras::GetPlatforms()
const {
return platforms_;
}

const GURL& GameExtras::GetIconUrl() const {
return icon_url_;
}

GameExtras* GameExtras::AsGameExtras() {
return this;
}

} // namespace apps
54 changes: 54 additions & 0 deletions chrome/browser/apps/app_discovery_service/game_extras.h
@@ -0,0 +1,54 @@
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_APPS_APP_DISCOVERY_SERVICE_GAME_EXTRAS_H_
#define CHROME_BROWSER_APPS_APP_DISCOVERY_SERVICE_GAME_EXTRAS_H_

#include <string>
#include <vector>

#include "chrome/browser/apps/app_discovery_service/result.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/gurl.h"

namespace apps {

class GameExtras : public SourceExtras {
public:
// Which cloud gaming source a result comes from. These values are persisted
// to logs. Entries should not be renumbered or reused.
enum class Source {
// TODO(crbug.com/1305880): Replace with real source.
kTemporarySource = 1,
};

GameExtras(const std::string& id,
const std::u16string& title,
Source source,
const absl::optional<std::vector<std::u16string>>& platforms,
const GURL& icon_url);
GameExtras(const GameExtras&) = delete;
GameExtras& operator=(const GameExtras&) = delete;
~GameExtras() override;

const std::string& GetId() const;
const std::u16string& GetTitle() const;
Source GetSource() const;
const absl::optional<std::vector<std::u16string>>& GetPlatforms() const;
const GURL& GetIconUrl() const;

// Result::SourceExtras:
GameExtras* AsGameExtras() override;

private:
std::string id_;
std::u16string title_;
Source source_;
absl::optional<std::vector<std::u16string>> platforms_;
GURL icon_url_;
};

} // namespace apps

#endif // CHROME_BROWSER_APPS_APP_DISCOVERY_SERVICE_GAME_EXTRAS_H_
20 changes: 10 additions & 10 deletions chrome/browser/apps/app_discovery_service/play_extras.h
Expand Up @@ -14,16 +14,16 @@ namespace apps {

class PlayExtras : public SourceExtras {
public:
explicit PlayExtras(const std::string& package_name,
const GURL& icon_url,
const std::u16string& category,
const std::u16string& description,
const std::u16string& content_rating,
const GURL& content_rating_icon_url,
const bool in_app_purchases,
const bool previously_installed,
const bool contains_ads,
const bool optimized_for_chrome);
PlayExtras(const std::string& package_name,
const GURL& icon_url,
const std::u16string& category,
const std::u16string& description,
const std::u16string& content_rating,
const GURL& content_rating_icon_url,
const bool in_app_purchases,
const bool previously_installed,
const bool contains_ads,
const bool optimized_for_chrome);
PlayExtras(const PlayExtras&) = delete;
PlayExtras& operator=(const PlayExtras&) = delete;
~PlayExtras() override;
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/apps/app_discovery_service/result.cc
Expand Up @@ -8,6 +8,10 @@

namespace apps {

GameExtras* SourceExtras::AsGameExtras() {
return nullptr;
}

PlayExtras* SourceExtras::AsPlayExtras() {
return nullptr;
}
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/apps/app_discovery_service/result.h
Expand Up @@ -11,6 +11,7 @@
namespace apps {

enum class AppSource;
class GameExtras;
class PlayExtras;

// Can be overridden by Sources that have unique fields.
Expand All @@ -23,6 +24,7 @@ class SourceExtras {
// virtual FooExtras* AsFooExtras { return nullptr; }

// Safe downcasts:
virtual GameExtras* AsGameExtras();
virtual PlayExtras* AsPlayExtras();
};

Expand Down

0 comments on commit 79c1639

Please sign in to comment.