Commit 2c6ef293 authored by dpolukhin's avatar dpolukhin Committed by Commit bot

Add minimal profile creation version for default apps install on Chrome OS

BUG=483627
TEST=unit_tests

Review URL: https://codereview.chromium.org/1128753003

Cr-Commit-Position: refs/heads/master@{#329412}
parent a16802db
...@@ -461,6 +461,8 @@ class MockProviderVisitor ...@@ -461,6 +461,8 @@ class MockProviderVisitor
EXPECT_TRUE(provider->IsReady()); EXPECT_TRUE(provider->IsReady());
} }
Profile* profile() { return profile_.get(); }
private: private:
int ids_found_; int ids_found_;
base::FilePath fake_base_path_; base::FilePath fake_base_path_;
...@@ -5533,6 +5535,36 @@ TEST_F(ExtensionServiceTest, ExternalPrefProvider) { ...@@ -5533,6 +5535,36 @@ TEST_F(ExtensionServiceTest, ExternalPrefProvider) {
" }" " }"
"}"; "}";
EXPECT_EQ(1, was_installed_by_eom_visitor.Visit(json_data)); EXPECT_EQ(1, was_installed_by_eom_visitor.Visit(json_data));
// Test min_profile_created_by_version.
MockProviderVisitor min_profile_created_by_version_visitor(base_path);
json_data =
"{"
" \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {"
" \"external_crx\": \"RandomExtension.crx\","
" \"external_version\": \"1.0\","
" \"min_profile_created_by_version\": \"42.0.0.1\""
" },"
" \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {"
" \"external_crx\": \"RandomExtension2.crx\","
" \"external_version\": \"1.0\","
" \"min_profile_created_by_version\": \"43.0.0.1\""
" },"
" \"cccccccccccccccccccccccccccccccc\": {"
" \"external_crx\": \"RandomExtension3.crx\","
" \"external_version\": \"3.0\","
" \"min_profile_created_by_version\": \"44.0.0.1\""
" }"
"}";
min_profile_created_by_version_visitor.profile()->GetPrefs()->SetString(
prefs::kProfileCreatedByVersion, "40.0.0.1");
EXPECT_EQ(0, min_profile_created_by_version_visitor.Visit(json_data));
min_profile_created_by_version_visitor.profile()->GetPrefs()->SetString(
prefs::kProfileCreatedByVersion, "43.0.0.1");
EXPECT_EQ(2, min_profile_created_by_version_visitor.Visit(json_data));
min_profile_created_by_version_visitor.profile()->GetPrefs()->SetString(
prefs::kProfileCreatedByVersion, "45.0.0.1");
EXPECT_EQ(3, min_profile_created_by_version_visitor.Visit(json_data));
} }
// Test loading good extensions from the profile directory. // Test loading good extensions from the profile directory.
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/linked_ptr.h" #include "base/memory/linked_ptr.h"
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "base/values.h" #include "base/values.h"
...@@ -26,6 +27,7 @@ ...@@ -26,6 +27,7 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "components/crx_file/id_util.h" #include "components/crx_file/id_util.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
...@@ -66,6 +68,8 @@ const char ExternalProviderImpl::kKeepIfPresent[] = "keep_if_present"; ...@@ -66,6 +68,8 @@ const char ExternalProviderImpl::kKeepIfPresent[] = "keep_if_present";
const char ExternalProviderImpl::kWasInstalledByOem[] = "was_installed_by_oem"; const char ExternalProviderImpl::kWasInstalledByOem[] = "was_installed_by_oem";
const char ExternalProviderImpl::kSupportedLocales[] = "supported_locales"; const char ExternalProviderImpl::kSupportedLocales[] = "supported_locales";
const char ExternalProviderImpl::kMayBeUntrusted[] = "may_be_untrusted"; const char ExternalProviderImpl::kMayBeUntrusted[] = "may_be_untrusted";
const char ExternalProviderImpl::kMinProfileCreatedByVersion[] =
"min_profile_created_by_version";
ExternalProviderImpl::ExternalProviderImpl( ExternalProviderImpl::ExternalProviderImpl(
VisitorInterface* service, VisitorInterface* service,
...@@ -218,6 +222,7 @@ void ExternalProviderImpl::SetPrefs(base::DictionaryValue* prefs) { ...@@ -218,6 +222,7 @@ void ExternalProviderImpl::SetPrefs(base::DictionaryValue* prefs) {
const Extension* extension = extension_service ? const Extension* extension = extension_service ?
extension_service->GetExtensionById(extension_id, true) : NULL; extension_service->GetExtensionById(extension_id, true) : NULL;
if (!extension) { if (!extension) {
unsupported_extensions.insert(extension_id);
VLOG(1) << "Skip installing (or uninstall) external extension: " VLOG(1) << "Skip installing (or uninstall) external extension: "
<< extension_id << " because the extension should be kept " << extension_id << " because the extension should be kept "
<< "only if it is already installed."; << "only if it is already installed.";
...@@ -235,6 +240,10 @@ void ExternalProviderImpl::SetPrefs(base::DictionaryValue* prefs) { ...@@ -235,6 +240,10 @@ void ExternalProviderImpl::SetPrefs(base::DictionaryValue* prefs) {
creation_flags |= Extension::MAY_BE_UNTRUSTED; creation_flags |= Extension::MAY_BE_UNTRUSTED;
} }
if (!ExternalProviderImpl::HandleMinProfileVersion(extension, extension_id,
&unsupported_extensions))
continue;
std::string install_parameter; std::string install_parameter;
extension->GetString(kInstallParam, &install_parameter); extension->GetString(kInstallParam, &install_parameter);
...@@ -360,6 +369,30 @@ bool ExternalProviderImpl::GetExtensionDetails( ...@@ -360,6 +369,30 @@ bool ExternalProviderImpl::GetExtensionDetails(
return true; return true;
} }
bool ExternalProviderImpl::HandleMinProfileVersion(
const base::DictionaryValue* extension,
const std::string& extension_id,
std::set<std::string>* unsupported_extensions) {
std::string min_profile_created_by_version;
if (profile_ &&
extension->GetString(kMinProfileCreatedByVersion,
&min_profile_created_by_version)) {
Version profile_version(
profile_->GetPrefs()->GetString(prefs::kProfileCreatedByVersion));
Version min_version(min_profile_created_by_version);
if (min_version.IsValid() && profile_version.CompareTo(min_version) < 0) {
unsupported_extensions->insert(extension_id);
VLOG(1) << "Skip installing (or uninstall) external extension: "
<< extension_id
<< " profile.created_by_version: " << profile_version.GetString()
<< " min_profile_created_by_version: "
<< min_profile_created_by_version;
return false;
}
}
return true;
}
// static // static
void ExternalProviderImpl::CreateExternalProviders( void ExternalProviderImpl::CreateExternalProviders(
VisitorInterface* service, VisitorInterface* service,
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_ #ifndef CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_
#define CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_ #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_PROVIDER_IMPL_H_
#include <set>
#include <string> #include <string>
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
...@@ -73,6 +74,7 @@ class ExternalProviderImpl : public ExternalProviderInterface { ...@@ -73,6 +74,7 @@ class ExternalProviderImpl : public ExternalProviderInterface {
static const char kSupportedLocales[]; static const char kSupportedLocales[];
static const char kWasInstalledByOem[]; static const char kWasInstalledByOem[];
static const char kMayBeUntrusted[]; static const char kMayBeUntrusted[];
static const char kMinProfileCreatedByVersion[];
void set_auto_acknowledge(bool auto_acknowledge) { void set_auto_acknowledge(bool auto_acknowledge) {
auto_acknowledge_ = auto_acknowledge; auto_acknowledge_ = auto_acknowledge;
...@@ -83,6 +85,10 @@ class ExternalProviderImpl : public ExternalProviderInterface { ...@@ -83,6 +85,10 @@ class ExternalProviderImpl : public ExternalProviderInterface {
} }
private: private:
bool HandleMinProfileVersion(const base::DictionaryValue* extension,
const std::string& extension_id,
std::set<std::string>* unsupported_extensions);
// Location for external extensions that are provided by this provider from // Location for external extensions that are provided by this provider from
// local crx files. // local crx files.
const Manifest::Location crx_location_; const Manifest::Location crx_location_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment