1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSIONS_INFO_H_
6 #define CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSIONS_INFO_H_
12 #include "base/callback.h"
13 #include "base/memory/singleton.h"
14 #include "chrome/common/extensions/permissions/api_permission.h"
15 #include "chrome/common/extensions/permissions/api_permission_set.h"
16 #include "chrome/common/extensions/permissions/permission_message.h"
18 namespace extensions
{
20 // Singleton that holds the extension permission instances and provides static
21 // methods for accessing them.
22 class PermissionsInfo
{
24 // Returns a pointer to the singleton instance.
25 static PermissionsInfo
* GetInstance();
27 // Returns the permission with the given |id|, and NULL if it doesn't exist.
28 const APIPermissionInfo
* GetByID(APIPermission::ID id
) const;
30 // Returns the permission with the given |name|, and NULL if none
32 const APIPermissionInfo
* GetByName(const std::string
& name
) const;
34 // Returns a set containing all valid api permission ids.
35 APIPermissionSet
GetAll() const;
37 // Converts all the permission names in |permission_names| to permission ids.
38 APIPermissionSet
GetAllByName(
39 const std::set
<std::string
>& permission_names
) const;
41 // Checks if any permissions have names that start with |name| followed by a
43 bool HasChildPermissions(const std::string
& name
) const;
45 // Gets the total number of API permissions.
46 size_t get_permission_count() const { return permission_count_
; }
49 friend class APIPermissionInfo
;
54 // Registers an |alias| for a given permission |name|.
55 void RegisterAlias(const char* name
, const char* alias
);
57 // Registers a permission with the specified attributes and flags.
58 const APIPermissionInfo
* RegisterPermission(
62 PermissionMessage::ID message_id
,
64 const APIPermissionInfo::APIPermissionConstructor constructor
);
66 // Maps permission ids to permissions.
67 typedef std::map
<APIPermission::ID
, APIPermissionInfo
*> IDMap
;
69 // Maps names and aliases to permissions.
70 typedef std::map
<std::string
, APIPermissionInfo
*> NameMap
;
75 size_t hosted_app_permission_count_
;
76 size_t permission_count_
;
78 friend struct DefaultSingletonTraits
<PermissionsInfo
>;
79 DISALLOW_COPY_AND_ASSIGN(PermissionsInfo
);
82 } // namespace extensions
84 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSIONS_INFO_H_