Chromium Code Reviews| Index: chrome/browser/chromeos/app_mode/kiosk_app_manager.cc |
| diff --git a/chrome/browser/chromeos/app_mode/kiosk_app_manager.cc b/chrome/browser/chromeos/app_mode/kiosk_app_manager.cc |
| index 8a6d7b0105b0f657940383047c50ef342bf45384..d364f8ac4687b969b334551515c49f6f3da13242 100644 |
| --- a/chrome/browser/chromeos/app_mode/kiosk_app_manager.cc |
| +++ b/chrome/browser/chromeos/app_mode/kiosk_app_manager.cc |
| @@ -15,8 +15,9 @@ |
| #include "base/logging.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/path_service.h" |
| -#include "base/stl_util.h" |
| +#include "base/strings/stringprintf.h" |
| #include "base/sys_info.h" |
| +#include "base/version.h" |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/chromeos/app_mode/app_session.h" |
| #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" |
| @@ -48,6 +49,7 @@ |
| #include "components/user_manager/user_manager.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "extensions/common/extension_urls.h" |
| +#include "extensions/common/manifest_handlers/kiosk_mode_info.h" |
| namespace chromeos { |
| @@ -134,6 +136,16 @@ scoped_refptr<base::SequencedTaskRunner> GetBackgroundTaskRunner() { |
| pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| } |
| +base::Version GetPlatformVersion() { |
| + int32_t major_version; |
| + int32_t minor_version; |
| + int32_t bugfix_version; |
| + base::SysInfo::OperatingSystemVersionNumbers(&major_version, &minor_version, |
| + &bugfix_version); |
| + return base::Version(base::StringPrintf("%d.%d.%d", major_version, |
| + minor_version, bugfix_version)); |
| +} |
| + |
| } // namespace |
| // static |
| @@ -568,6 +580,44 @@ void KioskAppManager::PutValidatedExternalExtension( |
| external_cache_->PutExternalExtension(app_id, crx_path, version, callback); |
| } |
| +bool KioskAppManager::IsPlatformCompliant( |
| + const std::string& required_platform_version) const { |
| + // Empty required version are compliant with any platform version. |
|
jennyz
2016/04/19 21:54:28
nit: are->is?
xiyuan
2016/04/19 22:28:45
Done.
|
| + if (required_platform_version.empty()) |
| + return true; |
| + |
| + // Not compliant for bad formatted required versions. |
| + const base::Version required_version(required_platform_version); |
| + if (!required_version.IsValid() || required_version.components().size() > 3u) |
|
jennyz
2016/04/19 21:54:28
Will it be helpful to add some log for such case?
xiyuan
2016/04/19 22:28:45
Done.
|
| + return false; |
| + |
| + // Not compliant if the platform version components do not match. |
| + const size_t count = required_version.components().size(); |
| + const base::Version platform_version = GetPlatformVersion(); |
| + const auto& platform_version_components = platform_version.components(); |
| + const auto& required_version_components = required_version.components(); |
| + for (size_t i = 0; i < count; ++i) { |
| + if (platform_version_components[i] != required_version_components[i]) |
| + return false; |
| + } |
| + |
| + return true; |
| +} |
| + |
| +bool KioskAppManager::IsPlatformCompliantWithApp( |
| + const extensions::Extension* app) const { |
| + // Compliant if the app is not the auto launched with zero delay app. |
| + if (currently_auto_launched_with_zero_delay_app_ != app->id()) |
| + return true; |
| + |
| + // Compliant if the app does not specify required platform version. |
| + const extensions::KioskModeInfo* info = extensions::KioskModeInfo::Get(app); |
| + if (info == nullptr) |
| + return true; |
| + |
| + return IsPlatformCompliant(info->required_platform_version); |
| +} |
| + |
| KioskAppManager::KioskAppManager() |
| : ownership_established_(false), |
| external_loader_created_(false), |