Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Unified Diff: chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service.cc

Issue 2496903003: arc: Add Arc Kiosk app service and ability to launch kiosk apps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@policy_comp_parse
Patch Set: Remove unnecessary null check. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..7b56ae3cf1c3ff0af96d76ff180438c0c0b85048
--- /dev/null
+++ b/chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service.cc
@@ -0,0 +1,121 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service.h>
+
+#include "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_service_factory.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
+#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
+#include "chrome/common/pref_names.h"
+#include "components/prefs/pref_service.h"
+
+namespace chromeos {
+
+ArcKioskAppService* ArcKioskAppService::Create(Profile* profile,
+ ArcAppListPrefs* prefs) {
+ return new ArcKioskAppService(profile, prefs);
+}
+
+ArcKioskAppService* ArcKioskAppService::Get(content::BrowserContext* context) {
+ return ArcKioskAppServiceFactory::GetForBrowserContext(context);
+}
+
+void ArcKioskAppService::OnAppRegistered(
+ const std::string& app_id,
+ const ArcAppListPrefs::AppInfo& app_info) {
+ if (app_id == app_id_) {
+ MaybeStartOrStopKioskApp();
+ }
+}
+
+void ArcKioskAppService::OnAppReadyChanged(const std::string& id, bool ready) {
+ if (id == app_id_) {
+ MaybeStartOrStopKioskApp();
+ }
+}
+
+void ArcKioskAppService::OnPackageListInitialRefreshed() {
+ // The app could already be registered.
+ app_id_ = GetAppId();
+ MaybeStartOrStopKioskApp();
+}
+
+void ArcKioskAppService::OnArcKioskAppsChanged() {
+ app_id_ = GetAppId();
+ MaybeStartOrStopKioskApp();
+}
+
+void ArcKioskAppService::OnTaskCreated(int32_t task_id,
+ const std::string& package_name,
+ const std::string& activity) {
+ // Store task id of the app to stop it later when needed.
+ if (app_info_ && package_name == app_info_->package_name &&
+ activity == app_info_->activity)
+ task_id_ = task_id;
+}
+
+void ArcKioskAppService::OnTaskDestroyed(int32_t task_id) {
+ if (task_id == task_id_) {
+ app_launcher_.reset();
+ task_id_ = -1;
+ }
+}
+
+ArcKioskAppService::ArcKioskAppService(Profile* profile, ArcAppListPrefs* prefs)
+ : profile_(profile), prefs_(prefs) {
+ if (prefs_)
+ prefs_->AddObserver(this);
+ app_manager_ = ArcKioskAppManager::Get();
+ if (app_manager_) {
+ app_manager_->AddObserver(this);
+ app_id_ = GetAppId();
+ }
+ pref_change_registrar_.reset(new PrefChangeRegistrar());
+ pref_change_registrar_->Init(profile_->GetPrefs());
+ // Try to start/stop kiosk app on policy compliance state change.
+ pref_change_registrar_->Add(
+ prefs::kArcPolicyCompliant,
+ base::Bind(&ArcKioskAppService::MaybeStartOrStopKioskApp,
+ base::Unretained(this)));
+ MaybeStartOrStopKioskApp();
+}
+
+ArcKioskAppService::~ArcKioskAppService() {
+ if (prefs_) {
+ prefs_->RemoveObserver(this);
+ }
+ if (app_manager_) {
+ app_manager_->RemoveObserver(this);
+ }
+}
+
+void ArcKioskAppService::MaybeStartOrStopKioskApp() {
+ app_info_ = std::move(prefs_->GetApp(app_id_));
+ if (app_info_ && app_info_->ready &&
+ profile_->GetPrefs()->GetBoolean(prefs::kArcPolicyCompliant)) {
Nikita (slow) 2016/11/16 15:33:28 nit: Same comment about policy compliance. On ARC+
Sergey Poromov 2016/11/16 15:54:09 This pref tracks whether ARC++ reported or not tha
+ if (!app_launcher_) {
+ app_launcher_.reset(new ArcKioskAppLauncher(profile_, app_id_));
+ }
+ } else if (task_id_ != -1) {
+ arc::CloseTask(task_id_);
+ }
+}
+
+std::string ArcKioskAppService::GetAppId() {
+ AccountId account_id = multi_user_util::GetAccountIdFromProfile(profile_);
+ const ArcKioskAppManager::ArcKioskApp* app =
+ app_manager_->GetAppByAccountId(account_id);
+ if (app) {
+ std::unordered_set<std::string> app_ids =
+ prefs_->GetAppsForPackage(app->app_info().package_name());
+ if (!app_ids.empty()) {
+ // TODO(poromov@): Choose appropriate app id to launch
Nikita (slow) 2016/11/16 15:33:28 nit: bug #?
Sergey Poromov 2016/11/16 15:54:09 Done.
+ return std::string(*app_ids.begin());
+ }
+ }
+ return std::string();
+}
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698