Commit ed90a677 authored by poromov's avatar poromov Committed by Commit bot

arc: Stop/start ARC++ kiosk app when maintenance session started/finished.

ARC Kiosk bridge is also moved from components/arc into chrome/browser/chromeos/arc
because it uses parts of chrome/browser/*

BUG=b/32370502

Review-Url: https://codereview.chromium.org/2524673003
Cr-Commit-Position: refs/heads/master@{#439775}
parent 78811128
...@@ -15,9 +15,8 @@ ...@@ -15,9 +15,8 @@
namespace chromeos { namespace chromeos {
// static // static
ArcKioskAppService* ArcKioskAppService::Create(Profile* profile, ArcKioskAppService* ArcKioskAppService::Create(Profile* profile) {
ArcAppListPrefs* prefs) { return new ArcKioskAppService(profile);
return new ArcKioskAppService(profile, prefs);
} }
// static // static
...@@ -25,6 +24,11 @@ ArcKioskAppService* ArcKioskAppService::Get(content::BrowserContext* context) { ...@@ -25,6 +24,11 @@ ArcKioskAppService* ArcKioskAppService::Get(content::BrowserContext* context) {
return ArcKioskAppServiceFactory::GetForBrowserContext(context); return ArcKioskAppServiceFactory::GetForBrowserContext(context);
} }
void ArcKioskAppService::Shutdown() {
ArcAppListPrefs::Get(profile_)->RemoveObserver(this);
app_manager_->RemoveObserver(this);
}
void ArcKioskAppService::OnAppRegistered( void ArcKioskAppService::OnAppRegistered(
const std::string& app_id, const std::string& app_id,
const ArcAppListPrefs::AppInfo& app_info) { const ArcAppListPrefs::AppInfo& app_info) {
...@@ -62,14 +66,21 @@ void ArcKioskAppService::OnTaskDestroyed(int32_t task_id) { ...@@ -62,14 +66,21 @@ void ArcKioskAppService::OnTaskDestroyed(int32_t task_id) {
} }
} }
ArcKioskAppService::ArcKioskAppService(Profile* profile, ArcAppListPrefs* prefs) void ArcKioskAppService::OnMaintenanceSessionCreated() {
: profile_(profile), prefs_(prefs) { maintenance_session_running_ = true;
if (prefs_) PreconditionsChanged();
prefs_->AddObserver(this); }
void ArcKioskAppService::OnMaintenanceSessionFinished() {
maintenance_session_running_ = false;
PreconditionsChanged();
}
ArcKioskAppService::ArcKioskAppService(Profile* profile) : profile_(profile) {
ArcAppListPrefs::Get(profile_)->AddObserver(this);
app_manager_ = ArcKioskAppManager::Get(); app_manager_ = ArcKioskAppManager::Get();
if (app_manager_) { DCHECK(app_manager_);
app_manager_->AddObserver(this); app_manager_->AddObserver(this);
}
pref_change_registrar_.reset(new PrefChangeRegistrar()); pref_change_registrar_.reset(new PrefChangeRegistrar());
pref_change_registrar_->Init(profile_->GetPrefs()); pref_change_registrar_->Init(profile_->GetPrefs());
// Try to start/stop kiosk app on policy compliance state change. // Try to start/stop kiosk app on policy compliance state change.
...@@ -80,22 +91,19 @@ ArcKioskAppService::ArcKioskAppService(Profile* profile, ArcAppListPrefs* prefs) ...@@ -80,22 +91,19 @@ ArcKioskAppService::ArcKioskAppService(Profile* profile, ArcAppListPrefs* prefs)
PreconditionsChanged(); PreconditionsChanged();
} }
ArcKioskAppService::~ArcKioskAppService() { ArcKioskAppService::~ArcKioskAppService() = default;
if (prefs_)
prefs_->RemoveObserver(this);
if (app_manager_)
app_manager_->RemoveObserver(this);
}
void ArcKioskAppService::PreconditionsChanged() { void ArcKioskAppService::PreconditionsChanged() {
app_id_ = GetAppId(); app_id_ = GetAppId();
if (app_id_.empty()) if (app_id_.empty())
return; return;
app_info_ = prefs_->GetApp(app_id_); app_info_ = ArcAppListPrefs::Get(profile_)->GetApp(app_id_);
if (app_info_ && app_info_->ready && if (app_info_ && app_info_->ready &&
profile_->GetPrefs()->GetBoolean(prefs::kArcPolicyCompliant)) { profile_->GetPrefs()->GetBoolean(prefs::kArcPolicyCompliant) &&
!maintenance_session_running_) {
if (!app_launcher_) if (!app_launcher_)
app_launcher_.reset(new ArcKioskAppLauncher(profile_, prefs_, app_id_)); app_launcher_.reset(new ArcKioskAppLauncher(
profile_, ArcAppListPrefs::Get(profile_), app_id_));
} else if (task_id_ != -1) { } else if (task_id_ != -1) {
arc::CloseTask(task_id_); arc::CloseTask(task_id_);
} }
...@@ -108,7 +116,8 @@ std::string ArcKioskAppService::GetAppId() { ...@@ -108,7 +116,8 @@ std::string ArcKioskAppService::GetAppId() {
if (!app) if (!app)
return std::string(); return std::string();
std::unordered_set<std::string> app_ids = std::unordered_set<std::string> app_ids =
prefs_->GetAppsForPackage(app->app_info().package_name()); ArcAppListPrefs::Get(profile_)->GetAppsForPackage(
app->app_info().package_name());
if (app_ids.empty()) if (app_ids.empty())
return std::string(); return std::string();
// TODO(poromov@): Choose appropriate app id to launch. See // TODO(poromov@): Choose appropriate app id to launch. See
......
...@@ -9,9 +9,15 @@ ...@@ -9,9 +9,15 @@
#include "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_launcher.h" #include "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_launcher.h"
#include "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_manager.h" #include "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_manager.h"
#include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
#include "components/arc/kiosk/arc_kiosk_bridge.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "components/prefs/pref_change_registrar.h" #include "components/prefs/pref_change_registrar.h"
#include "content/public/browser/browser_context.h"
class Profile;
namespace content {
class BrowserContext;
} // namespace content
namespace chromeos { namespace chromeos {
...@@ -24,11 +30,15 @@ namespace chromeos { ...@@ -24,11 +30,15 @@ namespace chromeos {
class ArcKioskAppService class ArcKioskAppService
: public KeyedService, : public KeyedService,
public ArcAppListPrefs::Observer, public ArcAppListPrefs::Observer,
public ArcKioskAppManager::ArcKioskAppManagerObserver { public ArcKioskAppManager::ArcKioskAppManagerObserver,
public arc::ArcKioskBridge::Delegate {
public: public:
static ArcKioskAppService* Create(Profile* profile, ArcAppListPrefs* prefs); static ArcKioskAppService* Create(Profile* profile);
static ArcKioskAppService* Get(content::BrowserContext* context); static ArcKioskAppService* Get(content::BrowserContext* context);
// KeyedService overrides
void Shutdown() override;
// ArcAppListPrefs::Observer overrides // ArcAppListPrefs::Observer overrides
void OnAppRegistered(const std::string& app_id, void OnAppRegistered(const std::string& app_id,
const ArcAppListPrefs::AppInfo& app_info) override; const ArcAppListPrefs::AppInfo& app_info) override;
...@@ -43,8 +53,12 @@ class ArcKioskAppService ...@@ -43,8 +53,12 @@ class ArcKioskAppService
// ArcKioskAppManager::Observer overrides // ArcKioskAppManager::Observer overrides
void OnArcKioskAppsChanged() override; void OnArcKioskAppsChanged() override;
// ArcKioskBridge::Delegate overrides
void OnMaintenanceSessionCreated() override;
void OnMaintenanceSessionFinished() override;
private: private:
ArcKioskAppService(Profile* profile, ArcAppListPrefs* prefs); explicit ArcKioskAppService(Profile* profile);
~ArcKioskAppService() override; ~ArcKioskAppService() override;
std::string GetAppId(); std::string GetAppId();
...@@ -52,7 +66,7 @@ class ArcKioskAppService ...@@ -52,7 +66,7 @@ class ArcKioskAppService
void PreconditionsChanged(); void PreconditionsChanged();
Profile* const profile_; Profile* const profile_;
ArcAppListPrefs* const prefs_; bool maintenance_session_running_ = false;
ArcKioskAppManager* app_manager_; ArcKioskAppManager* app_manager_;
std::string app_id_; std::string app_id_;
std::unique_ptr<ArcAppListPrefs::AppInfo> app_info_; std::unique_ptr<ArcAppListPrefs::AppInfo> app_info_;
......
...@@ -37,7 +37,7 @@ KeyedService* ArcKioskAppServiceFactory::BuildServiceInstanceFor( ...@@ -37,7 +37,7 @@ KeyedService* ArcKioskAppServiceFactory::BuildServiceInstanceFor(
Profile* profile = static_cast<Profile*>(context); Profile* profile = static_cast<Profile*>(context);
DCHECK(profile); DCHECK(profile);
return ArcKioskAppService::Create(profile, ArcAppListPrefs::Get(profile)); return ArcKioskAppService::Create(profile);
} }
} // namespace chromeos } // namespace chromeos
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service.h"
#include "chrome/browser/chromeos/arc/arc_auth_service.h" #include "chrome/browser/chromeos/arc/arc_auth_service.h"
#include "chrome/browser/chromeos/arc/arc_session_manager.h" #include "chrome/browser/chromeos/arc/arc_session_manager.h"
#include "chrome/browser/chromeos/arc/downloads_watcher/arc_downloads_watcher_service.h" #include "chrome/browser/chromeos/arc/downloads_watcher/arc_downloads_watcher_service.h"
...@@ -21,6 +22,7 @@ ...@@ -21,6 +22,7 @@
#include "chrome/browser/chromeos/arc/tts/arc_tts_service.h" #include "chrome/browser/chromeos/arc/tts/arc_tts_service.h"
#include "chrome/browser/chromeos/arc/video/gpu_arc_video_service_host.h" #include "chrome/browser/chromeos/arc/video/gpu_arc_video_service_host.h"
#include "chrome/browser/chromeos/arc/wallpaper/arc_wallpaper_service.h" #include "chrome/browser/chromeos/arc/wallpaper/arc_wallpaper_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h" #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "components/arc/arc_service_manager.h" #include "components/arc/arc_service_manager.h"
#include "components/arc/audio/arc_audio_bridge.h" #include "components/arc/audio/arc_audio_bridge.h"
...@@ -37,6 +39,7 @@ ...@@ -37,6 +39,7 @@
#include "components/arc/power/arc_power_bridge.h" #include "components/arc/power/arc_power_bridge.h"
#include "components/arc/storage_manager/arc_storage_manager.h" #include "components/arc/storage_manager/arc_storage_manager.h"
#include "components/prefs/pref_member.h" #include "components/prefs/pref_member.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "ui/arc/notification/arc_notification_manager.h" #include "ui/arc/notification/arc_notification_manager.h"
...@@ -108,8 +111,6 @@ void ArcServiceLauncher::Initialize() { ...@@ -108,8 +111,6 @@ void ArcServiceLauncher::Initialize() {
arc_service_manager_->AddService(std::move(intent_helper)); arc_service_manager_->AddService(std::move(intent_helper));
arc_service_manager_->AddService( arc_service_manager_->AddService(
base::MakeUnique<ArcImeService>(arc_bridge_service)); base::MakeUnique<ArcImeService>(arc_bridge_service));
arc_service_manager_->AddService(
base::MakeUnique<ArcKioskBridge>(arc_bridge_service));
arc_service_manager_->AddService( arc_service_manager_->AddService(
base::MakeUnique<ArcMetricsService>(arc_bridge_service)); base::MakeUnique<ArcMetricsService>(arc_bridge_service));
arc_service_manager_->AddService( arc_service_manager_->AddService(
...@@ -141,6 +142,16 @@ void ArcServiceLauncher::OnPrimaryUserProfilePrepared(Profile* profile) { ...@@ -141,6 +142,16 @@ void ArcServiceLauncher::OnPrimaryUserProfilePrepared(Profile* profile) {
arc_service_manager_->AddService(base::MakeUnique<ArcNotificationManager>( arc_service_manager_->AddService(base::MakeUnique<ArcNotificationManager>(
arc_service_manager_->arc_bridge_service(), arc_service_manager_->arc_bridge_service(),
multi_user_util::GetAccountIdFromProfile(profile))); multi_user_util::GetAccountIdFromProfile(profile)));
// Kiosk apps should be run only for kiosk sessions.
if (user_manager::UserManager::Get()->IsLoggedInAsArcKioskApp()) {
// ArcKioskAppService is BrowserContextKeyedService so that it's destroyed
// on destroying the Profile, that is after ArcServiceLauncher::Shutdown().
arc_service_manager_->AddService(base::MakeUnique<ArcKioskBridge>(
arc_service_manager_->arc_bridge_service(),
chromeos::ArcKioskAppService::Get(profile)));
}
arc_session_manager_->OnPrimaryUserProfilePrepared(profile); arc_session_manager_->OnPrimaryUserProfilePrepared(profile);
} }
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/task_runner_util.h" #include "base/task_runner_util.h"
#include "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service.h"
#include "chrome/browser/chromeos/arc/policy/arc_policy_util.h" #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_list_service.h" #include "chrome/browser/ui/app_list/app_list_service.h"
...@@ -668,12 +667,6 @@ void ArcAppListPrefs::OnInstanceReady() { ...@@ -668,12 +667,6 @@ void ArcAppListPrefs::OnInstanceReady() {
// Note, sync_service_ may be nullptr in testing. // Note, sync_service_ may be nullptr in testing.
sync_service_ = arc::ArcPackageSyncableService::Get(profile_); sync_service_ = arc::ArcPackageSyncableService::Get(profile_);
// Kiosk apps should be run only for kiosk sessions.
if (user_manager::UserManager::Get()->IsLoggedInAsArcKioskApp()) {
kiosk_app_service_ = chromeos::ArcKioskAppService::Get(profile_);
DCHECK(kiosk_app_service_);
}
// In some tests app_instance may not be set. // In some tests app_instance may not be set.
if (!app_instance) if (!app_instance)
return; return;
...@@ -693,7 +686,6 @@ void ArcAppListPrefs::OnInstanceClosed() { ...@@ -693,7 +686,6 @@ void ArcAppListPrefs::OnInstanceClosed() {
sync_service_ = nullptr; sync_service_ = nullptr;
} }
kiosk_app_service_ = nullptr;
is_initialized_ = false; is_initialized_ = false;
package_list_initial_refreshed_ = false; package_list_initial_refreshed_ = false;
} }
......
...@@ -34,10 +34,6 @@ namespace arc { ...@@ -34,10 +34,6 @@ namespace arc {
class ArcPackageSyncableService; class ArcPackageSyncableService;
} // namespace arc } // namespace arc
namespace chromeos {
class ArcKioskAppService;
} // namespace chromeos
namespace content { namespace content {
class BrowserContext; class BrowserContext;
} // namespace content } // namespace content
...@@ -381,8 +377,6 @@ class ArcAppListPrefs ...@@ -381,8 +377,6 @@ class ArcAppListPrefs
bool package_list_initial_refreshed_ = false; bool package_list_initial_refreshed_ = false;
arc::ArcPackageSyncableService* sync_service_ = nullptr; arc::ArcPackageSyncableService* sync_service_ = nullptr;
// Track ARC kiosk app and auto-launches it if needed.
chromeos::ArcKioskAppService* kiosk_app_service_ = nullptr;
mojo::Binding<arc::mojom::AppHost> binding_; mojo::Binding<arc::mojom::AppHost> binding_;
......
...@@ -5,12 +5,13 @@ ...@@ -5,12 +5,13 @@
#include "components/arc/kiosk/arc_kiosk_bridge.h" #include "components/arc/kiosk/arc_kiosk_bridge.h"
#include "components/arc/arc_bridge_service.h" #include "components/arc/arc_bridge_service.h"
#include "components/arc/arc_service_manager.h"
namespace arc { namespace arc {
ArcKioskBridge::ArcKioskBridge(ArcBridgeService* bridge_service) ArcKioskBridge::ArcKioskBridge(ArcBridgeService* bridge_service,
: ArcService(bridge_service), binding_(this) { Delegate* delegate)
: ArcService(bridge_service), binding_(this), delegate_(delegate) {
DCHECK(delegate_);
arc_bridge_service()->kiosk()->AddObserver(this); arc_bridge_service()->kiosk()->AddObserver(this);
} }
...@@ -26,12 +27,13 @@ void ArcKioskBridge::OnInstanceReady() { ...@@ -26,12 +27,13 @@ void ArcKioskBridge::OnInstanceReady() {
} }
void ArcKioskBridge::OnMaintenanceSessionCreated(int32_t session_id) { void ArcKioskBridge::OnMaintenanceSessionCreated(int32_t session_id) {
delegate_->OnMaintenanceSessionCreated();
// TODO(poromov@) Show appropriate splash screen. // TODO(poromov@) Show appropriate splash screen.
} }
void ArcKioskBridge::OnMaintenanceSessionFinished(int32_t session_id, void ArcKioskBridge::OnMaintenanceSessionFinished(int32_t session_id,
bool success) { bool success) {
// TODO(poromov@) Start kiosk app. delegate_->OnMaintenanceSessionFinished();
} }
} // namespace arc } // namespace arc
...@@ -21,7 +21,16 @@ class ArcKioskBridge : public ArcService, ...@@ -21,7 +21,16 @@ class ArcKioskBridge : public ArcService,
public InstanceHolder<mojom::KioskInstance>::Observer, public InstanceHolder<mojom::KioskInstance>::Observer,
public mojom::KioskHost { public mojom::KioskHost {
public: public:
explicit ArcKioskBridge(ArcBridgeService* bridge_service); // Received IPCs are passed to this delegate.
class Delegate {
public:
virtual ~Delegate() = default;
virtual void OnMaintenanceSessionCreated() = 0;
virtual void OnMaintenanceSessionFinished() = 0;
};
// |delegate| should be alive while the ArcKioskBridge instance is alive.
ArcKioskBridge(ArcBridgeService* bridge_service, Delegate* delegate);
~ArcKioskBridge() override; ~ArcKioskBridge() override;
// InstanceHolder<mojom::KioskInstance>::Observer overrides. // InstanceHolder<mojom::KioskInstance>::Observer overrides.
...@@ -33,6 +42,7 @@ class ArcKioskBridge : public ArcService, ...@@ -33,6 +42,7 @@ class ArcKioskBridge : public ArcService,
private: private:
mojo::Binding<mojom::KioskHost> binding_; mojo::Binding<mojom::KioskHost> binding_;
Delegate* const delegate_;
DISALLOW_COPY_AND_ASSIGN(ArcKioskBridge); DISALLOW_COPY_AND_ASSIGN(ArcKioskBridge);
}; };
......
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