Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7419)

Unified Diff: chrome/common/extensions/feature.cc

Issue 10054035: Allow extension APIs to be restricted to a subset of Chrome channels using the (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make default channel "trunk" Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/extensions/feature.h ('k') | chrome/common/extensions/feature_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/feature.cc
diff --git a/chrome/common/extensions/feature.cc b/chrome/common/extensions/feature.cc
index 9f7543574dd9dc8e6acd70cd5a137d28b62d4418..33ef54fb3507ed07ca8cecf2e5a81dac42f2796b 100644
--- a/chrome/common/extensions/feature.cc
+++ b/chrome/common/extensions/feature.cc
@@ -11,6 +11,8 @@
#include "base/stringprintf.h"
#include "chrome/common/chrome_switches.h"
+using chrome::VersionInfo;
+
namespace {
struct Mappings {
@@ -31,16 +33,30 @@ struct Mappings {
locations["component"] = extensions::Feature::COMPONENT_LOCATION;
platforms["chromeos"] = extensions::Feature::CHROMEOS_PLATFORM;
+
+ channels["trunk"] = VersionInfo::CHANNEL_UNKNOWN;
+ channels["canary"] = VersionInfo::CHANNEL_CANARY;
+ channels["dev"] = VersionInfo::CHANNEL_DEV;
+ channels["beta"] = VersionInfo::CHANNEL_BETA;
+ channels["stable"] = VersionInfo::CHANNEL_STABLE;
}
std::map<std::string, Extension::Type> extension_types;
std::map<std::string, extensions::Feature::Context> contexts;
std::map<std::string, extensions::Feature::Location> locations;
std::map<std::string, extensions::Feature::Platform> platforms;
+ std::map<std::string, VersionInfo::Channel> channels;
+};
+
+static base::LazyInstance<Mappings> g_mappings = LAZY_INSTANCE_INITIALIZER;
+
+struct Channel {
+ Channel() : channel(chrome::VersionInfo::GetChannel()) {}
+
+ chrome::VersionInfo::Channel channel;
};
-static base::LazyInstance<Mappings> g_mappings =
- LAZY_INSTANCE_INITIALIZER;
+static base::LazyInstance<Channel> g_channel = LAZY_INSTANCE_INITIALIZER;
// TODO(aa): Can we replace all this manual parsing with JSON schema stuff?
@@ -120,7 +136,8 @@ Feature::Feature()
: location_(UNSPECIFIED_LOCATION),
platform_(UNSPECIFIED_PLATFORM),
min_manifest_version_(0),
- max_manifest_version_(0) {
+ max_manifest_version_(0),
+ supported_channel_(VersionInfo::CHANNEL_UNKNOWN) {
}
Feature::Feature(const Feature& other)
@@ -130,7 +147,8 @@ Feature::Feature(const Feature& other)
location_(other.location_),
platform_(other.platform_),
min_manifest_version_(other.min_manifest_version_),
- max_manifest_version_(other.max_manifest_version_) {
+ max_manifest_version_(other.max_manifest_version_),
+ supported_channel_(other.supported_channel_) {
}
Feature::~Feature() {
@@ -143,7 +161,8 @@ bool Feature::Equals(const Feature& other) const {
location_ == other.location_ &&
platform_ == other.platform_ &&
min_manifest_version_ == other.min_manifest_version_ &&
- max_manifest_version_ == other.max_manifest_version_;
+ max_manifest_version_ == other.max_manifest_version_ &&
+ supported_channel_ == other.supported_channel_;
}
// static
@@ -175,6 +194,9 @@ void Feature::Parse(const DictionaryValue* value) {
g_mappings.Get().platforms);
value->GetInteger("min_manifest_version", &min_manifest_version_);
value->GetInteger("max_manifest_version", &max_manifest_version_);
+ ParseEnum<VersionInfo::Channel>(
+ value, "supported_channel", &supported_channel_,
+ g_mappings.Get().channels);
}
std::string Feature::GetErrorMessage(Feature::Availability result) {
@@ -198,10 +220,14 @@ std::string Feature::GetErrorMessage(Feature::Availability result) {
case INVALID_MAX_MANIFEST_VERSION:
return base::StringPrintf("Requires manifest version of %d or lower.",
max_manifest_version_);
- default:
- CHECK(false);
- return "";
+ case NOT_PRESENT:
+ return "Requires a different Feature that is not present.";
+ case UNSUPPORTED_CHANNEL:
+ return base::StringPrintf("Channel %d is unsupported.",
+ supported_channel_);
}
+
+ return "";
}
Feature::Availability Feature::IsAvailableToManifest(
@@ -247,6 +273,9 @@ Feature::Availability Feature::IsAvailableToManifest(
if (max_manifest_version_ != 0 && manifest_version > max_manifest_version_)
return INVALID_MAX_MANIFEST_VERSION;
+ if (supported_channel_ < g_channel.Get().channel)
+ return UNSUPPORTED_CHANNEL;
+
return IS_AVAILABLE;
}
@@ -271,4 +300,9 @@ Feature::Availability Feature::IsAvailableToContext(
return IS_AVAILABLE;
}
+// static
+void Feature::SetChannelForTesting(VersionInfo::Channel channel) {
+ g_channel.Get().channel = channel;
+}
+
} // namespace
« no previous file with comments | « chrome/common/extensions/feature.h ('k') | chrome/common/extensions/feature_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698