Chromium Code Reviews| Index: chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service.cc |
| diff --git a/chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service.cc b/chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service.cc |
| index 4c2aa1187891da7962ede8d519361e2666858b67..ed56783e504166b85e19e700fe3b48f7b401c143 100644 |
| --- a/chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service.cc |
| +++ b/chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service.cc |
| @@ -12,15 +12,25 @@ |
| #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| #include "chrome/common/pref_names.h" |
| #include "components/prefs/pref_service.h" |
| +#include "ui/base/layout.h" |
| +#include "ui/display/display.h" |
| +#include "ui/display/screen.h" |
| #include "ui/message_center/message_center.h" |
| #include "ui/message_center/notification_blocker.h" |
| namespace chromeos { |
| +namespace { |
| + |
| // Timeout maintenance session after 30 minutes. |
| constexpr base::TimeDelta kArcKioskMaintenanceSessionTimeout = |
| base::TimeDelta::FromMinutes(30); |
| +// ARC icon is available only for 48x48 dips. |
| +constexpr int kArcAppIconSizeInDp = 48; |
|
khmel
2017/03/27 22:56:32
nit: Probably it is better to use kGridIconDimensi
Sergey Poromov
2017/03/28 15:25:55
Done.
|
| + |
| +} // namespace |
| + |
| // Blocks all notifications for ARC Kiosk |
| class ArcKioskNotificationBlocker : public message_center::NotificationBlocker { |
| public: |
| @@ -134,6 +144,17 @@ void ArcKioskAppService::OnAppWindowLaunched() { |
| delegate_->OnAppWindowLaunched(); |
| } |
| +void ArcKioskAppService::OnIconUpdated(ArcAppIcon* icon) { |
| + if (icon == app_icon_.get()) { |
|
khmel
2017/03/27 22:56:32
nit: Do you expect OnIconUpdated is called for not
Sergey Poromov
2017/03/28 15:25:55
Yes, now it's requested mostly once at any time. I
|
| + if (icon->image_skia().isNull()) { |
| + app_icon_.release(); |
| + return; |
| + } |
| + app_manager_->UpdateNameAndIcon(app_info_->package_name, app_info_->name, |
| + app_icon_->image_skia()); |
| + } |
| +} |
| + |
| ArcKioskAppService::ArcKioskAppService(Profile* profile) : profile_(profile) { |
| ArcAppListPrefs::Get(profile_)->AddObserver(this); |
| app_manager_ = ArcKioskAppManager::Get(); |
| @@ -149,6 +170,16 @@ ArcKioskAppService::~ArcKioskAppService() { |
| maintenance_timeout_timer_.Stop(); |
| } |
| +void ArcKioskAppService::RequestNameAndIconUpdate() { |
| + // Request only once when app_icon_ is not initialized. |
| + if (!app_info_ || !app_info_->ready || app_icon_) |
| + return; |
| + app_icon_.reset(new ArcAppIcon(profile_, app_id_, kArcAppIconSizeInDp, this)); |
| + app_icon_->LoadForScaleFactor(ui::GetSupportedScaleFactor( |
| + display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor())); |
| + // Name and icon are updated when icon is loaded in OnIconUpdated() |
| +} |
| + |
| void ArcKioskAppService::PreconditionsChanged() { |
| app_id_ = GetAppId(); |
| if (app_id_.empty()) |
| @@ -161,17 +192,16 @@ void ArcKioskAppService::PreconditionsChanged() { |
| } else if (task_id_ != -1) { |
| arc::CloseTask(task_id_); |
| } |
| + RequestNameAndIconUpdate(); |
| } |
| std::string ArcKioskAppService::GetAppId() { |
| AccountId account_id = multi_user_util::GetAccountIdFromProfile(profile_); |
| - const ArcKioskAppManager::ArcKioskApp* app = |
| - app_manager_->GetAppByAccountId(account_id); |
| + const ArcKioskAppData* app = app_manager_->GetAppByAccountId(account_id); |
| if (!app) |
| return std::string(); |
| std::unordered_set<std::string> app_ids = |
| - ArcAppListPrefs::Get(profile_)->GetAppsForPackage( |
| - app->app_info().package_name()); |
| + ArcAppListPrefs::Get(profile_)->GetAppsForPackage(app->app_id()); |
| if (app_ids.empty()) |
| return std::string(); |
| // TODO(poromov@): Choose appropriate app id to launch. See |