#include "base/bind.h"
#include "base/files/file_path.h"
+#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/sys_info.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/app_mode/kiosk_app_data.h"
+#include "chrome/browser/chromeos/app_mode/kiosk_app_external_loader.h"
#include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h"
-#include "chrome/browser/chromeos/login/users/user_manager.h"
+#include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_factory.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/policy/device_local_account.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
-#include "chrome/browser/chromeos/settings/owner_key_util.h"
+#include "chrome/browser/extensions/external_loader.h"
#include "chrome/browser/extensions/external_provider_impl.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chromeos/chromeos_paths.h"
#include "chromeos/cryptohome/async_method_caller.h"
#include "chromeos/settings/cros_settings_names.h"
+#include "components/ownership/owner_key_util.h"
#include "content/public/browser/browser_thread.h"
+#include "extensions/common/extension_urls.h"
+
+#if !defined(USE_ATHENA)
+#include "chrome/browser/chromeos/app_mode/kiosk_external_updater.h"
+#endif
namespace chromeos {
// Check for presence of machine owner public key file.
void CheckOwnerFilePresence(bool *present) {
- scoped_refptr<OwnerKeyUtil> util = OwnerKeyUtil::Create();
- *present = util->IsPublicKeyPresent();
+ scoped_refptr<ownership::OwnerKeyUtil> util =
+ OwnerSettingsServiceChromeOSFactory::GetInstance()->GetOwnerKeyUtil();
+ *present = util.get() && util->IsPublicKeyPresent();
}
scoped_refptr<base::SequencedTaskRunner> GetBackgroundTaskRunner() {
const char KioskAppManager::kKeyAutoLoginState[] = "auto_login_state";
const char KioskAppManager::kIconCacheDir[] = "kiosk/icon";
const char KioskAppManager::kCrxCacheDir[] = "kiosk/crx";
+const char KioskAppManager::kCrxUnpackDir[] = "kiosk_unpack";
// static
static base::LazyInstance<KioskAppManager> instance = LAZY_INSTANCE_INITIALIZER;
device_local_accounts.push_back(policy::DeviceLocalAccount(
policy::DeviceLocalAccount::TYPE_KIOSK_APP,
GenerateKioskAppAccountId(app_id),
- app_id));
+ app_id,
+ std::string()));
policy::SetDeviceLocalAccounts(CrosSettings::Get(), device_local_accounts);
}
app_data->LoadFromInstalledApp(profile, app);
}
+void KioskAppManager::RetryFailedAppDataFetch() {
+ for (size_t i = 0; i < apps_.size(); ++i) {
+ if (apps_[i]->status() == KioskAppData::STATUS_ERROR)
+ apps_[i]->Load();
+ }
+}
+
+bool KioskAppManager::HasCachedCrx(const std::string& app_id) const {
+ base::FilePath crx_path;
+ std::string version;
+ return GetCachedCrx(app_id, &crx_path, &version);
+}
+
+bool KioskAppManager::GetCachedCrx(const std::string& app_id,
+ base::FilePath* file_path,
+ std::string* version) const {
+ return external_cache_->GetExtension(app_id, file_path, version);
+}
+
void KioskAppManager::AddObserver(KioskAppManagerObserver* observer) {
observers_.AddObserver(observer);
}
observers_.RemoveObserver(observer);
}
-KioskAppManager::KioskAppManager() : ownership_established_(false) {
+extensions::ExternalLoader* KioskAppManager::CreateExternalLoader() {
+ if (external_loader_created_) {
+ NOTREACHED();
+ return NULL;
+ }
+ external_loader_created_ = true;
+ KioskAppExternalLoader* loader = new KioskAppExternalLoader();
+ external_loader_ = loader->AsWeakPtr();
+
+ return loader;
+}
+
+void KioskAppManager::InstallFromCache(const std::string& id) {
+ const base::DictionaryValue* extension = NULL;
+ if (external_cache_->cached_extensions()->GetDictionary(id, &extension)) {
+ scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue);
+ base::DictionaryValue* extension_copy = extension->DeepCopy();
+ prefs->Set(id, extension_copy);
+ external_loader_->SetCurrentAppExtensions(prefs.Pass());
+ } else {
+ LOG(ERROR) << "Can't find app in the cached externsions"
+ << " id = " << id;
+ }
+}
+
+void KioskAppManager::UpdateExternalCache() {
+ UpdateAppData();
+}
+
+void KioskAppManager::OnKioskAppCacheUpdated(const std::string& app_id) {
+ FOR_EACH_OBSERVER(
+ KioskAppManagerObserver, observers_, OnKioskAppCacheUpdated(app_id));
+}
+
+void KioskAppManager::OnKioskAppExternalUpdateComplete(bool success) {
+ FOR_EACH_OBSERVER(KioskAppManagerObserver,
+ observers_,
+ OnKioskAppExternalUpdateComplete(success));
+}
+
+void KioskAppManager::PutValidatedExternalExtension(
+ const std::string& app_id,
+ const base::FilePath& crx_path,
+ const std::string& version,
+ const ExternalCache::PutExternalExtensionCallback& callback) {
+ external_cache_->PutExternalExtension(app_id, crx_path, version, callback);
+}
+
+KioskAppManager::KioskAppManager()
+ : ownership_established_(false), external_loader_created_(false) {
base::FilePath cache_dir;
GetCrxCacheDir(&cache_dir);
external_cache_.reset(
this,
true /* always_check_updates */,
false /* wait_for_cache_initialization */));
-
UpdateAppData();
local_accounts_subscription_ =
CrosSettings::Get()->AddSettingsObserver(
KioskAppManager::~KioskAppManager() {}
+void KioskAppManager::MonitorKioskExternalUpdate() {
+#if !defined(USE_ATHENA)
+ base::FilePath cache_dir;
+ GetCrxCacheDir(&cache_dir);
+ base::FilePath unpack_dir;
+ GetCrxUnpackDir(&unpack_dir);
+ usb_stick_updater_.reset(new KioskExternalUpdater(
+ GetBackgroundTaskRunner(), cache_dir, unpack_dir));
+#endif
+}
+
void KioskAppManager::CleanUp() {
local_accounts_subscription_.reset();
local_account_auto_login_id_subscription_.reset();
apps_.clear();
+#if !defined(USE_ATHENA)
+ usb_stick_updater_.reset();
+#endif
external_cache_.reset();
}
if (it->account_id == auto_login_account_id)
auto_launch_app_id_ = it->kiosk_app_id;
- // TODO(mnissler): Support non-CWS update URLs.
-
std::map<std::string, KioskAppData*>::iterator old_it =
old_apps.find(it->kiosk_app_id);
if (old_it != old_apps.end()) {
apps_.push_back(old_it->second);
old_apps.erase(old_it);
} else {
- KioskAppData* new_app =
- new KioskAppData(this, it->kiosk_app_id, it->user_id);
+ KioskAppData* new_app = new KioskAppData(
+ this, it->kiosk_app_id, it->user_id, GURL(it->kiosk_app_update_url));
apps_.push_back(new_app); // Takes ownership of |new_app|.
new_app->Load();
}
// Request external_cache_ to download new apps and update the existing
// apps.
scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue);
- for (size_t i = 0; i < apps_.size(); ++i)
- prefs->Set(apps_[i]->app_id(), new base::DictionaryValue);
+ for (size_t i = 0; i < apps_.size(); ++i) {
+ scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue);
+
+ if (apps_[i]->update_url().is_valid()) {
+ entry->SetString(extensions::ExternalProviderImpl::kExternalUpdateUrl,
+ apps_[i]->update_url().spec());
+ } else {
+ entry->SetString(extensions::ExternalProviderImpl::kExternalUpdateUrl,
+ extension_urls::GetWebstoreUpdateUrl().spec());
+ }
+
+ prefs->Set(apps_[i]->app_id(), entry.release());
+ }
external_cache_->UpdateExtensionsList(prefs.Pass());
+ RetryFailedAppDataFetch();
+
FOR_EACH_OBSERVER(KioskAppManagerObserver, observers_,
OnKioskAppsSettingsChanged());
}
KioskAppData* app_data = GetAppDataMutable(id);
if (!app_data)
return;
- OnKioskAppDataChanged(id);
+ FOR_EACH_OBSERVER(KioskAppManagerObserver,
+ observers_,
+ OnKioskExtensionLoadedInCache(id));
+
}
void KioskAppManager::OnExtensionDownloadFailed(
KioskAppData* app_data = GetAppDataMutable(id);
if (!app_data)
return;
- OnKioskAppDataLoadFailure(id);
+ FOR_EACH_OBSERVER(KioskAppManagerObserver,
+ observers_,
+ OnKioskExtensionDownloadFailed(id));
}
KioskAppManager::AutoLoginState KioskAppManager::GetAutoLoginState() const {
*cache_dir = user_data_dir.AppendASCII(kCrxCacheDir);
}
-bool KioskAppManager::GetCachedCrx(const std::string& app_id,
- base::FilePath* file_path,
- std::string* version) {
- return external_cache_->GetExtension(app_id, file_path, version);
+void KioskAppManager::GetCrxUnpackDir(base::FilePath* unpack_dir) {
+ base::FilePath temp_dir;
+ base::GetTempDir(&temp_dir);
+ *unpack_dir = temp_dir.AppendASCII(kCrxUnpackDir);
}
} // namespace chromeos