summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/api/extension_api.h
diff options
context:
space:
mode:
authorkalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-23 08:36:51 +0000
committerkalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-23 08:36:51 +0000
commita55aeaf12b43b0ccf6ec141894c4241632f4544e (patch)
tree34d5d6cf37e903c48062ebf45be25207beadc4ee /chrome/common/extensions/api/extension_api.h
parenta630d748945ef1055185c232298e3d738c0884fb (diff)
downloadchromium_src-a55aeaf12b43b0ccf6ec141894c4241632f4544e.zip
chromium_src-a55aeaf12b43b0ccf6ec141894c4241632f4544e.tar.gz
chromium_src-a55aeaf12b43b0ccf6ec141894c4241632f4544e.tar.bz2
Make ExtensionAPI load schemas lazily where possible.
BUG=118144 TEST=unit_tests --gtest_filter=ExtensionAPI.* Review URL: http://codereview.chromium.org/9677069 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128434 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/api/extension_api.h')
-rw-r--r--chrome/common/extensions/api/extension_api.h46
1 files changed, 24 insertions, 22 deletions
diff --git a/chrome/common/extensions/api/extension_api.h b/chrome/common/extensions/api/extension_api.h
index 4907152..1ae7824 100644
--- a/chrome/common/extensions/api/extension_api.h
+++ b/chrome/common/extensions/api/extension_api.h
@@ -14,6 +14,7 @@
#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
+#include "base/string_piece.h"
#include "base/values.h"
#include "chrome/common/extensions/feature.h"
#include "chrome/common/extensions/url_pattern_set.h"
@@ -36,76 +37,77 @@ class ExtensionAPI {
// Returns the single instance of this class.
static ExtensionAPI* GetInstance();
+ // Public for construction from unit tests. Use GetInstance() normally.
+ ExtensionAPI();
+ ~ExtensionAPI();
+
// Returns true if |name| is a privileged API path. Privileged paths can only
// be called from extension code which is running in its own designated
// extension process. They cannot be called from extension code running in
// content scripts, or other low-privileged contexts.
- bool IsPrivileged(const std::string& name) const;
+ bool IsPrivileged(const std::string& name);
// Gets the schema for the extension API with namespace |api_name|.
// Ownership remains with this object.
- const base::DictionaryValue* GetSchema(const std::string& api_name) const;
+ const base::DictionaryValue* GetSchema(const std::string& api_name);
// Gets the APIs available to |context| given an |extension| and |url|. The
// extension or URL may not be relevant to all contexts, and may be left
// NULL/empty.
scoped_ptr<std::set<std::string> > GetAPIsForContext(
- Feature::Context context,
- const Extension* extension,
- const GURL& url) const;
+ Feature::Context context, const Extension* extension, const GURL& url);
private:
friend struct DefaultSingletonTraits<ExtensionAPI>;
- ExtensionAPI();
- ~ExtensionAPI();
-
- // Loads a schema from a resource.
- void LoadSchemaFromResource(int resource_id);
-
- // Given a schema in ListValue form, registers it in a map. Takes ownership
- // of |loaded_schema|.
- void RegisterSchema(base::ListValue* loaded_schema);
+ // Loads a schema.
+ void LoadSchema(const base::StringPiece& schema);
// Find an item in |list| with the specified property name and value, or NULL
// if no such item exists.
base::DictionaryValue* FindListItem(const base::ListValue* list,
const std::string& property_name,
- const std::string& property_value) const;
+ const std::string& property_value);
// Returns true if the function or event under |namespace_node| with
// the specified |child_name| is privileged, or false otherwise. If the name
// is not found, defaults to privileged.
bool IsChildNamePrivileged(const base::DictionaryValue* namespace_node,
const std::string& child_kind,
- const std::string& child_name) const;
+ const std::string& child_name);
// Adds all APIs to |out| that |extension| has any permission (required or
// optional) to use.
- void GetAllowedAPIs(
- const Extension* extension, std::set<std::string>* out) const;
+ void GetAllowedAPIs(const Extension* extension, std::set<std::string>* out);
// Adds dependent schemas to |out| as determined by the "dependencies"
// property.
- void ResolveDependencies(std::set<std::string>* out) const;
+ void ResolveDependencies(std::set<std::string>* out);
// Adds any APIs listed in "dependencies" found in the schema for |api_name|
// but not in |excluding| to |out|.
void GetMissingDependencies(
const std::string& api_name,
const std::set<std::string>& excluding,
- std::set<std::string>* out) const;
+ std::set<std::string>* out);
// Removes all APIs from |apis| which are *entirely* privileged. This won't
// include APIs such as "storage" which is entirely unprivileged, nor
// "extension" which has unprivileged components.
- void RemovePrivilegedAPIs(std::set<std::string>* apis) const;
+ void RemovePrivilegedAPIs(std::set<std::string>* apis);
// Adds an APIs that match |url| to |out|.
- void GetAPIsMatchingURL(const GURL& url, std::set<std::string>* out) const;
+ void GetAPIsMatchingURL(const GURL& url, std::set<std::string>* out);
+
+ // Loads all remaining resources from |unloaded_schemas_|.
+ void LoadAllSchemas();
static ExtensionAPI* instance_;
+ // Map from each API that hasn't been loaded yet to the schema which defines
+ // it. Note that there may be multiple APIs per schema.
+ std::map<std::string, base::StringPiece> unloaded_schemas_;
+
// Schemas for each namespace.
typedef std::map<std::string, linked_ptr<const DictionaryValue> > SchemaMap;
SchemaMap schemas_;