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/permissions_provider.h"
18 namespace extensions
{
20 // A global object that holds the extension permission instances and provides
21 // methods for accessing them.
22 class PermissionsInfo
{
24 static PermissionsInfo
* GetInstance();
26 // Initializes the permissions from the provider.
27 void AddProvider(const PermissionsProvider
& provider
);
29 // Returns the permission with the given |id|, and NULL if it doesn't exist.
30 const APIPermissionInfo
* GetByID(APIPermission::ID id
) const;
32 // Returns the permission with the given |name|, and NULL if none
34 const APIPermissionInfo
* GetByName(const std::string
& name
) const;
36 // Returns a set containing all valid api permission ids.
37 APIPermissionSet
GetAll() const;
39 // Converts all the permission names in |permission_names| to permission ids.
40 APIPermissionSet
GetAllByName(
41 const std::set
<std::string
>& permission_names
) const;
43 // Checks if any permissions have names that start with |name| followed by a
45 bool HasChildPermissions(const std::string
& name
) const;
47 // Gets the total number of API permissions.
48 size_t get_permission_count() const { return permission_count_
; }
51 friend struct base::DefaultLazyInstanceTraits
<PermissionsInfo
>;
55 virtual ~PermissionsInfo();
57 // Registers an |alias| for a given permission |name|.
58 void RegisterAlias(const char* name
, const char* alias
);
60 // Registers a permission with the specified attributes and flags.
61 void RegisterPermission(APIPermissionInfo
* permission
);
63 // Maps permission ids to permissions.
64 typedef std::map
<APIPermission::ID
, APIPermissionInfo
*> IDMap
;
66 // Maps names and aliases to permissions.
67 typedef std::map
<std::string
, APIPermissionInfo
*> NameMap
;
72 size_t permission_count_
;
74 DISALLOW_COPY_AND_ASSIGN(PermissionsInfo
);
77 } // namespace extensions
79 #endif // EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_INFO_H_