| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" | 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/barrier_closure.h" | 11 #include "base/barrier_closure.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 18 #include "base/stl_util.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/sys_info.h" | 19 #include "base/sys_info.h" |
| 20 #include "base/version.h" |
| 20 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/chromeos/app_mode/app_session.h" | 22 #include "chrome/browser/chromeos/app_mode/app_session.h" |
| 22 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" | 23 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" |
| 23 #include "chrome/browser/chromeos/app_mode/kiosk_app_external_loader.h" | 24 #include "chrome/browser/chromeos/app_mode/kiosk_app_external_loader.h" |
| 24 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" | 25 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" |
| 25 #include "chrome/browser/chromeos/app_mode/kiosk_external_updater.h" | 26 #include "chrome/browser/chromeos/app_mode/kiosk_external_updater.h" |
| 26 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" | 27 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
| 27 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact
ory.h" | 28 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact
ory.h" |
| 28 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 29 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 29 #include "chrome/browser/chromeos/policy/device_local_account.h" | 30 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 41 #include "chromeos/settings/cros_settings_names.h" | 42 #include "chromeos/settings/cros_settings_names.h" |
| 42 #include "components/ownership/owner_key_util.h" | 43 #include "components/ownership/owner_key_util.h" |
| 43 #include "components/prefs/pref_registry_simple.h" | 44 #include "components/prefs/pref_registry_simple.h" |
| 44 #include "components/prefs/pref_service.h" | 45 #include "components/prefs/pref_service.h" |
| 45 #include "components/prefs/scoped_user_pref_update.h" | 46 #include "components/prefs/scoped_user_pref_update.h" |
| 46 #include "components/signin/core/account_id/account_id.h" | 47 #include "components/signin/core/account_id/account_id.h" |
| 47 #include "components/user_manager/known_user.h" | 48 #include "components/user_manager/known_user.h" |
| 48 #include "components/user_manager/user_manager.h" | 49 #include "components/user_manager/user_manager.h" |
| 49 #include "content/public/browser/browser_thread.h" | 50 #include "content/public/browser/browser_thread.h" |
| 50 #include "extensions/common/extension_urls.h" | 51 #include "extensions/common/extension_urls.h" |
| 52 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" |
| 51 | 53 |
| 52 namespace chromeos { | 54 namespace chromeos { |
| 53 | 55 |
| 54 namespace { | 56 namespace { |
| 55 | 57 |
| 56 // Domain that is used for kiosk-app account IDs. | 58 // Domain that is used for kiosk-app account IDs. |
| 57 const char kKioskAppAccountDomain[] = "kiosk-apps"; | 59 const char kKioskAppAccountDomain[] = "kiosk-apps"; |
| 58 | 60 |
| 59 // Preference for the dictionary of user ids for which cryptohomes have to be | 61 // Preference for the dictionary of user ids for which cryptohomes have to be |
| 60 // removed upon browser restart. | 62 // removed upon browser restart. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 *present = util.get() && util->IsPublicKeyPresent(); | 129 *present = util.get() && util->IsPublicKeyPresent(); |
| 128 } | 130 } |
| 129 | 131 |
| 130 scoped_refptr<base::SequencedTaskRunner> GetBackgroundTaskRunner() { | 132 scoped_refptr<base::SequencedTaskRunner> GetBackgroundTaskRunner() { |
| 131 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); | 133 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); |
| 132 CHECK(pool); | 134 CHECK(pool); |
| 133 return pool->GetSequencedTaskRunnerWithShutdownBehavior( | 135 return pool->GetSequencedTaskRunnerWithShutdownBehavior( |
| 134 pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 136 pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 135 } | 137 } |
| 136 | 138 |
| 139 base::Version GetPlatformVersion() { |
| 140 int32_t major_version; |
| 141 int32_t minor_version; |
| 142 int32_t bugfix_version; |
| 143 base::SysInfo::OperatingSystemVersionNumbers(&major_version, &minor_version, |
| 144 &bugfix_version); |
| 145 return base::Version(base::StringPrintf("%d.%d.%d", major_version, |
| 146 minor_version, bugfix_version)); |
| 147 } |
| 148 |
| 137 } // namespace | 149 } // namespace |
| 138 | 150 |
| 139 // static | 151 // static |
| 140 const char KioskAppManager::kKioskDictionaryName[] = "kiosk"; | 152 const char KioskAppManager::kKioskDictionaryName[] = "kiosk"; |
| 141 const char KioskAppManager::kKeyApps[] = "apps"; | 153 const char KioskAppManager::kKeyApps[] = "apps"; |
| 142 const char KioskAppManager::kKeyAutoLoginState[] = "auto_login_state"; | 154 const char KioskAppManager::kKeyAutoLoginState[] = "auto_login_state"; |
| 143 const char KioskAppManager::kIconCacheDir[] = "kiosk/icon"; | 155 const char KioskAppManager::kIconCacheDir[] = "kiosk/icon"; |
| 144 const char KioskAppManager::kCrxCacheDir[] = "kiosk/crx"; | 156 const char KioskAppManager::kCrxCacheDir[] = "kiosk/crx"; |
| 145 const char KioskAppManager::kCrxUnpackDir[] = "kiosk_unpack"; | 157 const char KioskAppManager::kCrxUnpackDir[] = "kiosk_unpack"; |
| 146 | 158 |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 } | 573 } |
| 562 | 574 |
| 563 void KioskAppManager::PutValidatedExternalExtension( | 575 void KioskAppManager::PutValidatedExternalExtension( |
| 564 const std::string& app_id, | 576 const std::string& app_id, |
| 565 const base::FilePath& crx_path, | 577 const base::FilePath& crx_path, |
| 566 const std::string& version, | 578 const std::string& version, |
| 567 const ExternalCache::PutExternalExtensionCallback& callback) { | 579 const ExternalCache::PutExternalExtensionCallback& callback) { |
| 568 external_cache_->PutExternalExtension(app_id, crx_path, version, callback); | 580 external_cache_->PutExternalExtension(app_id, crx_path, version, callback); |
| 569 } | 581 } |
| 570 | 582 |
| 583 bool KioskAppManager::IsPlatformCompliant( |
| 584 const std::string& required_platform_version) const { |
| 585 // Empty required version is compliant with any platform version. |
| 586 if (required_platform_version.empty()) |
| 587 return true; |
| 588 |
| 589 // Not compliant for bad formatted required versions. |
| 590 const base::Version required_version(required_platform_version); |
| 591 if (!required_version.IsValid() || |
| 592 required_version.components().size() > 3u) { |
| 593 LOG(ERROR) << "Bad formatted required platform version: " |
| 594 << required_platform_version; |
| 595 return false; |
| 596 } |
| 597 |
| 598 // Not compliant if the platform version components do not match. |
| 599 const size_t count = required_version.components().size(); |
| 600 const base::Version platform_version = GetPlatformVersion(); |
| 601 const auto& platform_version_components = platform_version.components(); |
| 602 const auto& required_version_components = required_version.components(); |
| 603 for (size_t i = 0; i < count; ++i) { |
| 604 if (platform_version_components[i] != required_version_components[i]) |
| 605 return false; |
| 606 } |
| 607 |
| 608 return true; |
| 609 } |
| 610 |
| 611 bool KioskAppManager::IsPlatformCompliantWithApp( |
| 612 const extensions::Extension* app) const { |
| 613 // Compliant if the app is not the auto launched with zero delay app. |
| 614 if (currently_auto_launched_with_zero_delay_app_ != app->id()) |
| 615 return true; |
| 616 |
| 617 // Compliant if the app does not specify required platform version. |
| 618 const extensions::KioskModeInfo* info = extensions::KioskModeInfo::Get(app); |
| 619 if (info == nullptr) |
| 620 return true; |
| 621 |
| 622 return IsPlatformCompliant(info->required_platform_version); |
| 623 } |
| 624 |
| 571 KioskAppManager::KioskAppManager() | 625 KioskAppManager::KioskAppManager() |
| 572 : ownership_established_(false), | 626 : ownership_established_(false), |
| 573 external_loader_created_(false), | 627 external_loader_created_(false), |
| 574 secondary_app_external_loader_created_(false) { | 628 secondary_app_external_loader_created_(false) { |
| 575 base::FilePath cache_dir; | 629 base::FilePath cache_dir; |
| 576 GetCrxCacheDir(&cache_dir); | 630 GetCrxCacheDir(&cache_dir); |
| 577 external_cache_.reset( | 631 external_cache_.reset( |
| 578 new ExternalCache(cache_dir, | 632 new ExternalCache(cache_dir, |
| 579 g_browser_process->system_request_context(), | 633 g_browser_process->system_request_context(), |
| 580 GetBackgroundTaskRunner(), | 634 GetBackgroundTaskRunner(), |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 base::TimeDelta KioskAppManager::GetAutoLaunchDelay() const { | 865 base::TimeDelta KioskAppManager::GetAutoLaunchDelay() const { |
| 812 int delay; | 866 int delay; |
| 813 if (!CrosSettings::Get()->GetInteger( | 867 if (!CrosSettings::Get()->GetInteger( |
| 814 kAccountsPrefDeviceLocalAccountAutoLoginDelay, &delay)) { | 868 kAccountsPrefDeviceLocalAccountAutoLoginDelay, &delay)) { |
| 815 return base::TimeDelta(); // Default delay is 0ms. | 869 return base::TimeDelta(); // Default delay is 0ms. |
| 816 } | 870 } |
| 817 return base::TimeDelta::FromMilliseconds(delay); | 871 return base::TimeDelta::FromMilliseconds(delay); |
| 818 } | 872 } |
| 819 | 873 |
| 820 } // namespace chromeos | 874 } // namespace chromeos |
| OLD | NEW |