diff options
author | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-23 23:22:18 +0000 |
---|---|---|
committer | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-23 23:22:18 +0000 |
commit | 6e3275c2a588dc134d0f350efd36c7d45f99d7f3 (patch) | |
tree | cb60c571efc20417681678038246772c54205370 /extensions/common/extension_api.cc | |
parent | 61539616259c0c7719a4024eaea49f06377c0a72 (diff) | |
download | chromium_src-6e3275c2a588dc134d0f350efd36c7d45f99d7f3.zip chromium_src-6e3275c2a588dc134d0f350efd36c7d45f99d7f3.tar.gz chromium_src-6e3275c2a588dc134d0f350efd36c7d45f99d7f3.tar.bz2 |
Resolve feature dependencies within the Feature implementations
(SimpleFeature) rather than external to them (ExtensionAPI).
This fixes ComplexFeature dependency checking.
R=rockot@chromium.org
Review URL: https://codereview.chromium.org/308423002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@279224 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/common/extension_api.cc')
-rw-r--r-- | extensions/common/extension_api.cc | 53 |
1 files changed, 24 insertions, 29 deletions
diff --git a/extensions/common/extension_api.cc b/extensions/common/extension_api.cc index 698e159..95fd3fb 100644 --- a/extensions/common/extension_api.cc +++ b/extensions/common/extension_api.cc @@ -20,6 +20,7 @@ #include "extensions/common/extensions_client.h" #include "extensions/common/features/feature.h" #include "extensions/common/features/feature_provider.h" +#include "extensions/common/features/simple_feature.h" #include "extensions/common/permissions/permission_set.h" #include "extensions/common/permissions/permissions_data.h" #include "ui/base/resource/resource_bundle.h" @@ -102,6 +103,9 @@ struct Static { base::LazyInstance<Static> g_lazy_instance = LAZY_INSTANCE_INITIALIZER; +// May override |g_lazy_instance| for a test. +ExtensionAPI* g_shared_instance_for_test = NULL; + // If it exists and does not already specify a namespace, then the value stored // with key |key| in |schema| will be updated to |schema_namespace| + "." + // |schema[key]|. @@ -166,7 +170,8 @@ void PrefixWithNamespace(const std::string& schema_namespace, // static ExtensionAPI* ExtensionAPI::GetSharedInstance() { - return g_lazy_instance.Get().api.get(); + return g_shared_instance_for_test ? g_shared_instance_for_test + : g_lazy_instance.Get().api.get(); } // static @@ -192,6 +197,16 @@ void ExtensionAPI::SplitDependencyName(const std::string& full_name, *feature_name = full_name.substr(colon_index + 1); } +ExtensionAPI::OverrideSharedInstanceForTest::OverrideSharedInstanceForTest( + ExtensionAPI* testing_api) + : original_api_(g_shared_instance_for_test) { + g_shared_instance_for_test = testing_api; +} + +ExtensionAPI::OverrideSharedInstanceForTest::~OverrideSharedInstanceForTest() { + g_shared_instance_for_test = original_api_; +} + void ExtensionAPI::LoadSchema(const std::string& name, const base::StringPiece& schema) { scoped_ptr<base::ListValue> schema_list(LoadSchemaList(name, schema)); @@ -247,16 +262,16 @@ bool ExtensionAPI::IsAnyFeatureAvailableToContext(const Feature& api, const GURL& url) { FeatureProviderMap::iterator provider = dependency_providers_.find("api"); CHECK(provider != dependency_providers_.end()); - if (IsAvailable(api, extension, context, url).is_available()) + if (api.IsAvailableToContext(extension, context, url).is_available()) return true; // Check to see if there are any parts of this API that are allowed in this // context. const std::vector<Feature*> features = provider->second->GetChildren(api); - for (std::vector<Feature*>::const_iterator feature = features.begin(); - feature != features.end(); - ++feature) { - if (IsAvailable(**feature, extension, context, url).is_available()) + for (std::vector<Feature*>::const_iterator it = features.begin(); + it != features.end(); + ++it) { + if ((*it)->IsAvailableToContext(extension, context, url).is_available()) return true; } return false; @@ -271,33 +286,13 @@ Feature::Availability ExtensionAPI::IsAvailable(const std::string& full_name, return Feature::CreateAvailability(Feature::NOT_PRESENT, std::string("Unknown feature: ") + full_name); } - return IsAvailable(*feature, extension, context, url); -} - -Feature::Availability ExtensionAPI::IsAvailable(const Feature& feature, - const Extension* extension, - Feature::Context context, - const GURL& url) { - Feature::Availability availability = - feature.IsAvailableToContext(extension, context, url); - if (!availability.is_available()) - return availability; - - for (std::set<std::string>::iterator iter = feature.dependencies().begin(); - iter != feature.dependencies().end(); ++iter) { - Feature::Availability dependency_availability = - IsAvailable(*iter, extension, context, url); - if (!dependency_availability.is_available()) - return dependency_availability; - } - - return Feature::CreateAvailability(Feature::IS_AVAILABLE, std::string()); + return feature->IsAvailableToContext(extension, context, url); } bool ExtensionAPI::IsPrivileged(const std::string& full_name) { Feature* feature = GetFeatureDependency(full_name); - CHECK(feature); - DCHECK(!feature->GetContexts()->empty()); + CHECK(feature) << full_name; + DCHECK(!feature->GetContexts()->empty()) << full_name; // An API is 'privileged' if it can only be run in a blessed context. return feature->GetContexts()->size() == feature->GetContexts()->count(Feature::BLESSED_EXTENSION_CONTEXT); |