Commit 6c21e1da authored by nancy's avatar nancy Committed by Commit Bot

Add PauseApp and UnpauseApp interfaces in publishers.

Add PauseApp and UnpauseApp interfaces to AppService mojo, and
publishers. For extension apps and ARC apps, set the icon effects for
the paused apps.

The icon effect is set based on the paused field of App structure, so
pass the AppRegistryCache to ExtensionApps, to check the App's paused
status.

For ARC apps, the AppRegistryCache can get from AppServiceProxy.

BUG=1011235

Change-Id: Iced5e0f36ba5b1d036fd2431e5810832c59d423a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1906851Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714782}
parent 1bc66d0f
......@@ -33,6 +33,8 @@ enum IconEffects : uint32_t {
kBadge = 0x02, // Another (Android) app has the same name.
kGray = 0x04, // Disabled apps are grayed out.
kRoundCorners = 0x08, // Bookmark apps get round corners.
kPaused = 0x10, // Paused apps are badged to indicate they cannot be
// launched.
};
// Modifies |image_skia| to apply icon post-processing effects like badging and
......
......@@ -293,8 +293,7 @@ void AppServiceProxy::PauseApps(
// TODO(crbug.com/1011235): Add the app running checking. If the app is not
// running, don't create the pause dialog, pause the app directly.
if (app_type != apps::mojom::AppType::kArc) {
// TODO(crbug.com/1011235): Add AppService interface to apply icon
// effects.
app_service_->PauseApp(app_type, data.first);
continue;
}
......@@ -313,15 +312,13 @@ void AppServiceProxy::UnpauseApps(const std::set<std::string>& app_ids) {
constexpr bool kPaused = false;
UpdatePausedStatus(app_type, app_id, kPaused);
// TODO(crbug.com/1011235): Add AppService interface to recover icon
// effects.
app_service_->UnpauseApps(app_type, app_id);
}
}
void AppServiceProxy::OnPauseDialogClosed(apps::mojom::AppType app_type,
const std::string& app_id) {
// TODO(crbug.com/1011235): Add AppService interface to apply the icon effect
// and stop the running app.
app_service_->PauseApp(app_type, app_id);
}
void AppServiceProxy::OpenNativeSettings(const std::string& app_id) {
......
......@@ -416,6 +416,26 @@ void ArcApps::Uninstall(const std::string& app_id,
arc::UninstallArcApp(app_id, profile_);
}
void ArcApps::PauseApp(const std::string& app_id) {
if (paused_apps.find(app_id) != paused_apps.end()) {
return;
}
paused_apps.insert(app_id);
SetIconEffect(app_id);
// TODO(crbug.com/1011235): If the app is running, Stop the app.
}
void ArcApps::UnpauseApps(const std::string& app_id) {
if (paused_apps.find(app_id) == paused_apps.end()) {
return;
}
paused_apps.erase(app_id);
SetIconEffect(app_id);
}
void ArcApps::OpenNativeSettings(const std::string& app_id) {
ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_);
if (!prefs) {
......@@ -747,6 +767,32 @@ void ArcApps::ConvertAndPublishPackageApps(
}
}
void ArcApps::SetIconEffect(const std::string& app_id) {
ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_);
if (!prefs) {
return;
}
std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = prefs->GetApp(app_id);
if (!app_info) {
return;
}
IconEffects icon_effects = IconEffects::kNone;
if (app_info->suspended) {
icon_effects = static_cast<IconEffects>(icon_effects | IconEffects::kGray);
}
if (paused_apps.find(app_id) != paused_apps.end()) {
icon_effects =
static_cast<IconEffects>(icon_effects | IconEffects::kPaused);
}
apps::mojom::AppPtr app = apps::mojom::App::New();
app->app_type = apps::mojom::AppType::kArc;
app->app_id = app_id;
app->icon_key = icon_key_factory_.MakeIconKey(icon_effects);
Publish(std::move(app));
}
void ArcApps::UpdateAppIntentFilters(
std::string package_name,
arc::ArcIntentHelperBridge* intent_helper_bridge,
......
......@@ -77,6 +77,8 @@ class ArcApps : public KeyedService,
void Uninstall(const std::string& app_id,
bool clear_site_data,
bool report_abuse) override;
void PauseApp(const std::string& app_id) override;
void UnpauseApps(const std::string& app_id) override;
void OpenNativeSettings(const std::string& app_id) override;
void OnPreferredAppSet(const std::string& app_id,
apps::mojom::IntentFilterPtr intent_filter,
......@@ -116,6 +118,7 @@ class ArcApps : public KeyedService,
void ConvertAndPublishPackageApps(
const arc::mojom::ArcPackageInfo& package_info,
bool update_icon = true);
void SetIconEffect(const std::string& app_id);
void UpdateAppIntentFilters(
std::string package_name,
arc::ArcIntentHelperBridge* intent_helper_bridge,
......@@ -129,6 +132,8 @@ class ArcApps : public KeyedService,
apps_util::IncrementingIconKeyFactory icon_key_factory_;
std::set<std::string> paused_apps;
ScopedObserver<arc::ArcIntentHelperBridge, arc::ArcIntentHelperObserver>
arc_intent_helper_observer_{this};
......
......@@ -178,6 +178,14 @@ void BuiltInChromeOsApps::Uninstall(const std::string& app_id,
<< app_id;
}
void BuiltInChromeOsApps::PauseApp(const std::string& app_id) {
NOTIMPLEMENTED();
}
void BuiltInChromeOsApps::UnpauseApps(const std::string& app_id) {
NOTIMPLEMENTED();
}
void BuiltInChromeOsApps::OpenNativeSettings(const std::string& app_id) {
NOTIMPLEMENTED();
}
......
......@@ -56,6 +56,8 @@ class BuiltInChromeOsApps : public apps::mojom::Publisher {
void Uninstall(const std::string& app_id,
bool clear_site_data,
bool report_abuse) override;
void PauseApp(const std::string& app_id) override;
void UnpauseApps(const std::string& app_id) override;
void OpenNativeSettings(const std::string& app_id) override;
void OnPreferredAppSet(const std::string& app_id,
apps::mojom::IntentFilterPtr intent_filter,
......
......@@ -164,6 +164,14 @@ void CrostiniApps::Uninstall(const std::string& app_id,
->QueueUninstallApplication(app_id);
}
void CrostiniApps::PauseApp(const std::string& app_id) {
NOTIMPLEMENTED();
}
void CrostiniApps::UnpauseApps(const std::string& app_id) {
NOTIMPLEMENTED();
}
void CrostiniApps::OpenNativeSettings(const std::string& app_id) {
NOTIMPLEMENTED();
}
......
......@@ -74,6 +74,8 @@ class CrostiniApps : public KeyedService,
void Uninstall(const std::string& app_id,
bool clear_site_data,
bool report_abuse) override;
void PauseApp(const std::string& app_id) override;
void UnpauseApps(const std::string& app_id) override;
void OpenNativeSettings(const std::string& app_id) override;
void OnPreferredAppSet(const std::string& app_id,
apps::mojom::IntentFilterPtr intent_filter,
......
......@@ -520,6 +520,26 @@ void ExtensionApps::Uninstall(const std::string& app_id,
}
}
void ExtensionApps::PauseApp(const std::string& app_id) {
if (paused_apps.find(app_id) != paused_apps.end()) {
return;
}
paused_apps.insert(app_id);
SetIconEffect(app_id);
// TODO(crbug.com/1011235): If the app is running, Stop the app.
}
void ExtensionApps::UnpauseApps(const std::string& app_id) {
if (paused_apps.find(app_id) == paused_apps.end()) {
return;
}
paused_apps.erase(app_id);
SetIconEffect(app_id);
}
void ExtensionApps::OpenNativeSettings(const std::string& app_id) {
if (!profile_) {
return;
......@@ -998,6 +1018,10 @@ IconEffects ExtensionApps::GetIconEffects(
icon_effects =
static_cast<IconEffects>(icon_effects | IconEffects::kRoundCorners);
}
if (paused_apps.find(extension->id()) != paused_apps.end()) {
icon_effects =
static_cast<IconEffects>(icon_effects | IconEffects::kPaused);
}
return icon_effects;
}
......@@ -1005,23 +1029,27 @@ void ExtensionApps::ApplyChromeBadge(const std::string& package_name) {
const std::vector<std::string> extension_ids =
extensions::util::GetEquivalentInstalledExtensions(profile_,
package_name);
extensions::ExtensionRegistry* registry =
extensions::ExtensionRegistry::Get(profile_);
for (auto& app_id : extension_ids) {
const extensions::Extension* extension =
registry->GetInstalledExtension(app_id);
if (!extension || !Accepts(extension)) {
continue;
}
apps::mojom::AppPtr app = apps::mojom::App::New();
app->app_type = app_type_;
app->app_id = extension->id();
app->icon_key = icon_key_factory_.MakeIconKey(GetIconEffects(extension));
SetIconEffect(app_id);
}
}
Publish(std::move(app));
void ExtensionApps::SetIconEffect(const std::string& app_id) {
extensions::ExtensionRegistry* registry =
extensions::ExtensionRegistry::Get(profile_);
DCHECK(registry);
const extensions::Extension* extension =
registry->GetInstalledExtension(app_id);
if (!extension || !Accepts(extension)) {
return;
}
apps::mojom::AppPtr app = apps::mojom::App::New();
app->app_type = app_type_;
app->app_id = app_id;
app->icon_key = icon_key_factory_.MakeIconKey(GetIconEffects(extension));
Publish(std::move(app));
}
} // namespace apps
......@@ -92,6 +92,8 @@ class ExtensionApps : public apps::mojom::Publisher,
void Uninstall(const std::string& app_id,
bool clear_site_data,
bool report_abuse) override;
void PauseApp(const std::string& app_id) override;
void UnpauseApps(const std::string& app_id) override;
void OpenNativeSettings(const std::string& app_id) override;
void OnPreferredAppSet(const std::string& app_id,
apps::mojom::IntentFilterPtr intent_filter,
......@@ -168,6 +170,8 @@ class ExtensionApps : public apps::mojom::Publisher,
// remove the Chrome app badge.
void ApplyChromeBadge(const std::string& arc_package_name);
void SetIconEffect(const std::string& app_id);
mojo::Receiver<apps::mojom::Publisher> receiver_{this};
mojo::RemoteSet<apps::mojom::Subscriber> subscribers_;
......@@ -188,6 +192,8 @@ class ExtensionApps : public apps::mojom::Publisher,
using EnableFlowPtr = std::unique_ptr<ExtensionAppsEnableFlow>;
std::map<std::string, EnableFlowPtr> enable_flow_map_;
std::set<std::string> paused_apps;
ArcAppListPrefs* arc_prefs_ = nullptr;
base::WeakPtrFactory<ExtensionApps> weak_factory_{this};
......
......@@ -162,6 +162,24 @@ void AppServiceImpl::Uninstall(apps::mojom::AppType app_type,
iter->second->Uninstall(app_id, clear_site_data, report_abuse);
}
void AppServiceImpl::PauseApp(apps::mojom::AppType app_type,
const std::string& app_id) {
auto iter = publishers_.find(app_type);
if (iter == publishers_.end()) {
return;
}
iter->second->PauseApp(app_id);
}
void AppServiceImpl::UnpauseApps(apps::mojom::AppType app_type,
const std::string& app_id) {
auto iter = publishers_.find(app_type);
if (iter == publishers_.end()) {
return;
}
iter->second->UnpauseApps(app_id);
}
void AppServiceImpl::OpenNativeSettings(apps::mojom::AppType app_type,
const std::string& app_id) {
auto iter = publishers_.find(app_type);
......
......@@ -70,6 +70,10 @@ class AppServiceImpl : public apps::mojom::AppService {
const std::string& app_id,
bool clear_site_data,
bool report_abuse) override;
void PauseApp(apps::mojom::AppType app_type,
const std::string& app_id) override;
void UnpauseApps(apps::mojom::AppType app_type,
const std::string& app_id) override;
void OpenNativeSettings(apps::mojom::AppType app_type,
const std::string& app_id) override;
void AddPreferredApp(apps::mojom::AppType app_type,
......
......@@ -84,6 +84,8 @@ class FakePublisher : public apps::mojom::Publisher {
void Uninstall(const std::string& app_id,
bool clear_site_data,
bool report_abuse) override {}
void PauseApp(const std::string& app_id) override {}
void UnpauseApps(const std::string& app_id) override {}
void OpenNativeSettings(const std::string& app_id) override {}
......
......@@ -71,6 +71,16 @@ interface AppService {
bool clear_site_data,
bool report_abuse);
// Pauses an app to stop the current running app, and apply the icon effect.
PauseApp(
AppType app_type,
string app_id);
// Unpauses an app, and recover the icon effect for the app.
UnpauseApps(
AppType app_type,
string app_id);
OpenNativeSettings(
AppType app_type,
string app_id);
......@@ -130,6 +140,14 @@ interface Publisher {
bool clear_site_data,
bool report_abuse);
// Pauses an app to stop the current running app, and apply the icon effect.
PauseApp(
string app_id);
// Unpauses an app, and recover the icon effect for the app.
UnpauseApps(
string app_id);
OpenNativeSettings(
string app_id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment