Commit f0170685 authored by nancy's avatar nancy Committed by Commit Bot

Delete the Chrome application instance for Crostini terminal window.

Set the window's property AppType for Crostini apps. This is the
current implementation in Crostini app window launcher controller:
https://cs.chromium.org/chromium/src/chrome/browser/ui/ash/launcher/crostini_app_window_shelf_controller.cc?q=ash::AppType::CROSTINI_APP&l=275&dr=C

BUG=1011235

Change-Id: I82a816e0f6dc631608bd368b16b765dfc345d131
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1985623Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728034}
parent dfb46ce9
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "ash/public/cpp/shelf_model.h" #include "ash/public/cpp/shelf_model.h"
#include "base/containers/flat_tree.h" #include "base/containers/flat_tree.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/chromeos/crostini/crostini_force_close_watcher.h" #include "chrome/browser/chromeos/crostini/crostini_force_close_watcher.h"
#include "chrome/browser/chromeos/crostini/crostini_registry_service.h" #include "chrome/browser/chromeos/crostini/crostini_registry_service.h"
#include "chrome/browser/chromeos/crostini/crostini_registry_service_factory.h" #include "chrome/browser/chromeos/crostini/crostini_registry_service_factory.h"
...@@ -221,6 +223,19 @@ std::string AppServiceAppWindowCrostiniTracker::GetShelfAppId( ...@@ -221,6 +223,19 @@ std::string AppServiceAppWindowCrostiniTracker::GetShelfAppId(
crostini::CrostiniAppIdFromAppName(browser->app_name()); crostini::CrostiniAppIdFromAppName(browser->app_name());
if (!app_id) if (!app_id)
return std::string(); return std::string();
// The browser window could be added to InstanceRegistry using Chrome
// application's app id, so if the window is for Crostini app, e.g.
// terminal, the Chrome instance should be deleted, otherwise, it could
// cause inconsistent error.
auto* proxy_ = apps::AppServiceProxyFactory::GetForProfile(
app_service_controller_->owner()->profile());
const ash::ShelfID shelf_id = proxy_->InstanceRegistry().GetShelfId(window);
if (shelf_id.app_id != app_id) {
app_service_controller_->app_service_instance_helper()->OnInstances(
shelf_id.app_id, window, std::string(),
apps::InstanceState::kDestroyed);
}
return app_id.value(); return app_id.value();
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include "ash/public/cpp/app_list/internal_app_id_constants.h" #include "ash/public/cpp/app_list/internal_app_id_constants.h"
#include "ash/public/cpp/app_types.h"
#include "ash/public/cpp/multi_user_window_manager.h" #include "ash/public/cpp/multi_user_window_manager.h"
#include "ash/public/cpp/shelf_model.h" #include "ash/public/cpp/shelf_model.h"
#include "ash/public/cpp/window_properties.h" #include "ash/public/cpp/window_properties.h"
...@@ -27,10 +28,12 @@ ...@@ -27,10 +28,12 @@
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h" #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_helper.h" #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_helper.h"
#include "chrome/services/app_service/public/cpp/instance.h" #include "chrome/services/app_service/public/cpp/instance.h"
#include "chrome/services/app_service/public/mojom/types.mojom-shared.h"
#include "chrome/services/app_service/public/mojom/types.mojom.h" #include "chrome/services/app_service/public/mojom/types.mojom.h"
#include "components/account_id/account_id.h" #include "components/account_id/account_id.h"
#include "components/arc/arc_util.h" #include "components/arc/arc_util.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h" #include "ui/aura/env.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
...@@ -268,6 +271,13 @@ void AppServiceAppWindowLauncherController::OnInstanceUpdate( ...@@ -268,6 +271,13 @@ void AppServiceAppWindowLauncherController::OnInstanceUpdate(
(update.State() & apps::InstanceState::kDestroyed) == (update.State() & apps::InstanceState::kDestroyed) ==
apps::InstanceState::kUnknown) { apps::InstanceState::kUnknown) {
std::string app_id = update.AppId(); std::string app_id = update.AppId();
if (proxy_->AppRegistryCache().GetAppType(app_id) ==
apps::mojom::AppType::kCrostini ||
base::StartsWith(app_id, crostini::kCrostiniAppIdPrefix,
base::CompareCase::SENSITIVE)) {
window->SetProperty(aura::client::kAppType,
static_cast<int>(ash::AppType::CROSTINI_APP));
}
window->SetProperty(ash::kAppIDKey, update.AppId()); window->SetProperty(ash::kAppIDKey, update.AppId());
window->SetProperty(ash::kShelfIDKey, shelf_id.Serialize()); window->SetProperty(ash::kShelfIDKey, shelf_id.Serialize());
window->SetProperty<int>(ash::kShelfItemTypeKey, ash::TYPE_APP); window->SetProperty<int>(ash::kShelfItemTypeKey, ash::TYPE_APP);
......
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