1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ash/app_mode/kiosk_app_manager_base.h"
#include <string>
#include <vector>
#include "base/check.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/notreached.h"
#include "base/path_service.h"
#include "chrome/browser/ash/app_mode/kiosk_app_data_base.h"
#include "chrome/browser/ash/app_mode/kiosk_app_manager_observer.h"
#include "chrome/browser/ash/app_mode/kiosk_cryptohome_remover.h"
#include "chrome/browser/ash/policy/core/device_local_account.h"
#include "chrome/common/chrome_paths.h"
#include "chromeos/ash/components/settings/cros_settings_names.h"
#include "components/account_id/account_id.h"
namespace ash {
namespace {
// Sub directory under DIR_USER_DATA to store cached icon files.
const char kIconCacheDir[] = "kiosk/icon";
} // namespace
KioskAppManagerBase::KioskAppManagerBase() {
local_accounts_subscription_ = CrosSettings::Get()->AddSettingsObserver(
kAccountsPrefDeviceLocalAccounts,
base::BindRepeating(&KioskAppManagerBase::UpdateAppsFromPolicy,
weak_ptr_factory_.GetWeakPtr()));
local_account_auto_login_id_subscription_ =
CrosSettings::Get()->AddSettingsObserver(
kAccountsPrefDeviceLocalAccountAutoLoginId,
base::BindRepeating(&KioskAppManagerBase::UpdateAppsFromPolicy,
weak_ptr_factory_.GetWeakPtr()));
}
KioskAppManagerBase::~KioskAppManagerBase() = default;
KioskAppManagerBase::App::App(const KioskAppDataBase& app)
: app_id(app.app_id()),
account_id(app.account_id()),
name(app.name()),
icon(app.icon()) {}
KioskAppManagerBase::App::App() : account_id(EmptyAccountId()) {}
KioskAppManagerBase::App::App(const App&) = default;
KioskAppManagerBase::App::~App() = default;
base::FilePath KioskAppManagerBase::GetKioskAppIconCacheDir() {
base::FilePath user_data_dir;
bool has_dir = base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
DCHECK(has_dir);
return user_data_dir.AppendASCII(kIconCacheDir);
}
void KioskAppManagerBase::OnKioskAppDataChanged(const std::string& app_id) {
for (auto& observer : observers_) {
observer.OnKioskAppDataChanged(app_id);
}
}
void KioskAppManagerBase::OnKioskAppDataLoadFailure(const std::string& app_id) {
for (auto& observer : observers_) {
observer.OnKioskAppDataLoadFailure(app_id);
}
}
void KioskAppManagerBase::OnExternalCacheDamaged(const std::string& app_id) {
// Should be implemented only in those kiosks that use ExternalCache.
NOTREACHED();
}
bool KioskAppManagerBase::GetDisableBailoutShortcut() const {
bool enable;
if (CrosSettings::Get()->GetBoolean(
kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled, &enable)) {
return !enable;
}
return false;
}
void KioskAppManagerBase::NotifyKioskAppsChanged() const {
for (auto& observer : observers_) {
observer.OnKioskAppsSettingsChanged();
}
}
void KioskAppManagerBase::NotifySessionInitialized() const {
for (auto& observer : observers_) {
observer.OnKioskSessionInitialized();
}
}
void KioskAppManagerBase::NotifyAppRemoved(const std::string& app_id) const {
for (auto& observer : observers_) {
observer.OnKioskAppDataRemoved(app_id);
}
}
void KioskAppManagerBase::AddObserver(KioskAppManagerObserver* observer) {
observers_.AddObserver(observer);
}
void KioskAppManagerBase::RemoveObserver(KioskAppManagerObserver* observer) {
observers_.RemoveObserver(observer);
}
void KioskAppManagerBase::ClearRemovedApps(
const std::vector<const KioskAppDataBase*>& old_apps) const {
std::vector<AccountId> account_ids_to_remove;
account_ids_to_remove.reserve(old_apps.size());
for (const KioskAppDataBase* entry : old_apps) {
entry->ClearCache();
account_ids_to_remove.push_back(entry->account_id());
}
KioskCryptohomeRemover::RemoveCryptohomesAndExitIfNeeded(
account_ids_to_remove);
for (const KioskAppDataBase* entry : old_apps) {
NotifyAppRemoved(entry->app_id());
}
}
} // namespace ash
|