summaryrefslogtreecommitdiffstats
path: root/extensions/common/permissions/permissions_info.h
diff options
context:
space:
mode:
authoryoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-08 00:47:19 +0000
committeryoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-08 00:47:19 +0000
commit793964ab2f1e7148e6e0948911ef8efc932e1858 (patch)
tree734208da1a20797afcac06483870cadf222ccf62 /extensions/common/permissions/permissions_info.h
parenta649a06f4312943e8a6ddc5f6ea450a011fa3d15 (diff)
downloadchromium_src-793964ab2f1e7148e6e0948911ef8efc932e1858.zip
chromium_src-793964ab2f1e7148e6e0948911ef8efc932e1858.tar.gz
chromium_src-793964ab2f1e7148e6e0948911ef8efc932e1858.tar.bz2
Move APIPermission, APIPermissionSet, PermissionsInfo to top-level extensions.
BUG=298586 TBR=sky@chromium.org Review URL: https://codereview.chromium.org/26024004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@227409 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/common/permissions/permissions_info.h')
-rw-r--r--extensions/common/permissions/permissions_info.h81
1 files changed, 81 insertions, 0 deletions
diff --git a/extensions/common/permissions/permissions_info.h b/extensions/common/permissions/permissions_info.h
new file mode 100644
index 0000000..9be7e6d
--- /dev/null
+++ b/extensions/common/permissions/permissions_info.h
@@ -0,0 +1,81 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_INFO_H_
+#define EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_INFO_H_
+
+#include <map>
+#include <set>
+#include <string>
+
+#include "base/callback.h"
+#include "base/lazy_instance.h"
+#include "extensions/common/permissions/api_permission.h"
+#include "extensions/common/permissions/api_permission_set.h"
+#include "extensions/common/permissions/permission_message.h"
+#include "extensions/common/permissions/permissions_provider.h"
+
+namespace extensions {
+
+// A global object that holds the extension permission instances and provides
+// methods for accessing them.
+class PermissionsInfo {
+ public:
+ static PermissionsInfo* GetInstance();
+
+ virtual ~PermissionsInfo();
+
+ // Returns the permission with the given |id|, and NULL if it doesn't exist.
+ const APIPermissionInfo* GetByID(APIPermission::ID id) const;
+
+ // Returns the permission with the given |name|, and NULL if none
+ // exists.
+ const APIPermissionInfo* GetByName(const std::string& name) const;
+
+ // Returns a set containing all valid api permission ids.
+ APIPermissionSet GetAll() const;
+
+ // Converts all the permission names in |permission_names| to permission ids.
+ APIPermissionSet GetAllByName(
+ const std::set<std::string>& permission_names) const;
+
+ // Checks if any permissions have names that start with |name| followed by a
+ // period.
+ bool HasChildPermissions(const std::string& name) const;
+
+ // Gets the total number of API permissions.
+ size_t get_permission_count() const { return permission_count_; }
+
+ private:
+ friend struct base::DefaultLazyInstanceTraits<PermissionsInfo>;
+
+ PermissionsInfo();
+
+ // Initializes the permissions from the provider.
+ void InitializeWithProvider(const PermissionsProvider& provider);
+
+ // Registers an |alias| for a given permission |name|.
+ void RegisterAlias(const char* name, const char* alias);
+
+ // Registers a permission with the specified attributes and flags.
+ void RegisterPermission(APIPermissionInfo* permission);
+
+ // Maps permission ids to permissions.
+ typedef std::map<APIPermission::ID, APIPermissionInfo*> IDMap;
+
+ // Maps names and aliases to permissions.
+ typedef std::map<std::string, APIPermissionInfo*> NameMap;
+
+ IDMap id_map_;
+ NameMap name_map_;
+
+ size_t hosted_app_permission_count_;
+ size_t permission_count_;
+
+ DISALLOW_COPY_AND_ASSIGN(PermissionsInfo);
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_INFO_H_