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 @@
namespace chromeos {
// static
ArcKioskAppService* ArcKioskAppService::Create(Profile* profile,
ArcAppListPrefs* prefs) {
return new ArcKioskAppService(profile, prefs);
ArcKioskAppService* ArcKioskAppService::Create(Profile* profile) {
return new ArcKioskAppService(profile);
}
// static
......@@ -25,6 +24,11 @@ ArcKioskAppService* ArcKioskAppService::Get(content::BrowserContext* context) {
return ArcKioskAppServiceFactory::GetForBrowserContext(context);
}
void ArcKioskAppService::Shutdown() {
ArcAppListPrefs::Get(profile_)->RemoveObserver(this);
app_manager_->RemoveObserver(this);
}
void ArcKioskAppService::OnAppRegistered(
const std::string& app_id,
const ArcAppListPrefs::AppInfo& app_info) {
......@@ -62,14 +66,21 @@ void ArcKioskAppService::OnTaskDestroyed(int32_t task_id) {
}
}
ArcKioskAppService::ArcKioskAppService(Profile* profile, ArcAppListPrefs* prefs)
: profile_(profile), prefs_(prefs) {
if (prefs_)
prefs_->AddObserver(this);
void ArcKioskAppService::OnMaintenanceSessionCreated() {
maintenance_session_running_ = true;
PreconditionsChanged();
}
void ArcKioskAppService::OnMaintenanceSessionFinished() {
maintenance_session_running_ = false;
PreconditionsChanged();
}
ArcKioskAppService::ArcKioskAppService(Profile* profile) : profile_(profile) {
ArcAppListPrefs::Get(profile_)->AddObserver(this);
app_manager_ = ArcKioskAppManager::Get();
if (app_manager_) {
app_manager_->AddObserver(this);
}
DCHECK(app_manager_);
app_manager_->AddObserver(this);
pref_change_registrar_.reset(new PrefChangeRegistrar());
pref_change_registrar_->Init(profile_->GetPrefs());
// Try to start/stop kiosk app on policy compliance state change.
......@@ -80,22 +91,19 @@ ArcKioskAppService::ArcKioskAppService(Profile* profile, ArcAppListPrefs* prefs)
PreconditionsChanged();
}
ArcKioskAppService::~ArcKioskAppService() {
if (prefs_)
prefs_->RemoveObserver(this);
if (app_manager_)
app_manager_->RemoveObserver(this);
}
ArcKioskAppService::~ArcKioskAppService() = default;
void ArcKioskAppService::PreconditionsChanged() {
app_id_ = GetAppId();
if (app_id_.empty())
return;
app_info_ = prefs_->GetApp(app_id_);
app_info_ = ArcAppListPrefs::Get(profile_)->GetApp(app_id_);
if (app_info_ && app_info_->ready &&
profile_->GetPrefs()->GetBoolean(prefs::kArcPolicyCompliant)) {
profile_->GetPrefs()->GetBoolean(prefs::kArcPolicyCompliant) &&
!maintenance_session_running_) {
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) {
arc::CloseTask(task_id_);
}
......@@ -108,7 +116,8 @@ std::string ArcKioskAppService::GetAppId() {
if (!app)
return std::string();
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())
return std::string();
// TODO(poromov@): Choose appropriate app id to launch. See
......
......@@ -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_manager.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/prefs/pref_change_registrar.h"
#include "content/public/browser/browser_context.h"
class Profile;
namespace content {
class BrowserContext;
} // namespace content
namespace chromeos {
......@@ -24,11 +30,15 @@ namespace chromeos {
class ArcKioskAppService
: public KeyedService,
public ArcAppListPrefs::Observer,
public ArcKioskAppManager::ArcKioskAppManagerObserver {
public ArcKioskAppManager::ArcKioskAppManagerObserver,
public arc::ArcKioskBridge::Delegate {
public:
static ArcKioskAppService* Create(Profile* profile, ArcAppListPrefs* prefs);
static ArcKioskAppService* Create(Profile* profile);
static ArcKioskAppService* Get(content::BrowserContext* context);
// KeyedService overrides
void Shutdown() override;
// ArcAppListPrefs::Observer overrides
void OnAppRegistered(const std::string& app_id,
const ArcAppListPrefs::AppInfo& app_info) override;
......@@ -43,8 +53,12 @@ class ArcKioskAppService
// ArcKioskAppManager::Observer overrides
void OnArcKioskAppsChanged() override;
// ArcKioskBridge::Delegate overrides
void OnMaintenanceSessionCreated() override;
void OnMaintenanceSessionFinished() override;
private:
ArcKioskAppService(Profile* profile, ArcAppListPrefs* prefs);
explicit ArcKioskAppService(Profile* profile);
~ArcKioskAppService() override;
std::string GetAppId();
......@@ -52,7 +66,7 @@ class ArcKioskAppService
void PreconditionsChanged();
Profile* const profile_;
ArcAppListPrefs* const prefs_;
bool maintenance_session_running_ = false;
ArcKioskAppManager* app_manager_;
std::string app_id_;
std::unique_ptr<ArcAppListPrefs::AppInfo> app_info_;
......
......@@ -37,7 +37,7 @@ KeyedService* ArcKioskAppServiceFactory::BuildServiceInstanceFor(
Profile* profile = static_cast<Profile*>(context);
DCHECK(profile);
return ArcKioskAppService::Create(profile, ArcAppListPrefs::Get(profile));
return ArcKioskAppService::Create(profile);
}
} // namespace chromeos
......@@ -8,6 +8,7 @@
#include "base/logging.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_session_manager.h"
#include "chrome/browser/chromeos/arc/downloads_watcher/arc_downloads_watcher_service.h"
......@@ -21,6 +22,7 @@
#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/wallpaper/arc_wallpaper_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "components/arc/arc_service_manager.h"
#include "components/arc/audio/arc_audio_bridge.h"
......@@ -37,6 +39,7 @@
#include "components/arc/power/arc_power_bridge.h"
#include "components/arc/storage_manager/arc_storage_manager.h"
#include "components/prefs/pref_member.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/browser_thread.h"
#include "ui/arc/notification/arc_notification_manager.h"
......@@ -108,8 +111,6 @@ void ArcServiceLauncher::Initialize() {
arc_service_manager_->AddService(std::move(intent_helper));
arc_service_manager_->AddService(
base::MakeUnique<ArcImeService>(arc_bridge_service));
arc_service_manager_->AddService(
base::MakeUnique<ArcKioskBridge>(arc_bridge_service));
arc_service_manager_->AddService(
base::MakeUnique<ArcMetricsService>(arc_bridge_service));
arc_service_manager_->AddService(
......@@ -141,6 +142,16 @@ void ArcServiceLauncher::OnPrimaryUserProfilePrepared(Profile* profile) {
arc_service_manager_->AddService(base::MakeUnique<ArcNotificationManager>(
arc_service_manager_->arc_bridge_service(),
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);
}
......
......@@ -12,7 +12,6 @@
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.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/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_list_service.h"
......@@ -668,12 +667,6 @@ void ArcAppListPrefs::OnInstanceReady() {
// Note, sync_service_ may be nullptr in testing.
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.
if (!app_instance)
return;
......@@ -693,7 +686,6 @@ void ArcAppListPrefs::OnInstanceClosed() {
sync_service_ = nullptr;
}
kiosk_app_service_ = nullptr;
is_initialized_ = false;
package_list_initial_refreshed_ = false;
}
......
......@@ -34,10 +34,6 @@ namespace arc {
class ArcPackageSyncableService;
} // namespace arc
namespace chromeos {
class ArcKioskAppService;
} // namespace chromeos
namespace content {
class BrowserContext;
} // namespace content
......@@ -381,8 +377,6 @@ class ArcAppListPrefs
bool package_list_initial_refreshed_ = false;
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_;
......
......@@ -5,12 +5,13 @@
#include "components/arc/kiosk/arc_kiosk_bridge.h"
#include "components/arc/arc_bridge_service.h"
#include "components/arc/arc_service_manager.h"
namespace arc {
ArcKioskBridge::ArcKioskBridge(ArcBridgeService* bridge_service)
: ArcService(bridge_service), binding_(this) {
ArcKioskBridge::ArcKioskBridge(ArcBridgeService* bridge_service,
Delegate* delegate)
: ArcService(bridge_service), binding_(this), delegate_(delegate) {
DCHECK(delegate_);
arc_bridge_service()->kiosk()->AddObserver(this);
}
......@@ -26,12 +27,13 @@ void ArcKioskBridge::OnInstanceReady() {
}
void ArcKioskBridge::OnMaintenanceSessionCreated(int32_t session_id) {
delegate_->OnMaintenanceSessionCreated();
// TODO(poromov@) Show appropriate splash screen.
}
void ArcKioskBridge::OnMaintenanceSessionFinished(int32_t session_id,
bool success) {
// TODO(poromov@) Start kiosk app.
delegate_->OnMaintenanceSessionFinished();
}
} // namespace arc
......@@ -21,7 +21,16 @@ class ArcKioskBridge : public ArcService,
public InstanceHolder<mojom::KioskInstance>::Observer,
public mojom::KioskHost {
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;
// InstanceHolder<mojom::KioskInstance>::Observer overrides.
......@@ -33,6 +42,7 @@ class ArcKioskBridge : public ArcService,
private:
mojo::Binding<mojom::KioskHost> binding_;
Delegate* const delegate_;
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