1 // Copyright 2013 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 EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_INFO_H_
6 #define EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_INFO_H_
12 #include "base/callback.h"
13 #include "base/lazy_instance.h"
14 #include "extensions/common/permissions/api_permission.h"
15 #include "extensions/common/permissions/api_permission_set.h"
16 #include "extensions/common/permissions/permission_message.h"
17 #include "extensions/common/permissions/permissions_provider.h"
19 namespace extensions
{
21 // A global object that holds the extension permission instances and provides
22 // methods for accessing them.
23 class PermissionsInfo
{
25 static PermissionsInfo
* GetInstance();
27 // Initializes the permissions from the provider.
28 void AddProvider(const PermissionsProvider
& provider
);
30 // Returns the permission with the given |id|, and NULL if it doesn't exist.
31 const APIPermissionInfo
* GetByID(APIPermission::ID id
) const;
33 // Returns the permission with the given |name|, and NULL if none
35 const APIPermissionInfo
* GetByName(const std::string
& name
) const;
37 // Returns a set containing all valid api permission ids.
38 APIPermissionSet
GetAll() const;
40 // Converts all the permission names in |permission_names| to permission ids.
41 APIPermissionSet
GetAllByName(
42 const std::set
<std::string
>& permission_names
) const;
44 // Checks if any permissions have names that start with |name| followed by a
46 bool HasChildPermissions(const std::string
& name
) const;
48 // Gets the total number of API permissions.
49 size_t get_permission_count() const { return permission_count_
; }
52 friend struct base::DefaultLazyInstanceTraits
<PermissionsInfo
>;
56 virtual ~PermissionsInfo();
58 // Registers an |alias| for a given permission |name|.
59 void RegisterAlias(const char* name
, const char* alias
);
61 // Registers a permission with the specified attributes and flags.
62 void RegisterPermission(APIPermissionInfo
* permission
);
64 // Maps permission ids to permissions.
65 typedef std::map
<APIPermission::ID
, APIPermissionInfo
*> IDMap
;
67 // Maps names and aliases to permissions.
68 typedef std::map
<std::string
, APIPermissionInfo
*> NameMap
;
73 size_t permission_count_
;
75 DISALLOW_COPY_AND_ASSIGN(PermissionsInfo
);
78 } // namespace extensions
80 #endif // EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_INFO_H_